drizzle-kit 1.0.0-beta.3-702eadc → 1.0.0-beta.4-03f09f7
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/api-mysql.js +11 -2
- package/api-mysql.mjs +11 -2
- package/api-postgres.d.mts +1619 -1619
- package/api-postgres.d.ts +1619 -1619
- package/api-postgres.js +271 -76
- package/api-postgres.mjs +271 -76
- package/api-sqlite.js +11 -2
- package/api-sqlite.mjs +11 -2
- package/bin.cjs +924 -425
- package/package.json +1 -1
package/bin.cjs
CHANGED
|
@@ -9499,6 +9499,7 @@ var init_stringify = __esm({
|
|
|
9499
9499
|
case `number`:
|
|
9500
9500
|
return Number.isFinite(value) ? value.toString() : `null`;
|
|
9501
9501
|
case `boolean`:
|
|
9502
|
+
return value.toString();
|
|
9502
9503
|
case `bigint`:
|
|
9503
9504
|
return n5 ? `${value.toString()}n` : value.toString();
|
|
9504
9505
|
case `object`: {
|
|
@@ -21141,7 +21142,7 @@ function formatTime(date2) {
|
|
|
21141
21142
|
const iso = instant.toString({ timeZone: "UTC" });
|
|
21142
21143
|
return iso;
|
|
21143
21144
|
}
|
|
21144
|
-
var SmallInt2, Int2, BigInt3, Numeric, Real2, Double2, Boolean3, Char2, Varchar2, Text2, toDefaultArray, Json2, Jsonb, Time2, TimeTz, DateType, Timestamp2, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum2, Serial2, BigSerial, SmallSerial, Custom2, typeFor2, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK2, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, defaultsCommutative, defaults;
|
|
21145
|
+
var SmallInt2, Int2, BigInt3, Numeric, Real2, Double2, Boolean3, Char2, Varchar2, Text2, toDefaultArray, Json2, Jsonb, Time2, TimeTz, DateType, Timestamp2, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum2, Serial2, BigSerial, SmallSerial, Custom2, typeFor2, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK2, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, mapSerialToInt, defaultsCommutative, defaults;
|
|
21145
21146
|
var init_grammar2 = __esm({
|
|
21146
21147
|
"src/dialects/postgres/grammar.ts"() {
|
|
21147
21148
|
"use strict";
|
|
@@ -22733,6 +22734,18 @@ var init_grammar2 = __esm({
|
|
|
22733
22734
|
isSerialType = (type) => {
|
|
22734
22735
|
return /^(?:serial|bigserial|smallserial)$/i.test(type);
|
|
22735
22736
|
};
|
|
22737
|
+
mapSerialToInt = (type) => {
|
|
22738
|
+
switch (type) {
|
|
22739
|
+
case "smallserial":
|
|
22740
|
+
return "smallint";
|
|
22741
|
+
case "serial":
|
|
22742
|
+
return "int";
|
|
22743
|
+
case "bigserial":
|
|
22744
|
+
return "bigint";
|
|
22745
|
+
default:
|
|
22746
|
+
throw new Error(`Unsupported type: ${type}`);
|
|
22747
|
+
}
|
|
22748
|
+
};
|
|
22736
22749
|
defaultsCommutative = (diffDef, type, dimensions) => {
|
|
22737
22750
|
if (!diffDef) return false;
|
|
22738
22751
|
let from = diffDef.from;
|
|
@@ -22908,7 +22921,7 @@ var init_common3 = __esm({
|
|
|
22908
22921
|
configCommonSchema = objectType({
|
|
22909
22922
|
dialect,
|
|
22910
22923
|
schema: unionType([stringType(), stringType().array()]).optional(),
|
|
22911
|
-
out: stringType().
|
|
22924
|
+
out: stringType().default("drizzle"),
|
|
22912
22925
|
breakpoints: booleanType().optional().default(true),
|
|
22913
22926
|
verbose: booleanType().optional().default(false),
|
|
22914
22927
|
driver: driver.optional(),
|
|
@@ -23087,7 +23100,7 @@ function formatOptionChanges(oldState, newState) {
|
|
|
23087
23100
|
}
|
|
23088
23101
|
return "";
|
|
23089
23102
|
}
|
|
23090
|
-
var import_hanji, warning, err, info, grey, error2, postgresSchemaWarning, sqliteSchemaError, explain, psqlExplain, mysqlExplain, sqliteExplain, postgresSchemaError, mysqlSchemaError, mssqlSchemaError, isRenamePromptItem, keyFor, ResolveSelect, Spinner, IntrospectProgress, MigrateProgress, ProgressView;
|
|
23103
|
+
var import_hanji, warning, err, info, grey, error2, postgresSchemaWarning, sqliteSchemaError, explain, psqlExplain, cockroachExplain, mysqlExplain, mssqlExplain, sqliteExplain, postgresSchemaError, cockraochSchemaError, mysqlSchemaError, mssqlSchemaError, isRenamePromptItem, keyFor, ResolveSelect, Spinner, IntrospectProgress, MigrateProgress, ProgressView;
|
|
23091
23104
|
var init_views = __esm({
|
|
23092
23105
|
"src/cli/views.ts"() {
|
|
23093
23106
|
"use strict";
|
|
@@ -23139,7 +23152,7 @@ var init_views = __esm({
|
|
|
23139
23152
|
const res = [];
|
|
23140
23153
|
const explains = [];
|
|
23141
23154
|
for (const { jsonStatement, sqlStatements } of grouped) {
|
|
23142
|
-
const res2 = dialect5 === "postgres" ? psqlExplain(jsonStatement) : dialect5 === "sqlite" ? sqliteExplain(jsonStatement) : dialect5 === "mysql" ? mysqlExplain(jsonStatement) : null;
|
|
23155
|
+
const res2 = dialect5 === "postgres" ? psqlExplain(jsonStatement) : dialect5 === "sqlite" ? sqliteExplain(jsonStatement) : dialect5 === "mysql" ? mysqlExplain(jsonStatement) : dialect5 === "mssql" ? mssqlExplain(jsonStatement) : dialect5 === "cockroach" ? cockroachExplain(jsonStatement) : null;
|
|
23143
23156
|
if (res2) {
|
|
23144
23157
|
let msg = `\u250C\u2500\u2500\u2500 ${res2.title}
|
|
23145
23158
|
`;
|
|
@@ -23365,6 +23378,146 @@ var init_views = __esm({
|
|
|
23365
23378
|
if (diff2.isGrantable) cause += `\u2502 isGrantable: [${diff2.isGrantable.from}] -> [${diff2.isGrantable.to}]
|
|
23366
23379
|
`;
|
|
23367
23380
|
if (diff2.type) cause += `\u2502 type: [${diff2.type.from}] -> [${diff2.type.to}]
|
|
23381
|
+
`;
|
|
23382
|
+
}
|
|
23383
|
+
if (title) return { title, cause };
|
|
23384
|
+
return null;
|
|
23385
|
+
};
|
|
23386
|
+
cockroachExplain = (st2) => {
|
|
23387
|
+
let title = "";
|
|
23388
|
+
let cause = "";
|
|
23389
|
+
if (st2.type === "alter_column") {
|
|
23390
|
+
const r6 = st2.to;
|
|
23391
|
+
const d5 = st2.diff;
|
|
23392
|
+
const key = `${r6.schema}.${r6.table}.${r6.name}`;
|
|
23393
|
+
title += `${key} column changed:`;
|
|
23394
|
+
if (d5.default) cause += `\u2502 default: ${d5.default.from} -> ${d5.default.to}
|
|
23395
|
+
`;
|
|
23396
|
+
if (d5.type) cause += `\u2502 type: ${d5.type.from} -> ${d5.type.to}
|
|
23397
|
+
`;
|
|
23398
|
+
if (d5.notNull) cause += `\u2502 notNull: ${d5.notNull.from} -> ${d5.notNull.to}
|
|
23399
|
+
`;
|
|
23400
|
+
if (d5.dimensions) cause += `\u2502 dimensions: ${d5.dimensions.from} -> ${d5.dimensions.to}
|
|
23401
|
+
`;
|
|
23402
|
+
if (d5.identity) cause += `\u2502 identity: ${formatOptionChanges(d5.identity.from, d5.identity.to)}
|
|
23403
|
+
`;
|
|
23404
|
+
}
|
|
23405
|
+
if (st2.type === "recreate_column") {
|
|
23406
|
+
const { diff: d5 } = st2;
|
|
23407
|
+
const key = `${d5.$right.schema}.${d5.$right.table}.${d5.$right.name}`;
|
|
23408
|
+
title += `${key} column recreated:`;
|
|
23409
|
+
if (d5.generated) {
|
|
23410
|
+
const from = d5.generated.from ? `${d5.generated.from.as} ${d5.generated.from.type}` : "null";
|
|
23411
|
+
const to2 = d5.generated.to ? `${d5.generated.to.as} ${d5.generated.to.type}` : "null";
|
|
23412
|
+
cause += `\u2502 generated: ${from} -> ${to2}
|
|
23413
|
+
`;
|
|
23414
|
+
}
|
|
23415
|
+
}
|
|
23416
|
+
if (st2.type === "recreate_index") {
|
|
23417
|
+
const diff2 = st2.diff;
|
|
23418
|
+
const idx = diff2.$right;
|
|
23419
|
+
const key = `${idx.schema}.${idx.table}.${idx.name}`;
|
|
23420
|
+
title += `${key} index changed:`;
|
|
23421
|
+
if (diff2.isUnique) cause += `\u2502 unique: ${diff2.isUnique.from} -> ${diff2.isUnique.to}
|
|
23422
|
+
`;
|
|
23423
|
+
if (diff2.where) cause += `\u2502 where: ${diff2.where.from} -> ${diff2.where.to}
|
|
23424
|
+
`;
|
|
23425
|
+
if (diff2.method) cause += `\u2502 method: ${diff2.method.from} -> ${diff2.method.to}
|
|
23426
|
+
`;
|
|
23427
|
+
}
|
|
23428
|
+
if (st2.type === "recreate_fk") {
|
|
23429
|
+
const { fk: fk5, diff: diff2 } = st2;
|
|
23430
|
+
const key = `${fk5.schema}.${fk5.table}.${fk5.name}`;
|
|
23431
|
+
title += `${key} index changed:`;
|
|
23432
|
+
if (diff2.onUpdate) cause += `\u2502 where: ${diff2.onUpdate.from} -> ${diff2.onUpdate.to}
|
|
23433
|
+
`;
|
|
23434
|
+
if (diff2.onDelete) cause += `\u2502 onDelete: ${diff2.onDelete.from} -> ${diff2.onDelete.to}
|
|
23435
|
+
`;
|
|
23436
|
+
}
|
|
23437
|
+
if (st2.type === "recreate_enum") {
|
|
23438
|
+
const { to: to2, from } = st2;
|
|
23439
|
+
title = `${to2.schema}.${to2.name} enum changed:`;
|
|
23440
|
+
cause += `\u2502 values shuffled/removed: [${from.values.join(",")}] -> [${to2.values.join(",")}]
|
|
23441
|
+
`;
|
|
23442
|
+
}
|
|
23443
|
+
if (st2.type === "alter_enum") {
|
|
23444
|
+
const r6 = st2.to;
|
|
23445
|
+
const l5 = st2.from;
|
|
23446
|
+
const d5 = st2.diff;
|
|
23447
|
+
title = `${r6.schema}.${r6.name} enum changed:`;
|
|
23448
|
+
cause += `\u2502 changes: [${r6.values.join(",")}] -> [${l5.values.join(",")}]
|
|
23449
|
+
`;
|
|
23450
|
+
cause += `\u2502 values added: ${d5.filter((it2) => it2.type === "added").map((it2) => it2.value).join(",")}
|
|
23451
|
+
`;
|
|
23452
|
+
}
|
|
23453
|
+
if (st2.type === "alter_role") {
|
|
23454
|
+
const d5 = st2.diff;
|
|
23455
|
+
const to2 = st2.role;
|
|
23456
|
+
const key = `${to2.name}`;
|
|
23457
|
+
title = `${key} role changed:`;
|
|
23458
|
+
if (d5.createDb) cause += `\u2502 createDb: ${d5.createDb.from} -> ${d5.createDb.to}
|
|
23459
|
+
`;
|
|
23460
|
+
if (d5.createRole) cause += `\u2502 createRole: ${d5.createRole.from} -> ${d5.createRole.to}
|
|
23461
|
+
`;
|
|
23462
|
+
}
|
|
23463
|
+
if (st2.type === "alter_sequence") {
|
|
23464
|
+
const d5 = st2.diff;
|
|
23465
|
+
const to2 = st2.sequence;
|
|
23466
|
+
const key = `${to2.schema}.${to2.name}`;
|
|
23467
|
+
title = `${key} sequence changed:`;
|
|
23468
|
+
if (d5.cacheSize) cause += `\u2502 cacheSize: ${d5.cacheSize.from} -> ${d5.cacheSize.to}
|
|
23469
|
+
`;
|
|
23470
|
+
if (d5.incrementBy) cause += `\u2502 incrementBy: ${d5.incrementBy.from} -> ${d5.incrementBy.to}
|
|
23471
|
+
`;
|
|
23472
|
+
if (d5.maxValue) cause += `\u2502 maxValue: ${d5.maxValue.from} -> ${d5.maxValue.to}
|
|
23473
|
+
`;
|
|
23474
|
+
if (d5.minValue) cause += `\u2502 minValue: ${d5.minValue.from} -> ${d5.minValue.to}
|
|
23475
|
+
`;
|
|
23476
|
+
if (d5.startWith) cause += `\u2502 startWith: ${d5.startWith.from} -> ${d5.startWith.to}
|
|
23477
|
+
`;
|
|
23478
|
+
}
|
|
23479
|
+
if (st2.type === "alter_rls") {
|
|
23480
|
+
const key = `${st2.schema}.${st2.name}`;
|
|
23481
|
+
title = `${key} rls changed:
|
|
23482
|
+
`;
|
|
23483
|
+
cause += `\u2502 rlsEnabled: ${!st2.isRlsEnabled} -> ${st2.isRlsEnabled}
|
|
23484
|
+
`;
|
|
23485
|
+
}
|
|
23486
|
+
if (st2.type === "alter_policy" || st2.type === "recreate_policy") {
|
|
23487
|
+
const d5 = st2.diff;
|
|
23488
|
+
const to2 = st2.policy;
|
|
23489
|
+
const key = `${to2.schema}.${to2.table}.${to2.name}`;
|
|
23490
|
+
title = `${key} policy changed:`;
|
|
23491
|
+
if (d5.as) cause += `\u2502 as: ${d5.as.from} -> ${d5.as.to}
|
|
23492
|
+
`;
|
|
23493
|
+
if (d5.for) cause += `\u2502 for: ${d5.for.from} -> ${d5.for.to}
|
|
23494
|
+
`;
|
|
23495
|
+
if (d5.roles) cause += `\u2502 roles: [${d5.roles.from.join(",")}] -> [${d5.roles.to.join(",")}]
|
|
23496
|
+
`;
|
|
23497
|
+
if (d5.using) cause += `\u2502 using: ${d5.using.from} -> ${d5.using.to}
|
|
23498
|
+
`;
|
|
23499
|
+
if (d5.withCheck) cause += `\u2502 withCheck: ${d5.withCheck.from} -> ${d5.withCheck.to}
|
|
23500
|
+
`;
|
|
23501
|
+
}
|
|
23502
|
+
if (st2.type === "alter_check") {
|
|
23503
|
+
const d5 = st2.diff;
|
|
23504
|
+
const key = `${d5.schema}.${d5.table}.${d5.name}`;
|
|
23505
|
+
title = `${key} check changed:`;
|
|
23506
|
+
if (d5.value) cause += `\u2502 definition: ${d5.value.from} -> ${d5.value.to}
|
|
23507
|
+
`;
|
|
23508
|
+
}
|
|
23509
|
+
if (st2.type === "alter_pk") {
|
|
23510
|
+
const d5 = st2.diff;
|
|
23511
|
+
const key = `${d5.schema}.${d5.table}.${d5.name}`;
|
|
23512
|
+
title += `${key} pk changed:`;
|
|
23513
|
+
if (d5.columns) cause += `\u2502 columns: [${d5.columns.from.join(",")}] -> [${d5.columns.to.join(",")}]
|
|
23514
|
+
`;
|
|
23515
|
+
}
|
|
23516
|
+
if (st2.type === "recreate_view") {
|
|
23517
|
+
const { from, to: to2 } = st2;
|
|
23518
|
+
const key = `${to2.schema}.${to2.name}`;
|
|
23519
|
+
title += `${key} view changed:`;
|
|
23520
|
+
cause += `\u2502 definition: [${from.definition}] -> [${to2.definition}]
|
|
23368
23521
|
`;
|
|
23369
23522
|
}
|
|
23370
23523
|
if (title) return { title, cause };
|
|
@@ -23427,6 +23580,75 @@ var init_views = __esm({
|
|
|
23427
23580
|
if (title) return { title, cause };
|
|
23428
23581
|
return null;
|
|
23429
23582
|
};
|
|
23583
|
+
mssqlExplain = (st2) => {
|
|
23584
|
+
let title = "";
|
|
23585
|
+
let cause = "";
|
|
23586
|
+
if (st2.type === "alter_column") {
|
|
23587
|
+
const r6 = st2.diff.$right;
|
|
23588
|
+
const d5 = st2.diff;
|
|
23589
|
+
const key = `${r6.schema}.${r6.table}.${r6.name}`;
|
|
23590
|
+
title += `${key} column changed:
|
|
23591
|
+
`;
|
|
23592
|
+
if (d5.type) cause += `\u2502 type: ${d5.type.from} -> ${d5.type.to}
|
|
23593
|
+
`;
|
|
23594
|
+
if (d5.notNull) cause += `\u2502 notNull: ${d5.notNull.from} -> ${d5.notNull.to}
|
|
23595
|
+
`;
|
|
23596
|
+
}
|
|
23597
|
+
if (st2.type === "recreate_column") {
|
|
23598
|
+
const { diff: diff2 } = st2;
|
|
23599
|
+
const key = `${diff2.$right.schema}.${diff2.$right.table}.${diff2.$right.name}`;
|
|
23600
|
+
title += `${key} column recreated:
|
|
23601
|
+
`;
|
|
23602
|
+
if (diff2.generated) {
|
|
23603
|
+
const from = diff2.generated.from ? `${diff2.generated.from.as} ${diff2.generated.from.type}` : "null";
|
|
23604
|
+
const to2 = diff2.generated.to ? `${diff2.generated.to.as} ${diff2.generated.to.type}` : "null";
|
|
23605
|
+
cause += `\u2502 generated: ${from} -> ${to2}
|
|
23606
|
+
`;
|
|
23607
|
+
}
|
|
23608
|
+
}
|
|
23609
|
+
if (st2.type === "recreate_identity_column") {
|
|
23610
|
+
const { column: column11 } = st2;
|
|
23611
|
+
const key = `${column11.$right.schema}.${column11.$right.table}.${column11.$right.name}`;
|
|
23612
|
+
title += `${key} column recreated:
|
|
23613
|
+
`;
|
|
23614
|
+
if (column11.identity) {
|
|
23615
|
+
const from = column11.identity.from ? `${column11.identity.from.increment} ${column11.identity.from.seed}` : "null";
|
|
23616
|
+
const to2 = column11.identity.to ? `${column11.identity.to.increment} ${column11.identity.to.seed}` : "null";
|
|
23617
|
+
cause += `\u2502 identity: ${from} -> ${to2}
|
|
23618
|
+
`;
|
|
23619
|
+
}
|
|
23620
|
+
}
|
|
23621
|
+
if (st2.type === "alter_view") {
|
|
23622
|
+
const { diff: diff2, view: view5 } = st2;
|
|
23623
|
+
const key = `${view5.schema}.${view5.name}`;
|
|
23624
|
+
title += `${key} view changed:
|
|
23625
|
+
`;
|
|
23626
|
+
if (diff2.checkOption) cause += `\u2502 checkOption: ${diff2.checkOption.from} -> ${diff2.checkOption.to}
|
|
23627
|
+
`;
|
|
23628
|
+
if (diff2.definition) cause += `\u2502 definition: ${diff2.definition.from} -> ${diff2.definition.to}
|
|
23629
|
+
`;
|
|
23630
|
+
if (diff2.encryption) cause += `\u2502 encryption: ${diff2.encryption.from} -> ${diff2.encryption.to}
|
|
23631
|
+
`;
|
|
23632
|
+
if (diff2.schemaBinding) {
|
|
23633
|
+
cause += `\u2502 schemaBinding: ${diff2.schemaBinding.from} -> ${diff2.schemaBinding.to}
|
|
23634
|
+
`;
|
|
23635
|
+
}
|
|
23636
|
+
if (diff2.viewMetadata) {
|
|
23637
|
+
cause += `\u2502 viewMetadata: ${diff2.viewMetadata.from} -> ${diff2.viewMetadata.to}
|
|
23638
|
+
`;
|
|
23639
|
+
}
|
|
23640
|
+
}
|
|
23641
|
+
if (st2.type === "recreate_default") {
|
|
23642
|
+
const { from, to: to2 } = st2;
|
|
23643
|
+
const key = `${to2.schema}.${to2.name}`;
|
|
23644
|
+
title += `${key} default changed:
|
|
23645
|
+
`;
|
|
23646
|
+
cause += `\u2502 default: ${from.default} -> ${to2.default}
|
|
23647
|
+
`;
|
|
23648
|
+
}
|
|
23649
|
+
if (title) return { title, cause };
|
|
23650
|
+
return null;
|
|
23651
|
+
};
|
|
23430
23652
|
sqliteExplain = (st2) => {
|
|
23431
23653
|
let title = "";
|
|
23432
23654
|
let cause = "";
|
|
@@ -23720,6 +23942,111 @@ You can check the "pg_vector" docs for more info: https://github.com/pgvector/pg
|
|
|
23720
23942
|
}
|
|
23721
23943
|
return "";
|
|
23722
23944
|
};
|
|
23945
|
+
cockraochSchemaError = (error4) => {
|
|
23946
|
+
if (error4.type === "constraint_name_duplicate") {
|
|
23947
|
+
const { name, schema: schema5, table: table6 } = error4;
|
|
23948
|
+
const tableName = source_default.underline.blue(`"${schema5}"."${table6}"`);
|
|
23949
|
+
const constraintName = source_default.underline.blue(`'${name}'`);
|
|
23950
|
+
return withStyle.errorWarning(
|
|
23951
|
+
`There's a duplicate constraint name ${constraintName} in ${tableName} table`
|
|
23952
|
+
);
|
|
23953
|
+
}
|
|
23954
|
+
if (error4.type === "index_duplicate") {
|
|
23955
|
+
const { schema: schema5, table: table6, name } = error4;
|
|
23956
|
+
const sch = source_default.underline.blue(`"${schema5}"`);
|
|
23957
|
+
const idx = source_default.underline.blue(`'${name}'`);
|
|
23958
|
+
const tableName = source_default.underline.blue(`"${schema5}"."${table6}"`);
|
|
23959
|
+
return withStyle.errorWarning(
|
|
23960
|
+
`There's a duplicate index name ${idx} in ${sch} schema in ${tableName}`
|
|
23961
|
+
);
|
|
23962
|
+
}
|
|
23963
|
+
if (error4.type === "index_no_name") {
|
|
23964
|
+
const { schema: schema5, table: table6, sql } = error4;
|
|
23965
|
+
const tableName = source_default.underline.blue(`"${schema5}"."${table6}"`);
|
|
23966
|
+
return withStyle.errorWarning(
|
|
23967
|
+
`Please specify an index name in ${tableName} table that has "${sql}" expression.
|
|
23968
|
+
|
|
23969
|
+
We can generate index names for indexes on columns only; for expressions in indexes, you need to specify index name yourself.`
|
|
23970
|
+
);
|
|
23971
|
+
}
|
|
23972
|
+
if (error4.type === "pgvector_index_noop") {
|
|
23973
|
+
const { table: table6, indexName: indexName3, column: column11, method } = error4;
|
|
23974
|
+
return withStyle.errorWarning(
|
|
23975
|
+
`You are specifying an index on the ${source_default.blueBright(
|
|
23976
|
+
`"${column11}"`
|
|
23977
|
+
)} column inside the ${source_default.blueBright(
|
|
23978
|
+
`"${table6}"`
|
|
23979
|
+
)} table with the ${source_default.blueBright(
|
|
23980
|
+
"vector"
|
|
23981
|
+
)} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${vectorOps.map((it2) => `${source_default.underline(`${it2}`)}`).join(", ")}].
|
|
23982
|
+
|
|
23983
|
+
You can specify it using current syntax: ${source_default.underline(
|
|
23984
|
+
`index("${indexName3}").using("${method}", table.${column11}.op("${vectorOps[0]}"))`
|
|
23985
|
+
)}
|
|
23986
|
+
|
|
23987
|
+
You can check the "pg_vector" docs for more info: https://github.com/pgvector/pgvector?tab=readme-ov-file#indexing
|
|
23988
|
+
`
|
|
23989
|
+
);
|
|
23990
|
+
}
|
|
23991
|
+
if (error4.type === "policy_duplicate") {
|
|
23992
|
+
const { schema: schema5, table: table6, policy: policy3 } = error4;
|
|
23993
|
+
const tableName = source_default.underline.blue(`"${schema5}"."${table6}"`);
|
|
23994
|
+
return withStyle.errorWarning(
|
|
23995
|
+
`We've found duplicated policy name across ${tableName} table. Please rename one of the policies with ${source_default.underline.blue(
|
|
23996
|
+
`"${policy3}"`
|
|
23997
|
+
)} name`
|
|
23998
|
+
);
|
|
23999
|
+
}
|
|
24000
|
+
if (error4.type === "view_name_duplicate") {
|
|
24001
|
+
const schema5 = source_default.underline.blue(`"${error4.schema ?? "public"}"`);
|
|
24002
|
+
const name = source_default.underline.blue(`"${error4.name}"`);
|
|
24003
|
+
return withStyle.errorWarning(
|
|
24004
|
+
`There's a view duplicate name ${name} in ${schema5} schema`
|
|
24005
|
+
);
|
|
24006
|
+
}
|
|
24007
|
+
if (error4.type === "sequence_name_duplicate") {
|
|
24008
|
+
return withStyle.errorWarning(`There's a sequence name duplicate '${error4.name}' in '${error4.schema}' schema`);
|
|
24009
|
+
}
|
|
24010
|
+
if (error4.type === "column_name_duplicate") {
|
|
24011
|
+
const { name, schema: schema5, table: table6 } = error4;
|
|
24012
|
+
const tableName = source_default.underline.blue(`"${schema5}"."${table6}"`);
|
|
24013
|
+
const columnName = source_default.underline.blue(`'${name}'`);
|
|
24014
|
+
return withStyle.errorWarning(
|
|
24015
|
+
`There's a duplicate column name ${columnName} in ${tableName} table`
|
|
24016
|
+
);
|
|
24017
|
+
}
|
|
24018
|
+
if (error4.type === "enum_name_duplicate") {
|
|
24019
|
+
const { name, schema: schema5 } = error4;
|
|
24020
|
+
const schemaName = source_default.underline.blue(`"${schema5}"`);
|
|
24021
|
+
const enumName = source_default.underline.blue(`'${name}'`);
|
|
24022
|
+
return withStyle.errorWarning(
|
|
24023
|
+
`There's a duplicate enum name ${enumName} in ${schemaName} schema`
|
|
24024
|
+
);
|
|
24025
|
+
}
|
|
24026
|
+
if (error4.type === "table_name_duplicate") {
|
|
24027
|
+
const { name, schema: schema5 } = error4;
|
|
24028
|
+
const schemaName = source_default.underline.blue(`"${schema5}"`);
|
|
24029
|
+
const tableName = source_default.underline.blue(`"${name}"`);
|
|
24030
|
+
return withStyle.errorWarning(
|
|
24031
|
+
`There's a duplicate table name ${tableName} in ${schemaName} schema`
|
|
24032
|
+
);
|
|
24033
|
+
}
|
|
24034
|
+
if (error4.type === "schema_name_duplicate") {
|
|
24035
|
+
const { name } = error4;
|
|
24036
|
+
const schemaName = source_default.underline.blue(`"${name}"`);
|
|
24037
|
+
return withStyle.errorWarning(
|
|
24038
|
+
`There's a duplicate schema name ${schemaName}`
|
|
24039
|
+
);
|
|
24040
|
+
}
|
|
24041
|
+
if (error4.type === "role_duplicate") {
|
|
24042
|
+
const { name } = error4;
|
|
24043
|
+
const roleName = source_default.underline.blue(`"${name}"`);
|
|
24044
|
+
return withStyle.errorWarning(
|
|
24045
|
+
`There's a duplicate role name ${roleName}`
|
|
24046
|
+
);
|
|
24047
|
+
}
|
|
24048
|
+
return "";
|
|
24049
|
+
};
|
|
23723
24050
|
mysqlSchemaError = (error4) => {
|
|
23724
24051
|
if (error4.type === "column_name_conflict") {
|
|
23725
24052
|
const { name, table: table6 } = error4;
|
|
@@ -23821,7 +24148,7 @@ We can generate index names for indexes on columns only; for expressions in inde
|
|
|
23821
24148
|
};
|
|
23822
24149
|
keyFor = (it2, defaultSchema = "public") => {
|
|
23823
24150
|
const schemaPrefix = it2.schema && it2.schema !== defaultSchema ? `${it2.schema}.` : "";
|
|
23824
|
-
const tablePrefix = it2.table ? `${it2.
|
|
24151
|
+
const tablePrefix = it2.table ? `${it2.table}.` : "";
|
|
23825
24152
|
return `${schemaPrefix}${tablePrefix}${it2.name}`;
|
|
23826
24153
|
};
|
|
23827
24154
|
ResolveSelect = class extends import_hanji.Prompt {
|
|
@@ -27924,7 +28251,36 @@ function parseSqliteFks(ddl7) {
|
|
|
27924
28251
|
}
|
|
27925
28252
|
return results;
|
|
27926
28253
|
}
|
|
27927
|
-
|
|
28254
|
+
function compareIntegerTimestamps(from, to2) {
|
|
28255
|
+
from = trimChar(trimChar(from, "'"), '"');
|
|
28256
|
+
to2 = trimChar(trimChar(to2, "'"), '"');
|
|
28257
|
+
const mappedFrom = /^\d+$/.test(from) ? Number(from) : from;
|
|
28258
|
+
const mappedTo = /^\d+$/.test(to2) ? Number(to2) : to2;
|
|
28259
|
+
let timestampFrom = new Date(mappedFrom).getTime();
|
|
28260
|
+
let timestampTo = new Date(mappedTo).getTime();
|
|
28261
|
+
if (timestampFrom === timestampTo) return true;
|
|
28262
|
+
if (typeof mappedFrom === "number") {
|
|
28263
|
+
timestampFrom = new Date(Number(from) * 1e3).getTime();
|
|
28264
|
+
return timestampFrom === timestampTo;
|
|
28265
|
+
}
|
|
28266
|
+
if (typeof mappedTo === "number") {
|
|
28267
|
+
timestampTo = new Date(Number(to2) * 1e3).getTime();
|
|
28268
|
+
return timestampFrom === timestampTo;
|
|
28269
|
+
}
|
|
28270
|
+
return false;
|
|
28271
|
+
}
|
|
28272
|
+
function parseToHex(value) {
|
|
28273
|
+
if (!value) return null;
|
|
28274
|
+
try {
|
|
28275
|
+
const parsed = JSON.parse(trimChar(value, "'"));
|
|
28276
|
+
if (parsed.type === "Buffer" && Array.isArray(parsed.data)) {
|
|
28277
|
+
value = Blob3.defaultFromDrizzle(Buffer.from(parsed.data));
|
|
28278
|
+
}
|
|
28279
|
+
} catch {
|
|
28280
|
+
}
|
|
28281
|
+
return value;
|
|
28282
|
+
}
|
|
28283
|
+
var namedCheckPattern, unnamedCheckPattern, viewAsStatementRegex2, nameForForeignKey, nameForUnique2, nameForPk, intAffinities, Int5, realAffinities, Real5, numericAffinities, Numeric3, textAffinities, Text4, Blob3, typeFor5, parseDefault2, parseTableSQL, parseViewSQL2, defaultsCommutative3, transformOnUpdateDelete;
|
|
27928
28284
|
var init_grammar5 = __esm({
|
|
27929
28285
|
"src/dialects/sqlite/grammar.ts"() {
|
|
27930
28286
|
"use strict";
|
|
@@ -27959,9 +28315,6 @@ var init_grammar5 = __esm({
|
|
|
27959
28315
|
},
|
|
27960
28316
|
drizzleImport: () => "integer",
|
|
27961
28317
|
defaultFromDrizzle: (value, mode) => {
|
|
27962
|
-
if (typeof value === "boolean") {
|
|
27963
|
-
return value ? "1" : "0";
|
|
27964
|
-
}
|
|
27965
28318
|
if (typeof value === "bigint") {
|
|
27966
28319
|
return `'${value.toString()}'`;
|
|
27967
28320
|
}
|
|
@@ -27980,6 +28333,9 @@ var init_grammar5 = __esm({
|
|
|
27980
28333
|
},
|
|
27981
28334
|
toTs: (value) => {
|
|
27982
28335
|
if (!value) return "";
|
|
28336
|
+
if (value === "true" || value === "false") {
|
|
28337
|
+
return { def: value, options: { mode: "boolean" } };
|
|
28338
|
+
}
|
|
27983
28339
|
const check2 = Number(value);
|
|
27984
28340
|
if (Number.isNaN(check2)) return `sql\`${value}\``;
|
|
27985
28341
|
if (check2 >= Number.MIN_SAFE_INTEGER && check2 <= Number.MAX_SAFE_INTEGER) return value;
|
|
@@ -28182,6 +28538,32 @@ var init_grammar5 = __esm({
|
|
|
28182
28538
|
const match3 = sql.match(viewAsStatementRegex2);
|
|
28183
28539
|
return match3 ? match3[1] : null;
|
|
28184
28540
|
};
|
|
28541
|
+
defaultsCommutative3 = (diffDef, type) => {
|
|
28542
|
+
if (!diffDef) return false;
|
|
28543
|
+
let from = diffDef.from;
|
|
28544
|
+
let to2 = diffDef.to;
|
|
28545
|
+
if (from === to2) return true;
|
|
28546
|
+
if (from === `(${to2})`) return true;
|
|
28547
|
+
if (to2 === `(${from})`) return true;
|
|
28548
|
+
if (type.startsWith("integer")) {
|
|
28549
|
+
if (from && to2) {
|
|
28550
|
+
return compareIntegerTimestamps(from, to2);
|
|
28551
|
+
}
|
|
28552
|
+
return false;
|
|
28553
|
+
}
|
|
28554
|
+
if (type.startsWith("blob")) {
|
|
28555
|
+
return parseToHex(from) === parseToHex(to2);
|
|
28556
|
+
}
|
|
28557
|
+
return false;
|
|
28558
|
+
};
|
|
28559
|
+
transformOnUpdateDelete = (on2) => {
|
|
28560
|
+
if (on2 === "no action") return "NO ACTION";
|
|
28561
|
+
if (on2 === "cascade") return "CASCADE";
|
|
28562
|
+
if (on2 === "restrict") return "RESTRICT";
|
|
28563
|
+
if (on2 === "set default") return "SET DEFAULT";
|
|
28564
|
+
if (on2 === "set null") return "SET NULL";
|
|
28565
|
+
assertUnreachable(on2);
|
|
28566
|
+
};
|
|
28185
28567
|
}
|
|
28186
28568
|
});
|
|
28187
28569
|
|
|
@@ -28256,6 +28638,14 @@ var init_ddl5 = __esm({
|
|
|
28256
28638
|
columns: "string[]",
|
|
28257
28639
|
nameExplicit: "boolean"
|
|
28258
28640
|
},
|
|
28641
|
+
/**
|
|
28642
|
+
* Unique constraints and unique indexes are functionally identical in terms of behavior
|
|
28643
|
+
* We decided to keep both constraints and indexes because when a unique constraint is created
|
|
28644
|
+
* it cannot be removed, whereas an index can be dropped
|
|
28645
|
+
* Removing unique constraints would require recreating the table
|
|
28646
|
+
* Before the beta v1 all unique constraints were created and stored in snapshots as indexes
|
|
28647
|
+
* We do not have sufficient information for upping snapshots to beta v1
|
|
28648
|
+
*/
|
|
28259
28649
|
uniques: {
|
|
28260
28650
|
table: "required",
|
|
28261
28651
|
columns: "string[]",
|
|
@@ -28408,7 +28798,7 @@ var init_snapshot6 = __esm({
|
|
|
28408
28798
|
}).strict();
|
|
28409
28799
|
compositePK5 = objectType({
|
|
28410
28800
|
columns: stringType().array(),
|
|
28411
|
-
name: stringType()
|
|
28801
|
+
name: stringType().optional()
|
|
28412
28802
|
}).strict();
|
|
28413
28803
|
column5 = objectType({
|
|
28414
28804
|
name: stringType(),
|
|
@@ -28509,7 +28899,14 @@ var init_snapshot6 = __esm({
|
|
|
28509
28899
|
sqliteSchemaV5 = schemaV52;
|
|
28510
28900
|
sqliteSchemaV6 = schemaV62;
|
|
28511
28901
|
toJsonSnapshot6 = (ddl7, id, prevIds, renames) => {
|
|
28512
|
-
return {
|
|
28902
|
+
return {
|
|
28903
|
+
dialect: "sqlite",
|
|
28904
|
+
id,
|
|
28905
|
+
prevIds,
|
|
28906
|
+
version: "7",
|
|
28907
|
+
ddl: ddl7.entities.list(),
|
|
28908
|
+
renames
|
|
28909
|
+
};
|
|
28513
28910
|
};
|
|
28514
28911
|
ddl6 = createDDL5();
|
|
28515
28912
|
snapshotValidator6 = validator({
|
|
@@ -37960,7 +38357,7 @@ var init_drizzle = __esm({
|
|
|
37960
38357
|
});
|
|
37961
38358
|
|
|
37962
38359
|
// src/dialects/postgres/drizzle.ts
|
|
37963
|
-
var import_drizzle_orm, import_relations, import_pg_core2, policyFrom, unwrapColumn, unwrapArray,
|
|
38360
|
+
var import_drizzle_orm, import_relations, import_pg_core2, policyFrom, unwrapColumn, unwrapArray, transformOnUpdateDelete2, defaultFromColumn, fromDrizzleSchema, fromExports, prepareFromSchemaFiles;
|
|
37964
38361
|
var init_drizzle2 = __esm({
|
|
37965
38362
|
"src/dialects/postgres/drizzle.ts"() {
|
|
37966
38363
|
"use strict";
|
|
@@ -38020,7 +38417,7 @@ var init_drizzle2 = __esm({
|
|
|
38020
38417
|
if ((0, import_drizzle_orm.is)(baseColumn, import_pg_core2.PgArray)) return unwrapArray(baseColumn, dimensions + 1);
|
|
38021
38418
|
return { baseColumn, dimensions };
|
|
38022
38419
|
};
|
|
38023
|
-
|
|
38420
|
+
transformOnUpdateDelete2 = (on2) => {
|
|
38024
38421
|
if (on2 === "no action") return "NO ACTION";
|
|
38025
38422
|
if (on2 === "cascade") return "CASCADE";
|
|
38026
38423
|
if (on2 === "restrict") return "RESTRICT";
|
|
@@ -38228,8 +38625,8 @@ var init_drizzle2 = __esm({
|
|
|
38228
38625
|
schemaTo,
|
|
38229
38626
|
columns: columnsFrom,
|
|
38230
38627
|
columnsTo,
|
|
38231
|
-
onDelete: onDelete ?
|
|
38232
|
-
onUpdate: onUpdate ?
|
|
38628
|
+
onDelete: onDelete ? transformOnUpdateDelete2(onDelete) : null,
|
|
38629
|
+
onUpdate: onUpdate ? transformOnUpdateDelete2(onUpdate) : null
|
|
38233
38630
|
};
|
|
38234
38631
|
})
|
|
38235
38632
|
);
|
|
@@ -38986,7 +39383,7 @@ var init_convertor = __esm({
|
|
|
38986
39383
|
});
|
|
38987
39384
|
alterColumnConvertor = convertor("alter_column", (st2) => {
|
|
38988
39385
|
var _a5;
|
|
38989
|
-
const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial } = st2;
|
|
39386
|
+
const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial, toSerial } = st2;
|
|
38990
39387
|
const statements = [];
|
|
38991
39388
|
const key = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}"` : `"${column11.table}"`;
|
|
38992
39389
|
const recreateDefault = diff2.type && (isEnum || wasEnum) && diff2.$left.default;
|
|
@@ -38996,17 +39393,21 @@ var init_convertor = __esm({
|
|
|
38996
39393
|
if (diff2.type) {
|
|
38997
39394
|
const typeSchema = column11.typeSchema && column11.typeSchema !== "public" ? `"${column11.typeSchema}".` : "";
|
|
38998
39395
|
const textProxy = wasEnum && isEnum ? "text::" : "";
|
|
38999
|
-
const suffix = isEnum ? ` USING "${column11.name}"::${textProxy}${typeSchema}"${column11.type}"${"[]".repeat(column11.dimensions)}` : ` USING "${column11.name}"::${column11.type}${"[]".repeat(column11.dimensions)}`;
|
|
39000
|
-
|
|
39001
|
-
if (diff2.type) {
|
|
39002
|
-
type = ((_a5 = diff2.typeSchema) == null ? void 0 : _a5.to) && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : diff2.type.to;
|
|
39003
|
-
} else {
|
|
39004
|
-
type = `${typeSchema}${column11.typeSchema ? `"${column11.type}"` : column11.type}`;
|
|
39005
|
-
}
|
|
39396
|
+
const suffix = isEnum ? ` USING "${column11.name}"::${textProxy}${typeSchema}"${column11.type}"${"[]".repeat(column11.dimensions)}` : ` USING "${column11.name}"::${toSerial ? mapSerialToInt(column11.type) : column11.type}${"[]".repeat(column11.dimensions)}`;
|
|
39397
|
+
const type = ((_a5 = diff2.typeSchema) == null ? void 0 : _a5.to) && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : toSerial ? mapSerialToInt(diff2.type.to) : diff2.type.to;
|
|
39006
39398
|
if (wasSerial) {
|
|
39007
|
-
statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT
|
|
39399
|
+
statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT;`);
|
|
39008
39400
|
const sequenceKey = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}_${column11.name}_seq"` : `"${column11.table}_${column11.name}_seq"`;
|
|
39009
|
-
statements.push(`DROP SEQUENCE ${sequenceKey}
|
|
39401
|
+
statements.push(`DROP SEQUENCE ${sequenceKey};`);
|
|
39402
|
+
}
|
|
39403
|
+
if (toSerial) {
|
|
39404
|
+
const sequenceKey = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}_${column11.name}_seq"` : `"${column11.table}_${column11.name}_seq"`;
|
|
39405
|
+
const sequenceName = column11.schema !== "public" ? `${column11.schema}.${column11.table}_${column11.name}_seq` : `${column11.table}_${column11.name}_seq`;
|
|
39406
|
+
statements.push(`CREATE SEQUENCE ${sequenceKey};`);
|
|
39407
|
+
statements.push(
|
|
39408
|
+
`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" SET DEFAULT nextval('${sequenceName}')`
|
|
39409
|
+
);
|
|
39410
|
+
statements.push(`ALTER SEQUENCE ${sequenceKey} OWNED BY "${column11.schema}"."${column11.table}"."${column11.name}";`);
|
|
39010
39411
|
}
|
|
39011
39412
|
statements.push(
|
|
39012
39413
|
`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" SET DATA TYPE ${type}${"[]".repeat(column11.dimensions)}${suffix};`
|
|
@@ -40312,6 +40713,7 @@ var init_diff = __esm({
|
|
|
40312
40713
|
}).map((it2) => {
|
|
40313
40714
|
const column11 = it2.$right;
|
|
40314
40715
|
const wasSerial = isSerialType(it2.$left.type);
|
|
40716
|
+
const toSerial = !isSerialType(it2.$left.type) && isSerialType(it2.$right.type);
|
|
40315
40717
|
const isEnum = ddl22.enums.one({ schema: column11.typeSchema ?? "public", name: column11.type }) !== null;
|
|
40316
40718
|
const wasEnum = (it2.type && ddl1.enums.one({ schema: column11.typeSchema ?? "public", name: it2.type.from }) !== null) ?? false;
|
|
40317
40719
|
return prepareStatement("alter_column", {
|
|
@@ -40319,7 +40721,8 @@ var init_diff = __esm({
|
|
|
40319
40721
|
to: column11,
|
|
40320
40722
|
isEnum,
|
|
40321
40723
|
wasEnum,
|
|
40322
|
-
wasSerial
|
|
40724
|
+
wasSerial,
|
|
40725
|
+
toSerial
|
|
40323
40726
|
});
|
|
40324
40727
|
});
|
|
40325
40728
|
const createSequences = createdSequences.map((it2) => prepareStatement("create_sequence", { sequence: it2 }));
|
|
@@ -40588,7 +40991,7 @@ var init_prompts = __esm({
|
|
|
40588
40991
|
const to2 = data2.to;
|
|
40589
40992
|
const schemaFromPrefix = newItem.schema ? newItem.schema !== defaultSchema ? `${newItem.schema}.` : "" : "";
|
|
40590
40993
|
const tableFromPrefix = newItem.table ? `${newItem.table}.` : "";
|
|
40591
|
-
const fromEntity = `${schemaFromPrefix}${tableFromPrefix}${
|
|
40994
|
+
const fromEntity = `${schemaFromPrefix}${tableFromPrefix}${data2.from.name}`;
|
|
40592
40995
|
const schemaToPrefix = to2.schema ? to2.schema !== defaultSchema ? `${to2.schema}.` : "" : "";
|
|
40593
40996
|
const tableToPrefix = to2.table ? `${to2.table}.` : "";
|
|
40594
40997
|
const toEntity = `${schemaToPrefix}${tableToPrefix}${to2.name}`;
|
|
@@ -41576,6 +41979,15 @@ var init_diff2 = __esm({
|
|
|
41576
41979
|
});
|
|
41577
41980
|
for (const pk of alters.filter((x6) => x6.entityType === "pks")) {
|
|
41578
41981
|
if (pk.columns) {
|
|
41982
|
+
const fks = ddl22.fks.list({ tableTo: pk.table });
|
|
41983
|
+
const fksFound = fks.filter((fk5) => {
|
|
41984
|
+
if (fk5.columnsTo.length !== pk.$left.columns.length) return false;
|
|
41985
|
+
return fk5.columnsTo.every((fkCol) => pk.$left.columns.includes(fkCol));
|
|
41986
|
+
});
|
|
41987
|
+
for (const fk5 of fksFound) {
|
|
41988
|
+
dropFKStatements.push({ type: "drop_constraint", table: fk5.table, constraint: fk5.name, dropAutoIndex: false });
|
|
41989
|
+
createFKsStatements.push({ type: "create_fk", fk: fk5, cause: "alter_pk" });
|
|
41990
|
+
}
|
|
41579
41991
|
dropPKStatements.push({ type: "drop_pk", pk: pk.$left });
|
|
41580
41992
|
createPKStatements.push({ type: "create_pk", pk: pk.$right });
|
|
41581
41993
|
}
|
|
@@ -41588,26 +42000,28 @@ var init_diff2 = __esm({
|
|
|
41588
42000
|
}
|
|
41589
42001
|
}
|
|
41590
42002
|
const statements = [
|
|
41591
|
-
|
|
41592
|
-
|
|
41593
|
-
|
|
41594
|
-
|
|
41595
|
-
|
|
41596
|
-
|
|
41597
|
-
|
|
41598
|
-
|
|
41599
|
-
|
|
41600
|
-
|
|
41601
|
-
|
|
41602
|
-
|
|
41603
|
-
|
|
41604
|
-
|
|
41605
|
-
|
|
41606
|
-
|
|
41607
|
-
|
|
41608
|
-
|
|
41609
|
-
|
|
41610
|
-
|
|
42003
|
+
.../* @__PURE__ */ new Set([
|
|
42004
|
+
...createTableStatements,
|
|
42005
|
+
...dropFKStatements,
|
|
42006
|
+
...dropTableStatements,
|
|
42007
|
+
...renameTableStatements,
|
|
42008
|
+
...renameColumnsStatement,
|
|
42009
|
+
...dropViewStatements,
|
|
42010
|
+
...renameViewStatements,
|
|
42011
|
+
...alterViewStatements,
|
|
42012
|
+
...dropCheckStatements,
|
|
42013
|
+
...dropIndexeStatements,
|
|
42014
|
+
...dropPKStatements,
|
|
42015
|
+
...columnAlterStatements,
|
|
42016
|
+
...columnRecreateStatatements,
|
|
42017
|
+
...addColumnsStatemets,
|
|
42018
|
+
...createPKStatements,
|
|
42019
|
+
...createIndexesStatements,
|
|
42020
|
+
...createFKsStatements,
|
|
42021
|
+
...createCheckStatements,
|
|
42022
|
+
...dropColumnStatements,
|
|
42023
|
+
...createViewStatements
|
|
42024
|
+
])
|
|
41611
42025
|
];
|
|
41612
42026
|
const res = fromJson2(statements);
|
|
41613
42027
|
return {
|
|
@@ -41624,9 +42038,10 @@ var init_diff2 = __esm({
|
|
|
41624
42038
|
var generate_mysql_exports = {};
|
|
41625
42039
|
__export(generate_mysql_exports, {
|
|
41626
42040
|
handle: () => handle2,
|
|
41627
|
-
handleExport: () => handleExport2
|
|
42041
|
+
handleExport: () => handleExport2,
|
|
42042
|
+
suggestions: () => suggestions
|
|
41628
42043
|
});
|
|
41629
|
-
var handle2, handleExport2;
|
|
42044
|
+
var suggestions, handle2, handleExport2;
|
|
41630
42045
|
var init_generate_mysql = __esm({
|
|
41631
42046
|
"src/cli/commands/generate-mysql.ts"() {
|
|
41632
42047
|
"use strict";
|
|
@@ -41636,8 +42051,57 @@ var init_generate_mysql = __esm({
|
|
|
41636
42051
|
init_ddl();
|
|
41637
42052
|
init_diff2();
|
|
41638
42053
|
init_prompts();
|
|
42054
|
+
init_outputs();
|
|
41639
42055
|
init_views();
|
|
41640
42056
|
init_generate_common();
|
|
42057
|
+
suggestions = (jsonStatements, ddl22) => {
|
|
42058
|
+
const grouped = { errors: [], hints: [] };
|
|
42059
|
+
for (const statement of jsonStatements) {
|
|
42060
|
+
if (statement.type === "create_fk" && statement.cause !== "alter_pk") {
|
|
42061
|
+
const { columnsTo, table: table6, tableTo, columns } = statement.fk;
|
|
42062
|
+
const indexes = ddl22.indexes.list({ isUnique: true, table: tableTo });
|
|
42063
|
+
const pk = ddl22.pks.one({ table: tableTo });
|
|
42064
|
+
const columnsToSet = new Set(columnsTo);
|
|
42065
|
+
const isUniqueFound = indexes.some((index6) => {
|
|
42066
|
+
if (index6.columns.length !== columnsToSet.size) {
|
|
42067
|
+
return false;
|
|
42068
|
+
}
|
|
42069
|
+
return index6.columns.every((col) => columnsToSet.has(col.value));
|
|
42070
|
+
});
|
|
42071
|
+
const isPkFound = pk && pk.columns.length === columnsToSet.size && pk.columns.every((col) => columnsToSet.has(col));
|
|
42072
|
+
if (isPkFound || isUniqueFound) continue;
|
|
42073
|
+
let composite = columnsTo.length > 1 ? "composite " : "";
|
|
42074
|
+
grouped.errors.push(
|
|
42075
|
+
`\xB7 You are trying to add reference from "${table6}" ("${columns.join('", ')}") to "${tableTo}" ("${columnsTo.join(
|
|
42076
|
+
'", '
|
|
42077
|
+
)}"). The referenced columns are not guaranteed to be unique together. A foreign key must point to a PRIMARY KEY or a set of columns with a UNIQUE constraint. You should add a ${composite}unique constraint to the referenced columns`
|
|
42078
|
+
);
|
|
42079
|
+
continue;
|
|
42080
|
+
}
|
|
42081
|
+
if (statement.type === "drop_pk") {
|
|
42082
|
+
const { table: table6, columns } = statement.pk;
|
|
42083
|
+
const fks = ddl22.fks.list({ tableTo: table6 });
|
|
42084
|
+
const indexes = ddl22.indexes.list({ table: table6 });
|
|
42085
|
+
const fkFound = fks.filter((fk5) => {
|
|
42086
|
+
if (fk5.columnsTo.length !== columns.length) return false;
|
|
42087
|
+
return fk5.columnsTo.every((fkCol) => columns.includes(fkCol));
|
|
42088
|
+
});
|
|
42089
|
+
if (fkFound.length === 0) continue;
|
|
42090
|
+
const indexesFound = indexes.some((index6) => {
|
|
42091
|
+
if (index6.columns.length !== columns.length) {
|
|
42092
|
+
return false;
|
|
42093
|
+
}
|
|
42094
|
+
return index6.columns.every((col) => columns.includes(col.value));
|
|
42095
|
+
});
|
|
42096
|
+
if (indexesFound) continue;
|
|
42097
|
+
grouped.errors.push(
|
|
42098
|
+
`\xB7 You are trying to drop primary key from "${table6}" ("${columns.join('", ')}"), but there is an existing reference on this column. You must either add a UNIQUE constraint to ("${columns.join('", ')}") or drop the foreign key constraint that references this column.`
|
|
42099
|
+
);
|
|
42100
|
+
continue;
|
|
42101
|
+
}
|
|
42102
|
+
}
|
|
42103
|
+
return grouped;
|
|
42104
|
+
};
|
|
41641
42105
|
handle2 = async (config) => {
|
|
41642
42106
|
const outFolder = config.out;
|
|
41643
42107
|
const schemaPath = config.schema;
|
|
@@ -41658,7 +42122,7 @@ var init_generate_mysql = __esm({
|
|
|
41658
42122
|
});
|
|
41659
42123
|
return;
|
|
41660
42124
|
}
|
|
41661
|
-
const { sqlStatements, renames, groupedStatements } = await ddlDiff2(
|
|
42125
|
+
const { sqlStatements, renames, groupedStatements, statements } = await ddlDiff2(
|
|
41662
42126
|
ddlPrev,
|
|
41663
42127
|
ddlCur,
|
|
41664
42128
|
resolver("table"),
|
|
@@ -41666,6 +42130,11 @@ var init_generate_mysql = __esm({
|
|
|
41666
42130
|
resolver("view"),
|
|
41667
42131
|
"default"
|
|
41668
42132
|
);
|
|
42133
|
+
const { errors } = suggestions(statements, ddlCur);
|
|
42134
|
+
if (errors.length) {
|
|
42135
|
+
console.log(errors.map((err2) => withStyle.errorWarning(err2)).join("\n\n"));
|
|
42136
|
+
process.exit(1);
|
|
42137
|
+
}
|
|
41669
42138
|
const explainMessage = explain("mysql", groupedStatements, false, []);
|
|
41670
42139
|
if (explainMessage) console.log(explainMessage);
|
|
41671
42140
|
writeResult({
|
|
@@ -41920,6 +42389,7 @@ var init_diff3 = __esm({
|
|
|
41920
42389
|
init_utils3();
|
|
41921
42390
|
init_convertor3();
|
|
41922
42391
|
init_ddl5();
|
|
42392
|
+
init_grammar5();
|
|
41923
42393
|
init_statements3();
|
|
41924
42394
|
ddlDiffDry3 = async (left, right, mode) => {
|
|
41925
42395
|
const empty = /* @__PURE__ */ new Set();
|
|
@@ -42107,12 +42577,19 @@ var init_diff3 = __esm({
|
|
|
42107
42577
|
return ddl22.fks.hasDiff(it2);
|
|
42108
42578
|
});
|
|
42109
42579
|
const checksAlters = updates.filter((it2) => it2.entityType === "checks");
|
|
42110
|
-
const
|
|
42111
|
-
(it2
|
|
42112
|
-
|
|
42113
|
-
return ((_b = (_a5 = it2.generated) == null ? void 0 : _a5.to) == null ? void 0 : _b.type) === "stored";
|
|
42580
|
+
const alteredColumns = updates.filter((it2) => it2.entityType === "columns").filter((it2) => {
|
|
42581
|
+
if (it2.notNull && ddl22.pks.one({ table: it2.table, columns: [it2.name] })) {
|
|
42582
|
+
delete it2.notNull;
|
|
42114
42583
|
}
|
|
42115
|
-
|
|
42584
|
+
if (it2.default && defaultsCommutative3(it2.default, it2.$right.type)) {
|
|
42585
|
+
delete it2.default;
|
|
42586
|
+
}
|
|
42587
|
+
return ddl22.columns.hasDiff(it2);
|
|
42588
|
+
});
|
|
42589
|
+
const alteredColumnsBecameGenerated = alteredColumns.filter((it2) => {
|
|
42590
|
+
var _a5, _b;
|
|
42591
|
+
return ((_b = (_a5 = it2.generated) == null ? void 0 : _a5.to) == null ? void 0 : _b.type) === "stored";
|
|
42592
|
+
});
|
|
42116
42593
|
const newStoredColumns = columnsToCreate.filter((it2) => it2.generated && it2.generated.type === "stored");
|
|
42117
42594
|
const setOfTablesToRecereate = new Set(
|
|
42118
42595
|
[
|
|
@@ -42134,8 +42611,8 @@ var init_diff3 = __esm({
|
|
|
42134
42611
|
for (const it2 of deletedTables) {
|
|
42135
42612
|
setOfTablesToRecereate.delete(it2.name);
|
|
42136
42613
|
}
|
|
42137
|
-
for (const it2 of
|
|
42138
|
-
if (it2.entityType === "columns" && (it2.type || it2.default || it2.
|
|
42614
|
+
for (const it2 of [...alteredColumns, ...pksAlters, ...fksAlters, ...uniquesAlters, ...checksAlters]) {
|
|
42615
|
+
if (it2.entityType === "columns" && (it2.type || it2.default || it2.autoincrement || it2.notNull)) {
|
|
42139
42616
|
setOfTablesToRecereate.add(it2.table);
|
|
42140
42617
|
}
|
|
42141
42618
|
if (pksAlters.length > 0 && it2.entityType === "pks") setOfTablesToRecereate.add(it2.table);
|
|
@@ -42152,7 +42629,7 @@ var init_diff3 = __esm({
|
|
|
42152
42629
|
newStoredColumns: newStoredColumns.filter((column11) => column11.table === it2),
|
|
42153
42630
|
checkDiffs: checksDiff.filter((checkDiff) => checkDiff.table === it2),
|
|
42154
42631
|
checksAlters: checksAlters.filter((checkAlter) => checkAlter.table === it2),
|
|
42155
|
-
columnAlters:
|
|
42632
|
+
columnAlters: alteredColumns.filter((column11) => column11.table === it2),
|
|
42156
42633
|
fksAlters: fksAlters.filter((fkAlters) => fkAlters.table === it2),
|
|
42157
42634
|
fksDiff: fksDiff.filter((fkDiff) => fkDiff.table === it2),
|
|
42158
42635
|
indexesDiff: indexesDiff.filter((indexDiff) => indexDiff.table === it2),
|
|
@@ -42162,9 +42639,7 @@ var init_diff3 = __esm({
|
|
|
42162
42639
|
uniquesDiff: uniquesDiff.filter((uniqueDiff) => uniqueDiff.table === it2)
|
|
42163
42640
|
});
|
|
42164
42641
|
});
|
|
42165
|
-
const jsonTableAlternations =
|
|
42166
|
-
(it2) => !setOfTablesToRecereate.has(it2.table)
|
|
42167
|
-
).map(
|
|
42642
|
+
const jsonTableAlternations = alteredColumns.filter((it2) => !setOfTablesToRecereate.has(it2.table)).map(
|
|
42168
42643
|
(it2) => prepareRecreateColumn(
|
|
42169
42644
|
it2,
|
|
42170
42645
|
ddl22.columns.one({ table: it2.table, name: it2.name }),
|
|
@@ -42243,25 +42718,16 @@ var init_diff3 = __esm({
|
|
|
42243
42718
|
});
|
|
42244
42719
|
|
|
42245
42720
|
// src/dialects/sqlite/drizzle.ts
|
|
42246
|
-
var import_drizzle_orm3, import_relations3, import_sqlite_core2,
|
|
42721
|
+
var import_drizzle_orm3, import_relations3, import_sqlite_core2, fromDrizzleSchema3, fromExports2, prepareFromSchemaFiles3, defaultFromColumn3;
|
|
42247
42722
|
var init_drizzle4 = __esm({
|
|
42248
42723
|
"src/dialects/sqlite/drizzle.ts"() {
|
|
42249
42724
|
"use strict";
|
|
42250
42725
|
import_drizzle_orm3 = require("drizzle-orm");
|
|
42251
42726
|
import_relations3 = require("drizzle-orm/_relations");
|
|
42252
42727
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
42253
|
-
init_utils2();
|
|
42254
42728
|
init_utils_node();
|
|
42255
42729
|
init_drizzle();
|
|
42256
42730
|
init_grammar5();
|
|
42257
|
-
transformOnUpdateDelete2 = (on2) => {
|
|
42258
|
-
if (on2 === "no action") return "NO ACTION";
|
|
42259
|
-
if (on2 === "cascade") return "CASCADE";
|
|
42260
|
-
if (on2 === "restrict") return "RESTRICT";
|
|
42261
|
-
if (on2 === "set default") return "SET DEFAULT";
|
|
42262
|
-
if (on2 === "set null") return "SET NULL";
|
|
42263
|
-
assertUnreachable(on2);
|
|
42264
|
-
};
|
|
42265
42731
|
fromDrizzleSchema3 = (dTables, dViews, casing2) => {
|
|
42266
42732
|
const dialect5 = new import_sqlite_core2.SQLiteSyncDialect({ casing: casing2 });
|
|
42267
42733
|
const tableConfigs = dTables.map((it2) => ({ table: it2, config: (0, import_sqlite_core2.getTableConfig)(it2) }));
|
|
@@ -42337,8 +42803,8 @@ var init_drizzle4 = __esm({
|
|
|
42337
42803
|
tableTo,
|
|
42338
42804
|
columns: columnsFrom,
|
|
42339
42805
|
columnsTo,
|
|
42340
|
-
onDelete:
|
|
42341
|
-
onUpdate:
|
|
42806
|
+
onDelete: transformOnUpdateDelete(onDelete ?? "no action"),
|
|
42807
|
+
onUpdate: transformOnUpdateDelete(onUpdate ?? "no action"),
|
|
42342
42808
|
nameExplicit: fk5.isNameExplicit()
|
|
42343
42809
|
};
|
|
42344
42810
|
});
|
|
@@ -43199,7 +43665,7 @@ WITH`;
|
|
|
43199
43665
|
if (viewMetadata) options.push(`VIEW_METADATA`);
|
|
43200
43666
|
statement += ` ${options.join(", ")}`;
|
|
43201
43667
|
}
|
|
43202
|
-
statement += ` AS
|
|
43668
|
+
statement += ` AS ${definition}`;
|
|
43203
43669
|
statement += checkOption ? `
|
|
43204
43670
|
WITH CHECK OPTION` : "";
|
|
43205
43671
|
statement += ";";
|
|
@@ -43228,7 +43694,7 @@ WITH`;
|
|
|
43228
43694
|
if (viewMetadata) options.push(`VIEW_METADATA`);
|
|
43229
43695
|
statement += ` ${options.join(", ")}`;
|
|
43230
43696
|
}
|
|
43231
|
-
statement += ` AS
|
|
43697
|
+
statement += ` AS ${definition}`;
|
|
43232
43698
|
statement += checkOption ? `
|
|
43233
43699
|
WITH CHECK OPTION` : "";
|
|
43234
43700
|
statement += ";";
|
|
@@ -169127,9 +169593,9 @@ var init_pull_mysql = __esm({
|
|
|
169127
169593
|
var push_mysql_exports = {};
|
|
169128
169594
|
__export(push_mysql_exports, {
|
|
169129
169595
|
handle: () => handle8,
|
|
169130
|
-
suggestions: () =>
|
|
169596
|
+
suggestions: () => suggestions2
|
|
169131
169597
|
});
|
|
169132
|
-
var import_hanji8, handle8, identifier,
|
|
169598
|
+
var import_hanji8, handle8, identifier, suggestions2;
|
|
169133
169599
|
var init_push_mysql = __esm({
|
|
169134
169600
|
"src/cli/commands/push-mysql.ts"() {
|
|
169135
169601
|
"use strict";
|
|
@@ -169176,7 +169642,7 @@ ${filenames.join("\n")}
|
|
|
169176
169642
|
if (filteredStatements.length === 0) {
|
|
169177
169643
|
(0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
169178
169644
|
}
|
|
169179
|
-
const hints = await
|
|
169645
|
+
const hints = await suggestions2(db, filteredStatements, ddl22);
|
|
169180
169646
|
const explainMessage = explain("mysql", groupedStatements, explainFlag, hints);
|
|
169181
169647
|
if (explainMessage) console.log(explainMessage);
|
|
169182
169648
|
if (explainFlag) return;
|
|
@@ -169201,7 +169667,7 @@ ${filenames.join("\n")}
|
|
|
169201
169667
|
identifier = ({ table: table6, column: column11 }) => {
|
|
169202
169668
|
return [table6, column11].filter(Boolean).map((t6) => `\`${t6}\``).join(".");
|
|
169203
169669
|
};
|
|
169204
|
-
|
|
169670
|
+
suggestions2 = async (db, jsonStatements, ddl22) => {
|
|
169205
169671
|
const grouped = [];
|
|
169206
169672
|
const filtered = jsonStatements.filter((it2) => {
|
|
169207
169673
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
@@ -169225,14 +169691,32 @@ ${filenames.join("\n")}
|
|
|
169225
169691
|
continue;
|
|
169226
169692
|
}
|
|
169227
169693
|
if (statement.type === "drop_pk") {
|
|
169228
|
-
const table6 = statement.pk
|
|
169694
|
+
const { table: table6, columns } = statement.pk;
|
|
169229
169695
|
const id = identifier({ table: table6 });
|
|
169230
169696
|
const res = await db.query(
|
|
169231
169697
|
`select 1 from ${id} limit 1`
|
|
169232
169698
|
);
|
|
169233
|
-
if (res.length
|
|
169234
|
-
|
|
169235
|
-
|
|
169699
|
+
if (res.length > 0) {
|
|
169700
|
+
const hint = `\xB7 You're about to drop ${source_default.underline(table6)} primary key, this statements may fail and your table may loose primary key`;
|
|
169701
|
+
grouped.push({ hint });
|
|
169702
|
+
}
|
|
169703
|
+
const fks = ddl22.fks.list({ tableTo: table6 });
|
|
169704
|
+
const indexes = ddl22.indexes.list({ isUnique: true, table: table6 });
|
|
169705
|
+
const fkFound = fks.filter((fk5) => {
|
|
169706
|
+
if (fk5.columnsTo.length !== columns.length) return false;
|
|
169707
|
+
return fk5.columnsTo.every((fkCol) => columns.includes(fkCol));
|
|
169708
|
+
});
|
|
169709
|
+
if (fkFound.length === 0) continue;
|
|
169710
|
+
const indexesFound = indexes.some((index6) => {
|
|
169711
|
+
if (index6.columns.length !== columns.length) {
|
|
169712
|
+
return false;
|
|
169713
|
+
}
|
|
169714
|
+
return index6.columns.every((col) => columns.includes(col.value));
|
|
169715
|
+
});
|
|
169716
|
+
if (indexesFound) continue;
|
|
169717
|
+
grouped.push({
|
|
169718
|
+
hint: `\xB7 You are trying to drop primary key from "${table6}" ("${columns.join('", ')}"), but there is an existing reference on this column. You must either add a UNIQUE constraint to ("${columns.join('", ')}") or drop the foreign key constraint that references this column.`
|
|
169719
|
+
});
|
|
169236
169720
|
continue;
|
|
169237
169721
|
}
|
|
169238
169722
|
if (statement.type === "add_column" && statement.column.notNull && statement.column.default === null && !statement.column.generated) {
|
|
@@ -169275,6 +169759,27 @@ ${filenames.join("\n")}
|
|
|
169275
169759
|
});
|
|
169276
169760
|
continue;
|
|
169277
169761
|
}
|
|
169762
|
+
if (statement.type === "create_fk" && statement.cause !== "alter_pk") {
|
|
169763
|
+
const { columnsTo, table: table6, tableTo, columns } = statement.fk;
|
|
169764
|
+
const indexes = ddl22.indexes.list({ isUnique: true, table: tableTo });
|
|
169765
|
+
const pk = ddl22.pks.one({ table: tableTo });
|
|
169766
|
+
const columnsToSet = new Set(columnsTo);
|
|
169767
|
+
const isUniqueFound = indexes.some((index6) => {
|
|
169768
|
+
if (index6.columns.length !== columnsToSet.size) {
|
|
169769
|
+
return false;
|
|
169770
|
+
}
|
|
169771
|
+
return index6.columns.every((col) => columnsToSet.has(col.value));
|
|
169772
|
+
});
|
|
169773
|
+
const isPkFound = pk && pk.columns.length === columnsToSet.size && pk.columns.every((col) => columnsToSet.has(col));
|
|
169774
|
+
if (isPkFound || isUniqueFound) continue;
|
|
169775
|
+
let composite = columnsTo.length > 1 ? "composite " : "";
|
|
169776
|
+
grouped.push({
|
|
169777
|
+
hint: `\xB7 You are trying to add reference from "${table6}" ("${columns.join('", ')}") to "${tableTo}" ("${columnsTo.join(
|
|
169778
|
+
'", '
|
|
169779
|
+
)}"). The referenced columns are not guaranteed to be unique together. A foreign key must point to a PRIMARY KEY or a set of columns with a UNIQUE constraint. You should add a ${composite}unique constraint to the referenced columns`
|
|
169780
|
+
});
|
|
169781
|
+
continue;
|
|
169782
|
+
}
|
|
169278
169783
|
}
|
|
169279
169784
|
return grouped;
|
|
169280
169785
|
};
|
|
@@ -170278,9 +170783,9 @@ var init_pull_postgres = __esm({
|
|
|
170278
170783
|
var push_postgres_exports = {};
|
|
170279
170784
|
__export(push_postgres_exports, {
|
|
170280
170785
|
handle: () => handle10,
|
|
170281
|
-
suggestions: () =>
|
|
170786
|
+
suggestions: () => suggestions3
|
|
170282
170787
|
});
|
|
170283
|
-
var import_hanji10, handle10, identifier2,
|
|
170788
|
+
var import_hanji10, handle10, identifier2, suggestions3;
|
|
170284
170789
|
var init_push_postgres = __esm({
|
|
170285
170790
|
"src/cli/commands/push-postgres.ts"() {
|
|
170286
170791
|
"use strict";
|
|
@@ -170317,7 +170822,7 @@ var init_push_postgres = __esm({
|
|
|
170317
170822
|
const { ddl: ddl1, errors: errors1 } = interimToDDL4(schemaFrom);
|
|
170318
170823
|
const { ddl: ddl22 } = interimToDDL4(schemaTo);
|
|
170319
170824
|
if (errors1.length > 0) {
|
|
170320
|
-
console.log(
|
|
170825
|
+
console.log(errors1.map((it2) => postgresSchemaError(it2)).join("\n"));
|
|
170321
170826
|
process.exit(1);
|
|
170322
170827
|
}
|
|
170323
170828
|
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff(
|
|
@@ -170343,7 +170848,7 @@ var init_push_postgres = __esm({
|
|
|
170343
170848
|
(0, import_hanji10.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
170344
170849
|
return;
|
|
170345
170850
|
}
|
|
170346
|
-
const hints = await
|
|
170851
|
+
const hints = await suggestions3(db, jsonStatements);
|
|
170347
170852
|
const explainMessage = explain("postgres", groupedStatements, explainFlag, hints);
|
|
170348
170853
|
if (explainMessage) console.log(explainMessage);
|
|
170349
170854
|
if (explainFlag) return;
|
|
@@ -170366,7 +170871,7 @@ var init_push_postgres = __esm({
|
|
|
170366
170871
|
const schemakey = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
|
|
170367
170872
|
return `${schemakey}"${name}"`;
|
|
170368
170873
|
};
|
|
170369
|
-
|
|
170874
|
+
suggestions3 = async (db, jsonStatements) => {
|
|
170370
170875
|
const grouped = [];
|
|
170371
170876
|
const filtered = jsonStatements.filter((it2) => {
|
|
170372
170877
|
if (it2.type === "drop_view" && it2.cause) return false;
|
|
@@ -170648,7 +171153,7 @@ ${it2.sql}`);
|
|
|
170648
171153
|
let checksCount = 0;
|
|
170649
171154
|
let viewsCount = 0;
|
|
170650
171155
|
const tableToParsedFks = dbTableColumns.reduce((acc, it2) => {
|
|
170651
|
-
if (!
|
|
171156
|
+
if (!acc[it2.table]) {
|
|
170652
171157
|
acc[it2.table] = parseSqliteFks(it2.sql);
|
|
170653
171158
|
}
|
|
170654
171159
|
return acc;
|
|
@@ -170803,12 +171308,12 @@ ${it2.sql}`);
|
|
|
170803
171308
|
return acc;
|
|
170804
171309
|
}, {});
|
|
170805
171310
|
const fks = [];
|
|
170806
|
-
for (const
|
|
171311
|
+
for (const entity of Object.values(fksToColumns)) {
|
|
170807
171312
|
foreignKeysCount += 1;
|
|
170808
171313
|
progressCallback("fks", foreignKeysCount, "fetching");
|
|
170809
|
-
const { columnsFrom, columnsTo } =
|
|
170810
|
-
const
|
|
170811
|
-
const constraint =
|
|
171314
|
+
const { columnsFrom, columnsTo, fk: fk5 } = entity;
|
|
171315
|
+
const parsedFks = tableToParsedFks[fk5.tableFrom];
|
|
171316
|
+
const constraint = parsedFks == null ? void 0 : parsedFks.find(
|
|
170812
171317
|
(it2) => areStringArraysEqual(it2.fromColumns, columnsFrom) && areStringArraysEqual(it2.toColumns, columnsTo) && it2.toTable === fk5.tableTo && it2.fromTable === fk5.tableFrom
|
|
170813
171318
|
);
|
|
170814
171319
|
let name;
|
|
@@ -171086,7 +171591,7 @@ import { sql } from "drizzle-orm"
|
|
|
171086
171591
|
const { def, options } = typeof res === "string" ? { def: res } : res;
|
|
171087
171592
|
const defaultStatement = def ? `.default(${def})` : "";
|
|
171088
171593
|
const opts = options ? `${JSON.stringify(options)}` : "";
|
|
171089
|
-
return `${withCasing3(name, casing2)}: ${drizzleType}(${dbColumnName3({ name, casing: casing2 })}${opts})${defaultStatement}`;
|
|
171594
|
+
return `${withCasing3(name, casing2)}: ${drizzleType}(${dbColumnName3({ name, casing: casing2, withMode: Boolean(opts) })}${opts})${defaultStatement}`;
|
|
171090
171595
|
}
|
|
171091
171596
|
if (lowered.startsWith("text")) {
|
|
171092
171597
|
const match3 = lowered.match(/\d+/);
|
|
@@ -171148,7 +171653,6 @@ import { sql } from "drizzle-orm"
|
|
|
171148
171653
|
const columnNames = it2.columns.filter((c5) => !c5.isExpression).map((c5) => c5.value);
|
|
171149
171654
|
const indexGeneratedName = `${tableName}_${columnNames.join("_")}_index`;
|
|
171150
171655
|
const escapedIndexName = indexGeneratedName === it2.name ? "" : `"${it2.name}"`;
|
|
171151
|
-
statement += ` ${idxKey}: `;
|
|
171152
171656
|
statement += it2.isUnique ? "uniqueIndex(" : "index(";
|
|
171153
171657
|
statement += `${escapedIndexName})`;
|
|
171154
171658
|
statement += `.on(${it2.columns.map((it3) => `table.${withCasing3(it3.value, casing2)}`).join(", ")}),`;
|
|
@@ -171305,9 +171809,9 @@ var init_pull_sqlite = __esm({
|
|
|
171305
171809
|
var push_sqlite_exports = {};
|
|
171306
171810
|
__export(push_sqlite_exports, {
|
|
171307
171811
|
handle: () => handle12,
|
|
171308
|
-
suggestions: () =>
|
|
171812
|
+
suggestions: () => suggestions4
|
|
171309
171813
|
});
|
|
171310
|
-
var import_hanji12, handle12,
|
|
171814
|
+
var import_hanji12, handle12, suggestions4;
|
|
171311
171815
|
var init_push_sqlite = __esm({
|
|
171312
171816
|
"src/cli/commands/push-sqlite.ts"() {
|
|
171313
171817
|
"use strict";
|
|
@@ -171349,7 +171853,7 @@ var init_push_sqlite = __esm({
|
|
|
171349
171853
|
[${source_default.blue("i")}] No changes detected`);
|
|
171350
171854
|
return;
|
|
171351
171855
|
}
|
|
171352
|
-
const hints = await
|
|
171856
|
+
const hints = await suggestions4(db, statements);
|
|
171353
171857
|
const explainMessage = explain("sqlite", groupedStatements, explainFlag, hints);
|
|
171354
171858
|
if (explainMessage) console.log(explainMessage);
|
|
171355
171859
|
if (explainFlag) return;
|
|
@@ -171383,7 +171887,7 @@ var init_push_sqlite = __esm({
|
|
|
171383
171887
|
(0, import_hanji12.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
171384
171888
|
}
|
|
171385
171889
|
};
|
|
171386
|
-
|
|
171890
|
+
suggestions4 = async (connection, jsonStatements) => {
|
|
171387
171891
|
const grouped = [];
|
|
171388
171892
|
for (const statement of jsonStatements) {
|
|
171389
171893
|
if (statement.type === "drop_table") {
|
|
@@ -171454,10 +171958,9 @@ var init_push_libsql = __esm({
|
|
|
171454
171958
|
// src/cli/commands/push-singlestore.ts
|
|
171455
171959
|
var push_singlestore_exports = {};
|
|
171456
171960
|
__export(push_singlestore_exports, {
|
|
171457
|
-
handle: () => handle14
|
|
171458
|
-
suggestions: () => suggestions4
|
|
171961
|
+
handle: () => handle14
|
|
171459
171962
|
});
|
|
171460
|
-
var import_hanji13, handle14
|
|
171963
|
+
var import_hanji13, handle14;
|
|
171461
171964
|
var init_push_singlestore = __esm({
|
|
171462
171965
|
"src/cli/commands/push-singlestore.ts"() {
|
|
171463
171966
|
"use strict";
|
|
@@ -171467,11 +171970,12 @@ var init_push_singlestore = __esm({
|
|
|
171467
171970
|
init_pull_utils();
|
|
171468
171971
|
init_utils_node();
|
|
171469
171972
|
init_diff4();
|
|
171973
|
+
init_highlighter();
|
|
171470
171974
|
init_prompts();
|
|
171471
171975
|
init_selector_ui();
|
|
171472
|
-
init_outputs();
|
|
171473
171976
|
init_views();
|
|
171474
|
-
|
|
171977
|
+
init_push_mysql();
|
|
171978
|
+
handle14 = async (schemaPath, credentials2, filters, verbose, force, casing2, explainFlag) => {
|
|
171475
171979
|
const { connectToSingleStore: connectToSingleStore2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
171476
171980
|
const { fromDatabaseForDrizzle: fromDatabaseForDrizzle6 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
|
171477
171981
|
const filter2 = prepareEntityFilter("singlestore", filters, []);
|
|
@@ -171493,7 +171997,7 @@ ${filenames.join("\n")}
|
|
|
171493
171997
|
const interimFromFiles = fromDrizzleSchema7(res.tables, casing2);
|
|
171494
171998
|
const { ddl: ddl1 } = interimToDDL(interimFromDB);
|
|
171495
171999
|
const { ddl: ddl22 } = interimToDDL(interimFromFiles);
|
|
171496
|
-
const { sqlStatements, statements } = await ddlDiff4(
|
|
172000
|
+
const { sqlStatements, statements, groupedStatements } = await ddlDiff4(
|
|
171497
172001
|
ddl1,
|
|
171498
172002
|
ddl22,
|
|
171499
172003
|
resolver("table"),
|
|
@@ -171504,57 +172008,28 @@ ${filenames.join("\n")}
|
|
|
171504
172008
|
const filteredStatements = statements;
|
|
171505
172009
|
if (filteredStatements.length === 0) {
|
|
171506
172010
|
(0, import_hanji13.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
171507
|
-
}
|
|
171508
|
-
|
|
171509
|
-
|
|
171510
|
-
|
|
171511
|
-
|
|
171512
|
-
|
|
171513
|
-
|
|
171514
|
-
|
|
171515
|
-
|
|
171516
|
-
|
|
171517
|
-
console.log();
|
|
171518
|
-
}
|
|
171519
|
-
if (!force && hints.length > 0) {
|
|
171520
|
-
const { data: data2 } = await (0, import_hanji13.render)(
|
|
171521
|
-
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
171522
|
-
);
|
|
171523
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
171524
|
-
(0, import_hanji13.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
171525
|
-
process.exit(0);
|
|
171526
|
-
}
|
|
171527
|
-
}
|
|
171528
|
-
if (!force && hints.length > 0) {
|
|
171529
|
-
console.log(withStyle.warning("Found data-loss statements:"));
|
|
171530
|
-
console.log(truncates.join("\n"));
|
|
171531
|
-
console.log();
|
|
171532
|
-
console.log(
|
|
171533
|
-
source_default.red.bold(
|
|
171534
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
171535
|
-
)
|
|
171536
|
-
);
|
|
171537
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
171538
|
-
const { data: data2 } = await (0, import_hanji13.render)(new Select(["No, abort", `Yes, execute`]));
|
|
171539
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
171540
|
-
(0, import_hanji13.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
171541
|
-
process.exit(0);
|
|
171542
|
-
}
|
|
171543
|
-
}
|
|
171544
|
-
for (const st2 of combinedStatements) {
|
|
171545
|
-
await db.query(st2);
|
|
171546
|
-
}
|
|
171547
|
-
if (filteredStatements.length > 0) {
|
|
171548
|
-
(0, import_hanji13.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
171549
|
-
} else {
|
|
171550
|
-
(0, import_hanji13.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
172011
|
+
}
|
|
172012
|
+
const hints = await suggestions2(db, filteredStatements, ddl22);
|
|
172013
|
+
const explainMessage = explain("singlestore", groupedStatements, explainFlag, hints);
|
|
172014
|
+
if (explainMessage) console.log(explainMessage);
|
|
172015
|
+
if (explainFlag) return;
|
|
172016
|
+
if (!force && hints.length > 0) {
|
|
172017
|
+
const { data: data2 } = await (0, import_hanji13.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
172018
|
+
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
172019
|
+
(0, import_hanji13.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
172020
|
+
process.exit(0);
|
|
171551
172021
|
}
|
|
171552
172022
|
}
|
|
171553
|
-
|
|
171554
|
-
|
|
171555
|
-
|
|
171556
|
-
|
|
171557
|
-
|
|
172023
|
+
const lossStatements = hints.map((x6) => x6.statement).filter((x6) => typeof x6 !== "undefined");
|
|
172024
|
+
for (const statement of [...lossStatements, ...sqlStatements]) {
|
|
172025
|
+
if (verbose) console.log(highlightSQL(statement));
|
|
172026
|
+
await db.query(statement);
|
|
172027
|
+
}
|
|
172028
|
+
if (filteredStatements.length > 0) {
|
|
172029
|
+
(0, import_hanji13.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
172030
|
+
} else {
|
|
172031
|
+
(0, import_hanji13.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
172032
|
+
}
|
|
171558
172033
|
};
|
|
171559
172034
|
}
|
|
171560
172035
|
});
|
|
@@ -172894,11 +173369,11 @@ var init_push_cockroach = __esm({
|
|
|
172894
173369
|
init_diff6();
|
|
172895
173370
|
init_drizzle7();
|
|
172896
173371
|
init_utils_node();
|
|
173372
|
+
init_highlighter();
|
|
172897
173373
|
init_prompts();
|
|
172898
173374
|
init_selector_ui();
|
|
172899
|
-
init_outputs();
|
|
172900
173375
|
init_views();
|
|
172901
|
-
handle16 = async (schemaPath, verbose, credentials2, filters, force, casing2) => {
|
|
173376
|
+
handle16 = async (schemaPath, verbose, credentials2, filters, force, casing2, explainFlag) => {
|
|
172902
173377
|
const { prepareCockroach: prepareCockroach2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
172903
173378
|
const { introspect: cockroachPushIntrospect } = await Promise.resolve().then(() => (init_pull_cockroach(), pull_cockroach_exports));
|
|
172904
173379
|
const db = await prepareCockroach2(credentials2);
|
|
@@ -172911,7 +173386,7 @@ var init_push_cockroach = __esm({
|
|
|
172911
173386
|
console.log(warnings.map((it2) => postgresSchemaWarning(it2)).join("\n\n"));
|
|
172912
173387
|
}
|
|
172913
173388
|
if (errors.length > 0) {
|
|
172914
|
-
console.log(errors.map((it2) =>
|
|
173389
|
+
console.log(errors.map((it2) => cockraochSchemaError(it2)).join("\n"));
|
|
172915
173390
|
process.exit(1);
|
|
172916
173391
|
}
|
|
172917
173392
|
const progress = new ProgressView("Pulling schema from database...", "Pulling schema from database...");
|
|
@@ -172919,10 +173394,10 @@ var init_push_cockroach = __esm({
|
|
|
172919
173394
|
const { ddl: ddl1, errors: errors1 } = interimToDDL2(schemaFrom);
|
|
172920
173395
|
const { ddl: ddl22 } = interimToDDL2(schemaTo);
|
|
172921
173396
|
if (errors1.length > 0) {
|
|
172922
|
-
console.log(
|
|
173397
|
+
console.log(errors1.map((it2) => cockraochSchemaError(it2)).join("\n"));
|
|
172923
173398
|
process.exit(1);
|
|
172924
173399
|
}
|
|
172925
|
-
const { sqlStatements, statements: jsonStatements } = await ddlDiff6(
|
|
173400
|
+
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff6(
|
|
172926
173401
|
ddl1,
|
|
172927
173402
|
ddl22,
|
|
172928
173403
|
resolver("schema"),
|
|
@@ -172942,38 +173417,20 @@ var init_push_cockroach = __esm({
|
|
|
172942
173417
|
(0, import_hanji15.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
172943
173418
|
return;
|
|
172944
173419
|
}
|
|
172945
|
-
const
|
|
172946
|
-
|
|
172947
|
-
|
|
172948
|
-
|
|
172949
|
-
console.log();
|
|
172950
|
-
console.log(losses.map((s6) => source_default.blue(s6)).join("\n"));
|
|
172951
|
-
console.log();
|
|
172952
|
-
}
|
|
172953
|
-
if (!force && hints.length === 0) {
|
|
172954
|
-
const { data: data2 } = await (0, import_hanji15.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
172955
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
172956
|
-
(0, import_hanji15.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
172957
|
-
process.exit(0);
|
|
172958
|
-
}
|
|
172959
|
-
}
|
|
173420
|
+
const hints = await suggestions5(db, jsonStatements);
|
|
173421
|
+
const explainMessage = explain("cockroach", groupedStatements, explainFlag, hints);
|
|
173422
|
+
if (explainMessage) console.log(explainMessage);
|
|
173423
|
+
if (explainFlag) return;
|
|
172960
173424
|
if (!force && hints.length > 0) {
|
|
172961
|
-
|
|
172962
|
-
console.log(hints.join("\n"));
|
|
172963
|
-
console.log();
|
|
172964
|
-
console.log(
|
|
172965
|
-
source_default.red.bold(
|
|
172966
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
172967
|
-
)
|
|
172968
|
-
);
|
|
172969
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
172970
|
-
const { data: data2 } = await (0, import_hanji15.render)(new Select(["No, abort", `Yes, proceed`]));
|
|
173425
|
+
const { data: data2 } = await (0, import_hanji15.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
172971
173426
|
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
172972
173427
|
(0, import_hanji15.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
172973
173428
|
process.exit(0);
|
|
172974
173429
|
}
|
|
172975
173430
|
}
|
|
172976
|
-
|
|
173431
|
+
const lossStatements = hints.map((x6) => x6.statement).filter((x6) => typeof x6 !== "undefined");
|
|
173432
|
+
for (const statement of [...lossStatements, ...sqlStatements]) {
|
|
173433
|
+
if (verbose) console.log(highlightSQL(statement));
|
|
172977
173434
|
await db.query(statement);
|
|
172978
173435
|
}
|
|
172979
173436
|
(0, import_hanji15.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
@@ -172984,8 +173441,7 @@ var init_push_cockroach = __esm({
|
|
|
172984
173441
|
return `${schemakey}"${name}"`;
|
|
172985
173442
|
};
|
|
172986
173443
|
suggestions5 = async (db, jsonStatements) => {
|
|
172987
|
-
const
|
|
172988
|
-
const hints = [];
|
|
173444
|
+
const grouped = [];
|
|
172989
173445
|
const filtered = jsonStatements.filter((it2) => {
|
|
172990
173446
|
if (it2.type === "recreate_view") return false;
|
|
172991
173447
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
@@ -172994,14 +173450,14 @@ var init_push_cockroach = __esm({
|
|
|
172994
173450
|
for (const statement of filtered) {
|
|
172995
173451
|
if (statement.type === "drop_table") {
|
|
172996
173452
|
const res = await db.query(`select 1 from ${statement.key} limit 1`);
|
|
172997
|
-
if (res.length > 0)
|
|
173453
|
+
if (res.length > 0) grouped.push({ hint: `\xB7 You're about to delete non-empty ${statement.key} table` });
|
|
172998
173454
|
continue;
|
|
172999
173455
|
}
|
|
173000
173456
|
if (statement.type === "drop_view" && statement.view.materialized) {
|
|
173001
173457
|
const id = identifier3(statement.view);
|
|
173002
173458
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173003
173459
|
if (res.length === 0) continue;
|
|
173004
|
-
|
|
173460
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty ${id} materialized view` });
|
|
173005
173461
|
continue;
|
|
173006
173462
|
}
|
|
173007
173463
|
if (statement.type === "drop_column") {
|
|
@@ -173009,7 +173465,7 @@ var init_push_cockroach = __esm({
|
|
|
173009
173465
|
const id = identifier3({ schema: column11.schema, name: column11.table });
|
|
173010
173466
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173011
173467
|
if (res.length === 0) continue;
|
|
173012
|
-
|
|
173468
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty ${column11.name} column in ${id} table` });
|
|
173013
173469
|
continue;
|
|
173014
173470
|
}
|
|
173015
173471
|
if (statement.type === "drop_schema") {
|
|
@@ -173018,7 +173474,7 @@ var init_push_cockroach = __esm({
|
|
|
173018
173474
|
);
|
|
173019
173475
|
const count2 = Number(res[0].count);
|
|
173020
173476
|
if (count2 === 0) continue;
|
|
173021
|
-
|
|
173477
|
+
grouped.push({ hint: `\xB7 You're about to delete ${source_default.underline(statement.name)} schema with ${count2} tables` });
|
|
173022
173478
|
continue;
|
|
173023
173479
|
}
|
|
173024
173480
|
if (statement.type === "drop_pk") {
|
|
@@ -173029,18 +173485,10 @@ var init_push_cockroach = __esm({
|
|
|
173029
173485
|
`select 1 from ${id} limit 1`
|
|
173030
173486
|
);
|
|
173031
173487
|
if (res.length > 0) {
|
|
173032
|
-
|
|
173033
|
-
`\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
173034
|
-
);
|
|
173488
|
+
grouped.push({
|
|
173489
|
+
hint: `\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
173490
|
+
});
|
|
173035
173491
|
}
|
|
173036
|
-
const [{ name: pkName }] = await db.query(`
|
|
173037
|
-
SELECT constraint_name as name
|
|
173038
|
-
FROM information_schema.table_constraints
|
|
173039
|
-
WHERE
|
|
173040
|
-
table_schema = '${schema5}'
|
|
173041
|
-
AND table_name = '${table6}'
|
|
173042
|
-
AND constraint_type = 'PRIMARY KEY';`);
|
|
173043
|
-
statements.push(`ALTER TABLE ${id} DROP CONSTRAINT "${pkName}"`);
|
|
173044
173492
|
continue;
|
|
173045
173493
|
}
|
|
173046
173494
|
if (statement.type === "add_column" && statement.column.notNull && statement.column.default === null) {
|
|
@@ -173048,9 +173496,9 @@ var init_push_cockroach = __esm({
|
|
|
173048
173496
|
const id = identifier3({ schema: column11.schema, name: column11.table });
|
|
173049
173497
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173050
173498
|
if (res.length === 0) continue;
|
|
173051
|
-
|
|
173052
|
-
`\xB7 You're about to add not-null ${source_default.underline(statement.column.name)} column without default value to a non-empty ${id} table`
|
|
173053
|
-
);
|
|
173499
|
+
grouped.push({
|
|
173500
|
+
hint: `\xB7 You're about to add not-null ${source_default.underline(statement.column.name)} column without default value to a non-empty ${id} table`
|
|
173501
|
+
});
|
|
173054
173502
|
continue;
|
|
173055
173503
|
}
|
|
173056
173504
|
if (statement.type === "create_index" && statement.index.isUnique && !statement.newTable) {
|
|
@@ -173058,16 +173506,13 @@ var init_push_cockroach = __esm({
|
|
|
173058
173506
|
const id = identifier3({ schema: unique.schema, name: unique.table });
|
|
173059
173507
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173060
173508
|
if (res.length === 0) continue;
|
|
173061
|
-
|
|
173062
|
-
`\xB7 You're about to add ${source_default.underline(unique.name)} unique index to a non-empty ${id} table which may fail`
|
|
173063
|
-
);
|
|
173509
|
+
grouped.push({
|
|
173510
|
+
hint: `\xB7 You're about to add ${source_default.underline(unique.name)} unique index to a non-empty ${id} table which may fail`
|
|
173511
|
+
});
|
|
173064
173512
|
continue;
|
|
173065
173513
|
}
|
|
173066
173514
|
}
|
|
173067
|
-
return
|
|
173068
|
-
losses: statements,
|
|
173069
|
-
hints
|
|
173070
|
-
};
|
|
173515
|
+
return grouped;
|
|
173071
173516
|
};
|
|
173072
173517
|
}
|
|
173073
173518
|
});
|
|
@@ -174097,15 +174542,18 @@ var init_push_mssql = __esm({
|
|
|
174097
174542
|
init_ddl3();
|
|
174098
174543
|
init_diff5();
|
|
174099
174544
|
init_drizzle6();
|
|
174545
|
+
init_highlighter();
|
|
174100
174546
|
init_prompts();
|
|
174101
174547
|
init_selector_ui();
|
|
174102
|
-
init_outputs();
|
|
174103
174548
|
init_views();
|
|
174104
|
-
handle18 = async (schemaPath, verbose, credentials2, filters, force, casing2) => {
|
|
174549
|
+
handle18 = async (schemaPath, verbose, credentials2, filters, force, casing2, explainFlag) => {
|
|
174105
174550
|
const { connectToMsSQL: connectToMsSQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
174106
174551
|
const { introspect: introspect6 } = await Promise.resolve().then(() => (init_pull_mssql(), pull_mssql_exports));
|
|
174107
174552
|
const { db } = await connectToMsSQL2(credentials2);
|
|
174108
174553
|
const filenames = prepareFilenames(schemaPath);
|
|
174554
|
+
console.log(source_default.gray(`Reading schema files:
|
|
174555
|
+
${filenames.join("\n")}
|
|
174556
|
+
`));
|
|
174109
174557
|
const res = await prepareFromSchemaFiles5(filenames);
|
|
174110
174558
|
const existing = extractMssqlExisting(res.schemas, res.views);
|
|
174111
174559
|
const filter2 = prepareEntityFilter("mssql", filters, existing);
|
|
@@ -174126,7 +174574,7 @@ var init_push_mssql = __esm({
|
|
|
174126
174574
|
console.log(errors.map((it2) => mssqlSchemaError(it2)).join("\n"));
|
|
174127
174575
|
process.exit(1);
|
|
174128
174576
|
}
|
|
174129
|
-
const { sqlStatements, statements: jsonStatements } = await ddlDiff5(
|
|
174577
|
+
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff5(
|
|
174130
174578
|
ddl1,
|
|
174131
174579
|
ddl22,
|
|
174132
174580
|
resolver("schema", "dbo"),
|
|
@@ -174151,42 +174599,27 @@ var init_push_mssql = __esm({
|
|
|
174151
174599
|
(0, import_hanji17.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
174152
174600
|
return;
|
|
174153
174601
|
}
|
|
174154
|
-
const
|
|
174155
|
-
const
|
|
174156
|
-
if (
|
|
174157
|
-
|
|
174158
|
-
console.log(withStyle.warning("You are about to execute these statements:"));
|
|
174159
|
-
console.log();
|
|
174160
|
-
console.log(statementsToExecute.map((s6) => source_default.blue(s6)).join("\n"));
|
|
174161
|
-
console.log();
|
|
174162
|
-
}
|
|
174163
|
-
if (!force && hints.length === 0) {
|
|
174164
|
-
const { data: data2 } = await (0, import_hanji17.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
174165
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
174166
|
-
(0, import_hanji17.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
174167
|
-
process.exit(0);
|
|
174168
|
-
}
|
|
174169
|
-
}
|
|
174602
|
+
const hints = await suggestions6(db, jsonStatements, ddl22);
|
|
174603
|
+
const explainMessage = explain("mssql", groupedStatements, explainFlag, hints);
|
|
174604
|
+
if (explainMessage) console.log(explainMessage);
|
|
174605
|
+
if (explainFlag) return;
|
|
174170
174606
|
if (!force && hints.length > 0) {
|
|
174171
|
-
|
|
174172
|
-
console.log(hints.join("\n"));
|
|
174173
|
-
console.log();
|
|
174174
|
-
console.log(
|
|
174175
|
-
source_default.red.bold(
|
|
174176
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
174177
|
-
)
|
|
174178
|
-
);
|
|
174179
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
174180
|
-
const { data: data2 } = await (0, import_hanji17.render)(new Select(["No, abort", `Yes, proceed`]));
|
|
174607
|
+
const { data: data2 } = await (0, import_hanji17.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
174181
174608
|
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
174182
174609
|
(0, import_hanji17.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
174183
174610
|
process.exit(0);
|
|
174184
174611
|
}
|
|
174185
174612
|
}
|
|
174186
|
-
|
|
174613
|
+
const lossStatements = hints.map((x6) => x6.statement).filter((x6) => typeof x6 !== "undefined");
|
|
174614
|
+
for (const statement of [...lossStatements, ...sqlStatements]) {
|
|
174615
|
+
if (verbose) console.log(highlightSQL(statement));
|
|
174187
174616
|
await db.query(statement);
|
|
174188
174617
|
}
|
|
174189
|
-
|
|
174618
|
+
if (sqlStatements.length > 0) {
|
|
174619
|
+
(0, import_hanji17.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
174620
|
+
} else {
|
|
174621
|
+
(0, import_hanji17.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
174622
|
+
}
|
|
174190
174623
|
};
|
|
174191
174624
|
identifier4 = (it2) => {
|
|
174192
174625
|
const { schema: schema5, table: table6 } = it2;
|
|
@@ -174195,8 +174628,7 @@ var init_push_mssql = __esm({
|
|
|
174195
174628
|
return `${schemaKey}${tableKey}`;
|
|
174196
174629
|
};
|
|
174197
174630
|
suggestions6 = async (db, jsonStatements, ddl22) => {
|
|
174198
|
-
const
|
|
174199
|
-
const hints = [];
|
|
174631
|
+
const grouped = [];
|
|
174200
174632
|
const filtered = jsonStatements.filter((it2) => {
|
|
174201
174633
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
174202
174634
|
return true;
|
|
@@ -174205,7 +174637,7 @@ var init_push_mssql = __esm({
|
|
|
174205
174637
|
if (statement.type === "drop_table") {
|
|
174206
174638
|
const tableName = identifier4({ schema: statement.table.schema, table: statement.table.name });
|
|
174207
174639
|
const res = await db.query(`select top(1) 1 from ${tableName};`);
|
|
174208
|
-
if (res.length > 0)
|
|
174640
|
+
if (res.length > 0) grouped.push({ hint: `\xB7 You're about to delete non-empty [${statement.table.name}] table` });
|
|
174209
174641
|
continue;
|
|
174210
174642
|
}
|
|
174211
174643
|
if (statement.type === "drop_column") {
|
|
@@ -174213,7 +174645,7 @@ var init_push_mssql = __esm({
|
|
|
174213
174645
|
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174214
174646
|
const res = await db.query(`SELECT TOP(1) 1 FROM ${key} WHERE [${column11.name}] IS NOT NULL;`);
|
|
174215
174647
|
if (res.length === 0) continue;
|
|
174216
|
-
|
|
174648
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty [${column11.name}] column in [${column11.table}] table` });
|
|
174217
174649
|
continue;
|
|
174218
174650
|
}
|
|
174219
174651
|
if (statement.type === "drop_schema") {
|
|
@@ -174223,24 +174655,7 @@ var init_push_mssql = __esm({
|
|
|
174223
174655
|
const count2 = Number(res[0].count);
|
|
174224
174656
|
if (count2 === 0) continue;
|
|
174225
174657
|
const tableGrammar = count2 === 1 ? "table" : "tables";
|
|
174226
|
-
|
|
174227
|
-
`\xB7 You're about to delete [${statement.name}] schema with ${count2} ${tableGrammar}`
|
|
174228
|
-
);
|
|
174229
|
-
continue;
|
|
174230
|
-
}
|
|
174231
|
-
if (statement.type === "add_column" && statement.column.notNull && !ddl22.defaults.one({
|
|
174232
|
-
column: statement.column.name,
|
|
174233
|
-
schema: statement.column.schema,
|
|
174234
|
-
table: statement.column.table
|
|
174235
|
-
})) {
|
|
174236
|
-
const column11 = statement.column;
|
|
174237
|
-
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174238
|
-
const res = await db.query(`select top(1) 1 from ${key}`);
|
|
174239
|
-
if (res.length === 0) continue;
|
|
174240
|
-
hints.push(
|
|
174241
|
-
`\xB7 You're about to add not-null [${column11.name}] column without default value to a non-empty ${key} table`
|
|
174242
|
-
);
|
|
174243
|
-
losses.push(`DELETE FROM ${key};`);
|
|
174658
|
+
grouped.push({ hint: `\xB7 You're about to delete [${statement.name}] schema with ${count2} ${tableGrammar}` });
|
|
174244
174659
|
continue;
|
|
174245
174660
|
}
|
|
174246
174661
|
if (statement.type === "alter_column" && statement.diff.$right.notNull && !ddl22.defaults.one({
|
|
@@ -174252,10 +174667,23 @@ var init_push_mssql = __esm({
|
|
|
174252
174667
|
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174253
174668
|
const res = await db.query(`select top(1) 1 from ${key};`);
|
|
174254
174669
|
if (res.length === 0) continue;
|
|
174255
|
-
|
|
174256
|
-
`\xB7 You're about to add not-null to [${statement.diff.$right.name}] column without default value to a non-empty ${key} table`
|
|
174257
|
-
);
|
|
174258
|
-
|
|
174670
|
+
grouped.push({
|
|
174671
|
+
hint: `\xB7 You're about to add not-null to [${statement.diff.$right.name}] column without default value to a non-empty ${key} table`
|
|
174672
|
+
});
|
|
174673
|
+
continue;
|
|
174674
|
+
}
|
|
174675
|
+
if (statement.type === "add_column" && statement.column.notNull && !ddl22.defaults.one({
|
|
174676
|
+
column: statement.column.name,
|
|
174677
|
+
schema: statement.column.schema,
|
|
174678
|
+
table: statement.column.table
|
|
174679
|
+
})) {
|
|
174680
|
+
const column11 = statement.column;
|
|
174681
|
+
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174682
|
+
const res = await db.query(`select top(1) 1 from ${key};`);
|
|
174683
|
+
if (res.length === 0) continue;
|
|
174684
|
+
grouped.push({
|
|
174685
|
+
hint: `\xB7 You're about to add not-null [${statement.column.name}] column without default value to a non-empty ${key} table`
|
|
174686
|
+
});
|
|
174259
174687
|
continue;
|
|
174260
174688
|
}
|
|
174261
174689
|
if (statement.type === "drop_pk") {
|
|
@@ -174266,9 +174694,9 @@ var init_push_mssql = __esm({
|
|
|
174266
174694
|
`select top(1) 1 from ${id};`
|
|
174267
174695
|
);
|
|
174268
174696
|
if (res.length > 0) {
|
|
174269
|
-
|
|
174270
|
-
`\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
174271
|
-
);
|
|
174697
|
+
grouped.push({
|
|
174698
|
+
hint: `\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
174699
|
+
});
|
|
174272
174700
|
}
|
|
174273
174701
|
continue;
|
|
174274
174702
|
}
|
|
@@ -174277,34 +174705,31 @@ var init_push_mssql = __esm({
|
|
|
174277
174705
|
const id = identifier4({ schema: unique.schema, table: unique.table });
|
|
174278
174706
|
const res = await db.query(`select top(1) 1 from ${id};`);
|
|
174279
174707
|
if (res.length === 0) continue;
|
|
174280
|
-
|
|
174281
|
-
`\xB7 You're about to add ${source_default.underline(unique.name)} unique constraint to a non-empty ${id} table which may fail`
|
|
174282
|
-
);
|
|
174708
|
+
grouped.push({
|
|
174709
|
+
hint: `\xB7 You're about to add ${source_default.underline(unique.name)} unique constraint to a non-empty ${id} table which may fail`
|
|
174710
|
+
});
|
|
174283
174711
|
continue;
|
|
174284
174712
|
}
|
|
174285
174713
|
if (statement.type === "rename_column" && ddl22.checks.one({ schema: statement.to.schema, table: statement.to.table })) {
|
|
174286
174714
|
const left = statement.from;
|
|
174287
174715
|
const right = statement.to;
|
|
174288
|
-
|
|
174289
|
-
`\xB7 You are trying to rename column from ${left.name} to ${right.name}, but it is not possible to rename a column if it is used in a check constraint on the table.
|
|
174716
|
+
grouped.push({
|
|
174717
|
+
hint: `\xB7 You are trying to rename column from ${left.name} to ${right.name}, but it is not possible to rename a column if it is used in a check constraint on the table.
|
|
174290
174718
|
To rename the column, first drop the check constraint, then rename the column, and finally recreate the check constraint`
|
|
174291
|
-
);
|
|
174719
|
+
});
|
|
174292
174720
|
continue;
|
|
174293
174721
|
}
|
|
174294
174722
|
if (statement.type === "rename_schema") {
|
|
174295
174723
|
const left = statement.from;
|
|
174296
174724
|
const right = statement.to;
|
|
174297
|
-
|
|
174298
|
-
`\xB7 You are trying to rename schema ${left.name} to ${right.name}, but it is not supported to rename a schema in mssql.
|
|
174725
|
+
grouped.push({
|
|
174726
|
+
hint: `\xB7 You are trying to rename schema ${left.name} to ${right.name}, but it is not supported to rename a schema in mssql.
|
|
174299
174727
|
You should create new schema and transfer everything to it`
|
|
174300
|
-
);
|
|
174728
|
+
});
|
|
174301
174729
|
continue;
|
|
174302
174730
|
}
|
|
174303
174731
|
}
|
|
174304
|
-
return
|
|
174305
|
-
losses,
|
|
174306
|
-
hints
|
|
174307
|
-
};
|
|
174732
|
+
return grouped;
|
|
174308
174733
|
};
|
|
174309
174734
|
}
|
|
174310
174735
|
});
|
|
@@ -180142,15 +180567,12 @@ init_views();
|
|
|
180142
180567
|
init_generate_common();
|
|
180143
180568
|
var prepareCheckParams = async (options, from) => {
|
|
180144
180569
|
const config = from === "config" ? await drizzleConfigFromFile(options.config) : options;
|
|
180145
|
-
if (!config.
|
|
180146
|
-
|
|
180147
|
-
|
|
180148
|
-
console.log(error2(text));
|
|
180149
|
-
console.log(wrapParam("database", config.out));
|
|
180150
|
-
console.log(wrapParam("secretArn", config.dialect));
|
|
180570
|
+
if (!config.dialect) {
|
|
180571
|
+
console.log(error2("Please provide required params:"));
|
|
180572
|
+
console.log(wrapParam("dialect", dialect));
|
|
180151
180573
|
process.exit(1);
|
|
180152
180574
|
}
|
|
180153
|
-
return { out: config.out, dialect: config.dialect };
|
|
180575
|
+
return { out: config.out || "drizzle", dialect: config.dialect };
|
|
180154
180576
|
};
|
|
180155
180577
|
var prepareGenerateConfig = async (options, from) => {
|
|
180156
180578
|
var _a5;
|
|
@@ -180334,11 +180756,7 @@ var preparePushConfig = async (options, from) => {
|
|
|
180334
180756
|
};
|
|
180335
180757
|
}
|
|
180336
180758
|
if (config.dialect === "gel") {
|
|
180337
|
-
console.log(
|
|
180338
|
-
error2(
|
|
180339
|
-
`You can't use 'push' command with Gel dialect`
|
|
180340
|
-
)
|
|
180341
|
-
);
|
|
180759
|
+
console.log(error2(`You can't use 'push' command with Gel dialect`));
|
|
180342
180760
|
process.exit(1);
|
|
180343
180761
|
}
|
|
180344
180762
|
if (config.dialect === "mssql") {
|
|
@@ -180792,11 +181210,7 @@ var prepareMigrateConfig = async (configPath) => {
|
|
|
180792
181210
|
};
|
|
180793
181211
|
}
|
|
180794
181212
|
if (dialect5 === "gel") {
|
|
180795
|
-
console.log(
|
|
180796
|
-
error2(
|
|
180797
|
-
`You can't use 'migrate' command with Gel dialect`
|
|
180798
|
-
)
|
|
180799
|
-
);
|
|
181213
|
+
console.log(error2(`You can't use 'migrate' command with Gel dialect`));
|
|
180800
181214
|
process.exit(1);
|
|
180801
181215
|
}
|
|
180802
181216
|
if (dialect5 === "mssql") {
|
|
@@ -180841,8 +181255,12 @@ var prepareMigrateConfig = async (configPath) => {
|
|
|
180841
181255
|
};
|
|
180842
181256
|
var drizzleConfigFromFile = async (configPath, isExport) => {
|
|
180843
181257
|
const prefix2 = process.env.TEST_CONFIG_PATH_PREFIX || "";
|
|
180844
|
-
const defaultTsConfigExists = (0, import_fs5.existsSync)(
|
|
180845
|
-
|
|
181258
|
+
const defaultTsConfigExists = (0, import_fs5.existsSync)(
|
|
181259
|
+
(0, import_path3.resolve)((0, import_path3.join)(prefix2, "drizzle.config.ts"))
|
|
181260
|
+
);
|
|
181261
|
+
const defaultJsConfigExists = (0, import_fs5.existsSync)(
|
|
181262
|
+
(0, import_path3.resolve)((0, import_path3.join)(prefix2, "drizzle.config.js"))
|
|
181263
|
+
);
|
|
180846
181264
|
const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
|
|
180847
181265
|
if (!configPath && !isExport) {
|
|
180848
181266
|
console.log(
|
|
@@ -180900,12 +181318,17 @@ var migrateToFoldersV3 = (out) => {
|
|
|
180900
181318
|
}
|
|
180901
181319
|
const oldSql = (0, import_fs5.readFileSync)(oldSqlPath);
|
|
180902
181320
|
(0, import_fs5.mkdirSync)((0, import_path3.join)(out, `${folderName}_${migrationName}`));
|
|
180903
|
-
(0, import_fs5.writeFileSync)(
|
|
180904
|
-
|
|
181321
|
+
(0, import_fs5.writeFileSync)(
|
|
181322
|
+
(0, import_path3.join)(out, `${folderName}_${migrationName}/snapshot.json`),
|
|
181323
|
+
oldSnapshot
|
|
181324
|
+
);
|
|
181325
|
+
(0, import_fs5.writeFileSync)(
|
|
181326
|
+
(0, import_path3.join)(out, `${folderName}_${migrationName}/migration.sql`),
|
|
181327
|
+
oldSql
|
|
181328
|
+
);
|
|
180905
181329
|
(0, import_fs5.unlinkSync)(oldSqlPath);
|
|
180906
181330
|
}
|
|
180907
|
-
(0, import_fs5.
|
|
180908
|
-
});
|
|
181331
|
+
(0, import_fs5.rmSync)(metaPath, { recursive: true, force: true });
|
|
180909
181332
|
return true;
|
|
180910
181333
|
}
|
|
180911
181334
|
return false;
|
|
@@ -180966,7 +181389,10 @@ var upToV6 = (it2) => {
|
|
|
180966
181389
|
for (const index6 of Object.values(table6.indexes)) {
|
|
180967
181390
|
const columns = index6.columns.map((x6) => {
|
|
180968
181391
|
const nameToCheck = trimChar(x6, "`");
|
|
180969
|
-
const isColumn = !!ddl7.columns.one({
|
|
181392
|
+
const isColumn = !!ddl7.columns.one({
|
|
181393
|
+
table: table6.name,
|
|
181394
|
+
name: nameToCheck
|
|
181395
|
+
});
|
|
180970
181396
|
return { value: x6, isExpression: !isColumn };
|
|
180971
181397
|
});
|
|
180972
181398
|
ddl7.indexes.push({
|
|
@@ -180980,61 +181406,72 @@ var upToV6 = (it2) => {
|
|
|
180980
181406
|
nameExplicit: true
|
|
180981
181407
|
});
|
|
180982
181408
|
}
|
|
180983
|
-
|
|
180984
|
-
const
|
|
180985
|
-
const
|
|
180986
|
-
|
|
180987
|
-
|
|
180988
|
-
|
|
180989
|
-
|
|
180990
|
-
|
|
180991
|
-
|
|
180992
|
-
|
|
180993
|
-
columns
|
|
180994
|
-
|
|
180995
|
-
|
|
180996
|
-
|
|
180997
|
-
|
|
180998
|
-
|
|
180999
|
-
|
|
181409
|
+
if (table6.uniqueConstraints) {
|
|
181410
|
+
for (const unique of Object.values(table6.uniqueConstraints)) {
|
|
181411
|
+
const columns = unique.columns.map((x6) => {
|
|
181412
|
+
const nameToCheck = trimChar(x6, "`");
|
|
181413
|
+
const isColumn = !!ddl7.columns.one({
|
|
181414
|
+
table: table6.name,
|
|
181415
|
+
name: nameToCheck
|
|
181416
|
+
});
|
|
181417
|
+
return { value: x6, isExpression: !isColumn };
|
|
181418
|
+
});
|
|
181419
|
+
let nameImplicit = `${table6.name}_${unique.columns.join("_")}_unique` === unique.name || `${table6.name}_${unique.columns.join("_")}` === unique.name;
|
|
181420
|
+
ddl7.indexes.push({
|
|
181421
|
+
table: table6.name,
|
|
181422
|
+
name: unique.name,
|
|
181423
|
+
columns,
|
|
181424
|
+
algorithm: null,
|
|
181425
|
+
isUnique: true,
|
|
181426
|
+
lock: null,
|
|
181427
|
+
using: null,
|
|
181428
|
+
nameExplicit: !nameImplicit
|
|
181429
|
+
});
|
|
181430
|
+
}
|
|
181000
181431
|
}
|
|
181001
|
-
|
|
181002
|
-
const
|
|
181003
|
-
|
|
181004
|
-
|
|
181005
|
-
|
|
181006
|
-
|
|
181007
|
-
|
|
181008
|
-
|
|
181009
|
-
|
|
181010
|
-
|
|
181011
|
-
|
|
181012
|
-
|
|
181432
|
+
if (table6.foreignKeys) {
|
|
181433
|
+
for (const fk5 of Object.values(table6.foreignKeys)) {
|
|
181434
|
+
const isNameImplicit = `${fk5.tableFrom}_${fk5.columnsFrom.join("_")}_${fk5.tableTo}_${fk5.columnsTo.join("_")}_fk` === fk5.name;
|
|
181435
|
+
ddl7.fks.push({
|
|
181436
|
+
table: table6.name,
|
|
181437
|
+
name: fk5.name,
|
|
181438
|
+
columns: fk5.columnsFrom,
|
|
181439
|
+
columnsTo: fk5.columnsTo,
|
|
181440
|
+
tableTo: fk5.tableTo,
|
|
181441
|
+
onUpdate: ((_a5 = fk5.onUpdate) == null ? void 0 : _a5.toUpperCase()) ?? null,
|
|
181442
|
+
onDelete: ((_b = fk5.onDelete) == null ? void 0 : _b.toUpperCase()) ?? null,
|
|
181443
|
+
nameExplicit: !isNameImplicit
|
|
181444
|
+
});
|
|
181445
|
+
}
|
|
181013
181446
|
}
|
|
181014
|
-
|
|
181015
|
-
|
|
181016
|
-
|
|
181017
|
-
|
|
181018
|
-
|
|
181019
|
-
|
|
181447
|
+
if (table6.checkConstraint) {
|
|
181448
|
+
for (const check2 of Object.values(table6.checkConstraint)) {
|
|
181449
|
+
ddl7.checks.push({
|
|
181450
|
+
table: table6.name,
|
|
181451
|
+
name: check2.name,
|
|
181452
|
+
value: check2.value
|
|
181453
|
+
});
|
|
181454
|
+
}
|
|
181455
|
+
for (const pk of Object.values(table6.compositePrimaryKeys)) {
|
|
181456
|
+
ddl7.pks.push({
|
|
181457
|
+
table: table6.name,
|
|
181458
|
+
name: "PRIMARY",
|
|
181459
|
+
columns: pk.columns
|
|
181460
|
+
});
|
|
181461
|
+
}
|
|
181020
181462
|
}
|
|
181021
|
-
|
|
181022
|
-
|
|
181023
|
-
|
|
181024
|
-
|
|
181025
|
-
|
|
181463
|
+
}
|
|
181464
|
+
if (json.views) {
|
|
181465
|
+
for (const view5 of Object.values(json.views)) {
|
|
181466
|
+
ddl7.views.push({
|
|
181467
|
+
name: view5.name,
|
|
181468
|
+
algorithm: view5.algorithm ?? null,
|
|
181469
|
+
sqlSecurity: view5.sqlSecurity ?? null,
|
|
181470
|
+
withCheckOption: view5.withCheckOption ?? null,
|
|
181471
|
+
definition: view5.definition
|
|
181026
181472
|
});
|
|
181027
181473
|
}
|
|
181028
181474
|
}
|
|
181029
|
-
for (const view5 of Object.values(json.views)) {
|
|
181030
|
-
ddl7.views.push({
|
|
181031
|
-
name: view5.name,
|
|
181032
|
-
algorithm: view5.algorithm ?? null,
|
|
181033
|
-
sqlSecurity: view5.sqlSecurity ?? null,
|
|
181034
|
-
withCheckOption: view5.withCheckOption ?? null,
|
|
181035
|
-
definition: view5.definition
|
|
181036
|
-
});
|
|
181037
|
-
}
|
|
181038
181475
|
return {
|
|
181039
181476
|
version: "6",
|
|
181040
181477
|
id: json.id,
|
|
@@ -181062,21 +181499,25 @@ var upToV8 = (it2) => {
|
|
|
181062
181499
|
for (const schema5 of Object.values(json.schemas)) {
|
|
181063
181500
|
ddl7.schemas.push({ name: schema5 });
|
|
181064
181501
|
}
|
|
181065
|
-
|
|
181066
|
-
|
|
181067
|
-
|
|
181068
|
-
|
|
181069
|
-
|
|
181070
|
-
|
|
181071
|
-
|
|
181072
|
-
|
|
181073
|
-
|
|
181074
|
-
|
|
181075
|
-
|
|
181502
|
+
if (json.sequences) {
|
|
181503
|
+
for (const seq of Object.values(json.sequences)) {
|
|
181504
|
+
ddl7.sequences.push({
|
|
181505
|
+
schema: seq.schema,
|
|
181506
|
+
name: seq.name,
|
|
181507
|
+
startWith: seq.startWith ?? null,
|
|
181508
|
+
incrementBy: seq.increment ?? null,
|
|
181509
|
+
minValue: seq.minValue ?? null,
|
|
181510
|
+
maxValue: seq.maxValue ?? null,
|
|
181511
|
+
cacheSize: seq.cache ? Number(seq.cache) : null,
|
|
181512
|
+
cycle: seq.cycle ?? null
|
|
181513
|
+
});
|
|
181514
|
+
}
|
|
181076
181515
|
}
|
|
181077
181516
|
for (const table6 of Object.values(json.tables)) {
|
|
181078
181517
|
const schema5 = table6.schema || "public";
|
|
181079
|
-
const isRlsEnabled = table6.isRLSEnabled || Object.keys(table6.policies).length > 0 || Object.values(json.policies).some(
|
|
181518
|
+
const isRlsEnabled = table6.isRLSEnabled || Object.keys(table6.policies).length > 0 || Object.values(json.policies).some(
|
|
181519
|
+
(it3) => it3.on === table6.name && (it3.schema ?? "public") === schema5
|
|
181520
|
+
);
|
|
181080
181521
|
ddl7.tables.push({
|
|
181081
181522
|
schema: schema5,
|
|
181082
181523
|
name: table6.name,
|
|
@@ -181117,33 +181558,41 @@ var upToV8 = (it2) => {
|
|
|
181117
181558
|
default: typeof column11.default === "undefined" ? null : trimDefaultValueSuffix(String(column11.default))
|
|
181118
181559
|
});
|
|
181119
181560
|
}
|
|
181120
|
-
|
|
181121
|
-
const
|
|
181122
|
-
|
|
181123
|
-
|
|
181561
|
+
if (table6.compositePrimaryKeys) {
|
|
181562
|
+
for (const pk of Object.values(table6.compositePrimaryKeys)) {
|
|
181563
|
+
const nameExplicit = `${table6.name}_${pk.columns.join("_")}_pk` !== pk.name;
|
|
181564
|
+
if (!nameExplicit) {
|
|
181565
|
+
hints.push(
|
|
181566
|
+
`update pk name: ${pk.name} -> ${defaultNameForPK(table6.name)}`
|
|
181567
|
+
);
|
|
181568
|
+
}
|
|
181569
|
+
ddl7.pks.push({
|
|
181570
|
+
schema: schema5,
|
|
181571
|
+
table: table6.name,
|
|
181572
|
+
name: pk.name,
|
|
181573
|
+
columns: pk.columns,
|
|
181574
|
+
nameExplicit
|
|
181575
|
+
// TODO: ??
|
|
181576
|
+
});
|
|
181124
181577
|
}
|
|
181125
|
-
ddl7.pks.push({
|
|
181126
|
-
schema: schema5,
|
|
181127
|
-
table: table6.name,
|
|
181128
|
-
name: pk.name,
|
|
181129
|
-
columns: pk.columns,
|
|
181130
|
-
nameExplicit
|
|
181131
|
-
// TODO: ??
|
|
181132
|
-
});
|
|
181133
181578
|
}
|
|
181134
|
-
|
|
181135
|
-
const
|
|
181136
|
-
|
|
181137
|
-
|
|
181579
|
+
if (table6.uniqueConstraints) {
|
|
181580
|
+
for (const unique of Object.values(table6.uniqueConstraints)) {
|
|
181581
|
+
const nameExplicit = `${table6.name}_${unique.columns.join("_")}_unique` !== unique.name;
|
|
181582
|
+
if (!nameExplicit) {
|
|
181583
|
+
hints.push(
|
|
181584
|
+
`update unique name: ${unique.name} -> ${defaultNameForUnique(table6.name, ...unique.columns)}`
|
|
181585
|
+
);
|
|
181586
|
+
}
|
|
181587
|
+
ddl7.uniques.push({
|
|
181588
|
+
schema: schema5,
|
|
181589
|
+
table: table6.name,
|
|
181590
|
+
columns: unique.columns,
|
|
181591
|
+
name: unique.name,
|
|
181592
|
+
nameExplicit,
|
|
181593
|
+
nullsNotDistinct: unique.nullsNotDistinct ?? defaults.nullsNotDistinct
|
|
181594
|
+
});
|
|
181138
181595
|
}
|
|
181139
|
-
ddl7.uniques.push({
|
|
181140
|
-
schema: schema5,
|
|
181141
|
-
table: table6.name,
|
|
181142
|
-
columns: unique.columns,
|
|
181143
|
-
name: unique.name,
|
|
181144
|
-
nameExplicit,
|
|
181145
|
-
nullsNotDistinct: unique.nullsNotDistinct ?? defaults.nullsNotDistinct
|
|
181146
|
-
});
|
|
181147
181596
|
}
|
|
181148
181597
|
for (const check2 of Object.values(table6.checkConstraints)) {
|
|
181149
181598
|
ddl7.checks.push({
|
|
@@ -181169,7 +181618,10 @@ var upToV8 = (it2) => {
|
|
|
181169
181618
|
const nameExplicit = columns.some((it3) => it3.isExpression === true) || `${table6.name}_${columns.map((it3) => it3.value).join("_")}_index` !== idx.name;
|
|
181170
181619
|
if (!nameExplicit) {
|
|
181171
181620
|
hints.push(
|
|
181172
|
-
`rename index name: ${idx.name} -> ${defaultNameForIndex(
|
|
181621
|
+
`rename index name: ${idx.name} -> ${defaultNameForIndex(
|
|
181622
|
+
table6.name,
|
|
181623
|
+
idx.columns.map((x6) => x6.expression)
|
|
181624
|
+
)}`
|
|
181173
181625
|
);
|
|
181174
181626
|
}
|
|
181175
181627
|
ddl7.indexes.push({
|
|
@@ -181261,16 +181713,43 @@ var upToV8 = (it2) => {
|
|
|
181261
181713
|
autovacuumEnabled: getOrNull(opt, "autovacuumEnabled"),
|
|
181262
181714
|
autovacuumFreezeMaxAge: getOrNull(opt, "autovacuumFreezeMaxAge"),
|
|
181263
181715
|
autovacuumFreezeMinAge: getOrNull(opt, "autovacuumFreezeMinAge"),
|
|
181264
|
-
autovacuumFreezeTableAge: getOrNull(
|
|
181265
|
-
|
|
181266
|
-
|
|
181267
|
-
|
|
181268
|
-
|
|
181269
|
-
|
|
181270
|
-
|
|
181271
|
-
|
|
181716
|
+
autovacuumFreezeTableAge: getOrNull(
|
|
181717
|
+
opt,
|
|
181718
|
+
"autovacuumFreezeTableAge"
|
|
181719
|
+
),
|
|
181720
|
+
autovacuumMultixactFreezeMaxAge: getOrNull(
|
|
181721
|
+
opt,
|
|
181722
|
+
"autovacuumMultixactFreezeMaxAge"
|
|
181723
|
+
),
|
|
181724
|
+
autovacuumMultixactFreezeMinAge: getOrNull(
|
|
181725
|
+
opt,
|
|
181726
|
+
"autovacuumMultixactFreezeMinAge"
|
|
181727
|
+
),
|
|
181728
|
+
autovacuumMultixactFreezeTableAge: getOrNull(
|
|
181729
|
+
opt,
|
|
181730
|
+
"autovacuumMultixactFreezeTableAge"
|
|
181731
|
+
),
|
|
181732
|
+
autovacuumVacuumCostDelay: getOrNull(
|
|
181733
|
+
opt,
|
|
181734
|
+
"autovacuumVacuumCostDelay"
|
|
181735
|
+
),
|
|
181736
|
+
autovacuumVacuumCostLimit: getOrNull(
|
|
181737
|
+
opt,
|
|
181738
|
+
"autovacuumVacuumCostLimit"
|
|
181739
|
+
),
|
|
181740
|
+
autovacuumVacuumScaleFactor: getOrNull(
|
|
181741
|
+
opt,
|
|
181742
|
+
"autovacuumVacuumScaleFactor"
|
|
181743
|
+
),
|
|
181744
|
+
autovacuumVacuumThreshold: getOrNull(
|
|
181745
|
+
opt,
|
|
181746
|
+
"autovacuumVacuumThreshold"
|
|
181747
|
+
),
|
|
181272
181748
|
fillfactor: getOrNull(opt, "fillfactor"),
|
|
181273
|
-
logAutovacuumMinDuration: getOrNull(
|
|
181749
|
+
logAutovacuumMinDuration: getOrNull(
|
|
181750
|
+
opt,
|
|
181751
|
+
"logAutovacuumMinDuration"
|
|
181752
|
+
),
|
|
181274
181753
|
parallelWorkers: getOrNull(opt, "parallelWorkers"),
|
|
181275
181754
|
toastTupleTarget: getOrNull(opt, "toastTupleTarget"),
|
|
181276
181755
|
userCatalogTable: getOrNull(opt, "userCatalogTable"),
|
|
@@ -181312,19 +181791,30 @@ var updateUpToV7 = (it2) => {
|
|
|
181312
181791
|
const mappedIndexes = Object.fromEntries(
|
|
181313
181792
|
Object.entries(table6.indexes).map((idx) => {
|
|
181314
181793
|
const { columns, ...rest } = idx[1];
|
|
181315
|
-
const mappedColumns = columns.map(
|
|
181316
|
-
|
|
181317
|
-
|
|
181318
|
-
|
|
181319
|
-
|
|
181320
|
-
|
|
181321
|
-
|
|
181322
|
-
|
|
181323
|
-
|
|
181794
|
+
const mappedColumns = columns.map(
|
|
181795
|
+
(it4) => {
|
|
181796
|
+
return {
|
|
181797
|
+
expression: it4,
|
|
181798
|
+
isExpression: false,
|
|
181799
|
+
asc: true,
|
|
181800
|
+
nulls: "last",
|
|
181801
|
+
opClass: void 0
|
|
181802
|
+
};
|
|
181803
|
+
}
|
|
181804
|
+
);
|
|
181324
181805
|
return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
|
|
181325
181806
|
})
|
|
181326
181807
|
);
|
|
181327
|
-
return [
|
|
181808
|
+
return [
|
|
181809
|
+
it3[0],
|
|
181810
|
+
{
|
|
181811
|
+
...table6,
|
|
181812
|
+
indexes: mappedIndexes,
|
|
181813
|
+
policies: {},
|
|
181814
|
+
isRLSEnabled: false,
|
|
181815
|
+
checkConstraints: {}
|
|
181816
|
+
}
|
|
181817
|
+
];
|
|
181328
181818
|
})
|
|
181329
181819
|
);
|
|
181330
181820
|
return {
|
|
@@ -181558,6 +182048,7 @@ init_source();
|
|
|
181558
182048
|
var import_fs9 = require("fs");
|
|
181559
182049
|
var import_path4 = require("path");
|
|
181560
182050
|
init_grammar5();
|
|
182051
|
+
init_grammar5();
|
|
181561
182052
|
init_utils_node();
|
|
181562
182053
|
init_ddl5();
|
|
181563
182054
|
init_snapshot6();
|
|
@@ -181596,12 +182087,13 @@ var updateToV7 = (snapshot) => {
|
|
|
181596
182087
|
name: table6.name
|
|
181597
182088
|
});
|
|
181598
182089
|
for (const column11 of Object.values(table6.columns)) {
|
|
182090
|
+
let def = typeof column11.default === "undefined" ? null : String(column11.default);
|
|
181599
182091
|
ddl7.columns.push({
|
|
181600
182092
|
table: table6.name,
|
|
181601
182093
|
name: column11.name,
|
|
181602
182094
|
type: column11.type,
|
|
181603
|
-
notNull: column11.notNull,
|
|
181604
|
-
default:
|
|
182095
|
+
notNull: column11.notNull && !column11.primaryKey,
|
|
182096
|
+
default: def,
|
|
181605
182097
|
autoincrement: column11.autoincrement,
|
|
181606
182098
|
generated: column11.generated ?? null
|
|
181607
182099
|
});
|
|
@@ -181650,16 +182142,16 @@ var updateToV7 = (snapshot) => {
|
|
|
181650
182142
|
});
|
|
181651
182143
|
}
|
|
181652
182144
|
for (const fk5 of Object.values(table6.foreignKeys)) {
|
|
181653
|
-
const
|
|
182145
|
+
const nameExplicit = fk5.name !== `${table6.name}_${fk5.columnsFrom.join("_")}_${fk5.tableTo}_${fk5.columnsTo.join("_")}_fk`;
|
|
181654
182146
|
ddl7.fks.push({
|
|
181655
182147
|
table: table6.name,
|
|
181656
182148
|
name: fk5.name,
|
|
181657
182149
|
columns: fk5.columnsFrom,
|
|
181658
182150
|
tableTo: fk5.tableTo,
|
|
181659
182151
|
columnsTo: fk5.columnsTo,
|
|
181660
|
-
onDelete: fk5.onDelete ?? "
|
|
181661
|
-
onUpdate: fk5.onUpdate ?? "
|
|
181662
|
-
nameExplicit
|
|
182152
|
+
onDelete: transformOnUpdateDelete(fk5.onDelete ?? "no action"),
|
|
182153
|
+
onUpdate: transformOnUpdateDelete(fk5.onUpdate ?? "no action"),
|
|
182154
|
+
nameExplicit
|
|
181663
182155
|
});
|
|
181664
182156
|
}
|
|
181665
182157
|
}
|
|
@@ -181709,6 +182201,7 @@ var updateUpToV62 = (json) => {
|
|
|
181709
182201
|
// src/cli/schema.ts
|
|
181710
182202
|
init_utils4();
|
|
181711
182203
|
init_common3();
|
|
182204
|
+
init_outputs();
|
|
181712
182205
|
init_views();
|
|
181713
182206
|
var optionDialect = string("dialect").enum(...dialects).desc(
|
|
181714
182207
|
`Database dialect: 'gel', 'postgresql', 'mysql', 'sqlite', 'turso', 'singlestore', 'duckdb' or 'mssql'`
|
|
@@ -181934,7 +182427,7 @@ var push = command({
|
|
|
181934
182427
|
...optionsFilters,
|
|
181935
182428
|
...optionsDatabaseCredentials,
|
|
181936
182429
|
verbose: boolean().desc("Print all statements for each push").default(false),
|
|
181937
|
-
strict: boolean().desc("Always ask for confirmation")
|
|
182430
|
+
strict: boolean().desc("Always ask for confirmation"),
|
|
181938
182431
|
force: boolean().desc(
|
|
181939
182432
|
"Auto-approve all data loss statements. Note: Data loss statements may truncate your tables and data"
|
|
181940
182433
|
).default(false),
|
|
@@ -181964,6 +182457,12 @@ var push = command({
|
|
|
181964
182457
|
"tlsSecurity"
|
|
181965
182458
|
]
|
|
181966
182459
|
);
|
|
182460
|
+
if (typeof opts.strict !== "undefined") {
|
|
182461
|
+
console.log(withStyle.fullWarning(
|
|
182462
|
+
"\u26A0\uFE0F Deprecated: Do not use 'strict' flag. Use 'explain' instead"
|
|
182463
|
+
));
|
|
182464
|
+
process.exit(1);
|
|
182465
|
+
}
|
|
181967
182466
|
return preparePushConfig(opts, from);
|
|
181968
182467
|
},
|
|
181969
182468
|
handler: async (config) => {
|
|
@@ -181995,13 +182494,13 @@ var push = command({
|
|
|
181995
182494
|
await libSQLPush(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
181996
182495
|
} else if (dialect5 === "singlestore") {
|
|
181997
182496
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_singlestore(), push_singlestore_exports));
|
|
181998
|
-
await handle21(schemaPath, credentials2, filters, verbose, force, casing2);
|
|
182497
|
+
await handle21(schemaPath, credentials2, filters, verbose, force, casing2, explain2);
|
|
181999
182498
|
} else if (dialect5 === "cockroach") {
|
|
182000
182499
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_cockroach(), push_cockroach_exports));
|
|
182001
|
-
await handle21(schemaPath, verbose, credentials2, filters, force, casing2);
|
|
182500
|
+
await handle21(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
182002
182501
|
} else if (dialect5 === "mssql") {
|
|
182003
182502
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_mssql(), push_mssql_exports));
|
|
182004
|
-
await handle21(schemaPath, verbose, credentials2, filters, force, casing2);
|
|
182503
|
+
await handle21(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
182005
182504
|
} else if (dialect5 === "gel") {
|
|
182006
182505
|
console.log(error2(`You can't use 'push' command with Gel dialect`));
|
|
182007
182506
|
} else {
|
|
@@ -182391,7 +182890,7 @@ init_views();
|
|
|
182391
182890
|
var version3 = async () => {
|
|
182392
182891
|
const { npmVersion } = await ormCoreVersions();
|
|
182393
182892
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
|
182394
|
-
const envVersion = "1.0.0-beta.
|
|
182893
|
+
const envVersion = "1.0.0-beta.4";
|
|
182395
182894
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
|
182396
182895
|
const versions = `drizzle-kit: ${kitVersion}
|
|
182397
182896
|
${ormVersion}`;
|