uql-orm 0.97.0 → 0.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/dialect/abstractSqlDialect.d.ts +1 -7
  2. package/dist/dialect/abstractSqlDialect.js +1 -9
  3. package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -0
  4. package/dist/dialect/mysqlLikeSqlDialect.js +4 -1
  5. package/dist/dialect/pgLikeSqlDialect.js +0 -1
  6. package/dist/migrate/acquireQuerierForMigrations.d.ts +4 -8
  7. package/dist/migrate/acquireQuerierForMigrations.js +10 -18
  8. package/dist/migrate/builder/columnBuilder.d.ts +1 -2
  9. package/dist/migrate/builder/columnBuilder.js +3 -10
  10. package/dist/migrate/builder/migrationBuilder.d.ts +6 -26
  11. package/dist/migrate/builder/migrationBuilder.js +21 -78
  12. package/dist/migrate/builder/tableBuilder.js +2 -3
  13. package/dist/migrate/builder/types.d.ts +57 -120
  14. package/dist/migrate/cli-config.d.ts +1 -0
  15. package/dist/migrate/cli-config.js +11 -26
  16. package/dist/migrate/cli.d.ts +0 -13
  17. package/dist/migrate/cli.js +55 -118
  18. package/dist/migrate/codegen/entityCodeGenerator.d.ts +7 -61
  19. package/dist/migrate/codegen/entityCodeGenerator.js +51 -168
  20. package/dist/migrate/codegen/fieldOptionsSource.js +3 -6
  21. package/dist/migrate/codegen/index.d.ts +2 -7
  22. package/dist/migrate/codegen/index.js +2 -8
  23. package/dist/migrate/codegen/migrationFile.d.ts +1 -8
  24. package/dist/migrate/codegen/migrationFile.js +9 -13
  25. package/dist/migrate/ddl/defaultSql.d.ts +2 -1
  26. package/dist/migrate/ddl/defaultSql.js +1 -3
  27. package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
  28. package/dist/migrate/ddl/indexCapabilities.js +60 -0
  29. package/dist/migrate/ddl/indexDdl.d.ts +11 -24
  30. package/dist/migrate/ddl/indexDdl.js +22 -28
  31. package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
  32. package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
  33. package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
  34. package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
  35. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
  36. package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
  37. package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
  38. package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
  39. package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
  40. package/dist/migrate/ddl/pgIndexDdl.js +5 -44
  41. package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
  42. package/dist/migrate/ddl/pgTableDdl.js +17 -1
  43. package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
  44. package/dist/migrate/ddl/tableDdl.d.ts +43 -24
  45. package/dist/migrate/ddl/tableDdl.js +56 -37
  46. package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
  47. package/dist/migrate/drift/driftDetector.d.ts +29 -32
  48. package/dist/migrate/drift/driftDetector.js +139 -205
  49. package/dist/migrate/drift/index.d.ts +1 -6
  50. package/dist/migrate/drift/index.js +1 -6
  51. package/dist/migrate/generator/definitionToNode.js +3 -3
  52. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +53 -76
  53. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +68 -90
  54. package/dist/migrate/introspection/mssqlIntrospector.d.ts +8 -43
  55. package/dist/migrate/introspection/mssqlIntrospector.js +44 -77
  56. package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -38
  57. package/dist/migrate/introspection/mysqlIntrospector.js +48 -57
  58. package/dist/migrate/introspection/postgresIntrospector.d.ts +12 -60
  59. package/dist/migrate/introspection/postgresIntrospector.js +62 -77
  60. package/dist/migrate/introspection/sqliteIntrospector.d.ts +14 -53
  61. package/dist/migrate/introspection/sqliteIntrospector.js +59 -119
  62. package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
  63. package/dist/migrate/introspection/tableSchemaAST.js +85 -0
  64. package/dist/migrate/migrationTarget.js +10 -2
  65. package/dist/migrate/migrator.d.ts +4 -21
  66. package/dist/migrate/migrator.js +47 -71
  67. package/dist/migrate/schemaChange.d.ts +0 -2
  68. package/dist/migrate/schemaChange.js +1 -1
  69. package/dist/migrate/schemaGenerator.d.ts +22 -97
  70. package/dist/migrate/schemaGenerator.js +113 -298
  71. package/dist/migrate/storage/databaseStorage.d.ts +2 -1
  72. package/dist/migrate/storage/databaseStorage.js +3 -2
  73. package/dist/migrate/storage/jsonStorage.d.ts +1 -2
  74. package/dist/migrate/storage/jsonStorage.js +11 -20
  75. package/dist/migrate/triggerSql.d.ts +3 -3
  76. package/dist/migrate/triggerSql.js +5 -4
  77. package/dist/mongo/index.d.ts +0 -1
  78. package/dist/mongo/index.js +0 -1
  79. package/dist/mongo/mongoDialect.js +0 -1
  80. package/dist/mongo/mongoIntrospector.d.ts +0 -3
  81. package/dist/mongo/mongoIntrospector.js +7 -14
  82. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -20
  83. package/dist/mongo/mongoSchemaGenerator.js +51 -70
  84. package/dist/mssql/mssqlDialect.js +0 -1
  85. package/dist/schema/canonicalType.d.ts +15 -19
  86. package/dist/schema/canonicalType.js +20 -43
  87. package/dist/schema/dependencyGraph.d.ts +2 -3
  88. package/dist/schema/dependencyGraph.js +0 -4
  89. package/dist/schema/indexDifferences.js +2 -2
  90. package/dist/schema/schemaAST.d.ts +1 -1
  91. package/dist/schema/schemaAST.js +4 -12
  92. package/dist/schema/schemaASTBuilder.d.ts +2 -5
  93. package/dist/schema/schemaASTBuilder.js +11 -14
  94. package/dist/schema/schemaASTDiffer.d.ts +4 -5
  95. package/dist/schema/schemaASTDiffer.js +22 -70
  96. package/dist/schema/types.d.ts +1 -48
  97. package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
  98. package/dist/sqlite/localSqliteQuerierPool.js +20 -4
  99. package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
  100. package/dist/sqlite/sqliteDialect.js +0 -1
  101. package/dist/sqlite/sqliteQuerierPool.js +3 -3
  102. package/dist/type/dialect.d.ts +0 -2
  103. package/dist/type/migration.d.ts +3 -54
  104. package/dist/util/ddlExpression.util.d.ts +2 -2
  105. package/dist/util/ddlExpression.util.js +3 -3
  106. package/dist/util/sql.util.d.ts +0 -8
  107. package/dist/util/sql.util.js +7 -12
  108. package/package.json +1 -1
  109. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
  110. package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
  111. package/dist/schema/index.d.ts +0 -2
  112. package/dist/schema/index.js +0 -1
  113. package/dist/sqlite/sqlitePragmas.d.ts +0 -3
  114. package/dist/sqlite/sqlitePragmas.js +0 -15
