metal-orm 1.1.26 → 1.1.27
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/index.cjs +783 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +154 -48
- package/dist/index.d.ts +154 -48
- package/dist/index.js +771 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ddl/dialects/index.ts +5 -6
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +129 -126
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +119 -111
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +173 -164
- package/src/core/ddl/dialects/render-reference.test.ts +37 -57
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +110 -121
- package/src/core/ddl/schema-dialect-composer.ts +129 -0
- package/src/core/ddl/schema-dialect.ts +40 -27
- package/src/core/ddl/schema-diff.ts +119 -90
- package/src/core/driver/mssql-driver.ts +6 -8
- package/src/core/driver/mysql-driver.ts +6 -8
- package/src/core/driver/postgres-driver.ts +6 -8
- package/src/core/driver/sqlite-driver.ts +6 -8
- package/src/index.ts +12 -0
- package/src/core/ddl/dialects/base-schema-dialect.ts +0 -96
package/dist/index.cjs
CHANGED
|
@@ -87,6 +87,7 @@ __export(index_exports, {
|
|
|
87
87
|
KeyvCacheAdapter: () => KeyvCacheAdapter,
|
|
88
88
|
Length: () => Length,
|
|
89
89
|
Lower: () => Lower,
|
|
90
|
+
MSSqlSchemaDialect: () => MSSqlSchemaDialect,
|
|
90
91
|
MemoryCacheAdapter: () => MemoryCacheAdapter,
|
|
91
92
|
MorphMany: () => MorphMany,
|
|
92
93
|
MorphOne: () => MorphOne,
|
|
@@ -99,6 +100,7 @@ __export(index_exports, {
|
|
|
99
100
|
MssqlUpdateCompiler: () => MssqlUpdateCompiler,
|
|
100
101
|
MySqlDialect: () => MySqlDialect,
|
|
101
102
|
MySqlProcedureCompiler: () => MySqlProcedureCompiler,
|
|
103
|
+
MySqlSchemaDialect: () => MySqlSchemaDialect,
|
|
102
104
|
MySqlUpsertStrategy: () => MySqlUpsertStrategy,
|
|
103
105
|
NestedSetStrategy: () => NestedSetStrategy,
|
|
104
106
|
NoReturningStrategy: () => NoReturningStrategy,
|
|
@@ -110,6 +112,7 @@ __export(index_exports, {
|
|
|
110
112
|
PostgresDialect: () => PostgresDialect,
|
|
111
113
|
PostgresProcedureCompiler: () => PostgresProcedureCompiler,
|
|
112
114
|
PostgresReturningStrategy: () => PostgresReturningStrategy,
|
|
115
|
+
PostgresSchemaDialect: () => PostgresSchemaDialect,
|
|
113
116
|
PostgresUpsertStrategy: () => PostgresUpsertStrategy,
|
|
114
117
|
PrimaryKey: () => PrimaryKey,
|
|
115
118
|
ProcedureCallBuilder: () => ProcedureCallBuilder,
|
|
@@ -117,6 +120,7 @@ __export(index_exports, {
|
|
|
117
120
|
QueryCacheManager: () => QueryCacheManager,
|
|
118
121
|
RedisCacheAdapter: () => RedisCacheAdapter,
|
|
119
122
|
RelationKinds: () => RelationKinds,
|
|
123
|
+
SQLiteSchemaDialect: () => SQLiteSchemaDialect,
|
|
120
124
|
STANDARD_COLUMN_TYPES: () => STANDARD_COLUMN_TYPES,
|
|
121
125
|
SelectQueryBuilder: () => SelectQueryBuilder,
|
|
122
126
|
SqlServerDialect: () => SqlServerDialect,
|
|
@@ -200,6 +204,7 @@ __export(index_exports, {
|
|
|
200
204
|
columnToOpenApiSchema: () => columnToOpenApiSchema,
|
|
201
205
|
columnTypeToOpenApiFormat: () => columnTypeToOpenApiFormat,
|
|
202
206
|
columnTypeToOpenApiType: () => columnTypeToOpenApiType,
|
|
207
|
+
composeSchemaDialect: () => composeSchemaDialect,
|
|
203
208
|
composeSqlDialect: () => composeSqlDialect,
|
|
204
209
|
computePaginationMetadata: () => computePaginationMetadata,
|
|
205
210
|
computeSchemaHash: () => computeSchemaHash,
|
|
@@ -218,19 +223,26 @@ __export(index_exports, {
|
|
|
218
223
|
createEntityFromRow: () => createEntityFromRow,
|
|
219
224
|
createEntityProxy: () => createEntityProxy,
|
|
220
225
|
createExecutorFromQueryRunner: () => createExecutorFromQueryRunner,
|
|
226
|
+
createLiteralFormatter: () => createLiteralFormatter,
|
|
221
227
|
createMssqlCompilerSet: () => createMssqlCompilerSet,
|
|
222
228
|
createMssqlExecutor: () => createMssqlExecutor,
|
|
229
|
+
createMssqlSchemaDialect: () => createMssqlSchemaDialect,
|
|
223
230
|
createMySqlDialect: () => createMySqlDialect,
|
|
231
|
+
createMySqlSchemaDialect: () => createMySqlSchemaDialect,
|
|
224
232
|
createMysqlExecutor: () => createMysqlExecutor,
|
|
225
233
|
createPooledExecutorFactory: () => createPooledExecutorFactory,
|
|
226
234
|
createPostgresDialect: () => createPostgresDialect,
|
|
227
235
|
createPostgresExecutor: () => createPostgresExecutor,
|
|
236
|
+
createPostgresSchemaDialect: () => createPostgresSchemaDialect,
|
|
228
237
|
createQueryLoggingExecutor: () => createQueryLoggingExecutor,
|
|
229
238
|
createRef: () => createRef,
|
|
230
239
|
createSqlDialect: () => createSqlDialect,
|
|
231
240
|
createSqlServerDialect: () => createSqlServerDialect,
|
|
232
241
|
createSqliteDialect: () => createSqliteDialect,
|
|
233
242
|
createSqliteExecutor: () => createSqliteExecutor,
|
|
243
|
+
createSqliteSchemaDialect: () => createSqliteSchemaDialect,
|
|
244
|
+
createStandardDropColumnCapability: () => createStandardDropColumnCapability,
|
|
245
|
+
createStandardDropTableCapability: () => createStandardDropTableCapability,
|
|
234
246
|
createTediousExecutor: () => createTediousExecutor,
|
|
235
247
|
createTediousMssqlClient: () => createTediousMssqlClient,
|
|
236
248
|
createTreeManager: () => createTreeManager,
|
|
@@ -2032,19 +2044,19 @@ var NoReturningStrategy = class {
|
|
|
2032
2044
|
if (!returning || returning.length === 0) return "";
|
|
2033
2045
|
throw new Error("RETURNING is not supported by this dialect.");
|
|
2034
2046
|
}
|
|
2035
|
-
formatReturningColumns(returning,
|
|
2047
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
2036
2048
|
return returning.map((column) => {
|
|
2037
|
-
const tablePart = column.table ? `${
|
|
2038
|
-
const aliasPart = column.alias ? ` AS ${
|
|
2039
|
-
return `${tablePart}${
|
|
2049
|
+
const tablePart = column.table ? `${quoteIdentifier9(column.table)}.` : "";
|
|
2050
|
+
const aliasPart = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
2051
|
+
return `${tablePart}${quoteIdentifier9(column.name)}${aliasPart}`;
|
|
2040
2052
|
}).join(", ");
|
|
2041
2053
|
}
|
|
2042
2054
|
};
|
|
2043
2055
|
var StandardReturningStrategy = class extends NoReturningStrategy {
|
|
2044
|
-
compileReturning(returning, _ctx,
|
|
2056
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
2045
2057
|
void _ctx;
|
|
2046
2058
|
if (!returning || returning.length === 0) return "";
|
|
2047
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
2059
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier9)}`;
|
|
2048
2060
|
}
|
|
2049
2061
|
};
|
|
2050
2062
|
|
|
@@ -2175,13 +2187,13 @@ var CteCompiler = class {
|
|
|
2175
2187
|
* @param stripTrailingSemicolon - Function to remove trailing semicolons from SQL.
|
|
2176
2188
|
* @returns SQL WITH clause string (e.g., "WITH cte_name AS (...) ") or empty string if no CTEs.
|
|
2177
2189
|
*/
|
|
2178
|
-
static compileCtes(ast, ctx,
|
|
2190
|
+
static compileCtes(ast, ctx, quoteIdentifier9, compileSelectAst, normalizeSelectAst, stripTrailingSemicolon) {
|
|
2179
2191
|
if (!ast.ctes || ast.ctes.length === 0) return "";
|
|
2180
2192
|
const hasRecursive = ast.ctes.some((cte) => cte.recursive);
|
|
2181
2193
|
const prefix = hasRecursive ? "WITH RECURSIVE " : "WITH ";
|
|
2182
2194
|
const cteDefs = ast.ctes.map((cte) => {
|
|
2183
|
-
const name =
|
|
2184
|
-
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) =>
|
|
2195
|
+
const name = quoteIdentifier9(cte.name);
|
|
2196
|
+
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) => quoteIdentifier9(c)).join(", ")})` : "";
|
|
2185
2197
|
const query = stripTrailingSemicolon(compileSelectAst(normalizeSelectAst(cte.query), ctx));
|
|
2186
2198
|
return `${name}${cols} AS (${query})`;
|
|
2187
2199
|
}).join(", ");
|
|
@@ -2734,15 +2746,15 @@ var PostgresTableFunctionStrategy = class extends StandardTableFunctionStrategy
|
|
|
2734
2746
|
this.registerOverrides();
|
|
2735
2747
|
}
|
|
2736
2748
|
registerOverrides() {
|
|
2737
|
-
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier:
|
|
2749
|
+
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier: quoteIdentifier9 }) => {
|
|
2738
2750
|
const lateral = node.lateral ?? true;
|
|
2739
2751
|
const withOrd = node.withOrdinality ?? false;
|
|
2740
2752
|
const base = `unnest(${compiledArgs.join(", ")})${withOrd ? " WITH ORDINALITY" : ""}`;
|
|
2741
2753
|
if (node.columnAliases?.length && !node.alias) {
|
|
2742
2754
|
throw new Error("tvf(ARRAY_UNNEST) with columnAliases requires an alias.");
|
|
2743
2755
|
}
|
|
2744
|
-
const alias = node.alias ? ` AS ${
|
|
2745
|
-
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(
|
|
2756
|
+
const alias = node.alias ? ` AS ${quoteIdentifier9(node.alias)}` : "";
|
|
2757
|
+
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(quoteIdentifier9).join(", ")})` : "";
|
|
2746
2758
|
return `${lateral ? "LATERAL " : ""}${base}${alias}${cols}`;
|
|
2747
2759
|
});
|
|
2748
2760
|
}
|
|
@@ -3241,15 +3253,15 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3241
3253
|
|
|
3242
3254
|
// src/core/dialect/sqlite/returning.ts
|
|
3243
3255
|
var SqliteReturningStrategy = class {
|
|
3244
|
-
compileReturning(returning, _ctx,
|
|
3256
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
3245
3257
|
void _ctx;
|
|
3246
3258
|
if (!returning || returning.length === 0) return "";
|
|
3247
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
3259
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier9)}`;
|
|
3248
3260
|
}
|
|
3249
|
-
formatReturningColumns(returning,
|
|
3261
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
3250
3262
|
return returning.map((column) => {
|
|
3251
|
-
const alias = column.alias ? ` AS ${
|
|
3252
|
-
return `${
|
|
3263
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
3264
|
+
return `${quoteIdentifier9(column.name)}${alias}`;
|
|
3253
3265
|
}).join(", ");
|
|
3254
3266
|
}
|
|
3255
3267
|
};
|
|
@@ -3463,22 +3475,22 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3463
3475
|
|
|
3464
3476
|
// src/core/dialect/mssql/output.ts
|
|
3465
3477
|
var MssqlOutputStrategy = class {
|
|
3466
|
-
compileReturning(returning, _ctx,
|
|
3478
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
3467
3479
|
void _ctx;
|
|
3468
|
-
return this.compileOutput(returning, "inserted",
|
|
3480
|
+
return this.compileOutput(returning, "inserted", quoteIdentifier9);
|
|
3469
3481
|
}
|
|
3470
|
-
compileOutput(returning, prefix,
|
|
3482
|
+
compileOutput(returning, prefix, quoteIdentifier9) {
|
|
3471
3483
|
if (!returning || returning.length === 0) return "";
|
|
3472
3484
|
const columns = returning.map((column) => {
|
|
3473
|
-
const alias = column.alias ? ` AS ${
|
|
3474
|
-
return `${prefix}.${
|
|
3485
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
3486
|
+
return `${prefix}.${quoteIdentifier9(column.name)}${alias}`;
|
|
3475
3487
|
}).join(", ");
|
|
3476
3488
|
return ` OUTPUT ${columns}`;
|
|
3477
3489
|
}
|
|
3478
|
-
formatReturningColumns(returning,
|
|
3490
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
3479
3491
|
return returning.map((column) => {
|
|
3480
|
-
const alias = column.alias ? ` AS ${
|
|
3481
|
-
return `${
|
|
3492
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
3493
|
+
return `${quoteIdentifier9(column.name)}${alias}`;
|
|
3482
3494
|
}).join(", ");
|
|
3483
3495
|
}
|
|
3484
3496
|
};
|
|
@@ -11549,6 +11561,59 @@ var deleteFrom = (target) => {
|
|
|
11549
11561
|
};
|
|
11550
11562
|
|
|
11551
11563
|
// src/core/ddl/sql-writing.ts
|
|
11564
|
+
var escapeSqlString = (value) => value.replace(/'/g, "''");
|
|
11565
|
+
var isRawDefault = (value) => typeof value === "object" && value !== null && "raw" in value && typeof value.raw === "string";
|
|
11566
|
+
var createLiteralFormatter = (options = {}) => {
|
|
11567
|
+
const {
|
|
11568
|
+
nullLiteral = "NULL",
|
|
11569
|
+
booleanTrue = "TRUE",
|
|
11570
|
+
booleanFalse = "FALSE",
|
|
11571
|
+
numberFormatter = (value) => Number.isFinite(value) ? String(value) : nullLiteral,
|
|
11572
|
+
dateFormatter = (value) => `'${escapeSqlString(value.toISOString())}'`,
|
|
11573
|
+
stringWrapper = (escaped) => `'${escaped}'`,
|
|
11574
|
+
jsonWrapper = (escaped) => `'${escaped}'`
|
|
11575
|
+
} = options;
|
|
11576
|
+
const wrapString = stringWrapper;
|
|
11577
|
+
const wrapJson = jsonWrapper;
|
|
11578
|
+
const format = (value) => {
|
|
11579
|
+
if (isRawDefault(value)) return value.raw;
|
|
11580
|
+
if (value === null) return nullLiteral;
|
|
11581
|
+
if (typeof value === "number") {
|
|
11582
|
+
return numberFormatter(value);
|
|
11583
|
+
}
|
|
11584
|
+
if (typeof value === "boolean") {
|
|
11585
|
+
return value ? booleanTrue : booleanFalse;
|
|
11586
|
+
}
|
|
11587
|
+
if (value instanceof Date) {
|
|
11588
|
+
return dateFormatter(value);
|
|
11589
|
+
}
|
|
11590
|
+
if (typeof value === "string") {
|
|
11591
|
+
return wrapString(escapeSqlString(value));
|
|
11592
|
+
}
|
|
11593
|
+
return wrapJson(escapeSqlString(JSON.stringify(value)));
|
|
11594
|
+
};
|
|
11595
|
+
return {
|
|
11596
|
+
formatLiteral: format
|
|
11597
|
+
};
|
|
11598
|
+
};
|
|
11599
|
+
var formatLiteral = (formatter, value) => formatter.formatLiteral(value);
|
|
11600
|
+
var quoteQualified = (quoter, identifier) => {
|
|
11601
|
+
const parts = identifier.split(".");
|
|
11602
|
+
return parts.map((part) => quoter.quoteIdentifier(part)).join(".");
|
|
11603
|
+
};
|
|
11604
|
+
var renderIndexColumns = (quoter, columns) => columns.map((col2) => {
|
|
11605
|
+
if (typeof col2 === "string") {
|
|
11606
|
+
return quoter.quoteIdentifier(col2);
|
|
11607
|
+
}
|
|
11608
|
+
const parts = [quoter.quoteIdentifier(col2.column)];
|
|
11609
|
+
if (col2.order) {
|
|
11610
|
+
parts.push(col2.order);
|
|
11611
|
+
}
|
|
11612
|
+
if (col2.nulls) {
|
|
11613
|
+
parts.push(`NULLS ${col2.nulls}`);
|
|
11614
|
+
}
|
|
11615
|
+
return parts.join(" ");
|
|
11616
|
+
}).join(", ");
|
|
11552
11617
|
var resolvePrimaryKey = (table) => {
|
|
11553
11618
|
if (Array.isArray(table.primaryKey) && table.primaryKey.length > 0) {
|
|
11554
11619
|
return table.primaryKey;
|
|
@@ -11685,13 +11750,11 @@ var deriveIndexName = (table, index) => {
|
|
|
11685
11750
|
var tableKey = (name, schema) => schema ? `${schema}.${name}` : name;
|
|
11686
11751
|
var mapTables = (schema) => {
|
|
11687
11752
|
const map = /* @__PURE__ */ new Map();
|
|
11688
|
-
for (const table of schema.tables)
|
|
11689
|
-
map.set(tableKey(table.name, table.schema), table);
|
|
11690
|
-
}
|
|
11753
|
+
for (const table of schema.tables) map.set(tableKey(table.name, table.schema), table);
|
|
11691
11754
|
return map;
|
|
11692
11755
|
};
|
|
11693
|
-
var buildAddColumnSql = (table,
|
|
11694
|
-
const column = table.columns[
|
|
11756
|
+
var buildAddColumnSql = (table, columnName, dialect) => {
|
|
11757
|
+
const column = table.columns[columnName];
|
|
11695
11758
|
const rendered = renderColumnDefinition(table, column, dialect);
|
|
11696
11759
|
return `ALTER TABLE ${dialect.formatTableName(table)} ADD ${rendered.sql};`;
|
|
11697
11760
|
};
|
|
@@ -11712,6 +11775,7 @@ var diffColumn = (expected, actual, dialect) => {
|
|
|
11712
11775
|
autoIncrementChanged: !!expected.autoIncrement !== !!actual.autoIncrement
|
|
11713
11776
|
};
|
|
11714
11777
|
};
|
|
11778
|
+
var unsupportedMutationWarning = (dialect, operation, target) => `Dialect "${dialect.name}" does not provide the ${operation} capability for ${target}; manual migration is required.`;
|
|
11715
11779
|
var diffSchema = (expectedTables, actualSchema, dialect, options = {}) => {
|
|
11716
11780
|
const allowDestructive = options.allowDestructive ?? false;
|
|
11717
11781
|
const plan = { changes: [], warnings: [] };
|
|
@@ -11730,87 +11794,121 @@ var diffSchema = (expectedTables, actualSchema, dialect, options = {}) => {
|
|
|
11730
11794
|
});
|
|
11731
11795
|
continue;
|
|
11732
11796
|
}
|
|
11733
|
-
const
|
|
11734
|
-
for (const
|
|
11735
|
-
if (!
|
|
11797
|
+
const actualColumns = new Map(actual.columns.map((column) => [column.name, column]));
|
|
11798
|
+
for (const columnName of Object.keys(table.columns)) {
|
|
11799
|
+
if (!actualColumns.has(columnName)) {
|
|
11736
11800
|
plan.changes.push({
|
|
11737
11801
|
kind: "addColumn",
|
|
11738
11802
|
table: key,
|
|
11739
|
-
description: `Add column ${
|
|
11740
|
-
statements: [buildAddColumnSql(table,
|
|
11803
|
+
description: `Add column ${columnName} to ${key}`,
|
|
11804
|
+
statements: [buildAddColumnSql(table, columnName, dialect)],
|
|
11741
11805
|
safe: true
|
|
11742
11806
|
});
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11807
|
+
continue;
|
|
11808
|
+
}
|
|
11809
|
+
const expectedColumn = table.columns[columnName];
|
|
11810
|
+
const actualColumn = actualColumns.get(columnName);
|
|
11811
|
+
const columnDiff = diffColumn(expectedColumn, actualColumn, dialect);
|
|
11812
|
+
const shouldAlter = columnDiff.typeChanged || columnDiff.nullabilityChanged || columnDiff.defaultChanged || columnDiff.autoIncrementChanged;
|
|
11813
|
+
if (shouldAlter) {
|
|
11814
|
+
const capability = dialect.mutations.alterColumn;
|
|
11815
|
+
if (capability) {
|
|
11816
|
+
const statements = capability.compile(table, expectedColumn, actualColumn, columnDiff);
|
|
11750
11817
|
if (statements.length > 0) {
|
|
11751
11818
|
plan.changes.push({
|
|
11752
11819
|
kind: "alterColumn",
|
|
11753
11820
|
table: key,
|
|
11754
|
-
description: `Alter column ${
|
|
11821
|
+
description: `Alter column ${columnName} on ${key}`,
|
|
11755
11822
|
statements,
|
|
11756
11823
|
safe: true
|
|
11757
11824
|
});
|
|
11758
11825
|
}
|
|
11759
|
-
const warning =
|
|
11826
|
+
const warning = capability.warning?.(table, expectedColumn, actualColumn, columnDiff);
|
|
11760
11827
|
if (warning) plan.warnings.push(warning);
|
|
11828
|
+
} else {
|
|
11829
|
+
plan.warnings.push(
|
|
11830
|
+
unsupportedMutationWarning(dialect, "ALTER COLUMN", `${key}.${columnName}`)
|
|
11831
|
+
);
|
|
11761
11832
|
}
|
|
11762
11833
|
}
|
|
11763
11834
|
}
|
|
11764
|
-
for (const
|
|
11765
|
-
if (
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11835
|
+
for (const columnName of actualColumns.keys()) {
|
|
11836
|
+
if (table.columns[columnName]) continue;
|
|
11837
|
+
const capability = dialect.mutations.dropColumn;
|
|
11838
|
+
const statements = allowDestructive && capability ? capability.compile(actual, columnName) : [];
|
|
11839
|
+
plan.changes.push({
|
|
11840
|
+
kind: "dropColumn",
|
|
11841
|
+
table: key,
|
|
11842
|
+
description: `Drop column ${columnName} from ${key}`,
|
|
11843
|
+
statements,
|
|
11844
|
+
safe: false
|
|
11845
|
+
});
|
|
11846
|
+
if (!capability) {
|
|
11847
|
+
plan.warnings.push(
|
|
11848
|
+
unsupportedMutationWarning(dialect, "DROP COLUMN", `${key}.${columnName}`)
|
|
11849
|
+
);
|
|
11850
|
+
} else {
|
|
11851
|
+
const warning = capability.warning?.(actual, columnName);
|
|
11774
11852
|
if (warning) plan.warnings.push(warning);
|
|
11775
11853
|
}
|
|
11776
11854
|
}
|
|
11777
11855
|
const expectedIndexes = table.indexes ?? [];
|
|
11778
11856
|
const actualIndexes = actual.indexes ?? [];
|
|
11779
|
-
const actualIndexMap = new Map(actualIndexes.map((
|
|
11780
|
-
for (const
|
|
11781
|
-
const name =
|
|
11857
|
+
const actualIndexMap = new Map(actualIndexes.map((index) => [index.name, index]));
|
|
11858
|
+
for (const index of expectedIndexes) {
|
|
11859
|
+
const name = index.name || deriveIndexName(table, index);
|
|
11782
11860
|
if (!actualIndexMap.has(name)) {
|
|
11783
11861
|
plan.changes.push({
|
|
11784
11862
|
kind: "addIndex",
|
|
11785
11863
|
table: key,
|
|
11786
11864
|
description: `Create index ${name} on ${key}`,
|
|
11787
|
-
statements: [dialect.renderIndex(table, { ...
|
|
11865
|
+
statements: [dialect.renderIndex(table, { ...index, name })],
|
|
11788
11866
|
safe: true
|
|
11789
11867
|
});
|
|
11790
11868
|
}
|
|
11791
11869
|
}
|
|
11792
|
-
for (const
|
|
11793
|
-
if (
|
|
11794
|
-
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11870
|
+
for (const index of actualIndexes) {
|
|
11871
|
+
if (!index.name) continue;
|
|
11872
|
+
const expected = expectedIndexes.find(
|
|
11873
|
+
(candidate) => (candidate.name || deriveIndexName(table, candidate)) === index.name
|
|
11874
|
+
);
|
|
11875
|
+
if (expected) continue;
|
|
11876
|
+
const capability = dialect.mutations.dropIndex;
|
|
11877
|
+
const statements = allowDestructive && capability ? capability.compile(actual, index.name) : [];
|
|
11878
|
+
plan.changes.push({
|
|
11879
|
+
kind: "dropIndex",
|
|
11880
|
+
table: key,
|
|
11881
|
+
description: `Drop index ${index.name} on ${key}`,
|
|
11882
|
+
statements,
|
|
11883
|
+
safe: false
|
|
11884
|
+
});
|
|
11885
|
+
if (!capability) {
|
|
11886
|
+
plan.warnings.push(
|
|
11887
|
+
unsupportedMutationWarning(dialect, "DROP INDEX", `${key}.${index.name}`)
|
|
11888
|
+
);
|
|
11889
|
+
} else {
|
|
11890
|
+
const warning = capability.warning?.(actual, index.name);
|
|
11891
|
+
if (warning) plan.warnings.push(warning);
|
|
11801
11892
|
}
|
|
11802
11893
|
}
|
|
11803
11894
|
}
|
|
11804
11895
|
for (const actual of actualSchema.tables) {
|
|
11805
11896
|
const key = tableKey(actual.name, actual.schema);
|
|
11806
|
-
if (
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11897
|
+
if (expectedTables.find((table) => tableKey(table.name, table.schema) === key)) continue;
|
|
11898
|
+
const capability = dialect.mutations.dropTable;
|
|
11899
|
+
const statements = allowDestructive && capability ? capability.compile(actual) : [];
|
|
11900
|
+
plan.changes.push({
|
|
11901
|
+
kind: "dropTable",
|
|
11902
|
+
table: key,
|
|
11903
|
+
description: `Drop table ${key}`,
|
|
11904
|
+
statements,
|
|
11905
|
+
safe: false
|
|
11906
|
+
});
|
|
11907
|
+
if (!capability) {
|
|
11908
|
+
plan.warnings.push(unsupportedMutationWarning(dialect, "DROP TABLE", key));
|
|
11909
|
+
} else {
|
|
11910
|
+
const warning = capability.warning?.(actual);
|
|
11911
|
+
if (warning) plan.warnings.push(warning);
|
|
11814
11912
|
}
|
|
11815
11913
|
}
|
|
11816
11914
|
return plan;
|
|
@@ -13756,6 +13854,604 @@ var introspectSchema = async (executor, dialect, options = {}) => {
|
|
|
13756
13854
|
return handler.introspect(ctx, options);
|
|
13757
13855
|
};
|
|
13758
13856
|
|
|
13857
|
+
// src/core/ddl/schema-dialect-composer.ts
|
|
13858
|
+
var composeSchemaDialect = (config) => {
|
|
13859
|
+
const quoteIdentifier9 = (id) => config.quoteIdentifier(id);
|
|
13860
|
+
const formatTableName = (table) => table.schema ? `${quoteIdentifier9(table.schema)}.${quoteIdentifier9(table.name)}` : quoteIdentifier9(table.name);
|
|
13861
|
+
let services;
|
|
13862
|
+
const renderDefault = (value, column) => config.renderDefault?.(value, column, services) ?? formatLiteral(config.literalFormatter, value);
|
|
13863
|
+
services = {
|
|
13864
|
+
name: config.name,
|
|
13865
|
+
quoteIdentifier: quoteIdentifier9,
|
|
13866
|
+
formatTableName,
|
|
13867
|
+
renderDefault
|
|
13868
|
+
};
|
|
13869
|
+
const mutations = config.mutations?.(services) ?? {};
|
|
13870
|
+
return {
|
|
13871
|
+
name: config.name,
|
|
13872
|
+
mutations,
|
|
13873
|
+
quoteIdentifier: quoteIdentifier9,
|
|
13874
|
+
formatTableName,
|
|
13875
|
+
renderColumnType: (column) => config.renderColumnType(column, services),
|
|
13876
|
+
renderDefault,
|
|
13877
|
+
renderAutoIncrement: (column, table) => config.renderAutoIncrement(column, table, services),
|
|
13878
|
+
renderReference(ref, table) {
|
|
13879
|
+
const parts = [
|
|
13880
|
+
"REFERENCES",
|
|
13881
|
+
quoteQualified({ quoteIdentifier: quoteIdentifier9 }, ref.table),
|
|
13882
|
+
`(${quoteIdentifier9(ref.column)})`
|
|
13883
|
+
];
|
|
13884
|
+
if (ref.onDelete) parts.push("ON DELETE", ref.onDelete);
|
|
13885
|
+
if (ref.onUpdate) parts.push("ON UPDATE", ref.onUpdate);
|
|
13886
|
+
const suffix = config.renderReferenceSuffix?.(ref, table, services);
|
|
13887
|
+
if (suffix) parts.push(suffix);
|
|
13888
|
+
return parts.join(" ");
|
|
13889
|
+
},
|
|
13890
|
+
renderIndex: (table, index) => config.renderIndex(table, index, services),
|
|
13891
|
+
renderTableOptions: (table) => config.renderTableOptions?.(table, services),
|
|
13892
|
+
supportsPartialIndexes: () => config.supportsPartialIndexes ?? false,
|
|
13893
|
+
preferInlinePkAutoincrement: (column, table, pk) => config.preferInlinePkAutoincrement?.(column, table, pk, services) ?? false
|
|
13894
|
+
};
|
|
13895
|
+
};
|
|
13896
|
+
var createStandardDropTableCapability = (services) => ({
|
|
13897
|
+
compile: (table) => [`DROP TABLE IF EXISTS ${services.formatTableName(table)};`]
|
|
13898
|
+
});
|
|
13899
|
+
var createStandardDropColumnCapability = (services) => ({
|
|
13900
|
+
compile: (table, column) => [
|
|
13901
|
+
`ALTER TABLE ${services.formatTableName(table)} DROP COLUMN ${services.quoteIdentifier(column)};`
|
|
13902
|
+
]
|
|
13903
|
+
});
|
|
13904
|
+
|
|
13905
|
+
// src/core/ddl/dialects/postgres-schema-dialect.ts
|
|
13906
|
+
var quoteIdentifier5 = (id) => `"${id}"`;
|
|
13907
|
+
var literalFormatter = createLiteralFormatter();
|
|
13908
|
+
var renderPostgresColumnType = (column, services) => {
|
|
13909
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
13910
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
13911
|
+
const type = normalizeColumnType(column.type);
|
|
13912
|
+
switch (type) {
|
|
13913
|
+
case "int":
|
|
13914
|
+
case "integer":
|
|
13915
|
+
return "integer";
|
|
13916
|
+
case "bigint":
|
|
13917
|
+
return "bigint";
|
|
13918
|
+
case "uuid":
|
|
13919
|
+
return "uuid";
|
|
13920
|
+
case "boolean":
|
|
13921
|
+
return "boolean";
|
|
13922
|
+
case "json":
|
|
13923
|
+
return "jsonb";
|
|
13924
|
+
case "decimal":
|
|
13925
|
+
return column.args?.length ? `numeric(${column.args[0]}, ${column.args[1] ?? 0})` : "numeric";
|
|
13926
|
+
case "float":
|
|
13927
|
+
case "double":
|
|
13928
|
+
return "double precision";
|
|
13929
|
+
case "timestamptz":
|
|
13930
|
+
return "timestamptz";
|
|
13931
|
+
case "timestamp":
|
|
13932
|
+
return "timestamp";
|
|
13933
|
+
case "date":
|
|
13934
|
+
return "date";
|
|
13935
|
+
case "datetime":
|
|
13936
|
+
return "timestamp";
|
|
13937
|
+
case "varchar":
|
|
13938
|
+
return column.args?.length ? `varchar(${column.args[0]})` : "varchar";
|
|
13939
|
+
case "text":
|
|
13940
|
+
return "text";
|
|
13941
|
+
case "enum":
|
|
13942
|
+
return "text";
|
|
13943
|
+
case "binary":
|
|
13944
|
+
case "varbinary":
|
|
13945
|
+
case "blob":
|
|
13946
|
+
case "bytea":
|
|
13947
|
+
return "bytea";
|
|
13948
|
+
case "vector":
|
|
13949
|
+
return column.vectorOptions?.elementType === "float16" ? `halfvec(${column.vectorOptions.dimensions})` : column.args?.length ? `vector(${column.args[0]})` : "vector";
|
|
13950
|
+
case "halfvec":
|
|
13951
|
+
return column.args?.length ? `halfvec(${column.args[0]})` : "halfvec";
|
|
13952
|
+
default:
|
|
13953
|
+
return renderTypeWithArgs(String(type).toLowerCase(), column.args);
|
|
13954
|
+
}
|
|
13955
|
+
};
|
|
13956
|
+
var renderPostgresIndex = (table, index, services) => {
|
|
13957
|
+
const name = index.name || deriveIndexName(table, index);
|
|
13958
|
+
let columns = renderIndexColumns(services, index.columns);
|
|
13959
|
+
if (index.ops) columns = `${columns} ${index.ops}`;
|
|
13960
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
13961
|
+
const using = index.using ? ` USING ${index.using}` : "";
|
|
13962
|
+
let withClause = "";
|
|
13963
|
+
if (index.with) {
|
|
13964
|
+
if (typeof index.with === "string") {
|
|
13965
|
+
withClause = ` WITH (${index.with})`;
|
|
13966
|
+
} else {
|
|
13967
|
+
const params = Object.entries(index.with).map(([key, value]) => `${key} = ${value}`).join(", ");
|
|
13968
|
+
withClause = ` WITH (${params})`;
|
|
13969
|
+
}
|
|
13970
|
+
}
|
|
13971
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
13972
|
+
return `CREATE ${unique}INDEX IF NOT EXISTS ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)}${using} (${columns})${withClause}${where};`;
|
|
13973
|
+
};
|
|
13974
|
+
var createPostgresSchemaDialect = () => composeSchemaDialect({
|
|
13975
|
+
name: "postgres",
|
|
13976
|
+
quoteIdentifier: quoteIdentifier5,
|
|
13977
|
+
literalFormatter,
|
|
13978
|
+
renderColumnType: renderPostgresColumnType,
|
|
13979
|
+
renderAutoIncrement: (column) => {
|
|
13980
|
+
if (!column.autoIncrement) return void 0;
|
|
13981
|
+
const strategy = column.generated === "always" ? "GENERATED ALWAYS" : "GENERATED BY DEFAULT";
|
|
13982
|
+
return `${strategy} AS IDENTITY`;
|
|
13983
|
+
},
|
|
13984
|
+
renderIndex: renderPostgresIndex,
|
|
13985
|
+
renderReferenceSuffix: (ref) => ref.deferrable ? "DEFERRABLE INITIALLY DEFERRED" : void 0,
|
|
13986
|
+
supportsPartialIndexes: true,
|
|
13987
|
+
mutations: (services) => ({
|
|
13988
|
+
dropTable: createStandardDropTableCapability(services),
|
|
13989
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
13990
|
+
dropIndex: {
|
|
13991
|
+
compile(table, index) {
|
|
13992
|
+
const qualified = table.schema ? `${services.quoteIdentifier(table.schema)}.${services.quoteIdentifier(index)}` : services.quoteIdentifier(index);
|
|
13993
|
+
return [`DROP INDEX IF EXISTS ${qualified};`];
|
|
13994
|
+
}
|
|
13995
|
+
},
|
|
13996
|
+
alterColumn: {
|
|
13997
|
+
compile(table, column, actualColumn, diff) {
|
|
13998
|
+
void actualColumn;
|
|
13999
|
+
const statements = [];
|
|
14000
|
+
const tableName = services.formatTableName(table);
|
|
14001
|
+
const columnName = services.quoteIdentifier(column.name);
|
|
14002
|
+
if (diff.typeChanged) {
|
|
14003
|
+
statements.push(
|
|
14004
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${renderPostgresColumnType(column, services)};`
|
|
14005
|
+
);
|
|
14006
|
+
}
|
|
14007
|
+
if (diff.defaultChanged) {
|
|
14008
|
+
statements.push(
|
|
14009
|
+
column.default === void 0 ? `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT;` : `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${services.renderDefault(column.default, column)};`
|
|
14010
|
+
);
|
|
14011
|
+
}
|
|
14012
|
+
if (diff.nullabilityChanged) {
|
|
14013
|
+
statements.push(
|
|
14014
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} ${column.notNull ? "SET" : "DROP"} NOT NULL;`
|
|
14015
|
+
);
|
|
14016
|
+
}
|
|
14017
|
+
if (diff.autoIncrementChanged) {
|
|
14018
|
+
if (column.autoIncrement) {
|
|
14019
|
+
const strategy = column.generated === "always" ? "ALWAYS" : "BY DEFAULT";
|
|
14020
|
+
statements.push(
|
|
14021
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} ADD GENERATED ${strategy} AS IDENTITY;`
|
|
14022
|
+
);
|
|
14023
|
+
} else {
|
|
14024
|
+
statements.push(`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP IDENTITY IF EXISTS;`);
|
|
14025
|
+
}
|
|
14026
|
+
}
|
|
14027
|
+
return statements;
|
|
14028
|
+
},
|
|
14029
|
+
warning(table, column, actualColumn, diff) {
|
|
14030
|
+
void table;
|
|
14031
|
+
void column;
|
|
14032
|
+
void actualColumn;
|
|
14033
|
+
return diff.autoIncrementChanged ? "Altering identity properties may fail if an existing sequence is attached; verify generated column state." : void 0;
|
|
14034
|
+
}
|
|
14035
|
+
}
|
|
14036
|
+
})
|
|
14037
|
+
});
|
|
14038
|
+
var PostgresSchemaDialect = class {
|
|
14039
|
+
delegate = createPostgresSchemaDialect();
|
|
14040
|
+
name = this.delegate.name;
|
|
14041
|
+
mutations = this.delegate.mutations;
|
|
14042
|
+
quoteIdentifier(id) {
|
|
14043
|
+
return this.delegate.quoteIdentifier(id);
|
|
14044
|
+
}
|
|
14045
|
+
formatTableName(table) {
|
|
14046
|
+
return this.delegate.formatTableName(table);
|
|
14047
|
+
}
|
|
14048
|
+
renderColumnType(column) {
|
|
14049
|
+
return this.delegate.renderColumnType(column);
|
|
14050
|
+
}
|
|
14051
|
+
renderDefault(value, column) {
|
|
14052
|
+
return this.delegate.renderDefault(value, column);
|
|
14053
|
+
}
|
|
14054
|
+
renderAutoIncrement(column, table) {
|
|
14055
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
14056
|
+
}
|
|
14057
|
+
renderReference(ref, table) {
|
|
14058
|
+
return this.delegate.renderReference(ref, table);
|
|
14059
|
+
}
|
|
14060
|
+
renderIndex(table, index) {
|
|
14061
|
+
return this.delegate.renderIndex(table, index);
|
|
14062
|
+
}
|
|
14063
|
+
renderTableOptions(table) {
|
|
14064
|
+
return this.delegate.renderTableOptions(table);
|
|
14065
|
+
}
|
|
14066
|
+
supportsPartialIndexes() {
|
|
14067
|
+
return this.delegate.supportsPartialIndexes();
|
|
14068
|
+
}
|
|
14069
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
14070
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
14071
|
+
}
|
|
14072
|
+
};
|
|
14073
|
+
|
|
14074
|
+
// src/core/ddl/dialects/mysql-schema-dialect.ts
|
|
14075
|
+
var quoteIdentifier6 = (id) => `\`${id}\``;
|
|
14076
|
+
var literalFormatter2 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
14077
|
+
var renderMySqlColumnType = (column, services) => {
|
|
14078
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
14079
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
14080
|
+
const type = normalizeColumnType(column.type);
|
|
14081
|
+
switch (type) {
|
|
14082
|
+
case "int":
|
|
14083
|
+
case "integer":
|
|
14084
|
+
return "INT";
|
|
14085
|
+
case "bigint":
|
|
14086
|
+
return "BIGINT";
|
|
14087
|
+
case "uuid":
|
|
14088
|
+
return "CHAR(36)";
|
|
14089
|
+
case "boolean":
|
|
14090
|
+
return "TINYINT(1)";
|
|
14091
|
+
case "json":
|
|
14092
|
+
return "JSON";
|
|
14093
|
+
case "decimal":
|
|
14094
|
+
return column.args?.length ? `DECIMAL(${column.args[0]},${column.args[1] ?? 0})` : "DECIMAL";
|
|
14095
|
+
case "float":
|
|
14096
|
+
return column.args?.length ? `FLOAT(${column.args[0]})` : "FLOAT";
|
|
14097
|
+
case "double":
|
|
14098
|
+
return "DOUBLE";
|
|
14099
|
+
case "timestamptz":
|
|
14100
|
+
case "timestamp":
|
|
14101
|
+
return "TIMESTAMP";
|
|
14102
|
+
case "datetime":
|
|
14103
|
+
return "DATETIME";
|
|
14104
|
+
case "date":
|
|
14105
|
+
return "DATE";
|
|
14106
|
+
case "varchar":
|
|
14107
|
+
return column.args?.length ? `VARCHAR(${column.args[0]})` : "VARCHAR(255)";
|
|
14108
|
+
case "text":
|
|
14109
|
+
return "TEXT";
|
|
14110
|
+
case "binary":
|
|
14111
|
+
return column.args?.length ? `BINARY(${column.args[0]})` : "BINARY(255)";
|
|
14112
|
+
case "varbinary":
|
|
14113
|
+
return column.args?.length ? `VARBINARY(${column.args[0]})` : "VARBINARY(255)";
|
|
14114
|
+
case "blob":
|
|
14115
|
+
case "bytea":
|
|
14116
|
+
return "BLOB";
|
|
14117
|
+
case "enum":
|
|
14118
|
+
return column.args?.length ? `ENUM(${column.args.map((value) => `'${escapeSqlString(String(value))}'`).join(",")})` : "ENUM";
|
|
14119
|
+
case "vector":
|
|
14120
|
+
case "halfvec": {
|
|
14121
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
14122
|
+
return `VECTOR(${dimensions})`;
|
|
14123
|
+
}
|
|
14124
|
+
default:
|
|
14125
|
+
return renderTypeWithArgs(String(type).toUpperCase(), column.args);
|
|
14126
|
+
}
|
|
14127
|
+
};
|
|
14128
|
+
var createMySqlSchemaDialect = () => {
|
|
14129
|
+
let dialect;
|
|
14130
|
+
dialect = composeSchemaDialect({
|
|
14131
|
+
name: "mysql",
|
|
14132
|
+
quoteIdentifier: quoteIdentifier6,
|
|
14133
|
+
literalFormatter: literalFormatter2,
|
|
14134
|
+
renderColumnType: renderMySqlColumnType,
|
|
14135
|
+
renderAutoIncrement: (column) => column.autoIncrement ? "AUTO_INCREMENT" : void 0,
|
|
14136
|
+
renderIndex(table, index, services) {
|
|
14137
|
+
if (index.where) throw new Error("MySQL does not support partial/filtered indexes");
|
|
14138
|
+
const name = index.name || deriveIndexName(table, index);
|
|
14139
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
14140
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
14141
|
+
return `CREATE ${unique}INDEX ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns});`;
|
|
14142
|
+
},
|
|
14143
|
+
renderTableOptions(table) {
|
|
14144
|
+
const parts = [];
|
|
14145
|
+
if (table.engine) parts.push(`ENGINE=${table.engine}`);
|
|
14146
|
+
if (table.charset) parts.push(`DEFAULT CHARSET=${table.charset}`);
|
|
14147
|
+
if (table.collation) parts.push(`COLLATE=${table.collation}`);
|
|
14148
|
+
return parts.length ? parts.join(" ") : void 0;
|
|
14149
|
+
},
|
|
14150
|
+
mutations: (services) => ({
|
|
14151
|
+
dropTable: createStandardDropTableCapability(services),
|
|
14152
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
14153
|
+
dropIndex: {
|
|
14154
|
+
compile: (table, index) => [
|
|
14155
|
+
`DROP INDEX ${services.quoteIdentifier(index)} ON ${services.formatTableName(table)};`
|
|
14156
|
+
]
|
|
14157
|
+
},
|
|
14158
|
+
alterColumn: {
|
|
14159
|
+
compile(table, column, actualColumn, diff) {
|
|
14160
|
+
void actualColumn;
|
|
14161
|
+
void diff;
|
|
14162
|
+
const rendered = renderColumnDefinition(table, column, dialect);
|
|
14163
|
+
return [`ALTER TABLE ${services.formatTableName(table)} MODIFY COLUMN ${rendered.sql};`];
|
|
14164
|
+
}
|
|
14165
|
+
}
|
|
14166
|
+
})
|
|
14167
|
+
});
|
|
14168
|
+
return dialect;
|
|
14169
|
+
};
|
|
14170
|
+
var MySqlSchemaDialect = class {
|
|
14171
|
+
delegate = createMySqlSchemaDialect();
|
|
14172
|
+
name = this.delegate.name;
|
|
14173
|
+
mutations = this.delegate.mutations;
|
|
14174
|
+
quoteIdentifier(id) {
|
|
14175
|
+
return this.delegate.quoteIdentifier(id);
|
|
14176
|
+
}
|
|
14177
|
+
formatTableName(table) {
|
|
14178
|
+
return this.delegate.formatTableName(table);
|
|
14179
|
+
}
|
|
14180
|
+
renderColumnType(column) {
|
|
14181
|
+
return this.delegate.renderColumnType(column);
|
|
14182
|
+
}
|
|
14183
|
+
renderDefault(value, column) {
|
|
14184
|
+
return this.delegate.renderDefault(value, column);
|
|
14185
|
+
}
|
|
14186
|
+
renderAutoIncrement(column, table) {
|
|
14187
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
14188
|
+
}
|
|
14189
|
+
renderReference(ref, table) {
|
|
14190
|
+
return this.delegate.renderReference(ref, table);
|
|
14191
|
+
}
|
|
14192
|
+
renderIndex(table, index) {
|
|
14193
|
+
return this.delegate.renderIndex(table, index);
|
|
14194
|
+
}
|
|
14195
|
+
renderTableOptions(table) {
|
|
14196
|
+
return this.delegate.renderTableOptions(table);
|
|
14197
|
+
}
|
|
14198
|
+
supportsPartialIndexes() {
|
|
14199
|
+
return this.delegate.supportsPartialIndexes();
|
|
14200
|
+
}
|
|
14201
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
14202
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
14203
|
+
}
|
|
14204
|
+
};
|
|
14205
|
+
|
|
14206
|
+
// src/core/ddl/dialects/sqlite-schema-dialect.ts
|
|
14207
|
+
var quoteIdentifier7 = (id) => `"${id}"`;
|
|
14208
|
+
var literalFormatter3 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
14209
|
+
var renderSqliteColumnType = (column, services) => {
|
|
14210
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
14211
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
14212
|
+
const type = normalizeColumnType(column.type);
|
|
14213
|
+
switch (type) {
|
|
14214
|
+
case "int":
|
|
14215
|
+
case "integer":
|
|
14216
|
+
case "bigint":
|
|
14217
|
+
case "boolean":
|
|
14218
|
+
return "INTEGER";
|
|
14219
|
+
case "decimal":
|
|
14220
|
+
case "float":
|
|
14221
|
+
case "double":
|
|
14222
|
+
return "REAL";
|
|
14223
|
+
case "date":
|
|
14224
|
+
case "datetime":
|
|
14225
|
+
case "timestamp":
|
|
14226
|
+
case "timestamptz":
|
|
14227
|
+
case "varchar":
|
|
14228
|
+
case "text":
|
|
14229
|
+
case "json":
|
|
14230
|
+
case "uuid":
|
|
14231
|
+
case "enum":
|
|
14232
|
+
return "TEXT";
|
|
14233
|
+
case "binary":
|
|
14234
|
+
case "varbinary":
|
|
14235
|
+
case "blob":
|
|
14236
|
+
case "bytea":
|
|
14237
|
+
return "BLOB";
|
|
14238
|
+
case "halfvec": {
|
|
14239
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
14240
|
+
return `float16[${dimensions}]`;
|
|
14241
|
+
}
|
|
14242
|
+
case "vector": {
|
|
14243
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
14244
|
+
const elementType = column.vectorOptions?.elementType === "float16" ? "float16" : "float32";
|
|
14245
|
+
return `${elementType}[${dimensions}]`;
|
|
14246
|
+
}
|
|
14247
|
+
default:
|
|
14248
|
+
return "TEXT";
|
|
14249
|
+
}
|
|
14250
|
+
};
|
|
14251
|
+
var createSqliteSchemaDialect = () => composeSchemaDialect({
|
|
14252
|
+
name: "sqlite",
|
|
14253
|
+
quoteIdentifier: quoteIdentifier7,
|
|
14254
|
+
literalFormatter: literalFormatter3,
|
|
14255
|
+
renderColumnType: renderSqliteColumnType,
|
|
14256
|
+
renderAutoIncrement(column, table) {
|
|
14257
|
+
const primaryKey = resolvePrimaryKey(table);
|
|
14258
|
+
return column.autoIncrement && primaryKey.length === 1 && primaryKey[0] === column.name ? "PRIMARY KEY AUTOINCREMENT" : void 0;
|
|
14259
|
+
},
|
|
14260
|
+
preferInlinePkAutoincrement: (column, table, primaryKey) => {
|
|
14261
|
+
void table;
|
|
14262
|
+
return !!(column.autoIncrement && primaryKey.length === 1 && primaryKey[0] === column.name);
|
|
14263
|
+
},
|
|
14264
|
+
renderIndex(table, index, services) {
|
|
14265
|
+
const name = index.name || deriveIndexName(table, index);
|
|
14266
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
14267
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
14268
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
14269
|
+
return `CREATE ${unique}INDEX IF NOT EXISTS ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns})${where};`;
|
|
14270
|
+
},
|
|
14271
|
+
supportsPartialIndexes: true,
|
|
14272
|
+
mutations: (services) => ({
|
|
14273
|
+
dropTable: createStandardDropTableCapability(services),
|
|
14274
|
+
dropIndex: {
|
|
14275
|
+
compile: (_table, index) => [`DROP INDEX IF EXISTS ${services.quoteIdentifier(index)};`]
|
|
14276
|
+
}
|
|
14277
|
+
})
|
|
14278
|
+
});
|
|
14279
|
+
var SQLiteSchemaDialect = class {
|
|
14280
|
+
delegate = createSqliteSchemaDialect();
|
|
14281
|
+
name = this.delegate.name;
|
|
14282
|
+
mutations = this.delegate.mutations;
|
|
14283
|
+
quoteIdentifier(id) {
|
|
14284
|
+
return this.delegate.quoteIdentifier(id);
|
|
14285
|
+
}
|
|
14286
|
+
formatTableName(table) {
|
|
14287
|
+
return this.delegate.formatTableName(table);
|
|
14288
|
+
}
|
|
14289
|
+
renderColumnType(column) {
|
|
14290
|
+
return this.delegate.renderColumnType(column);
|
|
14291
|
+
}
|
|
14292
|
+
renderDefault(value, column) {
|
|
14293
|
+
return this.delegate.renderDefault(value, column);
|
|
14294
|
+
}
|
|
14295
|
+
renderAutoIncrement(column, table) {
|
|
14296
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
14297
|
+
}
|
|
14298
|
+
renderReference(ref, table) {
|
|
14299
|
+
return this.delegate.renderReference(ref, table);
|
|
14300
|
+
}
|
|
14301
|
+
renderIndex(table, index) {
|
|
14302
|
+
return this.delegate.renderIndex(table, index);
|
|
14303
|
+
}
|
|
14304
|
+
renderTableOptions(table) {
|
|
14305
|
+
return this.delegate.renderTableOptions(table);
|
|
14306
|
+
}
|
|
14307
|
+
supportsPartialIndexes() {
|
|
14308
|
+
return this.delegate.supportsPartialIndexes();
|
|
14309
|
+
}
|
|
14310
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
14311
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
14312
|
+
}
|
|
14313
|
+
};
|
|
14314
|
+
|
|
14315
|
+
// src/core/ddl/dialects/mssql-schema-dialect.ts
|
|
14316
|
+
var quoteIdentifier8 = (id) => `[${id.replace(/]/g, "]]")}]`;
|
|
14317
|
+
var literalFormatter4 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
14318
|
+
var renderMssqlColumnType = (column, services) => {
|
|
14319
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
14320
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
14321
|
+
const type = normalizeColumnType(column.type);
|
|
14322
|
+
switch (type) {
|
|
14323
|
+
case "int":
|
|
14324
|
+
case "integer":
|
|
14325
|
+
return "INT";
|
|
14326
|
+
case "bigint":
|
|
14327
|
+
return "BIGINT";
|
|
14328
|
+
case "uuid":
|
|
14329
|
+
return "UNIQUEIDENTIFIER";
|
|
14330
|
+
case "boolean":
|
|
14331
|
+
return "BIT";
|
|
14332
|
+
case "json":
|
|
14333
|
+
return "NVARCHAR(MAX)";
|
|
14334
|
+
case "decimal":
|
|
14335
|
+
return column.args?.length ? `DECIMAL(${column.args[0]},${column.args[1] ?? 0})` : "DECIMAL(18,0)";
|
|
14336
|
+
case "float":
|
|
14337
|
+
case "double":
|
|
14338
|
+
return "FLOAT";
|
|
14339
|
+
case "timestamptz":
|
|
14340
|
+
case "timestamp":
|
|
14341
|
+
case "datetime":
|
|
14342
|
+
return "DATETIME2";
|
|
14343
|
+
case "date":
|
|
14344
|
+
return "DATE";
|
|
14345
|
+
case "varchar":
|
|
14346
|
+
return column.args?.length ? `NVARCHAR(${column.args[0]})` : "NVARCHAR(255)";
|
|
14347
|
+
case "text":
|
|
14348
|
+
return "NVARCHAR(MAX)";
|
|
14349
|
+
case "binary": {
|
|
14350
|
+
const length2 = column.args?.[0];
|
|
14351
|
+
return length2 !== void 0 ? `BINARY(${length2})` : "BINARY(255)";
|
|
14352
|
+
}
|
|
14353
|
+
case "varbinary": {
|
|
14354
|
+
const length2 = column.args?.[0];
|
|
14355
|
+
if (typeof length2 === "string" && length2.toLowerCase() === "max") return "VARBINARY(MAX)";
|
|
14356
|
+
return length2 !== void 0 ? `VARBINARY(${length2})` : "VARBINARY(255)";
|
|
14357
|
+
}
|
|
14358
|
+
case "blob":
|
|
14359
|
+
case "bytea":
|
|
14360
|
+
return "VARBINARY(MAX)";
|
|
14361
|
+
case "enum":
|
|
14362
|
+
return "NVARCHAR(255)";
|
|
14363
|
+
case "vector": {
|
|
14364
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
14365
|
+
const elementType = column.vectorOptions?.elementType;
|
|
14366
|
+
return elementType ? `VECTOR(${dimensions}, ${elementType})` : `VECTOR(${dimensions})`;
|
|
14367
|
+
}
|
|
14368
|
+
case "halfvec": {
|
|
14369
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
14370
|
+
return `VECTOR(${dimensions}, float16)`;
|
|
14371
|
+
}
|
|
14372
|
+
default:
|
|
14373
|
+
return renderTypeWithArgs(String(type).toUpperCase(), column.args);
|
|
14374
|
+
}
|
|
14375
|
+
};
|
|
14376
|
+
var createMssqlSchemaDialect = () => composeSchemaDialect({
|
|
14377
|
+
name: "mssql",
|
|
14378
|
+
quoteIdentifier: quoteIdentifier8,
|
|
14379
|
+
literalFormatter: literalFormatter4,
|
|
14380
|
+
renderColumnType: renderMssqlColumnType,
|
|
14381
|
+
renderAutoIncrement: (column) => column.autoIncrement ? "IDENTITY(1,1)" : void 0,
|
|
14382
|
+
renderIndex(table, index, services) {
|
|
14383
|
+
const name = index.name || deriveIndexName(table, index);
|
|
14384
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
14385
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
14386
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
14387
|
+
return `CREATE ${unique}INDEX ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns})${where};`;
|
|
14388
|
+
},
|
|
14389
|
+
supportsPartialIndexes: true,
|
|
14390
|
+
mutations: (services) => ({
|
|
14391
|
+
dropTable: createStandardDropTableCapability(services),
|
|
14392
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
14393
|
+
dropIndex: {
|
|
14394
|
+
compile: (table, index) => [
|
|
14395
|
+
`DROP INDEX ${services.quoteIdentifier(index)} ON ${services.formatTableName(table)};`
|
|
14396
|
+
]
|
|
14397
|
+
},
|
|
14398
|
+
alterColumn: {
|
|
14399
|
+
compile(table, column, actualColumn, diff) {
|
|
14400
|
+
void actualColumn;
|
|
14401
|
+
const statements = [];
|
|
14402
|
+
if (diff.typeChanged || diff.nullabilityChanged) {
|
|
14403
|
+
const nullability = column.notNull ? "NOT NULL" : "NULL";
|
|
14404
|
+
statements.push(
|
|
14405
|
+
`ALTER TABLE ${services.formatTableName(table)} ALTER COLUMN ${services.quoteIdentifier(column.name)} ${renderMssqlColumnType(column, services)} ${nullability};`
|
|
14406
|
+
);
|
|
14407
|
+
}
|
|
14408
|
+
return statements;
|
|
14409
|
+
},
|
|
14410
|
+
warning(table, column, actualColumn, diff) {
|
|
14411
|
+
void table;
|
|
14412
|
+
void column;
|
|
14413
|
+
void actualColumn;
|
|
14414
|
+
return diff.defaultChanged || diff.autoIncrementChanged ? "Altering defaults or identity on MSSQL is not automated (requires dropping/adding default or identity constraints manually)." : void 0;
|
|
14415
|
+
}
|
|
14416
|
+
}
|
|
14417
|
+
})
|
|
14418
|
+
});
|
|
14419
|
+
var MSSqlSchemaDialect = class {
|
|
14420
|
+
delegate = createMssqlSchemaDialect();
|
|
14421
|
+
name = this.delegate.name;
|
|
14422
|
+
mutations = this.delegate.mutations;
|
|
14423
|
+
quoteIdentifier(id) {
|
|
14424
|
+
return this.delegate.quoteIdentifier(id);
|
|
14425
|
+
}
|
|
14426
|
+
formatTableName(table) {
|
|
14427
|
+
return this.delegate.formatTableName(table);
|
|
14428
|
+
}
|
|
14429
|
+
renderColumnType(column) {
|
|
14430
|
+
return this.delegate.renderColumnType(column);
|
|
14431
|
+
}
|
|
14432
|
+
renderDefault(value, column) {
|
|
14433
|
+
return this.delegate.renderDefault(value, column);
|
|
14434
|
+
}
|
|
14435
|
+
renderAutoIncrement(column, table) {
|
|
14436
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
14437
|
+
}
|
|
14438
|
+
renderReference(ref, table) {
|
|
14439
|
+
return this.delegate.renderReference(ref, table);
|
|
14440
|
+
}
|
|
14441
|
+
renderIndex(table, index) {
|
|
14442
|
+
return this.delegate.renderIndex(table, index);
|
|
14443
|
+
}
|
|
14444
|
+
renderTableOptions(table) {
|
|
14445
|
+
return this.delegate.renderTableOptions(table);
|
|
14446
|
+
}
|
|
14447
|
+
supportsPartialIndexes() {
|
|
14448
|
+
return this.delegate.supportsPartialIndexes();
|
|
14449
|
+
}
|
|
14450
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
14451
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
14452
|
+
}
|
|
14453
|
+
};
|
|
14454
|
+
|
|
13759
14455
|
// src/core/functions/numeric.ts
|
|
13760
14456
|
var isColumnDef2 = (val) => !!val && typeof val === "object" && "type" in val && "name" in val;
|
|
13761
14457
|
var toOperand3 = (input) => {
|
|
@@ -22253,6 +22949,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22253
22949
|
KeyvCacheAdapter,
|
|
22254
22950
|
Length,
|
|
22255
22951
|
Lower,
|
|
22952
|
+
MSSqlSchemaDialect,
|
|
22256
22953
|
MemoryCacheAdapter,
|
|
22257
22954
|
MorphMany,
|
|
22258
22955
|
MorphOne,
|
|
@@ -22265,6 +22962,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22265
22962
|
MssqlUpdateCompiler,
|
|
22266
22963
|
MySqlDialect,
|
|
22267
22964
|
MySqlProcedureCompiler,
|
|
22965
|
+
MySqlSchemaDialect,
|
|
22268
22966
|
MySqlUpsertStrategy,
|
|
22269
22967
|
NestedSetStrategy,
|
|
22270
22968
|
NoReturningStrategy,
|
|
@@ -22276,6 +22974,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22276
22974
|
PostgresDialect,
|
|
22277
22975
|
PostgresProcedureCompiler,
|
|
22278
22976
|
PostgresReturningStrategy,
|
|
22977
|
+
PostgresSchemaDialect,
|
|
22279
22978
|
PostgresUpsertStrategy,
|
|
22280
22979
|
PrimaryKey,
|
|
22281
22980
|
ProcedureCallBuilder,
|
|
@@ -22283,6 +22982,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22283
22982
|
QueryCacheManager,
|
|
22284
22983
|
RedisCacheAdapter,
|
|
22285
22984
|
RelationKinds,
|
|
22985
|
+
SQLiteSchemaDialect,
|
|
22286
22986
|
STANDARD_COLUMN_TYPES,
|
|
22287
22987
|
SelectQueryBuilder,
|
|
22288
22988
|
SqlServerDialect,
|
|
@@ -22366,6 +23066,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22366
23066
|
columnToOpenApiSchema,
|
|
22367
23067
|
columnTypeToOpenApiFormat,
|
|
22368
23068
|
columnTypeToOpenApiType,
|
|
23069
|
+
composeSchemaDialect,
|
|
22369
23070
|
composeSqlDialect,
|
|
22370
23071
|
computePaginationMetadata,
|
|
22371
23072
|
computeSchemaHash,
|
|
@@ -22384,19 +23085,26 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22384
23085
|
createEntityFromRow,
|
|
22385
23086
|
createEntityProxy,
|
|
22386
23087
|
createExecutorFromQueryRunner,
|
|
23088
|
+
createLiteralFormatter,
|
|
22387
23089
|
createMssqlCompilerSet,
|
|
22388
23090
|
createMssqlExecutor,
|
|
23091
|
+
createMssqlSchemaDialect,
|
|
22389
23092
|
createMySqlDialect,
|
|
23093
|
+
createMySqlSchemaDialect,
|
|
22390
23094
|
createMysqlExecutor,
|
|
22391
23095
|
createPooledExecutorFactory,
|
|
22392
23096
|
createPostgresDialect,
|
|
22393
23097
|
createPostgresExecutor,
|
|
23098
|
+
createPostgresSchemaDialect,
|
|
22394
23099
|
createQueryLoggingExecutor,
|
|
22395
23100
|
createRef,
|
|
22396
23101
|
createSqlDialect,
|
|
22397
23102
|
createSqlServerDialect,
|
|
22398
23103
|
createSqliteDialect,
|
|
22399
23104
|
createSqliteExecutor,
|
|
23105
|
+
createSqliteSchemaDialect,
|
|
23106
|
+
createStandardDropColumnCapability,
|
|
23107
|
+
createStandardDropTableCapability,
|
|
22400
23108
|
createTediousExecutor,
|
|
22401
23109
|
createTediousMssqlClient,
|
|
22402
23110
|
createTreeManager,
|