Base class for managing metadata within the CodeGen system. This class can be sub-classed to extend/override base class functionality. Make sure to use the RegisterClass decorator from the @memberjunction/global package to properly register your subclass with a priority of 1+ to ensure it gets instantiated.

Constructors

Properties

Accessors

Methods

LogSQLAndExecute applicationExists applyAdvancedGeneration applyFormLayout applySmartFieldIdentification checkAndRemoveMetadataForDeletedTables checkDropSQLObject createDefaultConstraintForSpecialDateField createExcludeTablesAndSchemasFilter createNewApplication createNewEntities createNewEntity createNewEntityDisplayName createNewEntityFieldsFromSchema createNewEntityInsertSQL createNewEntityName createNewUUID deleteUnneededEntityFields dropAndCreateDefaultConstraintForSpecialDateField dropExistingDefaultConstraint ensureCreatedAtUpdatedAtFieldsExist ensureDeletedAtFieldsExist ensureSpecialDateFieldExistsAndHasCorrectDefaultValue generateNewEntityDescriptions generateValidatorFunctionFromCheckConstraint getApplicationIDForSchema getNewEntityNameRule getPendingEntityFieldINSERTSQL getPendingEntityFieldsSELECTSQL isSchemaNew loadGeneratedCode manageEntityFieldValuesAndValidatorFunctions manageEntityFields manageEntityRelationships manageManyToManyEntityRelationships manageMetadata manageOneToManyEntityRelationships manageSingleVirtualEntity manageSingleVirtualEntityField manageVirtualEntities markupEntityName newEntityNameWithAdvancedGeneration parseCheckConstraintValues parseDefaultValue processEntitiesBatched processEntityAdvancedGeneration runValidationGeneration setDefaultColumnWidthWhereNeeded shouldCreateNewEntity simpleNewEntityName syncEntityFieldValues updateEntityFieldDisplayNameWhereNull updateEntityFieldRelatedEntityNameFieldMap updateExistingEntitiesFromSchema updateExistingEntityFieldsFromSchema updateSchemaInfoFromDatabase addNewEntitiesToModifiedList

Constructors

Properties

_sqlUtilityObject: SQLUtilityBase = ...
_generatedValidators: ValidatorResult[] = []
_modifiedEntityList: string[] = []
_newEntityList: string[] = []

Accessors