@@ -1,11 +1,16 @@
1
1
  import type { AbstractSqlDialect } from '../../dialect/abstractSqlDialect.js';
2
- import type { Alteration, ColumnSchema } from '../../type/index.js';
2
+ import type { ColumnSchema, PrimaryKeySchema } from '../../type/index.js';
3
3
  import { UqlUsageError } from '../../util/uqlError.js';
4
- /**
5
- * A column's type with the size it was read back with, unless its spelling already carries one:
6
- * introspection reports `VARCHAR` and `255` apart, where a type from an entity is already whole.
7
- */
8
- export declare function sizedType(column: Pick<ColumnSchema, 'type' | 'length' | 'precision' | 'scale'>): string;
4
+ /** A column to change into `to`, from what it was where that is known: the builder alters a column it never read. */
5
+ export type ColumnAlteration = {
6
+ readonly from?: ColumnSchema;
7
+ readonly to: ColumnSchema;
8
+ };
9
+ /** What a comment documents: a column, by its name. */
10
+ export type Commented = {
11
+ readonly name: string;
12
+ readonly comment?: string;
13
+ };
9
14
  /**
10
15
  * Table DDL that engines spell differently. Like {@link IndexDdl}, it belongs to the migrator, so no runtime
11
16
  * entry carries it. This class holds the portable form, which SQLite takes; other families override what differs.
@@ -13,39 +18,53 @@ export declare function sizedType(column: Pick<ColumnSchema, 'type' | 'length' |
13
18
  export declare class TableDdl {
14
19
  protected readonly dialect: AbstractSqlDialect;
15
20
  constructor(dialect: AbstractSqlDialect);
16
- /** Options appended to `CREATE TABLE`, such as MySQL's engine; empty by default. */
17
- readonly tableOptions: string;
18
21
  /** A `CREATE TABLE` up to its column list, a no-op where `ifNotExists` and the table is already there. */
