Skip to main content
Version: Next

Class: SchemaComparator

knex.SchemaComparator

Compares two Schemas and return an instance of SchemaDifference.

Constructors#

constructor#

new SchemaComparator(platform)

Parameters#

NameType
platformAbstractSqlPlatform

Defined in#

packages/knex/src/schema/SchemaComparator.ts:12

Methods#

compare#

compare(fromSchema, toSchema): SchemaDifference

Returns a SchemaDifference object containing the differences between the schemas fromSchema and toSchema.

The returned differences are returned in such a way that they contain the operations to change the schema stored in fromSchema to the schema that is stored in toSchema.

Parameters#

NameType
fromSchemaDatabaseSchema
toSchemaDatabaseSchema

Returns#

SchemaDifference

Defined in#

packages/knex/src/schema/SchemaComparator.ts:23


diffColumn#

diffColumn(column1, column2): Set<string>

Returns the difference between the columns If there are differences this method returns field2, otherwise the boolean false.

Parameters#

NameType
column1Column
column2Column

Returns#

Set<string>

Defined in#

packages/knex/src/schema/SchemaComparator.ts:337


diffComment#

diffComment(comment1?, comment2?): boolean

Parameters#

NameType
comment1?string
comment2?string

Returns#

boolean

Defined in#

packages/knex/src/schema/SchemaComparator.ts:371


diffForeignKey#

diffForeignKey(key1, key2): boolean

Parameters#

NameType
key1ForeignKey
key2ForeignKey

Returns#

boolean

Defined in#

packages/knex/src/schema/SchemaComparator.ts:314


diffIndex#

diffIndex(index1, index2): boolean

Finds the difference between the indexes index1 and index2. Compares index1 with index2 and returns index2 if there are any differences or false in case there are no differences.

Parameters#

NameType
index1Index
index2Index

Returns#

boolean

Defined in#

packages/knex/src/schema/SchemaComparator.ts:381


diffTable#

diffTable(fromTable, toTable): false | TableDifference

Returns the difference between the tables fromTable and toTable. If there are no differences this method returns the boolean false.

Parameters#

NameType
fromTableDatabaseTable
toTableDatabaseTable

Returns#

false | TableDifference

Defined in#

packages/knex/src/schema/SchemaComparator.ts:109


hasSameDefaultValue#

hasSameDefaultValue(from, to): boolean

Parameters#

NameType
fromColumn
toColumn

Returns#

boolean

Defined in#

packages/knex/src/schema/SchemaComparator.ts:422


isIndexFulfilledBy#

isIndexFulfilledBy(index1, index2): boolean

Checks if the other index already fulfills all the indexing and constraint needs of the current one.

Parameters#

NameType
index1Index
index2Index

Returns#

boolean

Defined in#

packages/knex/src/schema/SchemaComparator.ts:388