MigrationSchema

View Source

Summary

DDL-focused operations mixed into the migration db object.

Signature

interface MigrationSchema {
  addCheck(
    table: TableInput,
    expression: string,
    options: NamedConstraintOptions,
  ): Promise<void>;
  addForeignKey(
    table: TableInput,
    columns: KeyColumns,
    refTable: TableInput,
    refColumns: KeyColumns,
    options: ForeignKeyOptions,
  ): Promise<void>;
  alterTable(
    table: TableInput,
    migrate: (table: AlterTableBuilder) => void,
    options: AlterTableOptions,
  ): Promise<void>;
  createIndex(
    table: TableInput,
    columns: IndexColumns,
    options: CreateIndexOptions,
  ): Promise<void>;
  createTable<table extends AnyTable>(
    table: table,
    options: CreateTableOptions,
  ): Promise<void>;
  dropCheck(table: TableInput, name: string): Promise<void>;
  dropForeignKey(table: TableInput, name: string): Promise<void>;
  dropIndex(
    table: TableInput,
    name: string,
    options: { ifExists?: boolean },
  ): Promise<void>;
  dropTable(table: TableInput, options: DropTableOptions): Promise<void>;
  hasColumn(table: TableInput, column: string): Promise<boolean>;
  hasTable(table: TableInput): Promise<boolean>;
  plan(sql: string | SqlStatement): Promise<void>;
  renameIndex(table: TableInput, from: string, to: string): Promise<void>;
  renameTable(from: TableInput, to: string): Promise<void>;
}

Methods

addCheck(table: TableInput, expression: string, options: NamedConstraintOptions): Promise

Adds a check constraint in the migration schema.

table

expression

options

addForeignKey(table: TableInput, columns: KeyColumns, refTable: TableInput, refColumns: KeyColumns, options: ForeignKeyOptions): Promise

Adds a foreign key in the migration schema.

table

columns

refTable

refColumns

options

alterTable(table: TableInput, migrate: (table: AlterTableBuilder) => void, options: AlterTableOptions): Promise

Alters an existing table in the migration schema.

table

migrate

options

createIndex(table: TableInput, columns: IndexColumns, options: CreateIndexOptions): Promise

Creates an index in the migration schema.

table

columns

options

createTable(table: table, options: CreateTableOptions): Promise

Creates a table in the migration schema.

table

options

dropCheck(table: TableInput, name: string): Promise

Drops a check constraint in the migration schema.

table

name

dropForeignKey(table: TableInput, name: string): Promise

Drops a foreign key in the migration schema.

table

name

dropIndex(table: TableInput, name: string, options: { ifExists?: boolean }): Promise

Drops an index from the migration schema.

table

name

options

dropTable(table: TableInput, options: DropTableOptions): Promise

Drops a table from the migration schema.

table

options

hasColumn(table: TableInput, column: string): Promise

Returns true when the column exists on the given table.

table

column

hasTable(table: TableInput): Promise

Returns true when the table exists in the current database.

table

plan(sql: string | SqlStatement): Promise

Adds raw SQL to the migration plan as a migration operation.

sql

renameIndex(table: TableInput, from: string, to: string): Promise

Renames an index in the migration schema.

table

from

to

renameTable(from: TableInput, to: string): Promise

Renames a table in the migration schema.

from

to