19
22
  createTable(target: string, ifNotExists: boolean): string;
20
- addColumn(table: string, definition: string): string;
21
- /** The statements that add `column`, whose definition `render` writes. */
22
- addColumnStatements(table: string, column: ColumnSchema, render: (column: ColumnSchema) => string): string[];
23
+ /** What follows a `CREATE TABLE`'s column list: the engine's options, and the table's comment where it keeps one there. */
24
+ tableSuffix(_comment?: string): string;
25
+ /**
26
+ * The one place a column definition is spelled. A key column states `NOT NULL` rather than leave it to the
27
+ * key: SQLite lets a key column hold NULL otherwise, and SQL Server adds no key over a nullable column. Never
28
+ * `UNIQUE`: a unique column is a unique index, which the table creates beside it. Nor an enum's `CHECK`.
29
+ */
30
+ columnDefinition(column: ColumnSchema): string;
31
+ /** What a column definition ends with to keep `comment`, where the engine keeps one there. */
32
+ protected columnComment(_comment?: string): string;
33
+ /** The statements documenting `table` and its `columns` once they exist, where the engine documents that way. */
34
+ commentStatements(_table: string, _comment: string | undefined, _columns: readonly Commented[]): string[];
35
+ /** The statements that add `column`, its definition followed by `constraints`, and document it. */
36
+ addColumnStatements(table: string, column: ColumnSchema, constraints?: string): string[];
37
+ protected addColumn(table: string, definition: string): string;
23
38
  dropColumn(table: string, column: string): string[];
24
- /** The statements that change a column from `from`, what it was, to `column`, whose definition is `definition`. */
25
- alterColumn(table: string, column: ColumnSchema, definition: string, from?: ColumnSchema): string[];
26
- /** The statements making `alterations` to one table, whose new definitions `render` writes. */
27
- alterColumns(table: string, alterations: readonly Alteration<ColumnSchema>[], render: (column: ColumnSchema) => string): string[];
39
+ /** The statements making `alterations` to one table. */
40
+ alterColumns(table: string, alterations: readonly ColumnAlteration[]): string[];
28
41
  /**
29
- * The `ALTER TABLE` clauses that change a column, as {@link alterColumn} takes it. None in the portable
30
- * form: SQLite changes a column only by rebuilding its table, which a diff states as `rebuild`.
42
+ * The `ALTER TABLE` clauses that change a column to `column` from `from`. None in the portable form: SQLite
43
+ * changes a column only by rebuilding its table, which a diff states as `rebuild`.
31
44
  */
32
- protected alterClauses(column: ColumnSchema, _definition: string, _from?: ColumnSchema): string[];
45
+ protected alterClauses(column: ColumnSchema, _from?: ColumnSchema): string[];
33
46
  /** One `ALTER TABLE` making every clause, and none for no clause. */
34
47
  protected alterTable(table: string, clauses: readonly string[]): string[];
35
48
  renameColumn(table: string, oldName: string, newName: string): string;
36
49
  renameTable(oldName: string, newName: string): string;
37
- /** `schema` is the table's schema, which also holds its indexes. */
38
- dropIndex(table: string, index: string, schema?: string): string;
50
+ /** An index lives in the schema of its table, whose name is qualified where it has one. */
51
+ dropIndex(table: string, index: string): string;
39
52
  dropForeignKey(table: string, constraint: string): string;
40
- /** Drops the primary key by its real constraint name: the introspected one, or the one uql derived when adding it. */
41
- dropPrimaryKey(table: string, constraint?: string): string;
53
+ /** `CONSTRAINT <name> PRIMARY KEY (...)`, in a `CREATE TABLE` or after `ADD`, under the name a drop finds it by. */
54
+ primaryKeyConstraint(table: string, key: PrimaryKeySchema): string;
55
+ /** A key change as statements: dropping `from` before what it holds changes, and adding `to` last. */
56
+ replacePrimaryKey(table: string, from?: PrimaryKeySchema, to?: PrimaryKeySchema): [string[], string[]];
57
+ /** The clauses of {@link replacePrimaryKey}, each its own statement. */
58
+ protected keyChange(table: string, drop?: string, add?: string): [string[], string[]];
59
+ /** The clause dropping `key` by its real constraint name: the introspected one, or the one uql derived adding it. */
60
+ protected dropPrimaryKey(table: string, key: PrimaryKeySchema): string;
42
61
  /** A stored generated column's type, with the clause computing it. */
