uql-orm 0.96.1 → 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 (117) 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 +59 -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 +53 -174
  20. package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -3
  21. package/dist/migrate/codegen/fieldOptionsSource.js +3 -11
  22. package/dist/migrate/codegen/index.d.ts +2 -7
  23. package/dist/migrate/codegen/index.js +2 -8
  24. package/dist/migrate/codegen/migrationFile.d.ts +1 -8
  25. package/dist/migrate/codegen/migrationFile.js +9 -13
  26. package/dist/migrate/ddl/defaultSql.d.ts +2 -1
  27. package/dist/migrate/ddl/defaultSql.js +1 -3
  28. package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
  29. package/dist/migrate/ddl/indexCapabilities.js +60 -0
  30. package/dist/migrate/ddl/indexDdl.d.ts +11 -24
  31. package/dist/migrate/ddl/indexDdl.js +22 -28
  32. package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
  33. package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
  34. package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
  35. package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
  36. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
  37. package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
  38. package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
  39. package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
  40. package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
  41. package/dist/migrate/ddl/pgIndexDdl.js +5 -44
  42. package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
  43. package/dist/migrate/ddl/pgTableDdl.js +17 -1
  44. package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
  45. package/dist/migrate/ddl/tableDdl.d.ts +43 -24
  46. package/dist/migrate/ddl/tableDdl.js +56 -37
  47. package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
  48. package/dist/migrate/drift/driftDetector.d.ts +29 -32
  49. package/dist/migrate/drift/driftDetector.js +155 -205
  50. package/dist/migrate/drift/index.d.ts +1 -6
  51. package/dist/migrate/drift/index.js +1 -6
  52. package/dist/migrate/generator/definitionToNode.d.ts +2 -2
  53. package/dist/migrate/generator/definitionToNode.js +6 -5
  54. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +56 -77
  55. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +75 -98
  56. package/dist/migrate/introspection/mssqlIntrospector.d.ts +10 -43
  57. package/dist/migrate/introspection/mssqlIntrospector.js +52 -77
  58. package/dist/migrate/introspection/mysqlIntrospector.d.ts +21 -37
  59. package/dist/migrate/introspection/mysqlIntrospector.js +75 -56
  60. package/dist/migrate/introspection/postgresIntrospector.d.ts +15 -60
  61. package/dist/migrate/introspection/postgresIntrospector.js +74 -77
  62. package/dist/migrate/introspection/sqliteIntrospector.d.ts +19 -53
  63. package/dist/migrate/introspection/sqliteIntrospector.js +73 -119
  64. package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
  65. package/dist/migrate/introspection/tableSchemaAST.js +85 -0
  66. package/dist/migrate/migrationTarget.js +10 -2
  67. package/dist/migrate/migrator.d.ts +9 -44
  68. package/dist/migrate/migrator.js +72 -150
  69. package/dist/migrate/schemaChange.d.ts +8 -5
  70. package/dist/migrate/schemaChange.js +25 -8
  71. package/dist/migrate/schemaGenerator.d.ts +35 -109
  72. package/dist/migrate/schemaGenerator.js +179 -353
  73. package/dist/migrate/storage/databaseStorage.d.ts +2 -1
  74. package/dist/migrate/storage/databaseStorage.js +3 -2
  75. package/dist/migrate/storage/jsonStorage.d.ts +1 -2
  76. package/dist/migrate/storage/jsonStorage.js +11 -20
  77. package/dist/migrate/triggerSql.d.ts +7 -9
  78. package/dist/migrate/triggerSql.js +17 -18
  79. package/dist/mongo/index.d.ts +0 -1
  80. package/dist/mongo/index.js +0 -1
  81. package/dist/mongo/mongoDialect.js +0 -1
  82. package/dist/mongo/mongoIntrospector.d.ts +1 -6
  83. package/dist/mongo/mongoIntrospector.js +7 -18
  84. package/dist/mongo/mongoSchemaGenerator.d.ts +7 -26
  85. package/dist/mongo/mongoSchemaGenerator.js +51 -75
  86. package/dist/mssql/mssqlDialect.js +0 -1
  87. package/dist/schema/canonicalType.d.ts +15 -19
  88. package/dist/schema/canonicalType.js +20 -43
  89. package/dist/schema/dependencyGraph.d.ts +2 -3
  90. package/dist/schema/dependencyGraph.js +0 -4
  91. package/dist/schema/indexDifferences.js +2 -2
  92. package/dist/schema/schemaAST.d.ts +1 -1
  93. package/dist/schema/schemaAST.js +5 -12
  94. package/dist/schema/schemaASTBuilder.d.ts +5 -6
  95. package/dist/schema/schemaASTBuilder.js +17 -18
  96. package/dist/schema/schemaASTDiffer.d.ts +4 -5
  97. package/dist/schema/schemaASTDiffer.js +40 -73
  98. package/dist/schema/types.d.ts +24 -54
  99. package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
  100. package/dist/sqlite/localSqliteQuerierPool.js +20 -4
  101. package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
  102. package/dist/sqlite/sqliteDialect.js +0 -1
  103. package/dist/sqlite/sqliteQuerierPool.js +3 -3
  104. package/dist/type/dialect.d.ts +0 -2
  105. package/dist/type/migration.d.ts +13 -73
  106. package/dist/util/ddlExpression.util.d.ts +13 -2
  107. package/dist/util/ddlExpression.util.js +27 -4
  108. package/dist/util/sql.util.d.ts +2 -12
  109. package/dist/util/sql.util.js +9 -18
  110. package/package.json +1 -1
  111. package/skills/uql-orm/SKILL.md +1 -1
  112. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
  113. package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
  114. package/dist/schema/index.d.ts +0 -2
  115. package/dist/schema/index.js +0 -1
  116. package/dist/sqlite/sqlitePragmas.d.ts +0 -3
  117. package/dist/sqlite/sqlitePragmas.js +0 -15
