drizzle-kit 1.0.0-beta.4-4605abe → 1.0.0-beta.5-5707f0d
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 +9 -0
- package/api-mysql.mjs +9 -0
- package/api-postgres.d.mts +1619 -1619
- package/api-postgres.d.ts +1619 -1619
- package/api-postgres.js +160 -18
- package/api-postgres.mjs +160 -18
- package/api-sqlite.js +9 -0
- package/api-sqlite.mjs +9 -0
- package/bin.cjs +720 -293
- 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;
|
|
@@ -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[]",
|
|
@@ -37967,7 +38357,7 @@ var init_drizzle = __esm({
|
|
|
37967
38357
|
});
|
|
37968
38358
|
|
|
37969
38359
|
// src/dialects/postgres/drizzle.ts
|
|
37970
|
-
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;
|
|
37971
38361
|
var init_drizzle2 = __esm({
|
|
37972
38362
|
"src/dialects/postgres/drizzle.ts"() {
|
|
37973
38363
|
"use strict";
|
|
@@ -38027,7 +38417,7 @@ var init_drizzle2 = __esm({
|
|
|
38027
38417
|
if ((0, import_drizzle_orm.is)(baseColumn, import_pg_core2.PgArray)) return unwrapArray(baseColumn, dimensions + 1);
|
|
38028
38418
|
return { baseColumn, dimensions };
|
|
38029
38419
|
};
|
|
38030
|
-
|
|
38420
|
+
transformOnUpdateDelete2 = (on2) => {
|
|
38031
38421
|
if (on2 === "no action") return "NO ACTION";
|
|
38032
38422
|
if (on2 === "cascade") return "CASCADE";
|
|
38033
38423
|
if (on2 === "restrict") return "RESTRICT";
|
|
@@ -38235,8 +38625,8 @@ var init_drizzle2 = __esm({
|
|
|
38235
38625
|
schemaTo,
|
|
38236
38626
|
columns: columnsFrom,
|
|
38237
38627
|
columnsTo,
|
|
38238
|
-
onDelete: onDelete ?
|
|
38239
|
-
onUpdate: onUpdate ?
|
|
38628
|
+
onDelete: onDelete ? transformOnUpdateDelete2(onDelete) : null,
|
|
38629
|
+
onUpdate: onUpdate ? transformOnUpdateDelete2(onUpdate) : null
|
|
38240
38630
|
};
|
|
38241
38631
|
})
|
|
38242
38632
|
);
|
|
@@ -38993,7 +39383,7 @@ var init_convertor = __esm({
|
|
|
38993
39383
|
});
|
|
38994
39384
|
alterColumnConvertor = convertor("alter_column", (st2) => {
|
|
38995
39385
|
var _a5;
|
|
38996
|
-
const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial } = st2;
|
|
39386
|
+
const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial, toSerial } = st2;
|
|
38997
39387
|
const statements = [];
|
|
38998
39388
|
const key = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}"` : `"${column11.table}"`;
|
|
38999
39389
|
const recreateDefault = diff2.type && (isEnum || wasEnum) && diff2.$left.default;
|
|
@@ -39003,17 +39393,21 @@ var init_convertor = __esm({
|
|
|
39003
39393
|
if (diff2.type) {
|
|
39004
39394
|
const typeSchema = column11.typeSchema && column11.typeSchema !== "public" ? `"${column11.typeSchema}".` : "";
|
|
39005
39395
|
const textProxy = wasEnum && isEnum ? "text::" : "";
|
|
39006
|
-
const suffix = isEnum ? ` USING "${column11.name}"::${textProxy}${typeSchema}"${column11.type}"${"[]".repeat(column11.dimensions)}` : ` USING "${column11.name}"::${column11.type}${"[]".repeat(column11.dimensions)}`;
|
|
39007
|
-
|
|
39008
|
-
if (diff2.type) {
|
|
39009
|
-
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;
|
|
39010
|
-
} else {
|
|
39011
|
-
type = `${typeSchema}${column11.typeSchema ? `"${column11.type}"` : column11.type}`;
|
|
39012
|
-
}
|
|
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;
|
|
39013
39398
|
if (wasSerial) {
|
|
39014
|
-
statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT
|
|
39399
|
+
statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT;`);
|
|
39015
39400
|
const sequenceKey = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}_${column11.name}_seq"` : `"${column11.table}_${column11.name}_seq"`;
|
|
39016
|
-
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}";`);
|
|
39017
39411
|
}
|
|
39018
39412
|
statements.push(
|
|
39019
39413
|
`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" SET DATA TYPE ${type}${"[]".repeat(column11.dimensions)}${suffix};`
|
|
@@ -40319,6 +40713,7 @@ var init_diff = __esm({
|
|
|
40319
40713
|
}).map((it2) => {
|
|
40320
40714
|
const column11 = it2.$right;
|
|
40321
40715
|
const wasSerial = isSerialType(it2.$left.type);
|
|
40716
|
+
const toSerial = !isSerialType(it2.$left.type) && isSerialType(it2.$right.type);
|
|
40322
40717
|
const isEnum = ddl22.enums.one({ schema: column11.typeSchema ?? "public", name: column11.type }) !== null;
|
|
40323
40718
|
const wasEnum = (it2.type && ddl1.enums.one({ schema: column11.typeSchema ?? "public", name: it2.type.from }) !== null) ?? false;
|
|
40324
40719
|
return prepareStatement("alter_column", {
|
|
@@ -40326,7 +40721,8 @@ var init_diff = __esm({
|
|
|
40326
40721
|
to: column11,
|
|
40327
40722
|
isEnum,
|
|
40328
40723
|
wasEnum,
|
|
40329
|
-
wasSerial
|
|
40724
|
+
wasSerial,
|
|
40725
|
+
toSerial
|
|
40330
40726
|
});
|
|
40331
40727
|
});
|
|
40332
40728
|
const createSequences = createdSequences.map((it2) => prepareStatement("create_sequence", { sequence: it2 }));
|
|
@@ -40595,7 +40991,7 @@ var init_prompts = __esm({
|
|
|
40595
40991
|
const to2 = data2.to;
|
|
40596
40992
|
const schemaFromPrefix = newItem.schema ? newItem.schema !== defaultSchema ? `${newItem.schema}.` : "" : "";
|
|
40597
40993
|
const tableFromPrefix = newItem.table ? `${newItem.table}.` : "";
|
|
40598
|
-
const fromEntity = `${schemaFromPrefix}${tableFromPrefix}${
|
|
40994
|
+
const fromEntity = `${schemaFromPrefix}${tableFromPrefix}${data2.from.name}`;
|
|
40599
40995
|
const schemaToPrefix = to2.schema ? to2.schema !== defaultSchema ? `${to2.schema}.` : "" : "";
|
|
40600
40996
|
const tableToPrefix = to2.table ? `${to2.table}.` : "";
|
|
40601
40997
|
const toEntity = `${schemaToPrefix}${tableToPrefix}${to2.name}`;
|
|
@@ -41583,6 +41979,15 @@ var init_diff2 = __esm({
|
|
|
41583
41979
|
});
|
|
41584
41980
|
for (const pk of alters.filter((x6) => x6.entityType === "pks")) {
|
|
41585
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
|
+
}
|
|
41586
41991
|
dropPKStatements.push({ type: "drop_pk", pk: pk.$left });
|
|
41587
41992
|
createPKStatements.push({ type: "create_pk", pk: pk.$right });
|
|
41588
41993
|
}
|
|
@@ -41595,26 +42000,28 @@ var init_diff2 = __esm({
|
|
|
41595
42000
|
}
|
|
41596
42001
|
}
|
|
41597
42002
|
const statements = [
|
|
41598
|
-
|
|
41599
|
-
|
|
41600
|
-
|
|
41601
|
-
|
|
41602
|
-
|
|
41603
|
-
|
|
41604
|
-
|
|
41605
|
-
|
|
41606
|
-
|
|
41607
|
-
|
|
41608
|
-
|
|
41609
|
-
|
|
41610
|
-
|
|
41611
|
-
|
|
41612
|
-
|
|
41613
|
-
|
|
41614
|
-
|
|
41615
|
-
|
|
41616
|
-
|
|
41617
|
-
|
|
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
|
+
])
|
|
41618
42025
|
];
|
|
41619
42026
|
const res = fromJson2(statements);
|
|
41620
42027
|
return {
|
|
@@ -41631,9 +42038,10 @@ var init_diff2 = __esm({
|
|
|
41631
42038
|
var generate_mysql_exports = {};
|
|
41632
42039
|
__export(generate_mysql_exports, {
|
|
41633
42040
|
handle: () => handle2,
|
|
41634
|
-
handleExport: () => handleExport2
|
|
42041
|
+
handleExport: () => handleExport2,
|
|
42042
|
+
suggestions: () => suggestions
|
|
41635
42043
|
});
|
|
41636
|
-
var handle2, handleExport2;
|
|
42044
|
+
var suggestions, handle2, handleExport2;
|
|
41637
42045
|
var init_generate_mysql = __esm({
|
|
41638
42046
|
"src/cli/commands/generate-mysql.ts"() {
|
|
41639
42047
|
"use strict";
|
|
@@ -41643,8 +42051,57 @@ var init_generate_mysql = __esm({
|
|
|
41643
42051
|
init_ddl();
|
|
41644
42052
|
init_diff2();
|
|
41645
42053
|
init_prompts();
|
|
42054
|
+
init_outputs();
|
|
41646
42055
|
init_views();
|
|
41647
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
|
+
};
|
|
41648
42105
|
handle2 = async (config) => {
|
|
41649
42106
|
const outFolder = config.out;
|
|
41650
42107
|
const schemaPath = config.schema;
|
|
@@ -41665,7 +42122,7 @@ var init_generate_mysql = __esm({
|
|
|
41665
42122
|
});
|
|
41666
42123
|
return;
|
|
41667
42124
|
}
|
|
41668
|
-
const { sqlStatements, renames, groupedStatements } = await ddlDiff2(
|
|
42125
|
+
const { sqlStatements, renames, groupedStatements, statements } = await ddlDiff2(
|
|
41669
42126
|
ddlPrev,
|
|
41670
42127
|
ddlCur,
|
|
41671
42128
|
resolver("table"),
|
|
@@ -41673,6 +42130,11 @@ var init_generate_mysql = __esm({
|
|
|
41673
42130
|
resolver("view"),
|
|
41674
42131
|
"default"
|
|
41675
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
|
+
}
|
|
41676
42138
|
const explainMessage = explain("mysql", groupedStatements, false, []);
|
|
41677
42139
|
if (explainMessage) console.log(explainMessage);
|
|
41678
42140
|
writeResult({
|
|
@@ -41927,6 +42389,7 @@ var init_diff3 = __esm({
|
|
|
41927
42389
|
init_utils3();
|
|
41928
42390
|
init_convertor3();
|
|
41929
42391
|
init_ddl5();
|
|
42392
|
+
init_grammar5();
|
|
41930
42393
|
init_statements3();
|
|
41931
42394
|
ddlDiffDry3 = async (left, right, mode) => {
|
|
41932
42395
|
const empty = /* @__PURE__ */ new Set();
|
|
@@ -42114,12 +42577,19 @@ var init_diff3 = __esm({
|
|
|
42114
42577
|
return ddl22.fks.hasDiff(it2);
|
|
42115
42578
|
});
|
|
42116
42579
|
const checksAlters = updates.filter((it2) => it2.entityType === "checks");
|
|
42117
|
-
const
|
|
42118
|
-
(it2
|
|
42119
|
-
|
|
42120
|
-
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;
|
|
42121
42583
|
}
|
|
42122
|
-
|
|
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
|
+
});
|
|
42123
42593
|
const newStoredColumns = columnsToCreate.filter((it2) => it2.generated && it2.generated.type === "stored");
|
|
42124
42594
|
const setOfTablesToRecereate = new Set(
|
|
42125
42595
|
[
|
|
@@ -42141,8 +42611,8 @@ var init_diff3 = __esm({
|
|
|
42141
42611
|
for (const it2 of deletedTables) {
|
|
42142
42612
|
setOfTablesToRecereate.delete(it2.name);
|
|
42143
42613
|
}
|
|
42144
|
-
for (const it2 of
|
|
42145
|
-
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)) {
|
|
42146
42616
|
setOfTablesToRecereate.add(it2.table);
|
|
42147
42617
|
}
|
|
42148
42618
|
if (pksAlters.length > 0 && it2.entityType === "pks") setOfTablesToRecereate.add(it2.table);
|
|
@@ -42159,7 +42629,7 @@ var init_diff3 = __esm({
|
|
|
42159
42629
|
newStoredColumns: newStoredColumns.filter((column11) => column11.table === it2),
|
|
42160
42630
|
checkDiffs: checksDiff.filter((checkDiff) => checkDiff.table === it2),
|
|
42161
42631
|
checksAlters: checksAlters.filter((checkAlter) => checkAlter.table === it2),
|
|
42162
|
-
columnAlters:
|
|
42632
|
+
columnAlters: alteredColumns.filter((column11) => column11.table === it2),
|
|
42163
42633
|
fksAlters: fksAlters.filter((fkAlters) => fkAlters.table === it2),
|
|
42164
42634
|
fksDiff: fksDiff.filter((fkDiff) => fkDiff.table === it2),
|
|
42165
42635
|
indexesDiff: indexesDiff.filter((indexDiff) => indexDiff.table === it2),
|
|
@@ -42169,9 +42639,7 @@ var init_diff3 = __esm({
|
|
|
42169
42639
|
uniquesDiff: uniquesDiff.filter((uniqueDiff) => uniqueDiff.table === it2)
|
|
42170
42640
|
});
|
|
42171
42641
|
});
|
|
42172
|
-
const jsonTableAlternations =
|
|
42173
|
-
(it2) => !setOfTablesToRecereate.has(it2.table)
|
|
42174
|
-
).map(
|
|
42642
|
+
const jsonTableAlternations = alteredColumns.filter((it2) => !setOfTablesToRecereate.has(it2.table)).map(
|
|
42175
42643
|
(it2) => prepareRecreateColumn(
|
|
42176
42644
|
it2,
|
|
42177
42645
|
ddl22.columns.one({ table: it2.table, name: it2.name }),
|
|
@@ -42250,25 +42718,16 @@ var init_diff3 = __esm({
|
|
|
42250
42718
|
});
|
|
42251
42719
|
|
|
42252
42720
|
// src/dialects/sqlite/drizzle.ts
|
|
42253
|
-
var import_drizzle_orm3, import_relations3, import_sqlite_core2,
|
|
42721
|
+
var import_drizzle_orm3, import_relations3, import_sqlite_core2, fromDrizzleSchema3, fromExports2, prepareFromSchemaFiles3, defaultFromColumn3;
|
|
42254
42722
|
var init_drizzle4 = __esm({
|
|
42255
42723
|
"src/dialects/sqlite/drizzle.ts"() {
|
|
42256
42724
|
"use strict";
|
|
42257
42725
|
import_drizzle_orm3 = require("drizzle-orm");
|
|
42258
42726
|
import_relations3 = require("drizzle-orm/_relations");
|
|
42259
42727
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
42260
|
-
init_utils2();
|
|
42261
42728
|
init_utils_node();
|
|
42262
42729
|
init_drizzle();
|
|
42263
42730
|
init_grammar5();
|
|
42264
|
-
transformOnUpdateDelete2 = (on2) => {
|
|
42265
|
-
if (on2 === "no action") return "NO ACTION";
|
|
42266
|
-
if (on2 === "cascade") return "CASCADE";
|
|
42267
|
-
if (on2 === "restrict") return "RESTRICT";
|
|
42268
|
-
if (on2 === "set default") return "SET DEFAULT";
|
|
42269
|
-
if (on2 === "set null") return "SET NULL";
|
|
42270
|
-
assertUnreachable(on2);
|
|
42271
|
-
};
|
|
42272
42731
|
fromDrizzleSchema3 = (dTables, dViews, casing2) => {
|
|
42273
42732
|
const dialect5 = new import_sqlite_core2.SQLiteSyncDialect({ casing: casing2 });
|
|
42274
42733
|
const tableConfigs = dTables.map((it2) => ({ table: it2, config: (0, import_sqlite_core2.getTableConfig)(it2) }));
|
|
@@ -42344,8 +42803,8 @@ var init_drizzle4 = __esm({
|
|
|
42344
42803
|
tableTo,
|
|
42345
42804
|
columns: columnsFrom,
|
|
42346
42805
|
columnsTo,
|
|
42347
|
-
onDelete:
|
|
42348
|
-
onUpdate:
|
|
42806
|
+
onDelete: transformOnUpdateDelete(onDelete ?? "no action"),
|
|
42807
|
+
onUpdate: transformOnUpdateDelete(onUpdate ?? "no action"),
|
|
42349
42808
|
nameExplicit: fk5.isNameExplicit()
|
|
42350
42809
|
};
|
|
42351
42810
|
});
|
|
@@ -43206,7 +43665,7 @@ WITH`;
|
|
|
43206
43665
|
if (viewMetadata) options.push(`VIEW_METADATA`);
|
|
43207
43666
|
statement += ` ${options.join(", ")}`;
|
|
43208
43667
|
}
|
|
43209
|
-
statement += ` AS
|
|
43668
|
+
statement += ` AS ${definition}`;
|
|
43210
43669
|
statement += checkOption ? `
|
|
43211
43670
|
WITH CHECK OPTION` : "";
|
|
43212
43671
|
statement += ";";
|
|
@@ -43235,7 +43694,7 @@ WITH`;
|
|
|
43235
43694
|
if (viewMetadata) options.push(`VIEW_METADATA`);
|
|
43236
43695
|
statement += ` ${options.join(", ")}`;
|
|
43237
43696
|
}
|
|
43238
|
-
statement += ` AS
|
|
43697
|
+
statement += ` AS ${definition}`;
|
|
43239
43698
|
statement += checkOption ? `
|
|
43240
43699
|
WITH CHECK OPTION` : "";
|
|
43241
43700
|
statement += ";";
|
|
@@ -169134,9 +169593,9 @@ var init_pull_mysql = __esm({
|
|
|
169134
169593
|
var push_mysql_exports = {};
|
|
169135
169594
|
__export(push_mysql_exports, {
|
|
169136
169595
|
handle: () => handle8,
|
|
169137
|
-
suggestions: () =>
|
|
169596
|
+
suggestions: () => suggestions2
|
|
169138
169597
|
});
|
|
169139
|
-
var import_hanji8, handle8, identifier,
|
|
169598
|
+
var import_hanji8, handle8, identifier, suggestions2;
|
|
169140
169599
|
var init_push_mysql = __esm({
|
|
169141
169600
|
"src/cli/commands/push-mysql.ts"() {
|
|
169142
169601
|
"use strict";
|
|
@@ -169183,7 +169642,7 @@ ${filenames.join("\n")}
|
|
|
169183
169642
|
if (filteredStatements.length === 0) {
|
|
169184
169643
|
(0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
169185
169644
|
}
|
|
169186
|
-
const hints = await
|
|
169645
|
+
const hints = await suggestions2(db, filteredStatements, ddl22);
|
|
169187
169646
|
const explainMessage = explain("mysql", groupedStatements, explainFlag, hints);
|
|
169188
169647
|
if (explainMessage) console.log(explainMessage);
|
|
169189
169648
|
if (explainFlag) return;
|
|
@@ -169208,7 +169667,7 @@ ${filenames.join("\n")}
|
|
|
169208
169667
|
identifier = ({ table: table6, column: column11 }) => {
|
|
169209
169668
|
return [table6, column11].filter(Boolean).map((t6) => `\`${t6}\``).join(".");
|
|
169210
169669
|
};
|
|
169211
|
-
|
|
169670
|
+
suggestions2 = async (db, jsonStatements, ddl22) => {
|
|
169212
169671
|
const grouped = [];
|
|
169213
169672
|
const filtered = jsonStatements.filter((it2) => {
|
|
169214
169673
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
@@ -169232,14 +169691,32 @@ ${filenames.join("\n")}
|
|
|
169232
169691
|
continue;
|
|
169233
169692
|
}
|
|
169234
169693
|
if (statement.type === "drop_pk") {
|
|
169235
|
-
const table6 = statement.pk
|
|
169694
|
+
const { table: table6, columns } = statement.pk;
|
|
169236
169695
|
const id = identifier({ table: table6 });
|
|
169237
169696
|
const res = await db.query(
|
|
169238
169697
|
`select 1 from ${id} limit 1`
|
|
169239
169698
|
);
|
|
169240
|
-
if (res.length
|
|
169241
|
-
|
|
169242
|
-
|
|
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
|
+
});
|
|
169243
169720
|
continue;
|
|
169244
169721
|
}
|
|
169245
169722
|
if (statement.type === "add_column" && statement.column.notNull && statement.column.default === null && !statement.column.generated) {
|
|
@@ -169282,6 +169759,27 @@ ${filenames.join("\n")}
|
|
|
169282
169759
|
});
|
|
169283
169760
|
continue;
|
|
169284
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
|
+
}
|
|
169285
169783
|
}
|
|
169286
169784
|
return grouped;
|
|
169287
169785
|
};
|
|
@@ -170285,9 +170783,9 @@ var init_pull_postgres = __esm({
|
|
|
170285
170783
|
var push_postgres_exports = {};
|
|
170286
170784
|
__export(push_postgres_exports, {
|
|
170287
170785
|
handle: () => handle10,
|
|
170288
|
-
suggestions: () =>
|
|
170786
|
+
suggestions: () => suggestions3
|
|
170289
170787
|
});
|
|
170290
|
-
var import_hanji10, handle10, identifier2,
|
|
170788
|
+
var import_hanji10, handle10, identifier2, suggestions3;
|
|
170291
170789
|
var init_push_postgres = __esm({
|
|
170292
170790
|
"src/cli/commands/push-postgres.ts"() {
|
|
170293
170791
|
"use strict";
|
|
@@ -170324,7 +170822,7 @@ var init_push_postgres = __esm({
|
|
|
170324
170822
|
const { ddl: ddl1, errors: errors1 } = interimToDDL4(schemaFrom);
|
|
170325
170823
|
const { ddl: ddl22 } = interimToDDL4(schemaTo);
|
|
170326
170824
|
if (errors1.length > 0) {
|
|
170327
|
-
console.log(
|
|
170825
|
+
console.log(errors1.map((it2) => postgresSchemaError(it2)).join("\n"));
|
|
170328
170826
|
process.exit(1);
|
|
170329
170827
|
}
|
|
170330
170828
|
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff(
|
|
@@ -170350,7 +170848,7 @@ var init_push_postgres = __esm({
|
|
|
170350
170848
|
(0, import_hanji10.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
170351
170849
|
return;
|
|
170352
170850
|
}
|
|
170353
|
-
const hints = await
|
|
170851
|
+
const hints = await suggestions3(db, jsonStatements);
|
|
170354
170852
|
const explainMessage = explain("postgres", groupedStatements, explainFlag, hints);
|
|
170355
170853
|
if (explainMessage) console.log(explainMessage);
|
|
170356
170854
|
if (explainFlag) return;
|
|
@@ -170373,7 +170871,7 @@ var init_push_postgres = __esm({
|
|
|
170373
170871
|
const schemakey = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
|
|
170374
170872
|
return `${schemakey}"${name}"`;
|
|
170375
170873
|
};
|
|
170376
|
-
|
|
170874
|
+
suggestions3 = async (db, jsonStatements) => {
|
|
170377
170875
|
const grouped = [];
|
|
170378
170876
|
const filtered = jsonStatements.filter((it2) => {
|
|
170379
170877
|
if (it2.type === "drop_view" && it2.cause) return false;
|
|
@@ -170655,7 +171153,7 @@ ${it2.sql}`);
|
|
|
170655
171153
|
let checksCount = 0;
|
|
170656
171154
|
let viewsCount = 0;
|
|
170657
171155
|
const tableToParsedFks = dbTableColumns.reduce((acc, it2) => {
|
|
170658
|
-
if (!
|
|
171156
|
+
if (!acc[it2.table]) {
|
|
170659
171157
|
acc[it2.table] = parseSqliteFks(it2.sql);
|
|
170660
171158
|
}
|
|
170661
171159
|
return acc;
|
|
@@ -170810,12 +171308,12 @@ ${it2.sql}`);
|
|
|
170810
171308
|
return acc;
|
|
170811
171309
|
}, {});
|
|
170812
171310
|
const fks = [];
|
|
170813
|
-
for (const
|
|
171311
|
+
for (const entity of Object.values(fksToColumns)) {
|
|
170814
171312
|
foreignKeysCount += 1;
|
|
170815
171313
|
progressCallback("fks", foreignKeysCount, "fetching");
|
|
170816
|
-
const { columnsFrom, columnsTo } =
|
|
170817
|
-
const
|
|
170818
|
-
const constraint =
|
|
171314
|
+
const { columnsFrom, columnsTo, fk: fk5 } = entity;
|
|
171315
|
+
const parsedFks = tableToParsedFks[fk5.tableFrom];
|
|
171316
|
+
const constraint = parsedFks == null ? void 0 : parsedFks.find(
|
|
170819
171317
|
(it2) => areStringArraysEqual(it2.fromColumns, columnsFrom) && areStringArraysEqual(it2.toColumns, columnsTo) && it2.toTable === fk5.tableTo && it2.fromTable === fk5.tableFrom
|
|
170820
171318
|
);
|
|
170821
171319
|
let name;
|
|
@@ -171093,7 +171591,7 @@ import { sql } from "drizzle-orm"
|
|
|
171093
171591
|
const { def, options } = typeof res === "string" ? { def: res } : res;
|
|
171094
171592
|
const defaultStatement = def ? `.default(${def})` : "";
|
|
171095
171593
|
const opts = options ? `${JSON.stringify(options)}` : "";
|
|
171096
|
-
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}`;
|
|
171097
171595
|
}
|
|
171098
171596
|
if (lowered.startsWith("text")) {
|
|
171099
171597
|
const match3 = lowered.match(/\d+/);
|
|
@@ -171155,7 +171653,6 @@ import { sql } from "drizzle-orm"
|
|
|
171155
171653
|
const columnNames = it2.columns.filter((c5) => !c5.isExpression).map((c5) => c5.value);
|
|
171156
171654
|
const indexGeneratedName = `${tableName}_${columnNames.join("_")}_index`;
|
|
171157
171655
|
const escapedIndexName = indexGeneratedName === it2.name ? "" : `"${it2.name}"`;
|
|
171158
|
-
statement += ` ${idxKey}: `;
|
|
171159
171656
|
statement += it2.isUnique ? "uniqueIndex(" : "index(";
|
|
171160
171657
|
statement += `${escapedIndexName})`;
|
|
171161
171658
|
statement += `.on(${it2.columns.map((it3) => `table.${withCasing3(it3.value, casing2)}`).join(", ")}),`;
|
|
@@ -171312,9 +171809,9 @@ var init_pull_sqlite = __esm({
|
|
|
171312
171809
|
var push_sqlite_exports = {};
|
|
171313
171810
|
__export(push_sqlite_exports, {
|
|
171314
171811
|
handle: () => handle12,
|
|
171315
|
-
suggestions: () =>
|
|
171812
|
+
suggestions: () => suggestions4
|
|
171316
171813
|
});
|
|
171317
|
-
var import_hanji12, handle12,
|
|
171814
|
+
var import_hanji12, handle12, suggestions4;
|
|
171318
171815
|
var init_push_sqlite = __esm({
|
|
171319
171816
|
"src/cli/commands/push-sqlite.ts"() {
|
|
171320
171817
|
"use strict";
|
|
@@ -171356,7 +171853,7 @@ var init_push_sqlite = __esm({
|
|
|
171356
171853
|
[${source_default.blue("i")}] No changes detected`);
|
|
171357
171854
|
return;
|
|
171358
171855
|
}
|
|
171359
|
-
const hints = await
|
|
171856
|
+
const hints = await suggestions4(db, statements);
|
|
171360
171857
|
const explainMessage = explain("sqlite", groupedStatements, explainFlag, hints);
|
|
171361
171858
|
if (explainMessage) console.log(explainMessage);
|
|
171362
171859
|
if (explainFlag) return;
|
|
@@ -171390,7 +171887,7 @@ var init_push_sqlite = __esm({
|
|
|
171390
171887
|
(0, import_hanji12.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
171391
171888
|
}
|
|
171392
171889
|
};
|
|
171393
|
-
|
|
171890
|
+
suggestions4 = async (connection, jsonStatements) => {
|
|
171394
171891
|
const grouped = [];
|
|
171395
171892
|
for (const statement of jsonStatements) {
|
|
171396
171893
|
if (statement.type === "drop_table") {
|
|
@@ -171461,10 +171958,9 @@ var init_push_libsql = __esm({
|
|
|
171461
171958
|
// src/cli/commands/push-singlestore.ts
|
|
171462
171959
|
var push_singlestore_exports = {};
|
|
171463
171960
|
__export(push_singlestore_exports, {
|
|
171464
|
-
handle: () => handle14
|
|
171465
|
-
suggestions: () => suggestions4
|
|
171961
|
+
handle: () => handle14
|
|
171466
171962
|
});
|
|
171467
|
-
var import_hanji13, handle14
|
|
171963
|
+
var import_hanji13, handle14;
|
|
171468
171964
|
var init_push_singlestore = __esm({
|
|
171469
171965
|
"src/cli/commands/push-singlestore.ts"() {
|
|
171470
171966
|
"use strict";
|
|
@@ -171474,11 +171970,12 @@ var init_push_singlestore = __esm({
|
|
|
171474
171970
|
init_pull_utils();
|
|
171475
171971
|
init_utils_node();
|
|
171476
171972
|
init_diff4();
|
|
171973
|
+
init_highlighter();
|
|
171477
171974
|
init_prompts();
|
|
171478
171975
|
init_selector_ui();
|
|
171479
|
-
init_outputs();
|
|
171480
171976
|
init_views();
|
|
171481
|
-
|
|
171977
|
+
init_push_mysql();
|
|
171978
|
+
handle14 = async (schemaPath, credentials2, filters, verbose, force, casing2, explainFlag) => {
|
|
171482
171979
|
const { connectToSingleStore: connectToSingleStore2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
171483
171980
|
const { fromDatabaseForDrizzle: fromDatabaseForDrizzle6 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
|
171484
171981
|
const filter2 = prepareEntityFilter("singlestore", filters, []);
|
|
@@ -171500,7 +171997,7 @@ ${filenames.join("\n")}
|
|
|
171500
171997
|
const interimFromFiles = fromDrizzleSchema7(res.tables, casing2);
|
|
171501
171998
|
const { ddl: ddl1 } = interimToDDL(interimFromDB);
|
|
171502
171999
|
const { ddl: ddl22 } = interimToDDL(interimFromFiles);
|
|
171503
|
-
const { sqlStatements, statements } = await ddlDiff4(
|
|
172000
|
+
const { sqlStatements, statements, groupedStatements } = await ddlDiff4(
|
|
171504
172001
|
ddl1,
|
|
171505
172002
|
ddl22,
|
|
171506
172003
|
resolver("table"),
|
|
@@ -171511,57 +172008,28 @@ ${filenames.join("\n")}
|
|
|
171511
172008
|
const filteredStatements = statements;
|
|
171512
172009
|
if (filteredStatements.length === 0) {
|
|
171513
172010
|
(0, import_hanji13.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
171514
|
-
}
|
|
171515
|
-
|
|
171516
|
-
|
|
171517
|
-
|
|
171518
|
-
|
|
171519
|
-
|
|
171520
|
-
|
|
171521
|
-
|
|
171522
|
-
|
|
171523
|
-
|
|
171524
|
-
console.log();
|
|
171525
|
-
}
|
|
171526
|
-
if (!force && hints.length > 0) {
|
|
171527
|
-
const { data: data2 } = await (0, import_hanji13.render)(
|
|
171528
|
-
new Select(["No, abort", `Yes, I want to execute all statements`])
|
|
171529
|
-
);
|
|
171530
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
171531
|
-
(0, import_hanji13.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
171532
|
-
process.exit(0);
|
|
171533
|
-
}
|
|
171534
|
-
}
|
|
171535
|
-
if (!force && hints.length > 0) {
|
|
171536
|
-
console.log(withStyle.warning("Found data-loss statements:"));
|
|
171537
|
-
console.log(truncates.join("\n"));
|
|
171538
|
-
console.log();
|
|
171539
|
-
console.log(
|
|
171540
|
-
source_default.red.bold(
|
|
171541
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
171542
|
-
)
|
|
171543
|
-
);
|
|
171544
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
171545
|
-
const { data: data2 } = await (0, import_hanji13.render)(new Select(["No, abort", `Yes, execute`]));
|
|
171546
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
171547
|
-
(0, import_hanji13.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
171548
|
-
process.exit(0);
|
|
171549
|
-
}
|
|
171550
|
-
}
|
|
171551
|
-
for (const st2 of combinedStatements) {
|
|
171552
|
-
await db.query(st2);
|
|
171553
|
-
}
|
|
171554
|
-
if (filteredStatements.length > 0) {
|
|
171555
|
-
(0, import_hanji13.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
171556
|
-
} else {
|
|
171557
|
-
(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);
|
|
171558
172021
|
}
|
|
171559
172022
|
}
|
|
171560
|
-
|
|
171561
|
-
|
|
171562
|
-
|
|
171563
|
-
|
|
171564
|
-
|
|
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
|
+
}
|
|
171565
172033
|
};
|
|
171566
172034
|
}
|
|
171567
172035
|
});
|
|
@@ -172901,11 +173369,11 @@ var init_push_cockroach = __esm({
|
|
|
172901
173369
|
init_diff6();
|
|
172902
173370
|
init_drizzle7();
|
|
172903
173371
|
init_utils_node();
|
|
173372
|
+
init_highlighter();
|
|
172904
173373
|
init_prompts();
|
|
172905
173374
|
init_selector_ui();
|
|
172906
|
-
init_outputs();
|
|
172907
173375
|
init_views();
|
|
172908
|
-
handle16 = async (schemaPath, verbose, credentials2, filters, force, casing2) => {
|
|
173376
|
+
handle16 = async (schemaPath, verbose, credentials2, filters, force, casing2, explainFlag) => {
|
|
172909
173377
|
const { prepareCockroach: prepareCockroach2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
172910
173378
|
const { introspect: cockroachPushIntrospect } = await Promise.resolve().then(() => (init_pull_cockroach(), pull_cockroach_exports));
|
|
172911
173379
|
const db = await prepareCockroach2(credentials2);
|
|
@@ -172918,7 +173386,7 @@ var init_push_cockroach = __esm({
|
|
|
172918
173386
|
console.log(warnings.map((it2) => postgresSchemaWarning(it2)).join("\n\n"));
|
|
172919
173387
|
}
|
|
172920
173388
|
if (errors.length > 0) {
|
|
172921
|
-
console.log(errors.map((it2) =>
|
|
173389
|
+
console.log(errors.map((it2) => cockraochSchemaError(it2)).join("\n"));
|
|
172922
173390
|
process.exit(1);
|
|
172923
173391
|
}
|
|
172924
173392
|
const progress = new ProgressView("Pulling schema from database...", "Pulling schema from database...");
|
|
@@ -172926,10 +173394,10 @@ var init_push_cockroach = __esm({
|
|
|
172926
173394
|
const { ddl: ddl1, errors: errors1 } = interimToDDL2(schemaFrom);
|
|
172927
173395
|
const { ddl: ddl22 } = interimToDDL2(schemaTo);
|
|
172928
173396
|
if (errors1.length > 0) {
|
|
172929
|
-
console.log(
|
|
173397
|
+
console.log(errors1.map((it2) => cockraochSchemaError(it2)).join("\n"));
|
|
172930
173398
|
process.exit(1);
|
|
172931
173399
|
}
|
|
172932
|
-
const { sqlStatements, statements: jsonStatements } = await ddlDiff6(
|
|
173400
|
+
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff6(
|
|
172933
173401
|
ddl1,
|
|
172934
173402
|
ddl22,
|
|
172935
173403
|
resolver("schema"),
|
|
@@ -172949,38 +173417,20 @@ var init_push_cockroach = __esm({
|
|
|
172949
173417
|
(0, import_hanji15.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
172950
173418
|
return;
|
|
172951
173419
|
}
|
|
172952
|
-
const
|
|
172953
|
-
|
|
172954
|
-
|
|
172955
|
-
|
|
172956
|
-
console.log();
|
|
172957
|
-
console.log(losses.map((s6) => source_default.blue(s6)).join("\n"));
|
|
172958
|
-
console.log();
|
|
172959
|
-
}
|
|
172960
|
-
if (!force && hints.length === 0) {
|
|
172961
|
-
const { data: data2 } = await (0, import_hanji15.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
172962
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
172963
|
-
(0, import_hanji15.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
172964
|
-
process.exit(0);
|
|
172965
|
-
}
|
|
172966
|
-
}
|
|
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;
|
|
172967
173424
|
if (!force && hints.length > 0) {
|
|
172968
|
-
|
|
172969
|
-
console.log(hints.join("\n"));
|
|
172970
|
-
console.log();
|
|
172971
|
-
console.log(
|
|
172972
|
-
source_default.red.bold(
|
|
172973
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
172974
|
-
)
|
|
172975
|
-
);
|
|
172976
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
172977
|
-
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"]));
|
|
172978
173426
|
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
172979
173427
|
(0, import_hanji15.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
172980
173428
|
process.exit(0);
|
|
172981
173429
|
}
|
|
172982
173430
|
}
|
|
172983
|
-
|
|
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));
|
|
172984
173434
|
await db.query(statement);
|
|
172985
173435
|
}
|
|
172986
173436
|
(0, import_hanji15.render)(`[${source_default.green("\u2713")}] Changes applied`);
|
|
@@ -172991,8 +173441,7 @@ var init_push_cockroach = __esm({
|
|
|
172991
173441
|
return `${schemakey}"${name}"`;
|
|
172992
173442
|
};
|
|
172993
173443
|
suggestions5 = async (db, jsonStatements) => {
|
|
172994
|
-
const
|
|
172995
|
-
const hints = [];
|
|
173444
|
+
const grouped = [];
|
|
172996
173445
|
const filtered = jsonStatements.filter((it2) => {
|
|
172997
173446
|
if (it2.type === "recreate_view") return false;
|
|
172998
173447
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
@@ -173001,14 +173450,14 @@ var init_push_cockroach = __esm({
|
|
|
173001
173450
|
for (const statement of filtered) {
|
|
173002
173451
|
if (statement.type === "drop_table") {
|
|
173003
173452
|
const res = await db.query(`select 1 from ${statement.key} limit 1`);
|
|
173004
|
-
if (res.length > 0)
|
|
173453
|
+
if (res.length > 0) grouped.push({ hint: `\xB7 You're about to delete non-empty ${statement.key} table` });
|
|
173005
173454
|
continue;
|
|
173006
173455
|
}
|
|
173007
173456
|
if (statement.type === "drop_view" && statement.view.materialized) {
|
|
173008
173457
|
const id = identifier3(statement.view);
|
|
173009
173458
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173010
173459
|
if (res.length === 0) continue;
|
|
173011
|
-
|
|
173460
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty ${id} materialized view` });
|
|
173012
173461
|
continue;
|
|
173013
173462
|
}
|
|
173014
173463
|
if (statement.type === "drop_column") {
|
|
@@ -173016,7 +173465,7 @@ var init_push_cockroach = __esm({
|
|
|
173016
173465
|
const id = identifier3({ schema: column11.schema, name: column11.table });
|
|
173017
173466
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173018
173467
|
if (res.length === 0) continue;
|
|
173019
|
-
|
|
173468
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty ${column11.name} column in ${id} table` });
|
|
173020
173469
|
continue;
|
|
173021
173470
|
}
|
|
173022
173471
|
if (statement.type === "drop_schema") {
|
|
@@ -173025,7 +173474,7 @@ var init_push_cockroach = __esm({
|
|
|
173025
173474
|
);
|
|
173026
173475
|
const count2 = Number(res[0].count);
|
|
173027
173476
|
if (count2 === 0) continue;
|
|
173028
|
-
|
|
173477
|
+
grouped.push({ hint: `\xB7 You're about to delete ${source_default.underline(statement.name)} schema with ${count2} tables` });
|
|
173029
173478
|
continue;
|
|
173030
173479
|
}
|
|
173031
173480
|
if (statement.type === "drop_pk") {
|
|
@@ -173036,18 +173485,10 @@ var init_push_cockroach = __esm({
|
|
|
173036
173485
|
`select 1 from ${id} limit 1`
|
|
173037
173486
|
);
|
|
173038
173487
|
if (res.length > 0) {
|
|
173039
|
-
|
|
173040
|
-
`\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
173041
|
-
);
|
|
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
|
+
});
|
|
173042
173491
|
}
|
|
173043
|
-
const [{ name: pkName }] = await db.query(`
|
|
173044
|
-
SELECT constraint_name as name
|
|
173045
|
-
FROM information_schema.table_constraints
|
|
173046
|
-
WHERE
|
|
173047
|
-
table_schema = '${schema5}'
|
|
173048
|
-
AND table_name = '${table6}'
|
|
173049
|
-
AND constraint_type = 'PRIMARY KEY';`);
|
|
173050
|
-
statements.push(`ALTER TABLE ${id} DROP CONSTRAINT "${pkName}"`);
|
|
173051
173492
|
continue;
|
|
173052
173493
|
}
|
|
173053
173494
|
if (statement.type === "add_column" && statement.column.notNull && statement.column.default === null) {
|
|
@@ -173055,9 +173496,9 @@ var init_push_cockroach = __esm({
|
|
|
173055
173496
|
const id = identifier3({ schema: column11.schema, name: column11.table });
|
|
173056
173497
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173057
173498
|
if (res.length === 0) continue;
|
|
173058
|
-
|
|
173059
|
-
`\xB7 You're about to add not-null ${source_default.underline(statement.column.name)} column without default value to a non-empty ${id} table`
|
|
173060
|
-
);
|
|
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
|
+
});
|
|
173061
173502
|
continue;
|
|
173062
173503
|
}
|
|
173063
173504
|
if (statement.type === "create_index" && statement.index.isUnique && !statement.newTable) {
|
|
@@ -173065,16 +173506,13 @@ var init_push_cockroach = __esm({
|
|
|
173065
173506
|
const id = identifier3({ schema: unique.schema, name: unique.table });
|
|
173066
173507
|
const res = await db.query(`select 1 from ${id} limit 1`);
|
|
173067
173508
|
if (res.length === 0) continue;
|
|
173068
|
-
|
|
173069
|
-
`\xB7 You're about to add ${source_default.underline(unique.name)} unique index to a non-empty ${id} table which may fail`
|
|
173070
|
-
);
|
|
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
|
+
});
|
|
173071
173512
|
continue;
|
|
173072
173513
|
}
|
|
173073
173514
|
}
|
|
173074
|
-
return
|
|
173075
|
-
losses: statements,
|
|
173076
|
-
hints
|
|
173077
|
-
};
|
|
173515
|
+
return grouped;
|
|
173078
173516
|
};
|
|
173079
173517
|
}
|
|
173080
173518
|
});
|
|
@@ -174104,15 +174542,18 @@ var init_push_mssql = __esm({
|
|
|
174104
174542
|
init_ddl3();
|
|
174105
174543
|
init_diff5();
|
|
174106
174544
|
init_drizzle6();
|
|
174545
|
+
init_highlighter();
|
|
174107
174546
|
init_prompts();
|
|
174108
174547
|
init_selector_ui();
|
|
174109
|
-
init_outputs();
|
|
174110
174548
|
init_views();
|
|
174111
|
-
handle18 = async (schemaPath, verbose, credentials2, filters, force, casing2) => {
|
|
174549
|
+
handle18 = async (schemaPath, verbose, credentials2, filters, force, casing2, explainFlag) => {
|
|
174112
174550
|
const { connectToMsSQL: connectToMsSQL2 } = await Promise.resolve().then(() => (init_connections(), connections_exports));
|
|
174113
174551
|
const { introspect: introspect6 } = await Promise.resolve().then(() => (init_pull_mssql(), pull_mssql_exports));
|
|
174114
174552
|
const { db } = await connectToMsSQL2(credentials2);
|
|
174115
174553
|
const filenames = prepareFilenames(schemaPath);
|
|
174554
|
+
console.log(source_default.gray(`Reading schema files:
|
|
174555
|
+
${filenames.join("\n")}
|
|
174556
|
+
`));
|
|
174116
174557
|
const res = await prepareFromSchemaFiles5(filenames);
|
|
174117
174558
|
const existing = extractMssqlExisting(res.schemas, res.views);
|
|
174118
174559
|
const filter2 = prepareEntityFilter("mssql", filters, existing);
|
|
@@ -174133,7 +174574,7 @@ var init_push_mssql = __esm({
|
|
|
174133
174574
|
console.log(errors.map((it2) => mssqlSchemaError(it2)).join("\n"));
|
|
174134
174575
|
process.exit(1);
|
|
174135
174576
|
}
|
|
174136
|
-
const { sqlStatements, statements: jsonStatements } = await ddlDiff5(
|
|
174577
|
+
const { sqlStatements, statements: jsonStatements, groupedStatements } = await ddlDiff5(
|
|
174137
174578
|
ddl1,
|
|
174138
174579
|
ddl22,
|
|
174139
174580
|
resolver("schema", "dbo"),
|
|
@@ -174158,42 +174599,27 @@ var init_push_mssql = __esm({
|
|
|
174158
174599
|
(0, import_hanji17.render)(`[${source_default.blue("i")}] No changes detected`);
|
|
174159
174600
|
return;
|
|
174160
174601
|
}
|
|
174161
|
-
const
|
|
174162
|
-
const
|
|
174163
|
-
if (
|
|
174164
|
-
|
|
174165
|
-
console.log(withStyle.warning("You are about to execute these statements:"));
|
|
174166
|
-
console.log();
|
|
174167
|
-
console.log(statementsToExecute.map((s6) => source_default.blue(s6)).join("\n"));
|
|
174168
|
-
console.log();
|
|
174169
|
-
}
|
|
174170
|
-
if (!force && hints.length === 0) {
|
|
174171
|
-
const { data: data2 } = await (0, import_hanji17.render)(new Select(["No, abort", "Yes, I want to execute all statements"]));
|
|
174172
|
-
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
174173
|
-
(0, import_hanji17.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
174174
|
-
process.exit(0);
|
|
174175
|
-
}
|
|
174176
|
-
}
|
|
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;
|
|
174177
174606
|
if (!force && hints.length > 0) {
|
|
174178
|
-
|
|
174179
|
-
console.log(hints.join("\n"));
|
|
174180
|
-
console.log();
|
|
174181
|
-
console.log(
|
|
174182
|
-
source_default.red.bold(
|
|
174183
|
-
"THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
|
|
174184
|
-
)
|
|
174185
|
-
);
|
|
174186
|
-
console.log(source_default.white("Do you still want to push changes?"));
|
|
174187
|
-
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"]));
|
|
174188
174608
|
if ((data2 == null ? void 0 : data2.index) === 0) {
|
|
174189
174609
|
(0, import_hanji17.render)(`[${source_default.red("x")}] All changes were aborted`);
|
|
174190
174610
|
process.exit(0);
|
|
174191
174611
|
}
|
|
174192
174612
|
}
|
|
174193
|
-
|
|
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));
|
|
174194
174616
|
await db.query(statement);
|
|
174195
174617
|
}
|
|
174196
|
-
|
|
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
|
+
}
|
|
174197
174623
|
};
|
|
174198
174624
|
identifier4 = (it2) => {
|
|
174199
174625
|
const { schema: schema5, table: table6 } = it2;
|
|
@@ -174202,8 +174628,7 @@ var init_push_mssql = __esm({
|
|
|
174202
174628
|
return `${schemaKey}${tableKey}`;
|
|
174203
174629
|
};
|
|
174204
174630
|
suggestions6 = async (db, jsonStatements, ddl22) => {
|
|
174205
|
-
const
|
|
174206
|
-
const hints = [];
|
|
174631
|
+
const grouped = [];
|
|
174207
174632
|
const filtered = jsonStatements.filter((it2) => {
|
|
174208
174633
|
if (it2.type === "alter_column" && it2.diff.generated) return false;
|
|
174209
174634
|
return true;
|
|
@@ -174212,7 +174637,7 @@ var init_push_mssql = __esm({
|
|
|
174212
174637
|
if (statement.type === "drop_table") {
|
|
174213
174638
|
const tableName = identifier4({ schema: statement.table.schema, table: statement.table.name });
|
|
174214
174639
|
const res = await db.query(`select top(1) 1 from ${tableName};`);
|
|
174215
|
-
if (res.length > 0)
|
|
174640
|
+
if (res.length > 0) grouped.push({ hint: `\xB7 You're about to delete non-empty [${statement.table.name}] table` });
|
|
174216
174641
|
continue;
|
|
174217
174642
|
}
|
|
174218
174643
|
if (statement.type === "drop_column") {
|
|
@@ -174220,7 +174645,7 @@ var init_push_mssql = __esm({
|
|
|
174220
174645
|
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174221
174646
|
const res = await db.query(`SELECT TOP(1) 1 FROM ${key} WHERE [${column11.name}] IS NOT NULL;`);
|
|
174222
174647
|
if (res.length === 0) continue;
|
|
174223
|
-
|
|
174648
|
+
grouped.push({ hint: `\xB7 You're about to delete non-empty [${column11.name}] column in [${column11.table}] table` });
|
|
174224
174649
|
continue;
|
|
174225
174650
|
}
|
|
174226
174651
|
if (statement.type === "drop_schema") {
|
|
@@ -174230,24 +174655,7 @@ var init_push_mssql = __esm({
|
|
|
174230
174655
|
const count2 = Number(res[0].count);
|
|
174231
174656
|
if (count2 === 0) continue;
|
|
174232
174657
|
const tableGrammar = count2 === 1 ? "table" : "tables";
|
|
174233
|
-
|
|
174234
|
-
`\xB7 You're about to delete [${statement.name}] schema with ${count2} ${tableGrammar}`
|
|
174235
|
-
);
|
|
174236
|
-
continue;
|
|
174237
|
-
}
|
|
174238
|
-
if (statement.type === "add_column" && statement.column.notNull && !ddl22.defaults.one({
|
|
174239
|
-
column: statement.column.name,
|
|
174240
|
-
schema: statement.column.schema,
|
|
174241
|
-
table: statement.column.table
|
|
174242
|
-
})) {
|
|
174243
|
-
const column11 = statement.column;
|
|
174244
|
-
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174245
|
-
const res = await db.query(`select top(1) 1 from ${key}`);
|
|
174246
|
-
if (res.length === 0) continue;
|
|
174247
|
-
hints.push(
|
|
174248
|
-
`\xB7 You're about to add not-null [${column11.name}] column without default value to a non-empty ${key} table`
|
|
174249
|
-
);
|
|
174250
|
-
losses.push(`DELETE FROM ${key};`);
|
|
174658
|
+
grouped.push({ hint: `\xB7 You're about to delete [${statement.name}] schema with ${count2} ${tableGrammar}` });
|
|
174251
174659
|
continue;
|
|
174252
174660
|
}
|
|
174253
174661
|
if (statement.type === "alter_column" && statement.diff.$right.notNull && !ddl22.defaults.one({
|
|
@@ -174259,10 +174667,23 @@ var init_push_mssql = __esm({
|
|
|
174259
174667
|
const key = identifier4({ schema: column11.schema, table: column11.table });
|
|
174260
174668
|
const res = await db.query(`select top(1) 1 from ${key};`);
|
|
174261
174669
|
if (res.length === 0) continue;
|
|
174262
|
-
|
|
174263
|
-
`\xB7 You're about to add not-null to [${statement.diff.$right.name}] column without default value to a non-empty ${key} table`
|
|
174264
|
-
);
|
|
174265
|
-
|
|
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
|
+
});
|
|
174266
174687
|
continue;
|
|
174267
174688
|
}
|
|
174268
174689
|
if (statement.type === "drop_pk") {
|
|
@@ -174273,9 +174694,9 @@ var init_push_mssql = __esm({
|
|
|
174273
174694
|
`select top(1) 1 from ${id};`
|
|
174274
174695
|
);
|
|
174275
174696
|
if (res.length > 0) {
|
|
174276
|
-
|
|
174277
|
-
`\xB7 You're about to drop ${source_default.underline(id)} primary key, this statements may fail and your table may loose primary key`
|
|
174278
|
-
);
|
|
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
|
+
});
|
|
174279
174700
|
}
|
|
174280
174701
|
continue;
|
|
174281
174702
|
}
|
|
@@ -174284,34 +174705,31 @@ var init_push_mssql = __esm({
|
|
|
174284
174705
|
const id = identifier4({ schema: unique.schema, table: unique.table });
|
|
174285
174706
|
const res = await db.query(`select top(1) 1 from ${id};`);
|
|
174286
174707
|
if (res.length === 0) continue;
|
|
174287
|
-
|
|
174288
|
-
`\xB7 You're about to add ${source_default.underline(unique.name)} unique constraint to a non-empty ${id} table which may fail`
|
|
174289
|
-
);
|
|
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
|
+
});
|
|
174290
174711
|
continue;
|
|
174291
174712
|
}
|
|
174292
174713
|
if (statement.type === "rename_column" && ddl22.checks.one({ schema: statement.to.schema, table: statement.to.table })) {
|
|
174293
174714
|
const left = statement.from;
|
|
174294
174715
|
const right = statement.to;
|
|
174295
|
-
|
|
174296
|
-
`\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.
|
|
174297
174718
|
To rename the column, first drop the check constraint, then rename the column, and finally recreate the check constraint`
|
|
174298
|
-
);
|
|
174719
|
+
});
|
|
174299
174720
|
continue;
|
|
174300
174721
|
}
|
|
174301
174722
|
if (statement.type === "rename_schema") {
|
|
174302
174723
|
const left = statement.from;
|
|
174303
174724
|
const right = statement.to;
|
|
174304
|
-
|
|
174305
|
-
`\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.
|
|
174306
174727
|
You should create new schema and transfer everything to it`
|
|
174307
|
-
);
|
|
174728
|
+
});
|
|
174308
174729
|
continue;
|
|
174309
174730
|
}
|
|
174310
174731
|
}
|
|
174311
|
-
return
|
|
174312
|
-
losses,
|
|
174313
|
-
hints
|
|
174314
|
-
};
|
|
174732
|
+
return grouped;
|
|
174315
174733
|
};
|
|
174316
174734
|
}
|
|
174317
174735
|
});
|
|
@@ -181630,6 +182048,7 @@ init_source();
|
|
|
181630
182048
|
var import_fs9 = require("fs");
|
|
181631
182049
|
var import_path4 = require("path");
|
|
181632
182050
|
init_grammar5();
|
|
182051
|
+
init_grammar5();
|
|
181633
182052
|
init_utils_node();
|
|
181634
182053
|
init_ddl5();
|
|
181635
182054
|
init_snapshot6();
|
|
@@ -181668,12 +182087,13 @@ var updateToV7 = (snapshot) => {
|
|
|
181668
182087
|
name: table6.name
|
|
181669
182088
|
});
|
|
181670
182089
|
for (const column11 of Object.values(table6.columns)) {
|
|
182090
|
+
let def = typeof column11.default === "undefined" ? null : String(column11.default);
|
|
181671
182091
|
ddl7.columns.push({
|
|
181672
182092
|
table: table6.name,
|
|
181673
182093
|
name: column11.name,
|
|
181674
182094
|
type: column11.type,
|
|
181675
|
-
notNull: column11.notNull,
|
|
181676
|
-
default:
|
|
182095
|
+
notNull: column11.notNull && !column11.primaryKey,
|
|
182096
|
+
default: def,
|
|
181677
182097
|
autoincrement: column11.autoincrement,
|
|
181678
182098
|
generated: column11.generated ?? null
|
|
181679
182099
|
});
|
|
@@ -181722,16 +182142,16 @@ var updateToV7 = (snapshot) => {
|
|
|
181722
182142
|
});
|
|
181723
182143
|
}
|
|
181724
182144
|
for (const fk5 of Object.values(table6.foreignKeys)) {
|
|
181725
|
-
const
|
|
182145
|
+
const nameExplicit = fk5.name !== `${table6.name}_${fk5.columnsFrom.join("_")}_${fk5.tableTo}_${fk5.columnsTo.join("_")}_fk`;
|
|
181726
182146
|
ddl7.fks.push({
|
|
181727
182147
|
table: table6.name,
|
|
181728
182148
|
name: fk5.name,
|
|
181729
182149
|
columns: fk5.columnsFrom,
|
|
181730
182150
|
tableTo: fk5.tableTo,
|
|
181731
182151
|
columnsTo: fk5.columnsTo,
|
|
181732
|
-
onDelete: fk5.onDelete ?? "
|
|
181733
|
-
onUpdate: fk5.onUpdate ?? "
|
|
181734
|
-
nameExplicit
|
|
182152
|
+
onDelete: transformOnUpdateDelete(fk5.onDelete ?? "no action"),
|
|
182153
|
+
onUpdate: transformOnUpdateDelete(fk5.onUpdate ?? "no action"),
|
|
182154
|
+
nameExplicit
|
|
181735
182155
|
});
|
|
181736
182156
|
}
|
|
181737
182157
|
}
|
|
@@ -181781,6 +182201,7 @@ var updateUpToV62 = (json) => {
|
|
|
181781
182201
|
// src/cli/schema.ts
|
|
181782
182202
|
init_utils4();
|
|
181783
182203
|
init_common3();
|
|
182204
|
+
init_outputs();
|
|
181784
182205
|
init_views();
|
|
181785
182206
|
var optionDialect = string("dialect").enum(...dialects).desc(
|
|
181786
182207
|
`Database dialect: 'gel', 'postgresql', 'mysql', 'sqlite', 'turso', 'singlestore', 'duckdb' or 'mssql'`
|
|
@@ -182006,7 +182427,7 @@ var push = command({
|
|
|
182006
182427
|
...optionsFilters,
|
|
182007
182428
|
...optionsDatabaseCredentials,
|
|
182008
182429
|
verbose: boolean().desc("Print all statements for each push").default(false),
|
|
182009
|
-
strict: boolean().desc("Always ask for confirmation")
|
|
182430
|
+
strict: boolean().desc("Always ask for confirmation"),
|
|
182010
182431
|
force: boolean().desc(
|
|
182011
182432
|
"Auto-approve all data loss statements. Note: Data loss statements may truncate your tables and data"
|
|
182012
182433
|
).default(false),
|
|
@@ -182036,6 +182457,12 @@ var push = command({
|
|
|
182036
182457
|
"tlsSecurity"
|
|
182037
182458
|
]
|
|
182038
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
|
+
}
|
|
182039
182466
|
return preparePushConfig(opts, from);
|
|
182040
182467
|
},
|
|
182041
182468
|
handler: async (config) => {
|
|
@@ -182067,13 +182494,13 @@ var push = command({
|
|
|
182067
182494
|
await libSQLPush(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
182068
182495
|
} else if (dialect5 === "singlestore") {
|
|
182069
182496
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_singlestore(), push_singlestore_exports));
|
|
182070
|
-
await handle21(schemaPath, credentials2, filters, verbose, force, casing2);
|
|
182497
|
+
await handle21(schemaPath, credentials2, filters, verbose, force, casing2, explain2);
|
|
182071
182498
|
} else if (dialect5 === "cockroach") {
|
|
182072
182499
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_cockroach(), push_cockroach_exports));
|
|
182073
|
-
await handle21(schemaPath, verbose, credentials2, filters, force, casing2);
|
|
182500
|
+
await handle21(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
182074
182501
|
} else if (dialect5 === "mssql") {
|
|
182075
182502
|
const { handle: handle21 } = await Promise.resolve().then(() => (init_push_mssql(), push_mssql_exports));
|
|
182076
|
-
await handle21(schemaPath, verbose, credentials2, filters, force, casing2);
|
|
182503
|
+
await handle21(schemaPath, verbose, credentials2, filters, force, casing2, explain2);
|
|
182077
182504
|
} else if (dialect5 === "gel") {
|
|
182078
182505
|
console.log(error2(`You can't use 'push' command with Gel dialect`));
|
|
182079
182506
|
} else {
|
|
@@ -182463,7 +182890,7 @@ init_views();
|
|
|
182463
182890
|
var version3 = async () => {
|
|
182464
182891
|
const { npmVersion } = await ormCoreVersions();
|
|
182465
182892
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
|
182466
|
-
const envVersion = "1.0.0-beta.
|
|
182893
|
+
const envVersion = "1.0.0-beta.5";
|
|
182467
182894
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
|
182468
182895
|
const versions = `drizzle-kit: ${kitVersion}
|
|
182469
182896
|
${ormVersion}`;
|