Methods

  • Executes the given SQL query using the given ConnectionPool object. If the appendToLogFile parameter is true, the query will also be appended to the log file. Note that in order to append to the log file, ManageMetadataBase.manageMetaDataLogging must be called first.

    Parameters

    • pool: ConnectionPool

      The ConnectionPool object to use to execute the query.

    • query: string

      The SQL query to execute.

    • Optional description: string

      A description of the query to append to the log file.

    • isRecurringScript: boolean = false

      if set to true tells the logger that the provided SQL represents a recurring script meaning it is something that is executed, generally, for all CodeGen runs. In these cases, the Config settings can result in omitting these recurring scripts from being logged because the configuration environment may have those recurring scripts already set to run after all run-specific migrations get run.

    Returns Promise<any>

    • The result of the query execution.
  • Apply Advanced Generation features - Smart Field Identification and Form Layout Generation

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]
    • currentUser: UserInfo

    Returns Promise<boolean>

  • Apply form layout generation results to set category on entity fields

    Parameters

    • pool: ConnectionPool

      Database connection pool

    • entityId: string

      Entity ID to update

    • fields: any[]

      Entity fields

    • result: FormLayoutResult

      Form layout result from LLM

    • isNewEntity: boolean = false

      If true, apply entityImportance; if false, skip it

    Returns Promise<void>

  • Apply smart field identification results to entity fields

    Parameters

    • pool: ConnectionPool
    • entityId: string
    • fields: any[]
    • result: SmartFieldIdentificationResult

    Returns Promise<void>

  • This method will look for situations where entity metadata exist in the entities metadata table but the underlying table has been deleted. In this case, the metadata for the entity should be removed. This method is called as part of the manageMetadata method and is not intended to be called directly.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

    Returns Promise<boolean>

  • Creates the default constraint for a special date field. This method is called as part of the ensureSpecialDateFieldExistsAndHasCorrectDefaultValue method and is not intended to be called directly.

    Parameters

    • pool: ConnectionPool
    • entity: any
    • fieldName: string

    Returns Promise<void>

  • Creates a new application using the entity framework. This ensures the server-side entity extension is used, which handles:

    • Auto-generation of Path from Name (via ApplicationEntityServerEntity)
    • Any other server-side business logic

    Parameters

    • pool: ConnectionPool

      SQL connection pool (unused but kept for signature compatibility)

    • appID: string

      Pre-generated UUID for the application

    • appName: string

      Name of the application

    • schemaName: string

      Schema name for SchemaAutoAddNewEntities

    • currentUser: UserInfo

      Current user for entity operations

    Returns Promise<null | string>

    The application ID if successful, null otherwise

  • Parameters

    • newEntityUUID: string
    • newEntityName: string
    • newEntity: any
    • newEntitySuffix: string
    • newEntityDisplayName: null | string

    Returns string

  • Drops and recreates the default constraint for a special date field. This method is called as part of the ensureSpecialDateFieldExistsAndHasCorrectDefaultValue method and is not intended to be called directly.

    Parameters

    • pool: ConnectionPool
    • entity: any
    • fieldName: string

    Returns Promise<void>

  • Drops an existing default constraint from a given column within a given entity, if it exists

    Parameters

    • pool: ConnectionPool
    • entity: any
    • fieldName: string

    Returns Promise<void>

  • This method ensures that the __mj_CreatedAt and __mj_UpdatedAt fields exist in each entity that has TrackRecordChanges set to true. If the fields do not exist, they are created. If the fields exist but have incorrect default values, the default values are updated. The default value that is to be used for these special fields is GETUTCDATE() which is the UTC date and time. This method is called as part of the manageEntityFields method and is not intended to be called directly.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

    Returns Promise<boolean>

  • This method ensures that the __mj_DeletedAt field exists in each entity that has DeleteType=Soft. If the field does not exist, it is created.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

    Returns Promise<boolean>

  • This method handles the validation of the existence of the specified special date field and if it does exist it makes sure the default value is set correctly, if it doesn't exist it makes sure that it is created. This method is called as part of the ensureCreatedAtUpdatedAtFieldsExist method and is not intended to be called directly.

    Parameters

    • pool: ConnectionPool
    • entity: any
    • fieldName: string
    • currentFieldData: any
    • allowNull: boolean

    Returns Promise<boolean>

  • This method generates descriptions for entities in teh system where there is no existing description. This is an experimental feature and is done using AI. In order for it to be invoked, the EntityDescriptions feature must be enabled in the Advanced Generation configuration.

    Parameters

    Returns Promise<void>

  • Generates a TypeScript field validator function from the text of a SQL CHECK constraint.

    Parameters

    • data: any

      the data object containing the entity name, column name, and constraint definition

    • allEntityFields: any[]

      all of the entity fields in the system

    • currentUser: UserInfo

      the current user

    • generateNewCode: boolean

      a flag indicating whether or not to generate new code, this is set to false when we are just loading the generated code from the database.

    Returns Promise<ValidatorResult>

    a data structure with the function text, function name, function description, and a success flag

  • Parameters

    • schemaName: string

    Returns undefined | {
        EntityNamePrefix: string;
        EntityNameSuffix: string;
        SchemaName: string;
    }

  • This method builds a SQL Statement that will insert a row into the EntityField table with information about a new field.

    Parameters

    • newEntityFieldUUID: string
    • n: any

      the new field

    Returns string

  • Creates a SQL statement to retrieve all of the pending entity fields that need to be created in the metadata. This method looks for fields that exist in the underlying database but are NOT in the metadata.

    IMPORTANT: The sequence calculation uses a dynamic offset based on the maximum existing sequence for each entity, plus 100,000, plus the column sequence. This ensures no collision with existing sequences while maintaining deterministic ordering. The spUpdateExistingEntityFieldsFromSchema stored procedure runs AFTER this method and will correct the sequences to ensure they are in the correct sequential order starting from 1. In a migration, the spUpdateExistingEntityFieldsFromSchema runs afterwards as well so this behavior ensures CodeGen works consistently.

    Returns string

    • The SQL statement to retrieve pending entity fields.
  • This method will load all generated code from the database - this is intended to be used when you are bypassing managing the metadata.

    Parameters

    • pool: ConnectionPool
    • currentUser: UserInfo

    Returns Promise<boolean>

  • Manages the creation, updating and deletion of entity field records in the metadata based on the database schema.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]
    • skipCreatedAtUpdatedAtDeletedAtFieldValidation: boolean
    • skipEntityFieldValues: boolean
    • currentUser: UserInfo
    • skipAdvancedGeneration: boolean

    Returns Promise<boolean>

  • This method creates and updates relationships in the metadata based on foreign key relationships in the database.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

      specify any schemas to exclude here and any relationships to/from the specified schemas will be ignored

    • md: Metadata
    • batchItems: number = 5

    Returns Promise<boolean>

  • Manages M->M relationships between entities in the metadata based on foreign key relationships in the database. NOT IMPLEMENTED IN CURRENT VERSION IN BASE CLASS. M->M relationships ARE supported fully, but they are not AUTO generated by this method, instead an administrator must manually create these relationships in the metadata.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]
    • batchItems: number = 5

    Returns Promise<boolean>

  • Primary function to manage metadata within the CodeGen system. This function will call a series of sub-functions to manage the metadata.

    Parameters

    • pool: ConnectionPool

      the ConnectionPool object to use for querying and updating the database

    • currentUser: UserInfo

    Returns Promise<boolean>

  • Manages 1->M relationships between entities in the metadata based on foreign key relationships in the database.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

      specify any schemas to exclude here and any relationships to/from the specified schemas will be ignored

    • md: Metadata
    • batchItems: number = 5

    Returns Promise<boolean>

  • Parameters

    • pool: ConnectionPool
    • virtualEntity: any
    • veField: any
    • fieldSequence: number
    • makePrimaryKey: boolean

    Returns Promise<{
        newFieldID: null | string;
        success: boolean;
        updatedField: boolean;
    }>

  • Uses the optional NameRulesBySchema section of the newEntityDefaults section of the config object to auto prefix/suffix a given entity name

    Parameters

    • schemaName: string
    • entityName: string

    Returns string

  • This method takes the stored DEFAULT CONSTRAINT value from the database and parses it to retrieve the actual default value. This is necessary because the default value is sometimes wrapped in parentheses and sometimes wrapped in single quotes. This method removes the wrapping characters and returns the actual default value. Some common raw values that exist in SQL Server include 'getdate()', '(getdate())', 'N''SomeValue''', etc. and this method will remove those wrapping characters to get the actual underlying default value. NOTE: For future versions of MemberJunction where multiple back-end providers could be used, this method will be moved to the Provider architecture so that database-specific versions can be implemented, along with many other aspects of this current codebase.

    Parameters

    • sqlDefaultValue: string

    Returns string

  • Process entities in batches with parallel execution

    Parameters

    • pool: ConnectionPool

      Database connection pool

    • entities: any[]

      Entities to process

    • allFields: any[]

      All fields for all entities (will be filtered per entity)

    • ag: AdvancedGeneration

      AdvancedGeneration instance

    • currentUser: UserInfo

      User context

    • batchSize: number = 5

      Number of entities to process in parallel (default 5)

    Returns Promise<boolean>

  • Process advanced generation for a single entity

    Parameters

    • pool: ConnectionPool

      Database connection pool

    • entity: any

      Entity to process

    • allFields: any[]

      All fields for all entities (will be filtered for this entity)

    • ag: AdvancedGeneration

      AdvancedGeneration instance

    • currentUser: UserInfo

      User context

    Returns Promise<void>

  • This method updates the DefaultColumnWidth field in the EntityField metadata. The default logic uses a stored procedure called spSetDefaultColumnWidthWhereNeeded which is part of the MJ Core Schema. You can override this method to implement custom logic for setting default column widths. It is NOT recommended to modify the stored procedure in the MJ Core Schema because your changes will be overriden during a future upgrade.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

    Returns Promise<boolean>

  • Parameters

    • ds: ConnectionPool
    • newEntity: any

    Returns Promise<{
        shouldCreate: boolean;
        validationMessage: string;
    }>

  • Parameters

    • ds: ConnectionPool
    • entityFieldID: number
    • possibleValues: string[]
    • allEntityFieldValues: any

    Returns Promise<boolean>

  • This method is responsible for generating a Display Name for each field where a display name is not already set. The approach in the base class uses a simple algorithm that looks for case changes in the field name and inserts spaces at those points. It also strips the trailing 'ID' from the field name if it exists. Override this method in a sub-class if you would like to implement a different approach for generating display names.

    Parameters

    • pool: ConnectionPool
    • excludeSchemas: string[]

    Returns Promise<boolean>

  • This method handles updating entity field related name field maps which is basically the process of finding the related entity field that is the "name" field for the related entity.

    Parameters

    • pool: ConnectionPool
    • entityFieldID: string
    • relatedEntityNameFieldMap: string

    Returns Promise<boolean>

  • Syncs SchemaInfo records from database schemas, capturing extended properties as descriptions. Creates new SchemaInfo records for schemas that don't exist yet and updates descriptions from schema extended properties for existing records.

    Parameters

    • pool: ConnectionPool

      SQL connection pool

    • excludeSchemas: string[]

      Array of schema names to exclude from processing

    Returns Promise<boolean>

    Promise - true if successful, false otherwise