@@ -1,50 +1,27 @@
1
- /**
2
- * Drift Detector
3
- *
4
- * Detects schema drift between expected schema (from entities) and
5
- * actual database schema.
6
- */
7
- import { canonicalToSql, engineType } from '../../schema/canonicalType.js';
8
- import { defaultsEqualAsWritten, diffSchemas, referentialActions } from '../../schema/schemaASTDiffer.js';
1
+ import { canonicalToSql } from '../../schema/canonicalType.js';
2
+ import { diffSchemas, referentialActions } from '../../schema/schemaASTDiffer.js';
9
3
  import { SqlExpression, writtenDefault } from '../../schema/sqlExpression.js';
10
- function resolveOptions(options) {
11
- return {
12
- checkTypes: options.checkTypes ?? true,
13
- checkNullable: options.checkNullable ?? true,
14
- checkIndexes: options.checkIndexes ?? true,
15
- checkForeignKeys: options.checkForeignKeys ?? true,
16
- checkDefaults: options.checkDefaults ?? options.defaultsEqual !== undefined,
17
- defaultsEqual: options.defaultsEqual ?? defaultsEqualAsWritten,
18
- excludeTables: options.excludeTables ?? [],
19
- dialect: options.dialect,
20
- };
21
- }
22
4
  /**
23
5
  * Compare an expected schema (from entities) with an actual one (from the database) and report every
24
6
  * way they have drifted apart.
25
7
  */
