drizzle-kit 0.24.0-38d6dab → 0.24.0-5df8253
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +10 -0
- package/api.d.ts +10 -0
- package/api.js +501 -1280
- package/api.mjs +501 -1280
- package/bin.cjs +756 -1832
- package/package.json +2 -1
- package/utils.js +2 -10
- package/utils.mjs +2 -9
package/api.mjs
CHANGED
@@ -7469,11 +7469,30 @@ var init_mysqlSchema = __esm({
|
|
7469
7469
|
}
|
7470
7470
|
});
|
7471
7471
|
|
7472
|
+
// src/extensions/vector.ts
|
7473
|
+
var vectorOps;
|
7474
|
+
var init_vector = __esm({
|
7475
|
+
"src/extensions/vector.ts"() {
|
7476
|
+
"use strict";
|
7477
|
+
vectorOps = [
|
7478
|
+
"vector_l2_ops",
|
7479
|
+
"vector_ip_ops",
|
7480
|
+
"vector_cosine_ops",
|
7481
|
+
"vector_l1_ops",
|
7482
|
+
"bit_hamming_ops",
|
7483
|
+
"bit_jaccard_ops",
|
7484
|
+
"halfvec_l2_ops",
|
7485
|
+
"sparsevec_l2_ops"
|
7486
|
+
];
|
7487
|
+
}
|
7488
|
+
});
|
7489
|
+
|
7472
7490
|
// src/serializer/pgSchema.ts
|
7473
7491
|
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7474
7492
|
var init_pgSchema = __esm({
|
7475
7493
|
"src/serializer/pgSchema.ts"() {
|
7476
7494
|
"use strict";
|
7495
|
+
init_vector();
|
7477
7496
|
init_global();
|
7478
7497
|
init_lib();
|
7479
7498
|
indexV2 = objectType({
|
@@ -7720,7 +7739,8 @@ var init_pgSchema = __esm({
|
|
7720
7739
|
objectType({
|
7721
7740
|
isArray: booleanType().optional(),
|
7722
7741
|
dimensions: numberType().optional(),
|
7723
|
-
rawType: stringType().optional()
|
7742
|
+
rawType: stringType().optional(),
|
7743
|
+
isDefaultAnExpression: booleanType().optional()
|
7724
7744
|
}).optional()
|
7725
7745
|
)
|
7726
7746
|
}).optional()
|
@@ -7858,7 +7878,7 @@ var init_pgSchema = __esm({
|
|
7858
7878
|
squashIdx: (idx) => {
|
7859
7879
|
index2.parse(idx);
|
7860
7880
|
return `${idx.name};${idx.columns.map(
|
7861
|
-
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
|
7881
|
+
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
|
7862
7882
|
).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
|
7863
7883
|
},
|
7864
7884
|
unsquashIdx: (input) => {
|
@@ -8346,13 +8366,6 @@ var init_sqliteSchema = __esm({
|
|
8346
8366
|
function isPgArrayType(sqlType) {
|
8347
8367
|
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8348
8368
|
}
|
8349
|
-
function findAddedAndRemoved(columnNames1, columnNames2) {
|
8350
|
-
const set1 = new Set(columnNames1);
|
8351
|
-
const set2 = new Set(columnNames2);
|
8352
|
-
const addedColumns = columnNames2.filter((it) => !set1.has(it));
|
8353
|
-
const removedColumns = columnNames1.filter((it) => !set2.has(it));
|
8354
|
-
return { addedColumns, removedColumns };
|
8355
|
-
}
|
8356
8369
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8357
8370
|
var init_utils = __esm({
|
8358
8371
|
"src/utils.ts"() {
|
@@ -11462,20 +11475,7 @@ var init_jsonDiffer = __esm({
|
|
11462
11475
|
});
|
11463
11476
|
|
11464
11477
|
// src/sqlgenerator.ts
|
11465
|
-
|
11466
|
-
const result = statements.flatMap((statement) => {
|
11467
|
-
const filtered = convertors.filter((it) => {
|
11468
|
-
return it.can(statement, dialect7, driver2);
|
11469
|
-
});
|
11470
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
11471
|
-
if (!convertor) {
|
11472
|
-
return "";
|
11473
|
-
}
|
11474
|
-
return convertor.convert(statement, json2, action);
|
11475
|
-
}).filter((it) => it !== "");
|
11476
|
-
return result;
|
11477
|
-
}
|
11478
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, LibSQLDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11478
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
11479
11479
|
var init_sqlgenerator = __esm({
|
11480
11480
|
"src/sqlgenerator.ts"() {
|
11481
11481
|
"use strict";
|
@@ -11527,7 +11527,7 @@ var init_sqlgenerator = __esm({
|
|
11527
11527
|
isPgNativeType = (it) => {
|
11528
11528
|
if (pgNativeTypes.has(it)) return true;
|
11529
11529
|
const toCheck = it.replace(/ /g, "");
|
11530
|
-
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11530
|
+
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("doubleprecision[") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11531
11531
|
};
|
11532
11532
|
Convertor = class {
|
11533
11533
|
};
|
@@ -11991,7 +11991,7 @@ var init_sqlgenerator = __esm({
|
|
11991
11991
|
}
|
11992
11992
|
convert(statement) {
|
11993
11993
|
const { tableName, oldColumnName, newColumnName } = statement;
|
11994
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
11994
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
|
11995
11995
|
}
|
11996
11996
|
};
|
11997
11997
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -12093,8 +12093,8 @@ var init_sqlgenerator = __esm({
|
|
12093
12093
|
}
|
12094
12094
|
};
|
12095
12095
|
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
12096
|
-
can(statement, dialect7
|
12097
|
-
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite"
|
12096
|
+
can(statement, dialect7) {
|
12097
|
+
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
12098
12098
|
}
|
12099
12099
|
convert(statement) {
|
12100
12100
|
return `/*
|
@@ -12405,46 +12405,6 @@ var init_sqlgenerator = __esm({
|
|
12405
12405
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
12406
12406
|
}
|
12407
12407
|
};
|
12408
|
-
LibSQLModifyColumn = class extends Convertor {
|
12409
|
-
can(statement, dialect7, driver2) {
|
12410
|
-
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect7 === "sqlite" && driver2 === "turso";
|
12411
|
-
}
|
12412
|
-
convert(statement, json2) {
|
12413
|
-
const { tableName, columnName } = statement;
|
12414
|
-
let columnType = ``;
|
12415
|
-
let columnDefault = "";
|
12416
|
-
let columnNotNull = "";
|
12417
|
-
switch (statement.type) {
|
12418
|
-
case "alter_table_alter_column_set_type":
|
12419
|
-
columnType = ` ${statement.newDataType}`;
|
12420
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12421
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12422
|
-
break;
|
12423
|
-
case "alter_table_alter_column_drop_notnull":
|
12424
|
-
columnType = ` ${statement.newDataType}`;
|
12425
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12426
|
-
columnNotNull = "";
|
12427
|
-
break;
|
12428
|
-
case "alter_table_alter_column_set_notnull":
|
12429
|
-
columnType = ` ${statement.newDataType}`;
|
12430
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12431
|
-
columnNotNull = ` NOT NULL`;
|
12432
|
-
break;
|
12433
|
-
case "alter_table_alter_column_set_default":
|
12434
|
-
columnType = ` ${statement.newDataType}`;
|
12435
|
-
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
12436
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12437
|
-
break;
|
12438
|
-
case "alter_table_alter_column_drop_default":
|
12439
|
-
columnType = ` ${statement.newDataType}`;
|
12440
|
-
columnDefault = "";
|
12441
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12442
|
-
break;
|
12443
|
-
}
|
12444
|
-
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
12445
|
-
return `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`;
|
12446
|
-
}
|
12447
|
-
};
|
12448
12408
|
MySqlModifyColumn = class extends Convertor {
|
12449
12409
|
can(statement, dialect7) {
|
12450
12410
|
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_generated" || statement.type === "alter_table_alter_column_drop_generated") && dialect7 === "mysql";
|
@@ -12785,8 +12745,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12785
12745
|
}
|
12786
12746
|
};
|
12787
12747
|
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
12788
|
-
can(statement, dialect7
|
12789
|
-
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite"
|
12748
|
+
can(statement, dialect7) {
|
12749
|
+
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
12790
12750
|
}
|
12791
12751
|
convert(statement) {
|
12792
12752
|
return `/*
|
@@ -12800,8 +12760,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12800
12760
|
}
|
12801
12761
|
};
|
12802
12762
|
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
12803
|
-
can(statement, dialect7
|
12804
|
-
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite"
|
12763
|
+
can(statement, dialect7) {
|
12764
|
+
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
12805
12765
|
}
|
12806
12766
|
convert(statement) {
|
12807
12767
|
return `/*
|
@@ -12815,8 +12775,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12815
12775
|
}
|
12816
12776
|
};
|
12817
12777
|
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
12818
|
-
can(statement, dialect7
|
12819
|
-
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite"
|
12778
|
+
can(statement, dialect7) {
|
12779
|
+
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
12820
12780
|
}
|
12821
12781
|
convert(statement) {
|
12822
12782
|
return `/*
|
@@ -12840,8 +12800,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12840
12800
|
}
|
12841
12801
|
};
|
12842
12802
|
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12843
|
-
can(statement, dialect7
|
12844
|
-
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite"
|
12803
|
+
can(statement, dialect7) {
|
12804
|
+
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
12845
12805
|
}
|
12846
12806
|
convert(statement) {
|
12847
12807
|
return `/*
|
@@ -12885,8 +12845,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12885
12845
|
}
|
12886
12846
|
};
|
12887
12847
|
SqliteCreateForeignKeyConvertor = class extends Convertor {
|
12888
|
-
can(statement, dialect7
|
12889
|
-
return statement.type === "create_reference" && dialect7 === "sqlite"
|
12848
|
+
can(statement, dialect7) {
|
12849
|
+
return statement.type === "create_reference" && dialect7 === "sqlite";
|
12890
12850
|
}
|
12891
12851
|
convert(statement) {
|
12892
12852
|
return `/*
|
@@ -12898,32 +12858,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12898
12858
|
*/`;
|
12899
12859
|
}
|
12900
12860
|
};
|
12901
|
-
LibSQLCreateForeignKeyConvertor = class extends Convertor {
|
12902
|
-
can(statement, dialect7, driver2) {
|
12903
|
-
return statement.type === "create_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
12904
|
-
}
|
12905
|
-
convert(statement, json2, action) {
|
12906
|
-
const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
12907
|
-
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
12908
|
-
if (isMulticolumn) {
|
12909
|
-
return `/*
|
12910
|
-
LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12911
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12912
|
-
https://www.sqlite.org/lang_altertable.html
|
12913
|
-
|
12914
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12915
|
-
*/`;
|
12916
|
-
}
|
12917
|
-
const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
|
12918
|
-
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
12919
|
-
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
12920
|
-
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
12921
|
-
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
12922
|
-
const columnFrom = columnsFrom[0];
|
12923
|
-
const columnTo = columnsTo[0];
|
12924
|
-
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
|
12925
|
-
}
|
12926
|
-
};
|
12927
12861
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
12928
12862
|
can(statement, dialect7) {
|
12929
12863
|
return statement.type === "create_reference" && dialect7 === "mysql";
|
@@ -12997,8 +12931,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12997
12931
|
}
|
12998
12932
|
};
|
12999
12933
|
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
13000
|
-
can(statement, dialect7
|
13001
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite"
|
12934
|
+
can(statement, dialect7) {
|
12935
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
13002
12936
|
}
|
13003
12937
|
convert(statement) {
|
13004
12938
|
return `/*
|
@@ -13010,29 +12944,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13010
12944
|
*/`;
|
13011
12945
|
}
|
13012
12946
|
};
|
13013
|
-
LibSQLDeleteForeignKeyConvertor = class extends Convertor {
|
13014
|
-
can(statement, dialect7, driver2) {
|
13015
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
13016
|
-
}
|
13017
|
-
convert(statement, json2, action) {
|
13018
|
-
const { columnsFrom, tableFrom } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
13019
|
-
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
13020
|
-
if (isMulticolumn) {
|
13021
|
-
return `/*
|
13022
|
-
LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
13023
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
13024
|
-
https://www.sqlite.org/lang_altertable.html
|
13025
|
-
|
13026
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
13027
|
-
*/`;
|
13028
|
-
}
|
13029
|
-
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
13030
|
-
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
13031
|
-
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
13032
|
-
const columnFrom = columnsFrom[0];
|
13033
|
-
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue};`;
|
13034
|
-
}
|
13035
|
-
};
|
13036
12947
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
13037
12948
|
can(statement, dialect7) {
|
13038
12949
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -13196,90 +13107,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13196
13107
|
return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
|
13197
13108
|
}
|
13198
13109
|
};
|
13199
|
-
SQLiteRecreateTableConvertor = class extends Convertor {
|
13200
|
-
can(statement, dialect7, driver2) {
|
13201
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
|
13202
|
-
}
|
13203
|
-
convert(statement) {
|
13204
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13205
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13206
|
-
const sqlStatements = [];
|
13207
|
-
sqlStatements.push(
|
13208
|
-
new SqliteRenameTableConvertor().convert({
|
13209
|
-
fromSchema: "",
|
13210
|
-
tableNameFrom: tableName,
|
13211
|
-
tableNameTo: `__old__generate_${tableName}`,
|
13212
|
-
toSchema: "",
|
13213
|
-
type: "rename_table"
|
13214
|
-
})
|
13215
|
-
);
|
13216
|
-
sqlStatements.push(
|
13217
|
-
new SQLiteCreateTableConvertor().convert({
|
13218
|
-
type: "sqlite_create_table",
|
13219
|
-
tableName,
|
13220
|
-
columns,
|
13221
|
-
referenceData,
|
13222
|
-
compositePKs
|
13223
|
-
})
|
13224
|
-
);
|
13225
|
-
sqlStatements.push(
|
13226
|
-
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
13227
|
-
);
|
13228
|
-
sqlStatements.push(
|
13229
|
-
new SQLiteDropTableConvertor().convert({
|
13230
|
-
type: "drop_table",
|
13231
|
-
tableName: `__old__generate_${tableName}`,
|
13232
|
-
schema: ""
|
13233
|
-
})
|
13234
|
-
);
|
13235
|
-
return sqlStatements;
|
13236
|
-
}
|
13237
|
-
};
|
13238
|
-
LibSQLRecreateTableConvertor = class extends Convertor {
|
13239
|
-
can(statement, dialect7, driver2) {
|
13240
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
|
13241
|
-
}
|
13242
|
-
convert(statement) {
|
13243
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
13244
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13245
|
-
const sqlStatements = [];
|
13246
|
-
sqlStatements.push(
|
13247
|
-
new SqliteRenameTableConvertor().convert({
|
13248
|
-
fromSchema: "",
|
13249
|
-
tableNameFrom: tableName,
|
13250
|
-
tableNameTo: `__old__generate_${tableName}`,
|
13251
|
-
toSchema: "",
|
13252
|
-
type: "rename_table"
|
13253
|
-
})
|
13254
|
-
);
|
13255
|
-
sqlStatements.push(
|
13256
|
-
new SQLiteCreateTableConvertor().convert({
|
13257
|
-
type: "sqlite_create_table",
|
13258
|
-
tableName,
|
13259
|
-
columns,
|
13260
|
-
referenceData,
|
13261
|
-
compositePKs
|
13262
|
-
})
|
13263
|
-
);
|
13264
|
-
sqlStatements.push(
|
13265
|
-
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
13266
|
-
);
|
13267
|
-
sqlStatements.push(
|
13268
|
-
new SQLiteDropTableConvertor().convert({
|
13269
|
-
type: "drop_table",
|
13270
|
-
tableName: `__old__generate_${tableName}`,
|
13271
|
-
schema: ""
|
13272
|
-
})
|
13273
|
-
);
|
13274
|
-
return sqlStatements;
|
13275
|
-
}
|
13276
|
-
};
|
13277
13110
|
convertors = [];
|
13278
13111
|
convertors.push(new PgCreateTableConvertor());
|
13279
13112
|
convertors.push(new MySqlCreateTableConvertor());
|
13280
13113
|
convertors.push(new SQLiteCreateTableConvertor());
|
13281
|
-
convertors.push(new SQLiteRecreateTableConvertor());
|
13282
|
-
convertors.push(new LibSQLRecreateTableConvertor());
|
13283
13114
|
convertors.push(new CreateTypeEnumConvertor());
|
13284
13115
|
convertors.push(new CreatePgSequenceConvertor());
|
13285
13116
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13327,7 +13158,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13327
13158
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
13328
13159
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
13329
13160
|
convertors.push(new MySqlModifyColumn());
|
13330
|
-
convertors.push(new LibSQLModifyColumn());
|
13331
13161
|
convertors.push(new PgCreateForeignKeyConvertor());
|
13332
13162
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
13333
13163
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -13342,9 +13172,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13342
13172
|
convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
13343
13173
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
13344
13174
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
13345
|
-
convertors.push(new LibSQLDeleteForeignKeyConvertor());
|
13346
13175
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
13347
|
-
convertors.push(new LibSQLCreateForeignKeyConvertor());
|
13348
13176
|
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
13349
13177
|
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
13350
13178
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
@@ -13367,6 +13195,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13367
13195
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
13368
13196
|
convertors.push(new MySqlAlterTableAddPk());
|
13369
13197
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
13198
|
+
fromJson = (statements, dialect7) => {
|
13199
|
+
const result = statements.flatMap((statement) => {
|
13200
|
+
const filtered = convertors.filter((it) => {
|
13201
|
+
return it.can(statement, dialect7);
|
13202
|
+
});
|
13203
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
13204
|
+
if (!convertor) {
|
13205
|
+
return "";
|
13206
|
+
}
|
13207
|
+
return convertor.convert(statement);
|
13208
|
+
}).filter((it) => it !== "");
|
13209
|
+
return result;
|
13210
|
+
};
|
13370
13211
|
https: `
|
13371
13212
|
create table users (
|
13372
13213
|
id int,
|
@@ -13393,237 +13234,12 @@ drop type __venum;
|
|
13393
13234
|
}
|
13394
13235
|
});
|
13395
13236
|
|
13396
|
-
// src/cli/commands/sqlitePushUtils.ts
|
13397
|
-
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
|
13398
|
-
var init_sqlitePushUtils = __esm({
|
13399
|
-
"src/cli/commands/sqlitePushUtils.ts"() {
|
13400
|
-
"use strict";
|
13401
|
-
init_source();
|
13402
|
-
init_sqliteSchema();
|
13403
|
-
init_sqlgenerator();
|
13404
|
-
init_utils();
|
13405
|
-
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
13406
|
-
const statements = [];
|
13407
|
-
statements.push(
|
13408
|
-
new SqliteRenameTableConvertor().convert({
|
13409
|
-
type: "rename_table",
|
13410
|
-
tableNameFrom: tableName,
|
13411
|
-
tableNameTo: `__old_push_${tableName}`,
|
13412
|
-
fromSchema: "",
|
13413
|
-
toSchema: ""
|
13414
|
-
})
|
13415
|
-
);
|
13416
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
13417
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
13418
|
-
const compositePKs = Object.values(
|
13419
|
-
json.tables[tableName].compositePrimaryKeys
|
13420
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
13421
|
-
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
13422
|
-
statements.push(
|
13423
|
-
new SQLiteCreateTableConvertor().convert({
|
13424
|
-
type: "sqlite_create_table",
|
13425
|
-
tableName,
|
13426
|
-
columns: tableColumns,
|
13427
|
-
referenceData: fks,
|
13428
|
-
compositePKs
|
13429
|
-
})
|
13430
|
-
);
|
13431
|
-
if (!dataLoss) {
|
13432
|
-
const columns = Object.keys(json.tables[tableName].columns).map(
|
13433
|
-
(c) => `"${c}"`
|
13434
|
-
);
|
13435
|
-
statements.push(
|
13436
|
-
`INSERT INTO \`${tableName}\`(${columns.join(
|
13437
|
-
", "
|
13438
|
-
)}) SELECT (${columns.join(", ")}) FROM \`__old_push_${tableName}\`;`
|
13439
|
-
);
|
13440
|
-
}
|
13441
|
-
statements.push(
|
13442
|
-
new SQLiteDropTableConvertor().convert({
|
13443
|
-
type: "drop_table",
|
13444
|
-
tableName: `__old_push_${tableName}`,
|
13445
|
-
schema: ""
|
13446
|
-
})
|
13447
|
-
);
|
13448
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
13449
|
-
statements.push(
|
13450
|
-
new CreateSqliteIndexConvertor().convert({
|
13451
|
-
type: "create_index",
|
13452
|
-
tableName,
|
13453
|
-
schema: "",
|
13454
|
-
data: idx
|
13455
|
-
})
|
13456
|
-
);
|
13457
|
-
}
|
13458
|
-
return statements;
|
13459
|
-
};
|
13460
|
-
getOldTableName = (tableName, meta) => {
|
13461
|
-
for (const key of Object.keys(meta.tables)) {
|
13462
|
-
const value = meta.tables[key];
|
13463
|
-
if (`"${tableName}"` === value) {
|
13464
|
-
return key.substring(1, key.length - 1);
|
13465
|
-
}
|
13466
|
-
}
|
13467
|
-
return tableName;
|
13468
|
-
};
|
13469
|
-
getNewTableName = (tableName, meta) => {
|
13470
|
-
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
13471
|
-
return meta.tables[`"${tableName}"`].substring(
|
13472
|
-
1,
|
13473
|
-
meta.tables[`"${tableName}"`].length - 1
|
13474
|
-
);
|
13475
|
-
}
|
13476
|
-
return tableName;
|
13477
|
-
};
|
13478
|
-
logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
13479
|
-
let shouldAskForApprove = false;
|
13480
|
-
const statementsToExecute = [];
|
13481
|
-
const infoToPrint = [];
|
13482
|
-
const tablesToRemove = [];
|
13483
|
-
const columnsToRemove = [];
|
13484
|
-
const schemasToRemove = [];
|
13485
|
-
const tablesToTruncate = [];
|
13486
|
-
for (const statement of statements) {
|
13487
|
-
if (statement.type === "drop_table") {
|
13488
|
-
const res = await connection.query(
|
13489
|
-
`select count(*) as count from \`${statement.tableName}\``
|
13490
|
-
);
|
13491
|
-
const count2 = Number(res[0].count);
|
13492
|
-
if (count2 > 0) {
|
13493
|
-
infoToPrint.push(
|
13494
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13495
|
-
statement.tableName
|
13496
|
-
)} table with ${count2} items`
|
13497
|
-
);
|
13498
|
-
tablesToRemove.push(statement.tableName);
|
13499
|
-
shouldAskForApprove = true;
|
13500
|
-
}
|
13501
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13502
|
-
statementsToExecute.push(
|
13503
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13504
|
-
);
|
13505
|
-
} else if (statement.type === "alter_table_drop_column") {
|
13506
|
-
const tableName = statement.tableName;
|
13507
|
-
const columnName = statement.columnName;
|
13508
|
-
const res = await connection.query(
|
13509
|
-
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
|
13510
|
-
);
|
13511
|
-
const count2 = Number(res[0].count);
|
13512
|
-
if (count2 > 0) {
|
13513
|
-
infoToPrint.push(
|
13514
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13515
|
-
columnName
|
13516
|
-
)} column in ${tableName} table with ${count2} items`
|
13517
|
-
);
|
13518
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
13519
|
-
shouldAskForApprove = true;
|
13520
|
-
}
|
13521
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13522
|
-
statementsToExecute.push(
|
13523
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13524
|
-
);
|
13525
|
-
} else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
|
13526
|
-
const tableName = statement.tableName;
|
13527
|
-
const columnName = statement.column.name;
|
13528
|
-
const res = await connection.query(
|
13529
|
-
`select count(*) as count from \`${tableName}\``
|
13530
|
-
);
|
13531
|
-
const count2 = Number(res[0].count);
|
13532
|
-
if (count2 > 0) {
|
13533
|
-
infoToPrint.push(
|
13534
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
13535
|
-
columnName
|
13536
|
-
)} column without default value, which contains ${count2} items`
|
13537
|
-
);
|
13538
|
-
tablesToTruncate.push(tableName);
|
13539
|
-
statementsToExecute.push(`delete from ${tableName};`);
|
13540
|
-
shouldAskForApprove = true;
|
13541
|
-
}
|
13542
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13543
|
-
statementsToExecute.push(
|
13544
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13545
|
-
);
|
13546
|
-
} else if (statement.type === "recreate_table") {
|
13547
|
-
const tableName = statement.tableName;
|
13548
|
-
const oldTableName = getOldTableName(tableName, meta);
|
13549
|
-
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
13550
|
-
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
13551
|
-
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
13552
|
-
prevColumnNames,
|
13553
|
-
currentColumnNames
|
13554
|
-
);
|
13555
|
-
if (removedColumns.length) {
|
13556
|
-
for (const removedColumn of removedColumns) {
|
13557
|
-
const res = await connection.query(
|
13558
|
-
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
13559
|
-
);
|
13560
|
-
const count2 = Number(res[0].count);
|
13561
|
-
if (count2 > 0) {
|
13562
|
-
infoToPrint.push(
|
13563
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13564
|
-
removedColumn
|
13565
|
-
)} column in ${tableName} table with ${count2} items`
|
13566
|
-
);
|
13567
|
-
columnsToRemove.push(removedColumn);
|
13568
|
-
shouldAskForApprove = true;
|
13569
|
-
}
|
13570
|
-
}
|
13571
|
-
}
|
13572
|
-
if (addedColumns.length) {
|
13573
|
-
for (const addedColumn of addedColumns) {
|
13574
|
-
const [res] = await connection.query(
|
13575
|
-
`select count(*) as count from \`${tableName}\``
|
13576
|
-
);
|
13577
|
-
const columnConf = json2.tables[tableName].columns[addedColumn];
|
13578
|
-
const count2 = Number(res.count);
|
13579
|
-
if (count2 > 0 && columnConf.notNull && !columnConf.default) {
|
13580
|
-
infoToPrint.push(
|
13581
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
13582
|
-
addedColumn
|
13583
|
-
)} column without default value to table, which contains ${count2} items`
|
13584
|
-
);
|
13585
|
-
shouldAskForApprove = true;
|
13586
|
-
tablesToTruncate.push(tableName);
|
13587
|
-
}
|
13588
|
-
}
|
13589
|
-
}
|
13590
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2));
|
13591
|
-
const tablesReferencingCurrent = [];
|
13592
|
-
for (const table4 of Object.values(json2.tables)) {
|
13593
|
-
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
13594
|
-
tablesReferencingCurrent.push(...tablesRefs);
|
13595
|
-
}
|
13596
|
-
const uniqueTableRefs = [...new Set(tablesReferencingCurrent)];
|
13597
|
-
for (const table4 of uniqueTableRefs) {
|
13598
|
-
statementsToExecute.push(..._moveDataStatements(table4, json2));
|
13599
|
-
}
|
13600
|
-
} else {
|
13601
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13602
|
-
statementsToExecute.push(
|
13603
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13604
|
-
);
|
13605
|
-
}
|
13606
|
-
}
|
13607
|
-
return {
|
13608
|
-
statementsToExecute,
|
13609
|
-
shouldAskForApprove,
|
13610
|
-
infoToPrint,
|
13611
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
13612
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
13613
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
13614
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
13615
|
-
};
|
13616
|
-
};
|
13617
|
-
}
|
13618
|
-
});
|
13619
|
-
|
13620
13237
|
// src/jsonStatements.ts
|
13621
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson,
|
13238
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13622
13239
|
var init_jsonStatements = __esm({
|
13623
13240
|
"src/jsonStatements.ts"() {
|
13624
13241
|
"use strict";
|
13625
13242
|
init_source();
|
13626
|
-
init_sqlitePushUtils();
|
13627
13243
|
init_views();
|
13628
13244
|
init_mysqlSchema();
|
13629
13245
|
init_pgSchema();
|
@@ -14407,49 +14023,6 @@ var init_jsonStatements = __esm({
|
|
14407
14023
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
14408
14024
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
14409
14025
|
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
14410
|
-
if (column4.autoincrement?.type === "added") {
|
14411
|
-
statements.push({
|
14412
|
-
type: "alter_table_alter_column_set_autoincrement",
|
14413
|
-
tableName,
|
14414
|
-
columnName,
|
14415
|
-
schema: schema4,
|
14416
|
-
newDataType: columnType,
|
14417
|
-
columnDefault,
|
14418
|
-
columnOnUpdate,
|
14419
|
-
columnNotNull,
|
14420
|
-
columnAutoIncrement,
|
14421
|
-
columnPk
|
14422
|
-
});
|
14423
|
-
}
|
14424
|
-
if (column4.autoincrement?.type === "changed") {
|
14425
|
-
const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
14426
|
-
statements.push({
|
14427
|
-
type,
|
14428
|
-
tableName,
|
14429
|
-
columnName,
|
14430
|
-
schema: schema4,
|
14431
|
-
newDataType: columnType,
|
14432
|
-
columnDefault,
|
14433
|
-
columnOnUpdate,
|
14434
|
-
columnNotNull,
|
14435
|
-
columnAutoIncrement,
|
14436
|
-
columnPk
|
14437
|
-
});
|
14438
|
-
}
|
14439
|
-
if (column4.autoincrement?.type === "deleted") {
|
14440
|
-
statements.push({
|
14441
|
-
type: "alter_table_alter_column_drop_autoincrement",
|
14442
|
-
tableName,
|
14443
|
-
columnName,
|
14444
|
-
schema: schema4,
|
14445
|
-
newDataType: columnType,
|
14446
|
-
columnDefault,
|
14447
|
-
columnOnUpdate,
|
14448
|
-
columnNotNull,
|
14449
|
-
columnAutoIncrement,
|
14450
|
-
columnPk
|
14451
|
-
});
|
14452
|
-
}
|
14453
14026
|
if (typeof column4.name !== "string") {
|
14454
14027
|
statements.push({
|
14455
14028
|
type: "alter_table_rename_column",
|
@@ -14713,94 +14286,16 @@ var init_jsonStatements = __esm({
|
|
14713
14286
|
};
|
14714
14287
|
});
|
14715
14288
|
};
|
14716
|
-
|
14289
|
+
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14717
14290
|
return Object.values(foreignKeys).map((fkData) => {
|
14718
|
-
const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14719
|
-
let isMulticolumn = false;
|
14720
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14721
|
-
isMulticolumn = true;
|
14722
|
-
return {
|
14723
|
-
type: "create_reference",
|
14724
|
-
tableName,
|
14725
|
-
data: fkData,
|
14726
|
-
schema: schema4,
|
14727
|
-
isMulticolumn
|
14728
|
-
};
|
14729
|
-
}
|
14730
|
-
const columnFrom = columnsFrom[0];
|
14731
|
-
const {
|
14732
|
-
notNull: columnNotNull,
|
14733
|
-
default: columnDefault,
|
14734
|
-
type: columnType
|
14735
|
-
} = json2.tables[tableFrom].columns[columnFrom];
|
14736
14291
|
return {
|
14737
|
-
type: "
|
14292
|
+
type: "delete_reference",
|
14738
14293
|
tableName,
|
14739
14294
|
data: fkData,
|
14740
|
-
schema: schema4
|
14741
|
-
columnNotNull,
|
14742
|
-
columnDefault,
|
14743
|
-
columnType
|
14295
|
+
schema: schema4
|
14744
14296
|
};
|
14745
14297
|
});
|
14746
14298
|
};
|
14747
|
-
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14748
|
-
return Object.values(foreignKeys).map((fkData) => {
|
14749
|
-
return {
|
14750
|
-
type: "delete_reference",
|
14751
|
-
tableName,
|
14752
|
-
data: fkData,
|
14753
|
-
schema: schema4
|
14754
|
-
};
|
14755
|
-
});
|
14756
|
-
};
|
14757
|
-
prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
|
14758
|
-
const statements = Object.values(foreignKeys).map((fkData) => {
|
14759
|
-
const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14760
|
-
const keys = Object.keys(json2.tables[tableName].columns);
|
14761
|
-
const filtered = columnsFrom.filter((it) => keys.includes(it));
|
14762
|
-
const fullDrop = filtered.length === 0;
|
14763
|
-
if (fullDrop) return;
|
14764
|
-
let isMulticolumn = false;
|
14765
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14766
|
-
isMulticolumn = true;
|
14767
|
-
return {
|
14768
|
-
type: "delete_reference",
|
14769
|
-
tableName,
|
14770
|
-
data: fkData,
|
14771
|
-
schema: schema4,
|
14772
|
-
isMulticolumn
|
14773
|
-
};
|
14774
|
-
}
|
14775
|
-
const columnFrom = columnsFrom[0];
|
14776
|
-
const newTableName = getNewTableName(tableFrom, meta);
|
14777
|
-
const {
|
14778
|
-
notNull: columnNotNull,
|
14779
|
-
default: columnDefault,
|
14780
|
-
type: columnType
|
14781
|
-
} = json2.tables[newTableName].columns[columnFrom];
|
14782
|
-
const fkToSquash = {
|
14783
|
-
columnsFrom,
|
14784
|
-
columnsTo,
|
14785
|
-
name: name2,
|
14786
|
-
tableFrom: newTableName,
|
14787
|
-
tableTo,
|
14788
|
-
onDelete,
|
14789
|
-
onUpdate
|
14790
|
-
};
|
14791
|
-
const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
|
14792
|
-
return {
|
14793
|
-
type: "delete_reference",
|
14794
|
-
tableName,
|
14795
|
-
data: foreignKey,
|
14796
|
-
schema: schema4,
|
14797
|
-
columnNotNull,
|
14798
|
-
columnDefault,
|
14799
|
-
columnType
|
14800
|
-
};
|
14801
|
-
});
|
14802
|
-
return statements.filter((it) => it);
|
14803
|
-
};
|
14804
14299
|
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
14805
14300
|
const stmts = [];
|
14806
14301
|
Object.values(foreignKeys).map((val) => {
|
@@ -14954,298 +14449,10 @@ var init_jsonStatements = __esm({
|
|
14954
14449
|
}
|
14955
14450
|
});
|
14956
14451
|
|
14957
|
-
// src/statementCombiner.ts
|
14958
|
-
var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
|
14959
|
-
var init_statementCombiner = __esm({
|
14960
|
-
"src/statementCombiner.ts"() {
|
14961
|
-
"use strict";
|
14962
|
-
init_jsonStatements();
|
14963
|
-
init_sqliteSchema();
|
14964
|
-
prepareLibSQLRecreateTable = (table4, action) => {
|
14965
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14966
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14967
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
14968
|
-
);
|
14969
|
-
const references2 = Object.values(table4.foreignKeys);
|
14970
|
-
const fks = references2.map(
|
14971
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14972
|
-
);
|
14973
|
-
const statements = [
|
14974
|
-
{
|
14975
|
-
type: "recreate_table",
|
14976
|
-
tableName: name2,
|
14977
|
-
columns: Object.values(columns),
|
14978
|
-
compositePKs: composites,
|
14979
|
-
referenceData: fks,
|
14980
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
14981
|
-
}
|
14982
|
-
];
|
14983
|
-
if (Object.keys(indexes).length) {
|
14984
|
-
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14985
|
-
}
|
14986
|
-
return statements;
|
14987
|
-
};
|
14988
|
-
prepareSQLiteRecreateTable = (table4, action) => {
|
14989
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14990
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14991
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
14992
|
-
);
|
14993
|
-
const references2 = Object.values(table4.foreignKeys);
|
14994
|
-
const fks = references2.map(
|
14995
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14996
|
-
);
|
14997
|
-
const statements = [
|
14998
|
-
{
|
14999
|
-
type: "recreate_table",
|
15000
|
-
tableName: name2,
|
15001
|
-
columns: Object.values(columns),
|
15002
|
-
compositePKs: composites,
|
15003
|
-
referenceData: fks,
|
15004
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
15005
|
-
}
|
15006
|
-
];
|
15007
|
-
if (Object.keys(indexes).length) {
|
15008
|
-
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
15009
|
-
}
|
15010
|
-
return statements;
|
15011
|
-
};
|
15012
|
-
libSQLCombineStatements = (statements, json2, action) => {
|
15013
|
-
const newStatements = {};
|
15014
|
-
for (const statement of statements) {
|
15015
|
-
if (statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
|
15016
|
-
const tableName2 = statement.tableName;
|
15017
|
-
const statementsForTable2 = newStatements[tableName2];
|
15018
|
-
if (!statementsForTable2) {
|
15019
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15020
|
-
continue;
|
15021
|
-
}
|
15022
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15023
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15024
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15025
|
-
if (wasRename) {
|
15026
|
-
newStatements[tableName2].push(...preparedStatements);
|
15027
|
-
} else {
|
15028
|
-
newStatements[tableName2] = preparedStatements;
|
15029
|
-
}
|
15030
|
-
continue;
|
15031
|
-
}
|
15032
|
-
continue;
|
15033
|
-
}
|
15034
|
-
if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") {
|
15035
|
-
const { tableName: tableName2, columnName, columnPk } = statement;
|
15036
|
-
const columnIsPartOfUniqueIndex = Object.values(
|
15037
|
-
json2.tables[tableName2].indexes
|
15038
|
-
).some((it) => {
|
15039
|
-
const unsquashIndex = SQLiteSquasher.unsquashIdx(it);
|
15040
|
-
return unsquashIndex.columns.includes(columnName) && unsquashIndex.isUnique;
|
15041
|
-
});
|
15042
|
-
const columnIsPartOfForeignKey = Object.values(
|
15043
|
-
json2.tables[tableName2].foreignKeys
|
15044
|
-
).some((it) => {
|
15045
|
-
const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
|
15046
|
-
return unsquashFk.columnsFrom.includes(columnName);
|
15047
|
-
});
|
15048
|
-
const statementsForTable2 = newStatements[tableName2];
|
15049
|
-
if (!statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15050
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15051
|
-
continue;
|
15052
|
-
}
|
15053
|
-
if (statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15054
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15055
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15056
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15057
|
-
if (wasRename) {
|
15058
|
-
newStatements[tableName2].push(...preparedStatements);
|
15059
|
-
} else {
|
15060
|
-
newStatements[tableName2] = preparedStatements;
|
15061
|
-
}
|
15062
|
-
}
|
15063
|
-
continue;
|
15064
|
-
}
|
15065
|
-
if (statementsForTable2 && !(columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15066
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15067
|
-
newStatements[tableName2].push(statement);
|
15068
|
-
}
|
15069
|
-
continue;
|
15070
|
-
}
|
15071
|
-
newStatements[tableName2] = [statement];
|
15072
|
-
continue;
|
15073
|
-
}
|
15074
|
-
if (statement.type === "create_reference") {
|
15075
|
-
const tableName2 = statement.tableName;
|
15076
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
15077
|
-
const statementsForTable2 = newStatements[tableName2];
|
15078
|
-
if (!statementsForTable2) {
|
15079
|
-
newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : newStatements[tableName2] = [statement];
|
15080
|
-
continue;
|
15081
|
-
}
|
15082
|
-
if (!statement.isMulticolumn && statementsForTable2.some(
|
15083
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
15084
|
-
)) {
|
15085
|
-
continue;
|
15086
|
-
}
|
15087
|
-
if (statement.isMulticolumn) {
|
15088
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15089
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15090
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15091
|
-
if (wasRename) {
|
15092
|
-
newStatements[tableName2].push(...preparedStatements);
|
15093
|
-
} else {
|
15094
|
-
newStatements[tableName2] = preparedStatements;
|
15095
|
-
}
|
15096
|
-
continue;
|
15097
|
-
}
|
15098
|
-
continue;
|
15099
|
-
}
|
15100
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15101
|
-
newStatements[tableName2].push(statement);
|
15102
|
-
}
|
15103
|
-
continue;
|
15104
|
-
}
|
15105
|
-
if (statement.type === "delete_reference") {
|
15106
|
-
const tableName2 = statement.tableName;
|
15107
|
-
const statementsForTable2 = newStatements[tableName2];
|
15108
|
-
if (!statementsForTable2) {
|
15109
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15110
|
-
continue;
|
15111
|
-
}
|
15112
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15113
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15114
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15115
|
-
if (wasRename) {
|
15116
|
-
newStatements[tableName2].push(...preparedStatements);
|
15117
|
-
} else {
|
15118
|
-
newStatements[tableName2] = preparedStatements;
|
15119
|
-
}
|
15120
|
-
continue;
|
15121
|
-
}
|
15122
|
-
continue;
|
15123
|
-
}
|
15124
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
15125
|
-
const tableName2 = statement.tableName;
|
15126
|
-
const statementsForTable2 = newStatements[tableName2];
|
15127
|
-
if (!statementsForTable2) {
|
15128
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15129
|
-
continue;
|
15130
|
-
}
|
15131
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15132
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15133
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15134
|
-
if (wasRename) {
|
15135
|
-
newStatements[tableName2].push(...preparedStatements);
|
15136
|
-
} else {
|
15137
|
-
newStatements[tableName2] = preparedStatements;
|
15138
|
-
}
|
15139
|
-
continue;
|
15140
|
-
}
|
15141
|
-
continue;
|
15142
|
-
}
|
15143
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
15144
|
-
const statementsForTable = newStatements[tableName];
|
15145
|
-
if (!statementsForTable) {
|
15146
|
-
newStatements[tableName] = [statement];
|
15147
|
-
continue;
|
15148
|
-
}
|
15149
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
15150
|
-
newStatements[tableName].push(statement);
|
15151
|
-
}
|
15152
|
-
}
|
15153
|
-
const combinedStatements = Object.values(newStatements).flat();
|
15154
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
15155
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
15156
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
15157
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
15158
|
-
};
|
15159
|
-
sqliteCombineStatements = (statements, json2, action) => {
|
15160
|
-
const newStatements = {};
|
15161
|
-
for (const statement of statements) {
|
15162
|
-
if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "delete_reference" || statement.type === "alter_reference" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
15163
|
-
const tableName2 = statement.tableName;
|
15164
|
-
const statementsForTable2 = newStatements[tableName2];
|
15165
|
-
if (!statementsForTable2) {
|
15166
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15167
|
-
continue;
|
15168
|
-
}
|
15169
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15170
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15171
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15172
|
-
if (wasRename) {
|
15173
|
-
newStatements[tableName2].push(...preparedStatements);
|
15174
|
-
} else {
|
15175
|
-
newStatements[tableName2] = preparedStatements;
|
15176
|
-
}
|
15177
|
-
continue;
|
15178
|
-
}
|
15179
|
-
continue;
|
15180
|
-
}
|
15181
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
15182
|
-
const tableName2 = statement.tableName;
|
15183
|
-
const statementsForTable2 = newStatements[tableName2];
|
15184
|
-
if (!statementsForTable2) {
|
15185
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15186
|
-
continue;
|
15187
|
-
}
|
15188
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15189
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15190
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15191
|
-
if (wasRename) {
|
15192
|
-
newStatements[tableName2].push(...preparedStatements);
|
15193
|
-
} else {
|
15194
|
-
newStatements[tableName2] = preparedStatements;
|
15195
|
-
}
|
15196
|
-
continue;
|
15197
|
-
}
|
15198
|
-
continue;
|
15199
|
-
}
|
15200
|
-
if (statement.type === "create_reference") {
|
15201
|
-
const tableName2 = statement.tableName;
|
15202
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
15203
|
-
const statementsForTable2 = newStatements[tableName2];
|
15204
|
-
if (!statementsForTable2) {
|
15205
|
-
newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
|
15206
|
-
continue;
|
15207
|
-
}
|
15208
|
-
if (data.columnsFrom.length === 1 && statementsForTable2.some(
|
15209
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
15210
|
-
)) {
|
15211
|
-
continue;
|
15212
|
-
}
|
15213
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15214
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15215
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15216
|
-
if (wasRename) {
|
15217
|
-
newStatements[tableName2].push(...preparedStatements);
|
15218
|
-
} else {
|
15219
|
-
newStatements[tableName2] = preparedStatements;
|
15220
|
-
}
|
15221
|
-
continue;
|
15222
|
-
}
|
15223
|
-
continue;
|
15224
|
-
}
|
15225
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
15226
|
-
const statementsForTable = newStatements[tableName];
|
15227
|
-
if (!statementsForTable) {
|
15228
|
-
newStatements[tableName] = [statement];
|
15229
|
-
continue;
|
15230
|
-
}
|
15231
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
15232
|
-
newStatements[tableName].push(statement);
|
15233
|
-
}
|
15234
|
-
}
|
15235
|
-
const combinedStatements = Object.values(newStatements).flat();
|
15236
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
15237
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
15238
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
15239
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
15240
|
-
};
|
15241
|
-
}
|
15242
|
-
});
|
15243
|
-
|
15244
14452
|
// src/snapshotsDiffer.ts
|
15245
14453
|
var snapshotsDiffer_exports = {};
|
15246
14454
|
__export(snapshotsDiffer_exports, {
|
15247
14455
|
alteredTableScheme: () => alteredTableScheme,
|
15248
|
-
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
15249
14456
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
15250
14457
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
15251
14458
|
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
@@ -15255,7 +14462,7 @@ __export(snapshotsDiffer_exports, {
|
|
15255
14462
|
makePatched: () => makePatched,
|
15256
14463
|
makeSelfOrPatched: () => makeSelfOrPatched
|
15257
14464
|
});
|
15258
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff
|
14465
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
15259
14466
|
var init_snapshotsDiffer = __esm({
|
15260
14467
|
"src/snapshotsDiffer.ts"() {
|
15261
14468
|
"use strict";
|
@@ -15267,7 +14474,6 @@ var init_snapshotsDiffer = __esm({
|
|
15267
14474
|
init_mysqlSchema();
|
15268
14475
|
init_pgSchema();
|
15269
14476
|
init_sqliteSchema();
|
15270
|
-
init_statementCombiner();
|
15271
14477
|
init_utils();
|
15272
14478
|
makeChanged = (schema4) => {
|
15273
14479
|
return objectType({
|
@@ -16311,313 +15517,29 @@ var init_snapshotsDiffer = __esm({
|
|
16311
15517
|
curFull,
|
16312
15518
|
curFull.internal
|
16313
15519
|
);
|
16314
|
-
});
|
16315
|
-
jsonStatements.push(...jsonMySqlCreateTables);
|
16316
|
-
jsonStatements.push(...jsonDropTables);
|
16317
|
-
jsonStatements.push(...jsonRenameTables);
|
16318
|
-
jsonStatements.push(...jsonRenameColumnsStatements);
|
16319
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16320
|
-
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16321
|
-
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16322
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
16323
|
-
jsonStatements.push(...jsonTableAlternations);
|
16324
|
-
jsonStatements.push(...jsonAddedCompositePKs);
|
16325
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16326
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16327
|
-
jsonStatements.push(...jsonAddColumnsStatemets);
|
16328
|
-
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16329
|
-
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16330
|
-
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16331
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16332
|
-
jsonStatements.push(...jsonDropColumnsStatemets);
|
16333
|
-
jsonStatements.push(...jsonAlteredCompositePKs);
|
16334
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16335
|
-
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16336
|
-
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16337
|
-
const uniqueSqlStatements = [];
|
16338
|
-
sqlStatements.forEach((ss) => {
|
16339
|
-
if (!uniqueSqlStatements.includes(ss)) {
|
16340
|
-
uniqueSqlStatements.push(ss);
|
16341
|
-
}
|
16342
|
-
});
|
16343
|
-
const rTables = renamedTables.map((it) => {
|
16344
|
-
return { from: it.from, to: it.to };
|
16345
|
-
});
|
16346
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16347
|
-
return {
|
16348
|
-
statements: jsonStatements,
|
16349
|
-
sqlStatements: uniqueSqlStatements,
|
16350
|
-
_meta
|
16351
|
-
};
|
16352
|
-
};
|
16353
|
-
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16354
|
-
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16355
|
-
const {
|
16356
|
-
created: createdTables,
|
16357
|
-
deleted: deletedTables,
|
16358
|
-
renamed: renamedTables
|
16359
|
-
} = await tablesResolver2({
|
16360
|
-
created: tablesDiff.added,
|
16361
|
-
deleted: tablesDiff.deleted
|
16362
|
-
});
|
16363
|
-
const tablesPatchedSnap1 = copy(json1);
|
16364
|
-
tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
|
16365
|
-
const { name: name2 } = nameChangeFor(it, renamedTables);
|
16366
|
-
it.name = name2;
|
16367
|
-
return [name2, it];
|
16368
|
-
});
|
16369
|
-
const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
|
16370
|
-
const columnRenames = [];
|
16371
|
-
const columnCreates = [];
|
16372
|
-
const columnDeletes = [];
|
16373
|
-
for (let entry of Object.values(res)) {
|
16374
|
-
const { renamed, created, deleted } = await columnsResolver2({
|
16375
|
-
tableName: entry.name,
|
16376
|
-
schema: entry.schema,
|
16377
|
-
deleted: entry.columns.deleted,
|
16378
|
-
created: entry.columns.added
|
16379
|
-
});
|
16380
|
-
if (created.length > 0) {
|
16381
|
-
columnCreates.push({
|
16382
|
-
table: entry.name,
|
16383
|
-
columns: created
|
16384
|
-
});
|
16385
|
-
}
|
16386
|
-
if (deleted.length > 0) {
|
16387
|
-
columnDeletes.push({
|
16388
|
-
table: entry.name,
|
16389
|
-
columns: deleted
|
16390
|
-
});
|
16391
|
-
}
|
16392
|
-
if (renamed.length > 0) {
|
16393
|
-
columnRenames.push({
|
16394
|
-
table: entry.name,
|
16395
|
-
renames: renamed
|
16396
|
-
});
|
16397
|
-
}
|
16398
|
-
}
|
16399
|
-
const columnRenamesDict = columnRenames.reduce(
|
16400
|
-
(acc, it) => {
|
16401
|
-
acc[it.table] = it.renames;
|
16402
|
-
return acc;
|
16403
|
-
},
|
16404
|
-
{}
|
16405
|
-
);
|
16406
|
-
const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
|
16407
|
-
columnsPatchedSnap1.tables = mapEntries(
|
16408
|
-
columnsPatchedSnap1.tables,
|
16409
|
-
(tableKey2, tableValue) => {
|
16410
|
-
const patchedColumns = mapKeys(
|
16411
|
-
tableValue.columns,
|
16412
|
-
(columnKey, column4) => {
|
16413
|
-
const rens = columnRenamesDict[tableValue.name] || [];
|
16414
|
-
const newName = columnChangeFor(columnKey, rens);
|
16415
|
-
column4.name = newName;
|
16416
|
-
return newName;
|
16417
|
-
}
|
16418
|
-
);
|
16419
|
-
tableValue.columns = patchedColumns;
|
16420
|
-
return [tableKey2, tableValue];
|
16421
|
-
}
|
16422
|
-
);
|
16423
|
-
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
16424
|
-
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16425
|
-
const tablesMap = {};
|
16426
|
-
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
16427
|
-
tablesMap[obj.name] = obj;
|
16428
|
-
});
|
16429
|
-
const jsonCreateTables = createdTables.map((it) => {
|
16430
|
-
return prepareSQLiteCreateTable(it, action);
|
16431
|
-
});
|
16432
|
-
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
16433
|
-
return prepareCreateIndexesJson(
|
16434
|
-
it.name,
|
16435
|
-
it.schema,
|
16436
|
-
it.indexes,
|
16437
|
-
curFull.internal
|
16438
|
-
);
|
16439
|
-
}).flat();
|
16440
|
-
const jsonDropTables = deletedTables.map((it) => {
|
16441
|
-
return prepareDropTableJson(it);
|
16442
|
-
});
|
16443
|
-
const jsonRenameTables = renamedTables.map((it) => {
|
16444
|
-
return prepareRenameTableJson(it.from, it.to);
|
16445
|
-
});
|
16446
|
-
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16447
|
-
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
16448
|
-
const jsonAddColumnsStatemets = columnCreates.map((it) => {
|
16449
|
-
return _prepareSqliteAddColumns(
|
16450
|
-
it.table,
|
16451
|
-
it.columns,
|
16452
|
-
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16453
|
-
);
|
16454
|
-
}).flat();
|
16455
|
-
const allAltered = typedResult.alteredTablesWithColumns;
|
16456
|
-
const jsonAddedCompositePKs = [];
|
16457
|
-
const jsonDeletedCompositePKs = [];
|
16458
|
-
const jsonAlteredCompositePKs = [];
|
16459
|
-
const jsonAddedUniqueConstraints = [];
|
16460
|
-
const jsonDeletedUniqueConstraints = [];
|
16461
|
-
const jsonAlteredUniqueConstraints = [];
|
16462
|
-
allAltered.forEach((it) => {
|
16463
|
-
let addedColumns = [];
|
16464
|
-
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16465
|
-
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16466
|
-
addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
|
16467
|
-
}
|
16468
|
-
let deletedColumns = [];
|
16469
|
-
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16470
|
-
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16471
|
-
deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
|
16472
|
-
}
|
16473
|
-
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16474
|
-
let addedCompositePKs = [];
|
16475
|
-
let deletedCompositePKs = [];
|
16476
|
-
let alteredCompositePKs = [];
|
16477
|
-
if (doPerformDeleteAndCreate) {
|
16478
|
-
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
16479
|
-
it.name,
|
16480
|
-
it.addedCompositePKs
|
16481
|
-
);
|
16482
|
-
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
16483
|
-
it.name,
|
16484
|
-
it.deletedCompositePKs
|
16485
|
-
);
|
16486
|
-
}
|
16487
|
-
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
16488
|
-
it.name,
|
16489
|
-
it.alteredCompositePKs
|
16490
|
-
);
|
16491
|
-
let addedUniqueConstraints = [];
|
16492
|
-
let deletedUniqueConstraints = [];
|
16493
|
-
let alteredUniqueConstraints = [];
|
16494
|
-
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16495
|
-
it.name,
|
16496
|
-
it.schema,
|
16497
|
-
it.addedUniqueConstraints
|
16498
|
-
);
|
16499
|
-
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
16500
|
-
it.name,
|
16501
|
-
it.schema,
|
16502
|
-
it.deletedUniqueConstraints
|
16503
|
-
);
|
16504
|
-
if (it.alteredUniqueConstraints) {
|
16505
|
-
const added = {};
|
16506
|
-
const deleted = {};
|
16507
|
-
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
16508
|
-
added[k] = it.alteredUniqueConstraints[k].__new;
|
16509
|
-
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
16510
|
-
}
|
16511
|
-
addedUniqueConstraints.push(
|
16512
|
-
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
16513
|
-
);
|
16514
|
-
deletedUniqueConstraints.push(
|
16515
|
-
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16516
|
-
);
|
16517
|
-
}
|
16518
|
-
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16519
|
-
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16520
|
-
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16521
|
-
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16522
|
-
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16523
|
-
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16524
|
-
});
|
16525
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16526
|
-
const tableName = it.tableName;
|
16527
|
-
const schema4 = it.schema;
|
16528
|
-
return {
|
16529
|
-
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16530
|
-
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16531
|
-
};
|
16532
|
-
});
|
16533
|
-
const jsonTableAlternations = allAltered.map((it) => {
|
16534
|
-
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16535
|
-
}).flat();
|
16536
|
-
const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
|
16537
|
-
return prepareCreateIndexesJson(
|
16538
|
-
it.name,
|
16539
|
-
it.schema,
|
16540
|
-
it.addedIndexes || {},
|
16541
|
-
curFull.internal
|
16542
|
-
);
|
16543
|
-
}).flat();
|
16544
|
-
const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
|
16545
|
-
return prepareDropIndexesJson(
|
16546
|
-
it.name,
|
16547
|
-
it.schema,
|
16548
|
-
it.deletedIndexes || {}
|
16549
|
-
);
|
16550
|
-
}).flat();
|
16551
|
-
allAltered.forEach((it) => {
|
16552
|
-
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
16553
|
-
(current, item) => {
|
16554
|
-
current[item] = it.alteredIndexes[item].__old;
|
16555
|
-
return current;
|
16556
|
-
},
|
16557
|
-
{}
|
16558
|
-
);
|
16559
|
-
const createdIndexes = Object.keys(it.alteredIndexes).reduce(
|
16560
|
-
(current, item) => {
|
16561
|
-
current[item] = it.alteredIndexes[item].__new;
|
16562
|
-
return current;
|
16563
|
-
},
|
16564
|
-
{}
|
16565
|
-
);
|
16566
|
-
jsonCreateIndexesForAllAlteredTables.push(
|
16567
|
-
...prepareCreateIndexesJson(
|
16568
|
-
it.name,
|
16569
|
-
it.schema,
|
16570
|
-
createdIndexes || {},
|
16571
|
-
curFull.internal
|
16572
|
-
)
|
16573
|
-
);
|
16574
|
-
jsonDropIndexesForAllAlteredTables.push(
|
16575
|
-
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
16576
|
-
);
|
16577
|
-
});
|
16578
|
-
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16579
|
-
const forAdded = prepareCreateReferencesJson(
|
16580
|
-
it.name,
|
16581
|
-
it.schema,
|
16582
|
-
it.addedForeignKeys
|
16583
|
-
);
|
16584
|
-
const forAltered = prepareDropReferencesJson(
|
16585
|
-
it.name,
|
16586
|
-
it.schema,
|
16587
|
-
it.deletedForeignKeys
|
16588
|
-
);
|
16589
|
-
const alteredFKs = prepareAlterReferencesJson(
|
16590
|
-
it.name,
|
16591
|
-
it.schema,
|
16592
|
-
it.alteredForeignKeys
|
16593
|
-
);
|
16594
|
-
return [...forAdded, ...forAltered, ...alteredFKs];
|
16595
|
-
}).flat();
|
16596
|
-
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16597
|
-
(t) => t.type === "create_reference"
|
16598
|
-
);
|
16599
|
-
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16600
|
-
(t) => t.type === "delete_reference"
|
16601
|
-
);
|
16602
|
-
const jsonStatements = [];
|
16603
|
-
jsonStatements.push(...jsonCreateTables);
|
15520
|
+
});
|
15521
|
+
jsonStatements.push(...jsonMySqlCreateTables);
|
16604
15522
|
jsonStatements.push(...jsonDropTables);
|
16605
15523
|
jsonStatements.push(...jsonRenameTables);
|
16606
15524
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15525
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16607
15526
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16608
15527
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16609
15528
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16610
15529
|
jsonStatements.push(...jsonTableAlternations);
|
16611
15530
|
jsonStatements.push(...jsonAddedCompositePKs);
|
15531
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15532
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16612
15533
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
15534
|
+
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16613
15535
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16614
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16615
15536
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
15537
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16616
15538
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16617
15539
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15540
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16618
15541
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16619
|
-
const
|
16620
|
-
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
15542
|
+
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16621
15543
|
const uniqueSqlStatements = [];
|
16622
15544
|
sqlStatements.forEach((ss) => {
|
16623
15545
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -16629,12 +15551,12 @@ var init_snapshotsDiffer = __esm({
|
|
16629
15551
|
});
|
16630
15552
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16631
15553
|
return {
|
16632
|
-
statements:
|
15554
|
+
statements: jsonStatements,
|
16633
15555
|
sqlStatements: uniqueSqlStatements,
|
16634
15556
|
_meta
|
16635
15557
|
};
|
16636
15558
|
};
|
16637
|
-
|
15559
|
+
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16638
15560
|
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16639
15561
|
const {
|
16640
15562
|
created: createdTables,
|
@@ -16736,18 +15658,6 @@ var init_snapshotsDiffer = __esm({
|
|
16736
15658
|
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16737
15659
|
);
|
16738
15660
|
}).flat();
|
16739
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16740
|
-
const tableName = it.tableName;
|
16741
|
-
const schema4 = it.schema;
|
16742
|
-
return {
|
16743
|
-
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16744
|
-
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16745
|
-
};
|
16746
|
-
});
|
16747
|
-
const rTables = renamedTables.map((it) => {
|
16748
|
-
return { from: it.from, to: it.to };
|
16749
|
-
});
|
16750
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16751
15661
|
const allAltered = typedResult.alteredTablesWithColumns;
|
16752
15662
|
const jsonAddedCompositePKs = [];
|
16753
15663
|
const jsonDeletedCompositePKs = [];
|
@@ -16818,6 +15728,14 @@ var init_snapshotsDiffer = __esm({
|
|
16818
15728
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16819
15729
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16820
15730
|
});
|
15731
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
15732
|
+
const tableName = it.tableName;
|
15733
|
+
const schema4 = it.schema;
|
15734
|
+
return {
|
15735
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
15736
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
15737
|
+
};
|
15738
|
+
});
|
16821
15739
|
const jsonTableAlternations = allAltered.map((it) => {
|
16822
15740
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16823
15741
|
}).flat();
|
@@ -16864,22 +15782,21 @@ var init_snapshotsDiffer = __esm({
|
|
16864
15782
|
);
|
16865
15783
|
});
|
16866
15784
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16867
|
-
const forAdded =
|
15785
|
+
const forAdded = prepareCreateReferencesJson(
|
16868
15786
|
it.name,
|
16869
15787
|
it.schema,
|
16870
|
-
it.addedForeignKeys
|
16871
|
-
json2,
|
16872
|
-
action
|
15788
|
+
it.addedForeignKeys
|
16873
15789
|
);
|
16874
|
-
const forAltered =
|
15790
|
+
const forAltered = prepareDropReferencesJson(
|
16875
15791
|
it.name,
|
16876
15792
|
it.schema,
|
16877
|
-
it.deletedForeignKeys
|
16878
|
-
|
16879
|
-
|
16880
|
-
|
15793
|
+
it.deletedForeignKeys
|
15794
|
+
);
|
15795
|
+
const alteredFKs = prepareAlterReferencesJson(
|
15796
|
+
it.name,
|
15797
|
+
it.schema,
|
15798
|
+
it.alteredForeignKeys
|
16881
15799
|
);
|
16882
|
-
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
16883
15800
|
return [...forAdded, ...forAltered, ...alteredFKs];
|
16884
15801
|
}).flat();
|
16885
15802
|
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
@@ -16905,22 +15822,19 @@ var init_snapshotsDiffer = __esm({
|
|
16905
15822
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16906
15823
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16907
15824
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16908
|
-
const
|
16909
|
-
const sqlStatements = fromJson(
|
16910
|
-
combinedJsonStatements,
|
16911
|
-
"sqlite",
|
16912
|
-
action,
|
16913
|
-
"turso",
|
16914
|
-
json2
|
16915
|
-
);
|
15825
|
+
const sqlStatements = fromJson(jsonStatements, "sqlite");
|
16916
15826
|
const uniqueSqlStatements = [];
|
16917
15827
|
sqlStatements.forEach((ss) => {
|
16918
15828
|
if (!uniqueSqlStatements.includes(ss)) {
|
16919
15829
|
uniqueSqlStatements.push(ss);
|
16920
15830
|
}
|
16921
15831
|
});
|
15832
|
+
const rTables = renamedTables.map((it) => {
|
15833
|
+
return { from: it.from, to: it.to };
|
15834
|
+
});
|
15835
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16922
15836
|
return {
|
16923
|
-
statements:
|
15837
|
+
statements: jsonStatements,
|
16924
15838
|
sqlStatements: uniqueSqlStatements,
|
16925
15839
|
_meta
|
16926
15840
|
};
|
@@ -20484,7 +19398,7 @@ function jaccardDistance(column4, value) {
|
|
20484
19398
|
}
|
20485
19399
|
return sql`${column4} <%> ${value}`;
|
20486
19400
|
}
|
20487
|
-
var
|
19401
|
+
var init_vector2 = __esm({
|
20488
19402
|
"../drizzle-orm/dist/sql/functions/vector.js"() {
|
20489
19403
|
"use strict";
|
20490
19404
|
init_sql();
|
@@ -20496,7 +19410,7 @@ var init_functions = __esm({
|
|
20496
19410
|
"../drizzle-orm/dist/sql/functions/index.js"() {
|
20497
19411
|
"use strict";
|
20498
19412
|
init_aggregate();
|
20499
|
-
|
19413
|
+
init_vector2();
|
20500
19414
|
}
|
20501
19415
|
});
|
20502
19416
|
|
@@ -22160,7 +21074,7 @@ var init_sparsevec = __esm({
|
|
22160
21074
|
|
22161
21075
|
// ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
|
22162
21076
|
var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
|
22163
|
-
var
|
21077
|
+
var init_vector3 = __esm({
|
22164
21078
|
"../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
|
22165
21079
|
"use strict";
|
22166
21080
|
init_entity();
|
@@ -22232,7 +21146,7 @@ var init_columns = __esm({
|
|
22232
21146
|
init_bit();
|
22233
21147
|
init_halfvec();
|
22234
21148
|
init_sparsevec();
|
22235
|
-
|
21149
|
+
init_vector3();
|
22236
21150
|
}
|
22237
21151
|
});
|
22238
21152
|
|
@@ -25730,24 +24644,6 @@ var init_pg_core = __esm({
|
|
25730
24644
|
}
|
25731
24645
|
});
|
25732
24646
|
|
25733
|
-
// src/extensions/vector.ts
|
25734
|
-
var vectorOps;
|
25735
|
-
var init_vector3 = __esm({
|
25736
|
-
"src/extensions/vector.ts"() {
|
25737
|
-
"use strict";
|
25738
|
-
vectorOps = [
|
25739
|
-
"vector_l2_ops",
|
25740
|
-
"vector_ip_ops",
|
25741
|
-
"vector_cosine_ops",
|
25742
|
-
"vector_l1_ops",
|
25743
|
-
"bit_hamming_ops",
|
25744
|
-
"bit_jaccard_ops",
|
25745
|
-
"halfvec_l2_ops",
|
25746
|
-
"sparsevec_l2_ops"
|
25747
|
-
];
|
25748
|
-
}
|
25749
|
-
});
|
25750
|
-
|
25751
24647
|
// src/serializer/pgSerializer.ts
|
25752
24648
|
function stringFromIdentityProperty(field) {
|
25753
24649
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
|
@@ -25785,7 +24681,7 @@ function buildArrayString(array, sqlType) {
|
|
25785
24681
|
}).join(",");
|
25786
24682
|
return `{${values}}`;
|
25787
24683
|
}
|
25788
|
-
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase,
|
24684
|
+
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
|
25789
24685
|
var init_pgSerializer = __esm({
|
25790
24686
|
"src/serializer/pgSerializer.ts"() {
|
25791
24687
|
"use strict";
|
@@ -25793,7 +24689,7 @@ var init_pgSerializer = __esm({
|
|
25793
24689
|
init_dist();
|
25794
24690
|
init_pg_core();
|
25795
24691
|
init_pg_core();
|
25796
|
-
|
24692
|
+
init_vector();
|
25797
24693
|
init_outputs();
|
25798
24694
|
init_utils();
|
25799
24695
|
init_serializer();
|
@@ -25906,7 +24802,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
25906
24802
|
columnToSet.default = `'${buildArrayString(
|
25907
24803
|
column4.default,
|
25908
24804
|
sqlTypeLowered
|
25909
|
-
)}'
|
24805
|
+
)}'`;
|
25910
24806
|
} else {
|
25911
24807
|
columnToSet.default = column4.default;
|
25912
24808
|
}
|
@@ -26253,7 +25149,7 @@ ${withStyle.errorWarning(
|
|
26253
25149
|
WHEN 'int2'::regtype THEN 'smallserial'
|
26254
25150
|
END
|
26255
25151
|
ELSE format_type(a.atttypid, a.atttypmod)
|
26256
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
|
25152
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
|
26257
25153
|
pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
|
26258
25154
|
INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
|
26259
25155
|
INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
|
@@ -26264,6 +25160,7 @@ ${withStyle.errorWarning(
|
|
26264
25160
|
INFORMATION_SCHEMA.COLUMNS.identity_cycle
|
26265
25161
|
FROM pg_attribute a
|
26266
25162
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
25163
|
+
JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
26267
25164
|
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
|
26268
25165
|
AND a.attnum > 0
|
26269
25166
|
AND NOT a.attisdropped
|
@@ -26283,30 +25180,42 @@ ${withStyle.errorWarning(
|
|
26283
25180
|
}
|
26284
25181
|
const tableForeignKeys = await db.query(
|
26285
25182
|
`SELECT
|
26286
|
-
|
26287
|
-
|
26288
|
-
|
26289
|
-
|
26290
|
-
|
26291
|
-
|
26292
|
-
|
26293
|
-
|
26294
|
-
|
26295
|
-
|
26296
|
-
|
26297
|
-
|
26298
|
-
|
26299
|
-
|
26300
|
-
|
26301
|
-
|
26302
|
-
|
26303
|
-
|
26304
|
-
|
26305
|
-
|
26306
|
-
|
26307
|
-
|
26308
|
-
|
26309
|
-
|
25183
|
+
con.contype AS constraint_type,
|
25184
|
+
nsp.nspname AS constraint_schema,
|
25185
|
+
con.conname AS constraint_name,
|
25186
|
+
rel.relname AS table_name,
|
25187
|
+
att.attname AS column_name,
|
25188
|
+
fnsp.nspname AS foreign_table_schema,
|
25189
|
+
frel.relname AS foreign_table_name,
|
25190
|
+
fatt.attname AS foreign_column_name,
|
25191
|
+
CASE con.confupdtype
|
25192
|
+
WHEN 'a' THEN 'NO ACTION'
|
25193
|
+
WHEN 'r' THEN 'RESTRICT'
|
25194
|
+
WHEN 'n' THEN 'SET NULL'
|
25195
|
+
WHEN 'c' THEN 'CASCADE'
|
25196
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25197
|
+
END AS update_rule,
|
25198
|
+
CASE con.confdeltype
|
25199
|
+
WHEN 'a' THEN 'NO ACTION'
|
25200
|
+
WHEN 'r' THEN 'RESTRICT'
|
25201
|
+
WHEN 'n' THEN 'SET NULL'
|
25202
|
+
WHEN 'c' THEN 'CASCADE'
|
25203
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25204
|
+
END AS delete_rule
|
25205
|
+
FROM
|
25206
|
+
pg_catalog.pg_constraint con
|
25207
|
+
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
25208
|
+
JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
|
25209
|
+
LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
|
25210
|
+
AND att.attrelid = con.conrelid
|
25211
|
+
LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
|
25212
|
+
LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
|
25213
|
+
LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
|
25214
|
+
AND fatt.attrelid = con.confrelid
|
25215
|
+
WHERE
|
25216
|
+
nsp.nspname = '${tableSchema}'
|
25217
|
+
AND rel.relname = '${tableName}'
|
25218
|
+
AND con.contype IN ('f');`
|
26310
25219
|
);
|
26311
25220
|
foreignKeysCount += tableForeignKeys.length;
|
26312
25221
|
if (progressCallback) {
|
@@ -26364,6 +25273,8 @@ ${withStyle.errorWarning(
|
|
26364
25273
|
const columnDimensions = columnResponse.array_dimensions;
|
26365
25274
|
const enumType2 = columnResponse.enum_name;
|
26366
25275
|
let columnType = columnResponse.data_type;
|
25276
|
+
const typeSchema = columnResponse.type_schema;
|
25277
|
+
const defaultValueRes = columnResponse.column_default;
|
26367
25278
|
const isGenerated = columnResponse.is_generated === "ALWAYS";
|
26368
25279
|
const generationExpression = columnResponse.generation_expression;
|
26369
25280
|
const isIdentity = columnResponse.is_identity === "YES";
|
@@ -26394,12 +25305,7 @@ ${withStyle.errorWarning(
|
|
26394
25305
|
columns: cprimaryKey.map((c) => c.column_name)
|
26395
25306
|
};
|
26396
25307
|
}
|
26397
|
-
const defaultValue = defaultForColumn(columnResponse);
|
26398
|
-
const isSerial = columnType === "serial";
|
26399
25308
|
let columnTypeMapped = columnType;
|
26400
|
-
if (columnTypeMapped.startsWith("numeric(")) {
|
26401
|
-
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
26402
|
-
}
|
26403
25309
|
if (columnAdditionalDT === "ARRAY") {
|
26404
25310
|
if (typeof internals.tables[tableName] === "undefined") {
|
26405
25311
|
internals.tables[tableName] = {
|
@@ -26427,6 +25333,34 @@ ${withStyle.errorWarning(
|
|
26427
25333
|
}
|
26428
25334
|
}
|
26429
25335
|
}
|
25336
|
+
const defaultValue = defaultForColumn(
|
25337
|
+
columnResponse,
|
25338
|
+
internals,
|
25339
|
+
tableName
|
25340
|
+
);
|
25341
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
25342
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25343
|
+
internals.tables[tableName] = {
|
25344
|
+
columns: {
|
25345
|
+
[columnName]: {
|
25346
|
+
isDefaultAnExpression: true
|
25347
|
+
}
|
25348
|
+
}
|
25349
|
+
};
|
25350
|
+
} else {
|
25351
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25352
|
+
internals.tables[tableName].columns[columnName] = {
|
25353
|
+
isDefaultAnExpression: true
|
25354
|
+
};
|
25355
|
+
} else {
|
25356
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25357
|
+
}
|
25358
|
+
}
|
25359
|
+
}
|
25360
|
+
const isSerial = columnType === "serial";
|
25361
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
25362
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
25363
|
+
}
|
26430
25364
|
if (columnAdditionalDT === "ARRAY") {
|
26431
25365
|
for (let i = 1; i < Number(columnDimensions); i++) {
|
26432
25366
|
columnTypeMapped += "[]";
|
@@ -26440,7 +25374,7 @@ ${withStyle.errorWarning(
|
|
26440
25374
|
// filter vectors, but in future we should filter any extension that was installed by user
|
26441
25375
|
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
26442
25376
|
),
|
26443
|
-
typeSchema: enumsToReturn[`${
|
25377
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
26444
25378
|
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
26445
25379
|
// default: isSerial ? undefined : defaultValue,
|
26446
25380
|
notNull: columnResponse.is_nullable === "NO",
|
@@ -26611,59 +25545,71 @@ ${withStyle.errorWarning(
|
|
26611
25545
|
internal: internals
|
26612
25546
|
};
|
26613
25547
|
};
|
26614
|
-
|
26615
|
-
|
26616
|
-
|
26617
|
-
// "character varying": "::character varying",
|
26618
|
-
// "double precision": "::double precision",
|
26619
|
-
// "time with time zone": "::time with time zone",
|
26620
|
-
"time without time zone": "::time without time zone",
|
26621
|
-
// "timestamp with time zone": "::timestamp with time zone",
|
26622
|
-
"timestamp without time zone": "::timestamp without time zone",
|
26623
|
-
"timestamp(": "::timestamp without time zone",
|
26624
|
-
// date: "::date",
|
26625
|
-
// interval: "::interval",
|
26626
|
-
// character: "::bpchar",
|
26627
|
-
// macaddr8: "::macaddr8",
|
26628
|
-
// macaddr: "::macaddr",
|
26629
|
-
// inet: "::inet",
|
26630
|
-
// cidr: "::cidr",
|
26631
|
-
// jsonb: "::jsonb",
|
26632
|
-
// json: "::json",
|
26633
|
-
"character(": "::bpchar"
|
26634
|
-
};
|
26635
|
-
defaultForColumn = (column4) => {
|
25548
|
+
defaultForColumn = (column4, internals, tableName) => {
|
25549
|
+
const columnName = column4.attname;
|
25550
|
+
const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
|
26636
25551
|
if (column4.column_default === null) {
|
26637
25552
|
return void 0;
|
26638
25553
|
}
|
26639
25554
|
if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
|
26640
25555
|
return void 0;
|
26641
25556
|
}
|
26642
|
-
|
25557
|
+
if (column4.column_default.endsWith("[]")) {
|
25558
|
+
column4.column_default = column4.column_default.slice(0, -2);
|
25559
|
+
}
|
25560
|
+
column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
|
26643
25561
|
const columnDefaultAsString = column4.column_default.toString();
|
26644
|
-
if (
|
26645
|
-
|
26646
|
-
|
26647
|
-
|
26648
|
-
|
26649
|
-
|
26650
|
-
|
26651
|
-
|
26652
|
-
|
26653
|
-
|
26654
|
-
|
26655
|
-
|
26656
|
-
|
26657
|
-
|
26658
|
-
|
26659
|
-
|
26660
|
-
|
25562
|
+
if (isArray) {
|
25563
|
+
return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
|
25564
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
|
25565
|
+
return value;
|
25566
|
+
} else if (column4.data_type.startsWith("timestamp")) {
|
25567
|
+
return `${value}`;
|
25568
|
+
} else if (column4.data_type.slice(0, -2) === "interval") {
|
25569
|
+
return value.replaceAll('"', `"`);
|
25570
|
+
} else if (column4.data_type.slice(0, -2) === "boolean") {
|
25571
|
+
return value === "t" ? "true" : "false";
|
25572
|
+
} else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
|
25573
|
+
return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
|
25574
|
+
} else {
|
25575
|
+
return `"${value}"`;
|
25576
|
+
}
|
25577
|
+
}).join(",")}}'`;
|
25578
|
+
}
|
25579
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
|
25580
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
|
26661
25581
|
return Number(columnDefaultAsString);
|
26662
|
-
} else if (column4.data_type === "boolean") {
|
26663
|
-
return column4.column_default === "true";
|
26664
25582
|
} else {
|
26665
|
-
|
25583
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25584
|
+
internals.tables[tableName] = {
|
25585
|
+
columns: {
|
25586
|
+
[columnName]: {
|
25587
|
+
isDefaultAnExpression: true
|
25588
|
+
}
|
25589
|
+
}
|
25590
|
+
};
|
25591
|
+
} else {
|
25592
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25593
|
+
internals.tables[tableName].columns[columnName] = {
|
25594
|
+
isDefaultAnExpression: true
|
25595
|
+
};
|
25596
|
+
} else {
|
25597
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25598
|
+
}
|
25599
|
+
}
|
25600
|
+
return columnDefaultAsString;
|
26666
25601
|
}
|
25602
|
+
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
25603
|
+
const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
|
25604
|
+
return `'${jsonWithoutSpaces}'::${column4.data_type}`;
|
25605
|
+
} else if (column4.data_type === "boolean") {
|
25606
|
+
return column4.column_default === "true";
|
25607
|
+
} else if (columnDefaultAsString === "NULL") {
|
25608
|
+
return `NULL`;
|
25609
|
+
} else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
|
25610
|
+
return columnDefaultAsString;
|
25611
|
+
} else {
|
25612
|
+
return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
|
26667
25613
|
}
|
26668
25614
|
};
|
26669
25615
|
}
|
@@ -34982,8 +33928,7 @@ var init_cli = __esm({
|
|
34982
33928
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34983
33929
|
extensionsFilters: literalType("postgis").array().optional(),
|
34984
33930
|
verbose: booleanType().optional(),
|
34985
|
-
strict: booleanType().optional()
|
34986
|
-
driver: driver.optional()
|
33931
|
+
strict: booleanType().optional()
|
34987
33932
|
}).passthrough();
|
34988
33933
|
pullParams = objectType({
|
34989
33934
|
config: stringType().optional(),
|
@@ -34994,7 +33939,7 @@ var init_cli = __esm({
|
|
34994
33939
|
extensionsFilters: literalType("postgis").array().optional(),
|
34995
33940
|
introspectCasing: casing,
|
34996
33941
|
breakpoints: booleanType().optional().default(true),
|
34997
|
-
|
33942
|
+
migrations: objectType({
|
34998
33943
|
prefix: prefix.optional().default("index")
|
34999
33944
|
}).optional()
|
35000
33945
|
}).passthrough();
|
@@ -36135,8 +35080,284 @@ var sqlitePushIntrospect = async (db, filters) => {
|
|
36135
35080
|
return { schema: schema4 };
|
36136
35081
|
};
|
36137
35082
|
|
35083
|
+
// src/cli/commands/sqlitePushUtils.ts
|
35084
|
+
init_source();
|
35085
|
+
init_sqliteSchema();
|
35086
|
+
init_sqlgenerator();
|
35087
|
+
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
35088
|
+
const statements = [];
|
35089
|
+
statements.push(
|
35090
|
+
new SqliteRenameTableConvertor().convert({
|
35091
|
+
type: "rename_table",
|
35092
|
+
tableNameFrom: tableName,
|
35093
|
+
tableNameTo: `__old_push_${tableName}`,
|
35094
|
+
fromSchema: "",
|
35095
|
+
toSchema: ""
|
35096
|
+
})
|
35097
|
+
);
|
35098
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
35099
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
35100
|
+
const compositePKs = Object.values(
|
35101
|
+
json.tables[tableName].compositePrimaryKeys
|
35102
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
35103
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
35104
|
+
statements.push(
|
35105
|
+
new SQLiteCreateTableConvertor().convert({
|
35106
|
+
type: "sqlite_create_table",
|
35107
|
+
tableName,
|
35108
|
+
columns: tableColumns,
|
35109
|
+
referenceData: fks,
|
35110
|
+
compositePKs
|
35111
|
+
})
|
35112
|
+
);
|
35113
|
+
if (!dataLoss) {
|
35114
|
+
statements.push(
|
35115
|
+
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
35116
|
+
);
|
35117
|
+
}
|
35118
|
+
statements.push(
|
35119
|
+
new SQLiteDropTableConvertor().convert({
|
35120
|
+
type: "drop_table",
|
35121
|
+
tableName: `__old_push_${tableName}`,
|
35122
|
+
schema: ""
|
35123
|
+
})
|
35124
|
+
);
|
35125
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
35126
|
+
statements.push(
|
35127
|
+
new CreateSqliteIndexConvertor().convert({
|
35128
|
+
type: "create_index",
|
35129
|
+
tableName,
|
35130
|
+
schema: "",
|
35131
|
+
data: idx
|
35132
|
+
})
|
35133
|
+
);
|
35134
|
+
}
|
35135
|
+
return statements;
|
35136
|
+
};
|
35137
|
+
var getOldTableName = (tableName, meta) => {
|
35138
|
+
for (const key of Object.keys(meta.tables)) {
|
35139
|
+
const value = meta.tables[key];
|
35140
|
+
if (`"${tableName}"` === value) {
|
35141
|
+
return key.substring(1, key.length - 1);
|
35142
|
+
}
|
35143
|
+
}
|
35144
|
+
return tableName;
|
35145
|
+
};
|
35146
|
+
var getNewTableName = (tableName, meta) => {
|
35147
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
35148
|
+
return meta.tables[`"${tableName}"`].substring(
|
35149
|
+
1,
|
35150
|
+
meta.tables[`"${tableName}"`].length - 1
|
35151
|
+
);
|
35152
|
+
}
|
35153
|
+
return tableName;
|
35154
|
+
};
|
35155
|
+
var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
35156
|
+
let shouldAskForApprove = false;
|
35157
|
+
const statementsToExecute = [];
|
35158
|
+
const infoToPrint = [];
|
35159
|
+
const tablesToRemove = [];
|
35160
|
+
const columnsToRemove = [];
|
35161
|
+
const schemasToRemove = [];
|
35162
|
+
const tablesToTruncate = [];
|
35163
|
+
const tablesContext = {};
|
35164
|
+
for (const statement of statements) {
|
35165
|
+
if (statement.type === "drop_table") {
|
35166
|
+
const res = await connection.query(
|
35167
|
+
`select count(*) as count from \`${statement.tableName}\``
|
35168
|
+
);
|
35169
|
+
const count2 = Number(res[0].count);
|
35170
|
+
if (count2 > 0) {
|
35171
|
+
infoToPrint.push(
|
35172
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35173
|
+
statement.tableName
|
35174
|
+
)} table with ${count2} items`
|
35175
|
+
);
|
35176
|
+
tablesToRemove.push(statement.tableName);
|
35177
|
+
shouldAskForApprove = true;
|
35178
|
+
}
|
35179
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35180
|
+
statementsToExecute.push(stmnt);
|
35181
|
+
} else if (statement.type === "alter_table_drop_column") {
|
35182
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35183
|
+
const columnIsPartOfPk = Object.values(
|
35184
|
+
json1.tables[newTableName].compositePrimaryKeys
|
35185
|
+
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
35186
|
+
const columnIsPartOfIndex = Object.values(
|
35187
|
+
json1.tables[newTableName].indexes
|
35188
|
+
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
35189
|
+
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
35190
|
+
const columnIsPartOfFk = Object.values(
|
35191
|
+
json1.tables[newTableName].foreignKeys
|
35192
|
+
).find(
|
35193
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
|
35194
|
+
statement.columnName
|
35195
|
+
)
|
35196
|
+
);
|
35197
|
+
const res = await connection.query(
|
35198
|
+
`select count(*) as count from \`${newTableName}\``
|
35199
|
+
);
|
35200
|
+
const count2 = Number(res[0].count);
|
35201
|
+
if (count2 > 0) {
|
35202
|
+
infoToPrint.push(
|
35203
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35204
|
+
statement.columnName
|
35205
|
+
)} column in ${newTableName} table with ${count2} items`
|
35206
|
+
);
|
35207
|
+
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
35208
|
+
shouldAskForApprove = true;
|
35209
|
+
}
|
35210
|
+
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
35211
|
+
tablesContext[newTableName] = [
|
35212
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35213
|
+
];
|
35214
|
+
const tablesReferncingCurrent = [];
|
35215
|
+
for (const table4 of Object.values(json1.tables)) {
|
35216
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35217
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35218
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35219
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35220
|
+
}
|
35221
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35222
|
+
for (const table4 of uniqueTableRefs) {
|
35223
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35224
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35225
|
+
}
|
35226
|
+
}
|
35227
|
+
} else {
|
35228
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35229
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35230
|
+
statementsToExecute.push(stmnt);
|
35231
|
+
}
|
35232
|
+
}
|
35233
|
+
} else if (statement.type === "sqlite_alter_table_add_column") {
|
35234
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35235
|
+
if (statement.column.notNull && !statement.column.default) {
|
35236
|
+
const res = await connection.query(
|
35237
|
+
`select count(*) as count from \`${newTableName}\``
|
35238
|
+
);
|
35239
|
+
const count2 = Number(res[0].count);
|
35240
|
+
if (count2 > 0) {
|
35241
|
+
infoToPrint.push(
|
35242
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
35243
|
+
statement.column.name
|
35244
|
+
)} column without default value, which contains ${count2} items`
|
35245
|
+
);
|
35246
|
+
tablesToTruncate.push(newTableName);
|
35247
|
+
statementsToExecute.push(`delete from ${newTableName};`);
|
35248
|
+
shouldAskForApprove = true;
|
35249
|
+
}
|
35250
|
+
}
|
35251
|
+
if (statement.column.primaryKey) {
|
35252
|
+
tablesContext[newTableName] = [
|
35253
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35254
|
+
];
|
35255
|
+
const tablesReferncingCurrent = [];
|
35256
|
+
for (const table4 of Object.values(json1.tables)) {
|
35257
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35258
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35259
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35260
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35261
|
+
}
|
35262
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35263
|
+
for (const table4 of uniqueTableRefs) {
|
35264
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35265
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35266
|
+
}
|
35267
|
+
}
|
35268
|
+
} else {
|
35269
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35270
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35271
|
+
statementsToExecute.push(stmnt);
|
35272
|
+
}
|
35273
|
+
}
|
35274
|
+
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
35275
|
+
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
35276
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35277
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
35278
|
+
const res = await connection.query(
|
35279
|
+
`select count(*) as count from \`${newTableName}\``
|
35280
|
+
);
|
35281
|
+
const count2 = Number(res[0].count);
|
35282
|
+
if (count2 > 0) {
|
35283
|
+
infoToPrint.push(
|
35284
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
35285
|
+
statement.columnName
|
35286
|
+
)} column without default value, which contains ${count2} items`
|
35287
|
+
);
|
35288
|
+
tablesToTruncate.push(newTableName);
|
35289
|
+
shouldAskForApprove = true;
|
35290
|
+
}
|
35291
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35292
|
+
statement.tableName,
|
35293
|
+
json1,
|
35294
|
+
true
|
35295
|
+
);
|
35296
|
+
} else {
|
35297
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35298
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35299
|
+
statement.tableName,
|
35300
|
+
json1
|
35301
|
+
);
|
35302
|
+
}
|
35303
|
+
}
|
35304
|
+
const tablesReferncingCurrent = [];
|
35305
|
+
for (const table4 of Object.values(json1.tables)) {
|
35306
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35307
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35308
|
+
).map((t) => {
|
35309
|
+
return getNewTableName(
|
35310
|
+
SQLiteSquasher.unsquashPushFK(t).tableFrom,
|
35311
|
+
meta
|
35312
|
+
);
|
35313
|
+
});
|
35314
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35315
|
+
}
|
35316
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35317
|
+
for (const table4 of uniqueTableRefs) {
|
35318
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35319
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
35320
|
+
}
|
35321
|
+
}
|
35322
|
+
}
|
35323
|
+
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
35324
|
+
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
35325
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
35326
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
35327
|
+
statement.tableName,
|
35328
|
+
json2
|
35329
|
+
);
|
35330
|
+
}
|
35331
|
+
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
35332
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35333
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35334
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35335
|
+
statement.tableName,
|
35336
|
+
json2
|
35337
|
+
);
|
35338
|
+
}
|
35339
|
+
} else {
|
35340
|
+
const stmnt = fromJson([statement], "sqlite");
|
35341
|
+
if (typeof stmnt !== "undefined") {
|
35342
|
+
statementsToExecute.push(...stmnt);
|
35343
|
+
}
|
35344
|
+
}
|
35345
|
+
}
|
35346
|
+
for (const context of Object.values(tablesContext)) {
|
35347
|
+
statementsToExecute.push(...context);
|
35348
|
+
}
|
35349
|
+
return {
|
35350
|
+
statementsToExecute,
|
35351
|
+
shouldAskForApprove,
|
35352
|
+
infoToPrint,
|
35353
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
35354
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
35355
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
35356
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
35357
|
+
};
|
35358
|
+
};
|
35359
|
+
|
36138
35360
|
// src/api.ts
|
36139
|
-
init_sqlitePushUtils();
|
36140
35361
|
init_global();
|
36141
35362
|
init_migrationPreparator();
|
36142
35363
|
init_mysqlSchema();
|