43
- storedGeneratedColumn(type: string, expression: string): string;
62
+ protected storedGeneratedColumn(type: string, expression: string): string;
44
63
  /**
45
64
  * ` DEFAULT <sql>`, or nothing where the column declares none. Empty rather than `DEFAULT NULL`, so
46
65
  * an absent default stays absent - `defaultValue: null` is the way to ask for one.
47
66
  */
48
- defaultClause(column: {
67
+ protected defaultClause(column: {
49
68
  readonly defaultValue?: unknown;
50
69
  readonly type: string;
51
70
  }): string;
@@ -1,19 +1,6 @@
1
+ import { derivedPrimaryKeyName, splitQualifiedName } from '../../util/sql.util.js';
1
2
  import { UqlUsageError } from '../../util/uqlError.js';
2
3
  import { formatDefaultValue } from './defaultSql.js';
3
- /**
4
- * A column's type with the size it was read back with, unless its spelling already carries one:
5
- * introspection reports `VARCHAR` and `255` apart, where a type from an entity is already whole.
6
- */
7
- export function sizedType(column) {
8
- if (column.type.includes('(')) {
9
- return column.type;
10
- }
11
- if (column.precision !== undefined) {
12
- const size = column.scale === undefined ? column.precision : `${column.precision}, ${column.scale}`;
13
- return `${column.type}(${size})`;
14
- }
15
- return column.length === undefined ? column.type : `${column.type}(${column.length})`;
16
- }
17
4
  /**
18
5
  * Table DDL that engines spell differently. Like {@link IndexDdl}, it belongs to the migrator, so no runtime
19
6
  * entry carries it. This class holds the portable form, which SQLite takes; other families override what differs.
@@ -23,35 +10,54 @@ export class TableDdl {
23
10
  constructor(dialect) {
24
11
  this.dialect = dialect;
25
12
  }
26
- /** Options appended to `CREATE TABLE`, such as MySQL's engine; empty by default. */
27
- tableOptions = '';
28
13
  /** A `CREATE TABLE` up to its column list, a no-op where `ifNotExists` and the table is already there. */
29
14
  createTable(target, ifNotExists) {
30
15
  return `CREATE TABLE ${ifNotExists ? 'IF NOT EXISTS ' : ''}${target}`;
31
16
  }
17
+ /** What follows a `CREATE TABLE`'s column list: the engine's options, and the table's comment where it keeps one there. */
18
+ tableSuffix(_comment) {
19
+ return '';
20
+ }
21
+ /**
22
+ * The one place a column definition is spelled. A key column states `NOT NULL` rather than leave it to the
23
+ * key: SQLite lets a key column hold NULL otherwise, and SQL Server adds no key over a nullable column. Never
24
+ * `UNIQUE`: a unique column is a unique index, which the table creates beside it. Nor an enum's `CHECK`.
25
+ */
26
+ columnDefinition(column) {
27
+ const type = column.generatedAs ? this.storedGeneratedColumn(column.type, column.generatedAs) : column.type;
28
+ const notNull = column.nullable ? '' : ' NOT NULL';
29
+ return `${this.dialect.escapeId(column.name)} ${type}${notNull}${this.defaultClause(column)}${this.columnComment(column.comment)}`;
30
+ }
31
+ /** What a column definition ends with to keep `comment`, where the engine keeps one there. */
32
+ columnComment(_comment) {
33
+ return '';
34
+ }
35
+ /** The statements documenting `table` and its `columns` once they exist, where the engine documents that way. */
36
+ commentStatements(_table, _comment, _columns) {
37
+ return [];
38
+ }
39
+ /** The statements that add `column`, its definition followed by `constraints`, and document it. */
40
+ addColumnStatements(table, column, constraints = '') {
41
+ return [
42
+ this.addColumn(table, this.columnDefinition(column) + constraints),
43
+ ...this.commentStatements(table, undefined, [column]),
44
+ ];
45
+ }
32
46
  addColumn(table, definition) {
33
47
  return `ALTER TABLE ${this.dialect.escapeId(table)} ADD COLUMN ${definition};`;
34
48
  }
35
- /** The statements that add `column`, whose definition `render` writes. */
36
- addColumnStatements(table, column, render) {
37
- return [this.addColumn(table, render(column))];
38
- }
39
49
  dropColumn(table, column) {
40
50
  return [`ALTER TABLE ${this.dialect.escapeId(table)} DROP COLUMN ${this.dialect.escapeId(column)};`];
41
51
  }
42
- /** The statements that change a column from `from`, what it was, to `column`, whose definition is `definition`. */
43
- alterColumn(table, column, definition, from) {
44
- return this.alterTable(table, this.alterClauses(column, definition, from));
45
- }
46
- /** The statements making `alterations` to one table, whose new definitions `render` writes. */
47
- alterColumns(table, alterations, render) {
48
- return this.alterTable(table, alterations.flatMap(({ from, to }) => this.alterClauses(to, render(to), from)));
52
+ /** The statements making `alterations` to one table. */
53
+ alterColumns(table, alterations) {
54
+ return this.alterTable(table, alterations.flatMap(({ from, to }) => this.alterClauses(to, from)));
49
55
  }
50
56
  /**
51
- * The `ALTER TABLE` clauses that change a column, as {@link alterColumn} takes it. None in the portable
52
- * form: SQLite changes a column only by rebuilding its table, which a diff states as `rebuild`.
57
+ * The `ALTER TABLE` clauses that change a column to `column` from `from`. None in the portable form: SQLite
58
+ * changes a column only by rebuilding its table, which a diff states as `rebuild`.
53
59
  */
54
- alterClauses(column, _definition, _from) {
60
+ alterClauses(column, _from) {
55
61
  throw rebuildRefusal(this.dialect, `Altering the column "${column.name}"`);
56
62
  }
57
63
  /** One `ALTER TABLE` making every clause, and none for no clause. */
@@ -65,20 +71,33 @@ export class TableDdl {
65
71
  renameTable(oldName, newName) {
66
72
  return `ALTER TABLE ${this.dialect.escapeId(oldName)} RENAME TO ${this.dialect.escapeId(newName)};`;
67
73
  }
68
- /** `schema` is the table's schema, which also holds its indexes. */
69
- dropIndex(table, index, schema) {
70
- return `DROP INDEX IF EXISTS ${this.dialect.escapeQualifiedId(index, schema)};`;
74
+ /** An index lives in the schema of its table, whose name is qualified where it has one. */
75
+ dropIndex(table, index) {
76
+ return `DROP INDEX IF EXISTS ${this.dialect.escapeQualifiedId(index, splitQualifiedName(table).schema)};`;
71
77
  }
72
78
  dropForeignKey(table, constraint) {
73
79
  return `ALTER TABLE ${this.dialect.escapeId(table)} DROP CONSTRAINT ${this.dialect.escapeId(constraint)};`;
74
80
  }
75
- /** Drops the primary key by its real constraint name: the introspected one, or the one uql derived when adding it. */
76
- dropPrimaryKey(table, constraint) {
77
- if (!constraint) {
81
+ /** `CONSTRAINT <name> PRIMARY KEY (...)`, in a `CREATE TABLE` or after `ADD`, under the name a drop finds it by. */
82
+ primaryKeyConstraint(table, key) {
83
+ const name = this.dialect.escapeId(key.name ?? derivedPrimaryKeyName(table, key.columns));
84
+ return `CONSTRAINT ${name} PRIMARY KEY (${key.columns.map((column) => this.dialect.escapeId(column)).join(', ')})`;
85
+ }
86
+ /** A key change as statements: dropping `from` before what it holds changes, and adding `to` last. */
87
+ replacePrimaryKey(table, from, to) {
88
+ return this.keyChange(table, from && this.dropPrimaryKey(table, from), to && `ADD ${this.primaryKeyConstraint(table, to)}`);
89
+ }
90
+ /** The clauses of {@link replacePrimaryKey}, each its own statement. */
91
+ keyChange(table, drop, add) {
92
+ return [this.alterTable(table, drop ? [drop] : []), this.alterTable(table, add ? [add] : [])];
93
+ }
94
+ /** The clause dropping `key` by its real constraint name: the introspected one, or the one uql derived adding it. */
95
+ dropPrimaryKey(table, key) {
96
+ if (!key.name) {
78
97
  throw new UqlUsageError(`Cannot drop the primary key of "${table}": ${this.dialect.dialectName} names the constraint, and ` +
79
98
  'introspection did not report a name for it.');
80
99
  }
81
- return `ALTER TABLE ${this.dialect.escapeId(table)} DROP CONSTRAINT ${this.dialect.escapeId(constraint)};`;
100
+ return `DROP CONSTRAINT ${this.dialect.escapeId(key.name)}`;
82
101
  }
83
102
  /** A stored generated column's type, with the clause computing it. */
84
103
  storedGeneratedColumn(type, expression) {
@@ -1,7 +1,7 @@
1
1
  import type { AbstractSqlDialect } from '../../dialect/index.js';
2
2
  import type { Alteration, RebuiltTable, Rename } from '../../type/index.js';
3
3
  /** What the copy reads besides the columns both sides share: renamed ones, and a default filling a column's nulls. */
4
- export type RebuildCopy = {
4
+ type RebuildCopy = {
5
5
  readonly renames: readonly Rename[];
6
6
  readonly fills: ReadonlyMap<string, string>;
7
7
  };
@@ -12,3 +12,4 @@ export type RebuildCopy = {
12
12
  * rebuild first unless foreign keys are off, as the migrator turns them off on a SQLite connection.
13
13
  */
14
14
  export declare function rebuildTable(dialect: AbstractSqlDialect, table: string, { from, to }: Alteration<RebuiltTable>, copy: RebuildCopy): string[];
15
+ export {};
@@ -1,39 +1,36 @@
1
- /**
2
- * Drift Detector
3
- *
4
- * Detects schema drift between expected schema (from entities) and
5
- * actual database schema.
6
- */
7
1
  import type { AbstractDialect } from '../../dialect/abstractDialect.js';
8
2
  import type { SchemaAST } from '../../schema/schemaAST.js';
9
- import type { DriftReport } from '../../schema/types.js';
3
+ import { type DiffOptions } from '../../schema/schemaASTDiffer.js';
10
4
  /**
11
- * Options for drift detection.
5
+ * How drift compares: as a migration does, given its generator's `diffOptions()`, with the tables to leave out
6
+ * (the migrations log, which no entity names), and the dialect that renders a type, without which no type
7
+ * drift is reported.
12
8
  */
13
- export interface DriftDetectorOptions {
14
- /** Include column type mismatches */
15
- checkTypes?: boolean;
16
- /** Include nullable mismatches */
17
- checkNullable?: boolean;
18
- /** Include index differences */
19
- checkIndexes?: boolean;
20
- /** Include foreign key differences */
21
- checkForeignKeys?: boolean;
22
- /**
23
- * Include default value differences. Off unless {@link defaultsEqual} is given: without it defaults
24
- * compare as written, and an engine reports one as it stored it (`now()`, `'active'::text`).
25
- */
26
- checkDefaults?: boolean;
27
- /** How the engine's generator compares a default, so drift reports the ones a migration would change. */
28
- defaultsEqual?: (expected: unknown, actual: unknown) => boolean;
29
- /**
30
- * Tables to leave out of the comparison. The migrations bookkeeping table belongs here - it exists in
31
- * the database by design and has no entity, so reporting it as unexpected told every project to
32
- * "create entity or drop table" for its own migration log.
33
- */
34
- excludeTables?: string[];
35
- /** Dialect instance for type formatting */
36
- dialect?: AbstractDialect;
9
+ export type DriftDetectorOptions = DiffOptions & {
10
+ readonly dialect?: AbstractDialect;
11
+ };
12
+ export type DriftSeverity = 'critical' | 'warning' | 'info';
13
+ export type DriftType = 'missing_table' | 'unexpected_table' | 'missing_column' | 'unexpected_column' | 'type_mismatch' | 'constraint_mismatch' | 'missing_index' | 'unexpected_index' | 'index_mismatch' | 'missing_relationship' | 'unexpected_relationship' | 'relationship_mismatch';
14
+ /** One way the database differs from the entities. */
15
+ export interface Drift {
16
+ readonly type: DriftType;
17
+ readonly severity: DriftSeverity;
18
+ readonly table?: string;
19
+ readonly column?: string;
20
+ readonly index?: string;
21
+ readonly relationship?: string;
22
+ readonly expected?: unknown;
23
+ readonly actual?: unknown;
24
+ readonly details: string;
25
+ readonly suggestion: string;
26
+ }
27
+ export type DriftStatus = 'in_sync' | 'drifted' | 'critical';
28
+ export interface DriftReport {
29
+ readonly status: DriftStatus;
30
+ readonly drifts: Drift[];
31
+ readonly generatedAt: Date;
32
+ /** How many drifts of each severity. */
33
+ readonly summary: Readonly<Record<DriftSeverity, number>>;
37
34
  }
38
35
  /**
39
36
  * Compare an expected schema (from entities) with an actual one (from the database) and report every