26
8
  export function detectDrift(expectedAST, actualAST, options = {}) {
27
- const opts = resolveOptions(options);
28
- const { dialect } = opts;
29
- const diff = diffSchemas(expectedAST, actualAST, {
30
- compareIndexes: opts.checkIndexes,
31
- compareRelationships: opts.checkForeignKeys,
32
- excludeTables: opts.excludeTables,
33
- defaultsEqual: opts.defaultsEqual,
34
- // Types are normalized through the dialect's engine; without a dialect, no type drift is reported.
35
- ...(dialect && { normalizeType: engineType(dialect) }),
36
- });
9
+ const diff = diffSchemas(expectedAST, actualAST, options);
37
10
  const drifts = [
38
- ...detectTableDrifts(diff),
39
- ...detectColumnDrifts(diff, opts),
40
- ...detectIndexDrifts(diff),
11
+ ...diff.tables.map(tableDrift),
12
+ ...diff.columns.flatMap((change) => columnDrifts(change, options.dialect)),
13
+ ...diff.indexes.map(indexDrift),
41
14
  ...detectPrimaryKeyDrifts(diff),
42
- ...detectRelationshipDrifts(diff),
15
+ ...detectOwnedDrifts('Check', diff.checks),
16
+ ...detectOwnedDrifts('Trigger', diff.triggers),
17
+ ...diff.relationships.map(relationshipDrift),
43
18
  ];
19
+ const count = (severity) => drifts.filter((drift) => drift.severity === severity).length;
20
+ const summary = { critical: count('critical'), warning: count('warning'), info: count('info') };
44
21
  return {
45
- status: calculateStatus(drifts),
22
+ status: drifts.length === 0 ? 'in_sync' : summary.critical ? 'critical' : 'drifted',
46
23
  drifts,
47
- summary: createSummary(drifts),
24
+ summary,
48
25
  generatedAt: new Date(),
49
26
  };
50
27
  }
@@ -63,15 +40,26 @@ function detectPrimaryKeyDrifts(diff) {
63
40
  suggestion: 'Generate a migration to change the primary key',
64
41
  }));
65
42
  }
43
+ /**
44
+ * A check or trigger the database lacks, critical since rows are written otherwise than the entity says, or
45
+ * one uql installed that nothing declares.
46
+ */
47
+ function detectOwnedDrifts(kind, changes) {
48
+ return changes.map(({ table, from, to }) => ({
49
+ type: 'constraint_mismatch',
50
+ table,
51
+ suggestion: 'Generate a migration to match the entity',
52
+ ...(to
53
+ ? { severity: 'critical', details: `${kind} "${to.name}" expected but not found in database` }
54
+ : { severity: 'warning', details: `${kind} "${from?.name}" exists in database but not in entity` }),
55
+ }));
56
+ }
66
57
  /** A key's columns as a drift names them, `none` where there is no key. */
67
58
  function keyColumns(key) {
68
59
  return key?.columns.join(', ') || 'none';
69
60
  }
