abstractSchemaHelper
Hierarchy
Index
Constructors
Accessors
Methods
- alterTable
- alterTableColumn
- alterTableComment
- append
- appendComments
- castColumn
- createCheck
- createForeignKey
- createIndex
- createMaterializedView
- createRoutine
- createTable
- createTableColumn
- createTrigger
- createView
- databaseExists
- disableForeignKeysSQL
- dropConstraint
- dropForeignKey
- dropIndex
- dropMaterializedViewIfExists
- dropRoutine
- dropTableIfExists
- dropTrigger
- dropViewIfExists
- enableForeignKeysSQL
- finalizeTable
- getAddColumnsSQL
- getAllRoutines
- getAllTables
- getAlterNativeEnumSQL
- getChangeColumnCommentSQL
- getCreateDatabaseSQL
- getCreateIndexSQL
- getCreateNamespaceSQL
- getCreateNativeEnumSQL
- getDatabaseExistsSQL
- getDatabaseNotExistsError
- getDefaultEmptyString
- getDropColumnsSQL
- getDropDatabaseSQL
- getDropIndexSQL
- getDropNamespaceSQL
- getDropNativeEnumSQL
- getListMaterializedViewsSQL
- getListTablesSQL
- getListViewsSQL
- getManagementDbName
- getNamespaces
- getPostAlterTable
- getPreAlterTable
- getPrimaryKeys
- getReferencedTableName
- getRenameColumnSQL
- getRenameIndexSQL
- getResetSchemaSQL
- getSchemaBeginning
- getSchemaEnd
- getSetSchemaSQL
- getTablesGroupedBySchemas
- hasNonDefaultPrimaryKeyName
- inferLengthFromColumnType
- loadInformationSchema
- loadMaterializedViews
- loadViews
- mapForeignKeys
- normaliseRoutineParamDirection
- normalizeDefaultValue
- refreshMaterializedView
- resolveMigrationSchema
- routineParamReference
- splitTableName
- supportsMigrationSchema
- supportsSchemaConstraints
- tableExists
Constructors
constructor
Parameters
platform: AbstractSqlPlatform
Returns SchemaHelper
Accessors
options
Returns { createForeignKeyConstraints?: boolean; defaultDeleteRule?: cascade | no action | set null | set default | restrict; defaultUpdateRule?: cascade | no action | set null | set default | restrict; disableForeignKeys?: boolean; disableForeignKeysForClear?: boolean; ignoreSchema?: string[]; managementDbName?: string; skipColumns?: Dictionary<(string | RegExp)[]>; skipTables?: (string | RegExp)[]; skipViews?: (string | RegExp)[]; tableSpace?: string }
optionalcreateForeignKeyConstraints?: boolean
Generate foreign key constraints.
optionaldefaultDeleteRule?: cascade | no action | set null | set default | restrict
Default ON DELETE rule for foreign keys. When not set, no rule is emitted and the database uses its native default (NO ACTION/RESTRICT).
optionaldefaultUpdateRule?: cascade | no action | set null | set default | restrict
Default ON UPDATE rule for foreign keys. When not set, no rule is emitted and the database uses its native default (NO ACTION/RESTRICT).
optionaldisableForeignKeys?: boolean
Try to disable foreign key checks during schema operations.
optionaldisableForeignKeysForClear?: boolean
Try to disable foreign key checks during
schema.clear(). Enabled by default for MySQL/MariaDB.optionalignoreSchema?: string[]
Schema names to ignore when comparing schemas.
optionalmanagementDbName?: string
Database name to use for management operations (e.g., creating/dropping databases).
optionalskipColumns?: Dictionary<(string | RegExp)[]>
Column names or patterns to skip during schema generation, keyed by table name.
optionalskipTables?: (string | RegExp)[]
Table names or patterns to skip during schema generation.
optionalskipViews?: (string | RegExp)[]
View names or patterns to skip during schema generation (e.g. PostGIS system views).
optionaltableSpace?: string
Methods
alterTable
Returns SQL statements to apply a table difference (add/drop/alter columns, indexes, foreign keys).
Parameters
diff: TableDifference
optionalsafe: boolean
Returns string[]
alterTableColumn
Parameters
column: Column
table: DatabaseTable
changedProperties: Set<string>
Returns string[]
alterTableComment
Parameters
table: DatabaseTable
optionalcomment: string
Returns string
append
Parameters
array: string[]
sql: string | string[]
pad: boolean = false
Returns void
appendComments
Parameters
table: DatabaseTable
Returns string[]
castColumn
Parameters
name: string
type: string
Returns string
createCheck
Parameters
table: DatabaseTable
check: CheckDef<unknown>
Returns string
createForeignKey
Returns SQL to create a foreign key constraint on a table.
Parameters
table: DatabaseTable
foreignKey: ForeignKey
alterTable: boolean = true
inline: boolean = false
Returns string
createIndex
Parameters
index: IndexDef
table: DatabaseTable
createPrimary: boolean = false
Returns string
createMaterializedView
Parameters
name: string
schema: undefined | string
definition: string
withData: boolean = true
Returns string
createRoutine
Default no-op so SQLite/libSQL silent-skip routine DDL; routine-capable dialects override.
Parameters
_routine: SqlRoutineDef
Returns string
createTable
Returns SQL statements to create a table with all its columns, primary key, indexes, and checks.
Parameters
table: DatabaseTable
optionalalter: boolean
Returns string[]
createTableColumn
Parameters
column: Column
table: DatabaseTable
optionalchangedProperties: Set<string>
Returns undefined | string
createTrigger
Generates SQL to create a database trigger on a table. Override in driver-specific helpers for custom DDL (e.g., PostgreSQL function wrapping).
Parameters
table: DatabaseTable
trigger: SqlTriggerDef
Returns string
createView
Parameters
name: string
schema: undefined | string
definition: string
Returns string
databaseExists
Parameters
connection: Connection
name: string
Returns Promise<boolean>
disableForeignKeysSQL
Returns SQL to disable foreign key checks.
Returns string
dropConstraint
Parameters
table: string
name: string
Returns string
dropForeignKey
Parameters
tableName: string
constraintName: string
Returns string
dropIndex
Parameters
table: string
index: IndexDef
oldIndexName: string = index.keyName
Returns string
dropMaterializedViewIfExists
Parameters
name: string
optionalschema: string
Returns string
dropRoutine
Parameters
_routine: SqlRoutineDef
Returns string
dropTableIfExists
Returns SQL to drop a table if it exists.
Parameters
name: string
optionalschema: string
Returns string
dropTrigger
Generates SQL to drop a database trigger from a table. Override in driver-specific helpers for custom DDL.
Parameters
table: DatabaseTable
trigger: SqlTriggerDef
Returns string
dropViewIfExists
Parameters
name: string
optionalschema: string
Returns string
enableForeignKeysSQL
Returns SQL to re-enable foreign key checks.
Returns string
finalizeTable
Parameters
table: DatabaseTable
charset: string
optionalcollate: string
Returns string
getAddColumnsSQL
Returns SQL to add columns to an existing table.
Parameters
table: DatabaseTable
columns: Column[]
Returns string[]
getAllRoutines
Parameters
_connection: AbstractSqlConnection
_schemas: string[] = []
Returns Promise<SqlRoutineDef[]>
getAllTables
Retrieves all tables from the database.
Parameters
connection: AbstractSqlConnection
optionalschemas: string[]
optionalctx: any
Returns Promise<Table[]>
getAlterNativeEnumSQL
Parameters
name: string
optionalschema: string
optionalvalue: string
optionalitems: string[]
optionaloldItems: string[]
Returns string
getChangeColumnCommentSQL
Parameters
tableName: string
to: Column
optionalschemaName: string
Returns string
getCreateDatabaseSQL
Parameters
name: string
Returns string
getCreateIndexSQL
Returns SQL to create an index on a table.
Parameters
tableName: string
index: IndexDef
Returns string
getCreateNamespaceSQL
Parameters
name: string
Returns string
getCreateNativeEnumSQL
Parameters
name: string
values: unknown[]
optionalschema: string
Returns string
getDatabaseExistsSQL
Parameters
name: string
Returns string
getDatabaseNotExistsError
Parameters
dbName: string
Returns string
getDefaultEmptyString
Returns string
getDropColumnsSQL
Parameters
tableName: string
columns: Column[]
optionalschemaName: string
Returns string
getDropDatabaseSQL
Parameters
name: string
Returns string
getDropIndexSQL
Returns SQL to drop an index.
Parameters
tableName: string
index: IndexDef
Returns string
getDropNamespaceSQL
Parameters
name: string
Returns string
getDropNativeEnumSQL
Parameters
name: string
optionalschema: string
Returns string
getListMaterializedViewsSQL
Returns string
getListTablesSQL
Returns the SQL query to list all tables in the database.
Returns string
getListViewsSQL
Returns string
getManagementDbName
Returns string
getNamespaces
Parameters
connection: AbstractSqlConnection
optionalctx: any
Returns Promise<string[]>
getPostAlterTable
Parameters
tableDiff: TableDifference
safe: boolean
Returns string[]
getPreAlterTable
Parameters
tableDiff: TableDifference
safe: boolean
Returns string[]
getPrimaryKeys
Parameters
connection: AbstractSqlConnection
indexes: IndexDef[] = []
tableName: string
optionalschemaName: string
Returns Promise<string[]>
getReferencedTableName
Parameters
referencedTableName: string
optionalschema: string
Returns string
getRenameColumnSQL
Returns SQL to rename a column in a table.
Parameters
tableName: string
oldColumnName: string
to: Column
optionalschemaName: string
Returns string
getRenameIndexSQL
Parameters
tableName: string
index: IndexDef
oldIndexName: string
Returns string[]
getResetSchemaSQL
Restores the session's schema to the connection's default after a migration.
Parameters
_defaultSchema: string
Returns string
getSchemaBeginning
Returns SQL to prepend to schema migration scripts (e.g., disabling FK checks).
Parameters
_charset: string
optionaldisableForeignKeys: boolean
Returns string
getSchemaEnd
Returns SQL to append to schema migration scripts (e.g., re-enabling FK checks).
Parameters
optionaldisableForeignKeys: boolean
Returns string
getSetSchemaSQL
Sets the current schema for the session (e.g.
SET search_path).Parameters
_schema: string
Returns string
getTablesGroupedBySchemas
hasNonDefaultPrimaryKeyName
Parameters
table: DatabaseTable
Returns boolean
inferLengthFromColumnType
Parameters
type: string
Returns undefined | number
abstractloadInformationSchema
Loads table metadata (columns, indexes, foreign keys) from the database information schema.
Parameters
schema: DatabaseSchema
connection: AbstractSqlConnection
tables: Table[]
optionalschemas: string[]
optionalctx: any
Returns Promise<void>
loadMaterializedViews
Parameters
schema: DatabaseSchema
connection: AbstractSqlConnection
optionalschemaName: string
optionalctx: any
Returns Promise<void>
loadViews
Parameters
schema: DatabaseSchema
connection: AbstractSqlConnection
optionalschemaName: string
optionalctx: any
Returns Promise<void>
mapForeignKeys
Parameters
fks: any[]
tableName: string
optionalschemaName: string
Returns Dictionary
normaliseRoutineParamDirection
T-SQL doesn't distinguish
OUTfromINOUTin the catalog — overrides fold'out'into'inout'.Parameters
direction: in | out | inout
Returns in | out | inout
normalizeDefaultValue
Parameters
defaultValue: string | RawQueryFragment<string>
optionallength: number
defaultValues: Dictionary<string[]> = {}
Returns string | number
refreshMaterializedView
Parameters
name: string
optionalschema: string
concurrently: boolean = false
Returns string
resolveMigrationSchema
Returns
undefinedfor schemaless drivers, throws for drivers that have schemas but no session switch.Parameters
schema: undefined | string
Returns undefined | string
routineParamReference
T-SQL requires
@nameinside the body; PG/MySQL/Oracle use the bare name.Parameters
name: string
Returns string
splitTableName
Parameters
name: string
skipDefaultSchema: boolean = false
Returns [undefined | string, string]
supportsMigrationSchema
Whether the driver supports setting a runtime schema per migration run.
Returns boolean
supportsSchemaConstraints
Returns boolean
tableExists
Checks whether a specific table exists in a given schema (not the connection's current schema).
Parameters
connection: AbstractSqlConnection
tableName: string
schemaName: undefined | string
optionalctx: any
Returns Promise<boolean>
Base class for database-specific schema helpers. Provides SQL generation for DDL operations.