uql-orm 0.97.0 → 0.99.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.
- package/dist/dialect/abstractSqlDialect.d.ts +1 -7
- package/dist/dialect/abstractSqlDialect.js +1 -9
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +2 -0
- package/dist/dialect/mysqlLikeSqlDialect.js +4 -1
- package/dist/dialect/pgLikeSqlDialect.js +0 -1
- package/dist/migrate/acquireQuerierForMigrations.d.ts +4 -8
- package/dist/migrate/acquireQuerierForMigrations.js +10 -18
- package/dist/migrate/builder/columnBuilder.d.ts +1 -2
- package/dist/migrate/builder/columnBuilder.js +3 -10
- package/dist/migrate/builder/migrationBuilder.d.ts +6 -26
- package/dist/migrate/builder/migrationBuilder.js +21 -78
- package/dist/migrate/builder/tableBuilder.js +2 -3
- package/dist/migrate/builder/types.d.ts +57 -120
- package/dist/migrate/cli-config.d.ts +1 -0
- package/dist/migrate/cli-config.js +11 -26
- package/dist/migrate/cli.d.ts +0 -13
- package/dist/migrate/cli.js +55 -118
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +7 -61
- package/dist/migrate/codegen/entityCodeGenerator.js +51 -168
- package/dist/migrate/codegen/fieldOptionsSource.js +3 -6
- package/dist/migrate/codegen/index.d.ts +2 -7
- package/dist/migrate/codegen/index.js +2 -8
- package/dist/migrate/codegen/migrationFile.d.ts +1 -8
- package/dist/migrate/codegen/migrationFile.js +9 -13
- package/dist/migrate/ddl/defaultSql.d.ts +2 -1
- package/dist/migrate/ddl/defaultSql.js +1 -3
- package/dist/migrate/ddl/indexCapabilities.d.ts +18 -0
- package/dist/migrate/ddl/indexCapabilities.js +60 -0
- package/dist/migrate/ddl/indexDdl.d.ts +11 -24
- package/dist/migrate/ddl/indexDdl.js +22 -28
- package/dist/migrate/ddl/mssqlIndexDdl.d.ts +1 -7
- package/dist/migrate/ddl/mssqlIndexDdl.js +1 -7
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +6 -9
- package/dist/migrate/ddl/mssqlTableDdl.js +14 -17
- package/dist/migrate/ddl/mysqlIndexDdl.d.ts +0 -21
- package/dist/migrate/ddl/mysqlIndexDdl.js +4 -48
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +6 -5
- package/dist/migrate/ddl/mysqlTableDdl.js +15 -10
- package/dist/migrate/ddl/pgIndexDdl.d.ts +0 -10
- package/dist/migrate/ddl/pgIndexDdl.js +5 -44
- package/dist/migrate/ddl/pgTableDdl.d.ts +6 -2
- package/dist/migrate/ddl/pgTableDdl.js +17 -1
- package/dist/migrate/ddl/sqliteIndexDdl.js +2 -7
- package/dist/migrate/ddl/tableDdl.d.ts +43 -24
- package/dist/migrate/ddl/tableDdl.js +56 -37
- package/dist/migrate/ddl/tableRebuild.d.ts +2 -1
- package/dist/migrate/drift/driftDetector.d.ts +29 -32
- package/dist/migrate/drift/driftDetector.js +139 -205
- package/dist/migrate/drift/index.d.ts +1 -6
- package/dist/migrate/drift/index.js +1 -6
- package/dist/migrate/generator/definitionToNode.js +3 -3
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +53 -76
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +68 -90
- package/dist/migrate/introspection/mssqlIntrospector.d.ts +8 -43
- package/dist/migrate/introspection/mssqlIntrospector.js +44 -77
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -38
- package/dist/migrate/introspection/mysqlIntrospector.js +48 -57
- package/dist/migrate/introspection/postgresIntrospector.d.ts +12 -60
- package/dist/migrate/introspection/postgresIntrospector.js +62 -77
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +14 -53
- package/dist/migrate/introspection/sqliteIntrospector.js +59 -119
- package/dist/migrate/introspection/tableSchemaAST.d.ts +13 -0
- package/dist/migrate/introspection/tableSchemaAST.js +85 -0
- package/dist/migrate/migrationTarget.js +10 -2
- package/dist/migrate/migrator.d.ts +14 -37
- package/dist/migrate/migrator.js +89 -126
- package/dist/migrate/schemaChange.d.ts +0 -2
- package/dist/migrate/schemaChange.js +1 -1
- package/dist/migrate/schemaGenerator.d.ts +22 -97
- package/dist/migrate/schemaGenerator.js +113 -298
- package/dist/migrate/storage/databaseStorage.d.ts +2 -1
- package/dist/migrate/storage/databaseStorage.js +3 -2
- package/dist/migrate/storage/jsonStorage.d.ts +1 -2
- package/dist/migrate/storage/jsonStorage.js +11 -20
- package/dist/migrate/triggerSql.d.ts +3 -3
- package/dist/migrate/triggerSql.js +5 -4
- package/dist/mongo/index.d.ts +0 -1
- package/dist/mongo/index.js +0 -1
- package/dist/mongo/mongoDialect.js +0 -1
- package/dist/mongo/mongoIntrospector.d.ts +0 -3
- package/dist/mongo/mongoIntrospector.js +7 -14
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -20
- package/dist/mongo/mongoSchemaGenerator.js +51 -70
- package/dist/mssql/mssqlDialect.js +0 -1
- package/dist/schema/canonicalType.d.ts +15 -19
- package/dist/schema/canonicalType.js +20 -43
- package/dist/schema/dependencyGraph.d.ts +2 -3
- package/dist/schema/dependencyGraph.js +0 -4
- package/dist/schema/indexDifferences.js +2 -2
- package/dist/schema/schemaAST.d.ts +1 -1
- package/dist/schema/schemaAST.js +4 -12
- package/dist/schema/schemaASTBuilder.d.ts +2 -5
- package/dist/schema/schemaASTBuilder.js +11 -14
- package/dist/schema/schemaASTDiffer.d.ts +4 -5
- package/dist/schema/schemaASTDiffer.js +22 -70
- package/dist/schema/types.d.ts +1 -48
- package/dist/sqlite/localSqliteQuerierPool.d.ts +16 -2
- package/dist/sqlite/localSqliteQuerierPool.js +20 -4
- package/dist/sqlite/nodeSqliteQuerierPool.js +2 -2
- package/dist/sqlite/sqliteDialect.js +0 -1
- package/dist/sqlite/sqliteQuerierPool.js +3 -3
- package/dist/type/dialect.d.ts +0 -2
- package/dist/type/migration.d.ts +3 -54
- package/dist/util/ddlExpression.util.d.ts +2 -2
- package/dist/util/ddlExpression.util.js +3 -3
- package/dist/util/sql.util.d.ts +0 -8
- package/dist/util/sql.util.js +7 -12
- package/package.json +1 -1
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -36
- package/dist/migrate/introspection/baseSqlIntrospector.js +0 -133
- package/dist/schema/index.d.ts +0 -2
- package/dist/schema/index.js +0 -1
- package/dist/sqlite/sqlitePragmas.d.ts +0 -3
- package/dist/sqlite/sqlitePragmas.js +0 -15
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { AbstractSqlDialect } from '../../dialect/abstractSqlDialect.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ColumnSchema, PrimaryKeySchema } from '../../type/index.js';
|
|
3
3
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
25
|
-
|
|
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
|
|
30
|
-
*
|
|
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,
|
|
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
|
-
/**
|
|
38
|
-
dropIndex(table: string, index: 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
|
-
/**
|
|
41
|
-
|
|
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
|
|
43
|
-
|
|
44
|
-
return this.alterTable(table, this.alterClauses(
|
|
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
|
|
52
|
-
*
|
|
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,
|
|
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
|
-
/**
|
|
69
|
-
dropIndex(table, index
|
|
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
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
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 `
|
|
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
|
-
|
|
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
|
|
3
|
+
import { type DiffOptions } from '../../schema/schemaASTDiffer.js';
|
|
10
4
|
/**
|
|
11
|
-
*
|
|
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
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|