70
- /**
71
- * Detect table-level drifts (missing/unexpected tables).
72
- */
73
- function detectTableDrifts(diff) {
74
- return diff.tables.map((change) => change.from === undefined
61
+ function tableDrift(change) {
62
+ return change.from === undefined
75
63
  ? {
76
64
  type: 'missing_table',
77
65
  severity: 'critical',
@@ -85,166 +73,149 @@ function detectTableDrifts(diff) {
85
73
  table: change.from.name,
86
74
  details: `Table "${change.from.name}" exists in database but no matching entity`,
87
75
  suggestion: 'Create entity or drop table',
88
- });
76
+ };
89
77
  }
90
- /**
91
- * Detect column-level drifts.
92
- */
93
- function detectColumnDrifts(diff, opts) {
94
- const drifts = [];
95
- for (const colDiff of diff.columns) {
96
- if (colDiff.from === undefined) {
97
- drifts.push({
78
+ /** A column the database lacks or no entity declares, or each part of one the differ found changed. */
79
+ function columnDrifts(change, dialect) {
80
+ const { table, column } = change;
81
+ if (change.from === undefined) {
82
+ return [
83
+ {
98
84
  type: 'missing_column',
99
85
  severity: 'critical',
100
- table: colDiff.table,
101
- column: colDiff.column,
102
- details: `Column "${colDiff.column}" expected but not found in database`,
86
+ table,
87
+ column,
88
+ details: `Column "${column}" expected but not found in database`,
103
89
  suggestion: 'Run migration to add column',
104
- });
105
- }
106
- else if (colDiff.to === undefined) {
107
- drifts.push({
90
+ },
91
+ ];
92
+ }
93
+ if (change.to === undefined) {
94
+ return [
95
+ {
108
96
  type: 'unexpected_column',
109
97
  severity: 'warning',
110
- table: colDiff.table,
111
- column: colDiff.column,
112
- details: `Column "${colDiff.column}" exists in database but not in entity`,
98
+ table,
99
+ column,
100
+ details: `Column "${column}" exists in database but not in entity`,
113
101
  suggestion: 'Add to entity or create migration to drop',
114
- });
102
+ },
103
+ ];
104
+ }
105
+ const { from, to, isBreaking } = change;
106
+ return change.changed.flatMap((facet) => {
107
+ if (facet === 'type') {
108
+ // Type drift needs a dialect to render both types.
109
+ if (!dialect) {
110
+ return [];
111
+ }
112
+ const [expected, actual] = [canonicalToSql(to.type, dialect), canonicalToSql(from.type, dialect)];
113
+ return [
114
+ {
115
+ type: 'type_mismatch',
116
+ severity: isBreaking ? 'critical' : 'warning',
117
+ table,
118
+ column,
119
+ expected,
120
+ actual,
121
+ details: `Type mismatch for "${column}": expected ${expected}, got ${actual}`,
122
+ suggestion: isBreaking ? 'Data truncation risk! Create migration to fix.' : 'Create migration to align types',
123
+ },
124
+ ];
115
125
  }
116
- else {
117
- addAlterColumnDrifts(colDiff, drifts, opts);
126
+ if (facet === 'nullable') {
127
+ return [
128
+ {
129
+ type: 'constraint_mismatch',
130
+ severity: 'warning',
131
+ table,
132
+ column,
133
+ expected: to.nullable ? 'NULLABLE' : 'NOT NULL',
134
+ actual: from.nullable ? 'NULLABLE' : 'NOT NULL',
135
+ details: `Nullable mismatch for "${column}"`,
136
+ suggestion: 'Align nullable setting in entity or database',
137
+ },
138
+ ];
118
139
  }
119
- }
120
- return drifts;
140
+ return [
141
+ {
142
+ type: 'constraint_mismatch',
143
+ severity: 'info',
144
+ table,
145
+ column,
146
+ expected: shownDefault(to.defaultValue),
147
+ actual: shownDefault(from.defaultValue),
148
+ details: `Default mismatch for "${column}"`,
149
+ suggestion: 'Align the default in the entity or the database',
150
+ },
151
+ ];
152
+ });
121
153
  }
122
- /** The drifts for each part of a column the differ found changed: type, nullability and default. */
123
- function addAlterColumnDrifts(colDiff, drifts, opts) {
124
- const { changed } = colDiff;
125
- // Type drift needs a dialect to render both types.
126
- if (opts.checkTypes && opts.dialect && changed.includes('type')) {
127
- const expectedType = canonicalToSql(colDiff.to.type, opts.dialect);
128
- const actualType = canonicalToSql(colDiff.from.type, opts.dialect);
129
- drifts.push({
130
- type: 'type_mismatch',
131
- severity: colDiff.isBreaking ? 'critical' : 'warning',
132
- table: colDiff.table,
133
- column: colDiff.column,
134
- expected: expectedType,
135
- actual: actualType,
136
- details: `Type mismatch for "${colDiff.column}": expected ${expectedType}, got ${actualType}`,
137
- suggestion: colDiff.isBreaking
138
- ? 'Data truncation risk! Create migration to fix.'
139
- : 'Create migration to align types',
140
- });
141
- }
142
- if (opts.checkNullable && changed.includes('nullable')) {
143
- drifts.push({
144
- type: 'constraint_mismatch',
154
+ function indexDrift(change) {
155
+ const { table, name: index } = change;
156
+ if (change.from === undefined) {
157
+ return {
158
+ type: 'missing_index',
145
159
  severity: 'warning',
146
- table: colDiff.table,
147
- column: colDiff.column,
148
- expected: colDiff.to.nullable ? 'NULLABLE' : 'NOT NULL',
149
- actual: colDiff.from.nullable ? 'NULLABLE' : 'NOT NULL',
150
- details: `Nullable mismatch for "${colDiff.column}"`,
151
- suggestion: 'Align nullable setting in entity or database',
152
- });
160
+ table,
161
+ index,
162
+ details: `Index "${index}" expected but not found in database`,
163
+ suggestion: 'Create index via migration',
164
+ };
153
165
  }
154
- if (opts.checkDefaults && changed.includes('default')) {
155
- drifts.push({
156
- type: 'constraint_mismatch',
166
+ if (change.to === undefined) {
167
+ return {
168
+ type: 'unexpected_index',
157
169
  severity: 'info',
158
- table: colDiff.table,
159
- column: colDiff.column,
160
- expected: shownDefault(colDiff.to.defaultValue),
161
- actual: shownDefault(colDiff.from.defaultValue),
162
- details: `Default mismatch for "${colDiff.column}"`,
163
- suggestion: 'Align the default in the entity or the database',
164
- });
170
+ table,
171
+ index,
172
+ details: `Index "${index}" exists in database but not defined in entity`,
173
+ suggestion: 'Declare it, or drop it via migration: generate:entities drops one uql named',
174
+ };
165
175
  }
176
+ // No `expected`/`actual`: the CLI prints those by interpolation, where an `IndexNode` renders as
177
+ // `[object Object]`. What differs is already spelled out in `description`.
178
+ return {
179
+ type: 'index_mismatch',
180
+ severity: 'warning',
181
+ table,
182
+ index,
183
+ details: `Index "${index}" differs from the entity (${change.description})`,
184
+ suggestion: 'Recreate it via migration, which generate:entities writes',
185
+ };
166
186
  }
167
- /**
168
- * Detect index drifts.
169
- */
170
- function detectIndexDrifts(diff) {
171
- const drifts = [];
172
- for (const idxDiff of diff.indexes) {
173
- if (idxDiff.from === undefined) {
174
- drifts.push({
175
- type: 'missing_index',
176
- severity: 'warning',
177
- table: idxDiff.table,
178
- index: idxDiff.name,
179
- details: `Index "${idxDiff.name}" expected but not found in database`,
180
- suggestion: 'Create index via migration',
181
- });
182
- }
183
- else if (idxDiff.to === undefined) {
184
- drifts.push({
185
- type: 'unexpected_index',
186
- severity: 'info',
187
- table: idxDiff.table,
188
- index: idxDiff.name,
189
- details: `Index "${idxDiff.name}" exists in database but not defined in entity`,
190
- suggestion: 'Declare it, or drop it via migration: generate:entities drops one uql named',
191
- });
192
- }
193
- else {
194
- // No `expected`/`actual` here: the CLI prints those by interpolation, where an `IndexNode`
195
- // renders as `[object Object]`. What differs is already spelled out in `description`.
196
- drifts.push({
197
- type: 'index_mismatch',
198
- severity: 'warning',
199
- table: idxDiff.table,
200
- index: idxDiff.name,
201
- details: `Index "${idxDiff.name}" differs from the entity (${idxDiff.description})`,
202
- suggestion: 'Recreate it via migration, which generate:entities writes',
203
- });
204
- }
187
+ function relationshipDrift(change) {
188
+ const { fromTable: table, name: relationship } = change;
189
+ if (change.from === undefined) {
190
+ return {
191
+ type: 'missing_relationship',
192
+ severity: 'warning',
193
+ table,
194
+ relationship,
195
+ details: `FK "${relationship}" expected but not found in database`,
196
+ suggestion: 'Add FK constraint or remove relation from entity',
197
+ };
205
198
  }
206
- return drifts;
207
- }
208
- /**
209
- * Detect relationship/FK drifts.
210
- */
211
- function detectRelationshipDrifts(diff) {
212
- const drifts = [];
213
- for (const relDiff of diff.relationships) {
214
- if (relDiff.from === undefined) {
215
- drifts.push({
216
- type: 'missing_relationship',
217
- severity: 'warning',
218
- table: relDiff.fromTable,
219
- relationship: relDiff.name,
220
- details: `FK "${relDiff.name}" expected but not found in database`,
221
- suggestion: 'Add FK constraint or remove relation from entity',
222
- });
223
- }
224
- else if (relDiff.to === undefined) {
225
- drifts.push({
226
- type: 'unexpected_relationship',
227
- severity: 'info',
228
- table: relDiff.fromTable,
229
- relationship: relDiff.name,
230
- details: `FK "${relDiff.name}" exists in database but not in entity`,
231
- suggestion: 'Add relation to entity or drop FK',
232
- });
233
- }
234
- else {
235
- drifts.push({
236
- type: 'relationship_mismatch',
237
- severity: 'warning',
238
- table: relDiff.fromTable,
239
- relationship: relDiff.name,
240
- expected: formatActions(relDiff.to),
241
- actual: formatActions(relDiff.from),
242
- details: `FK "${relDiff.name}" has other referential actions in the database than in the entity`,
243
- suggestion: 'Generate a migration, which drops and re-adds the constraint',
244
- });
245
- }
199
+ if (change.to === undefined) {
200
+ return {
201
+ type: 'unexpected_relationship',
202
+ severity: 'info',
203
+ table,
204
+ relationship,
205
+ details: `FK "${relationship}" exists in database but not in entity`,
206
+ suggestion: 'Add relation to entity or drop FK',
207
+ };
246
208
  }
247
- return drifts;
209
+ return {
210
+ type: 'relationship_mismatch',
211
+ severity: 'warning',
212
+ table,
213
+ relationship,
214
+ expected: formatActions(change.to),
215
+ actual: formatActions(change.from),
216
+ details: `FK "${relationship}" has other referential actions in the database than in the entity`,
217
+ suggestion: 'Generate a migration, which drops and re-adds the constraint',
218
+ };
248
219
  }
249
220
  /** A default as a report shows it: SQL as its SQL, a JSON document as JSON rather than `[object Object]`. */
250
221
  function shownDefault(value) {
@@ -255,24 +226,3 @@ function formatActions(rel) {
255
226
  const { onDelete, onUpdate } = referentialActions(rel);
256
227
  return `ON DELETE ${onDelete} ON UPDATE ${onUpdate}`;
257
228
  }
258
- /**
259
- * Calculate overall status based on drifts.
260
- */
261
- function calculateStatus(drifts) {
262
- if (drifts.length === 0)
263
- return 'in_sync';
264
- const hasCritical = drifts.some((d) => d.severity === 'critical');
265
- if (hasCritical)
266
- return 'critical';
267
- return 'drifted';
268
- }
269
- /**
270
- * Create a summary of drifts by severity.
271
- */
272
- function createSummary(drifts) {
273
- return {
274
- critical: drifts.filter((d) => d.severity === 'critical').length,
275
- warning: drifts.filter((d) => d.severity === 'warning').length,
276
- info: drifts.filter((d) => d.severity === 'info').length,
277
- };
278
- }
@@ -1,6 +1 @@
1
- /**
2
- * Drift Detection Module
3
- *
4
- * Detects schema drift between expected and actual database schemas.
5
- */
6
- export { type DriftDetectorOptions, detectDrift } from './driftDetector.js';
1
+ export { type Drift, type DriftDetectorOptions, type DriftReport, type DriftSeverity, type DriftStatus, type DriftType, detectDrift, } from './driftDetector.js';
@@ -1,6 +1 @@
1
- /**
2
- * Drift Detection Module
3
- *
4
- * Detects schema drift between expected and actual database schemas.
5
- */
6
- export { detectDrift } from './driftDetector.js';
1
+ export { detectDrift, } from './driftDetector.js';
@@ -9,8 +9,8 @@ import type { ColumnDefinition, FullColumnDefinition, IndexDefinition, TableDefi
9
9
  * `render`. Free functions and not generator methods: the dialect reaches them only through `render`.
10
10
  */
11
11
  export declare function tableDefinitionToNode(def: TableDefinition, render: (sql: QueryRaw) => string): TableNode;
12
- /** A builder's column without its `index` and `foreignKey`, which are lifted onto the table. */
13
- export declare function bareColumn({ index: _index, foreignKey: _foreignKey, ...column }: FullColumnDefinition): ColumnDefinition;
12
+ /** A builder's column without its `index`, `foreignKey` and `enum`, which are lifted onto the table. */
13
+ export declare function bareColumn({ index: _index, foreignKey: _foreignKey, enum: _enum, ...column }: FullColumnDefinition): ColumnDefinition;
14
14
  /**
15
15
  * The index a column-level `index` or `unique` declares, or nothing: a unique column is a unique index.
16
16
  *
@@ -1,5 +1,5 @@
1
1
  import { createTableNode, keyOfColumns } from '../../schema/schemaAST.js';
2
- import { indexNameParts, normalizeIndexColumn, renderIndexColumn } from '../../util/ddlExpression.util.js';
2
+ import { declaredIndexName, enumCheck, normalizeIndexColumn, renderIndexColumn, } from '../../util/ddlExpression.util.js';
3
3
  import { derivedIndexName, splitQualifiedName } from '../../util/sql.util.js';
4
4
  /**
5
5
  * A migration builder's table definition as the AST nodes the generators render from, so a hand-written
@@ -16,8 +16,9 @@ export function tableDefinitionToNode(def, render) {
16
16
  };
17
17
  const { columns } = table;
18
18
  for (const colDef of def.columns) {
19
- columns.set(colDef.name, { ...bareColumn(colDef), table, referencedBy: [] });
19
+ columns.set(colDef.name, { ...bareColumn(colDef), table });
20
20
  }
21
+ table.checks.push(...def.columns.flatMap((column) => enumCheck(name, column, render)));
21
22
  // A declared key keeps only the columns the table has, in its own order.
22
23
  table.primaryKey = def.primaryKey
23
24
  ? { columns: def.primaryKey.filter((name) => columns.has(name)) }
@@ -27,8 +28,8 @@ export function tableDefinitionToNode(def, render) {
27
28
  }
28
29
  return table;
29
30
  }
30
- /** A builder's column without its `index` and `foreignKey`, which are lifted onto the table. */
31
- export function bareColumn({ index: _index, foreignKey: _foreignKey, ...column }) {
31
+ /** A builder's column without its `index`, `foreignKey` and `enum`, which are lifted onto the table. */
32
+ export function bareColumn({ index: _index, foreignKey: _foreignKey, enum: _enum, ...column }) {
32
33
  return column;
33
34
  }
34
35
  /**
@@ -56,7 +57,7 @@ export function indexDefinition(tableName, columns, { name, unique = false, ...o
56
57
  const entries = columns.map(normalizeIndexColumn);
57
58
  return {
58
59
  ...options,
59
- name: name ?? derivedIndexName(tableName, indexNameParts(entries), uniqueName),
60
+ name: declaredIndexName(name, tableName, entries, uniqueName),
60
61
  entries,
61
62
  unique,
62
63
  };