drizzle-kit 0.23.2 → 0.24.0-38d6dab
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +20 -4
- package/api.d.ts +20 -4
- package/api.js +1315 -404
- package/api.mjs +1315 -404
- package/bin.cjs +1658 -394
- package/package.json +1 -1
- package/utils.js +14 -0
- package/utils.mjs +12 -0
package/api.js
CHANGED
@@ -8338,6 +8338,16 @@ var init_sqliteSchema = __esm({
|
|
8338
8338
|
});
|
8339
8339
|
|
8340
8340
|
// src/utils.ts
|
8341
|
+
function isPgArrayType(sqlType) {
|
8342
|
+
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8343
|
+
}
|
8344
|
+
function findAddedAndRemoved(columnNames1, columnNames2) {
|
8345
|
+
const set1 = new Set(columnNames1);
|
8346
|
+
const set2 = new Set(columnNames2);
|
8347
|
+
const addedColumns = columnNames2.filter((it) => !set1.has(it));
|
8348
|
+
const removedColumns = columnNames1.filter((it) => !set2.has(it));
|
8349
|
+
return { addedColumns, removedColumns };
|
8350
|
+
}
|
8341
8351
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8342
8352
|
var init_utils = __esm({
|
8343
8353
|
"src/utils.ts"() {
|
@@ -8711,14 +8721,14 @@ var require_heap = __commonJS({
|
|
8711
8721
|
return item;
|
8712
8722
|
};
|
8713
8723
|
heapify = function(array, cmp) {
|
8714
|
-
var i, _i2,
|
8724
|
+
var i, _i2, _j2, _len, _ref, _ref1, _results, _results1;
|
8715
8725
|
if (cmp == null) {
|
8716
8726
|
cmp = defaultCmp;
|
8717
8727
|
}
|
8718
8728
|
_ref1 = function() {
|
8719
8729
|
_results1 = [];
|
8720
|
-
for (var
|
8721
|
-
_results1.push(
|
8730
|
+
for (var _j3 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j3 < _ref2 : _j3 > _ref2; 0 <= _ref2 ? _j3++ : _j3--) {
|
8731
|
+
_results1.push(_j3);
|
8722
8732
|
}
|
8723
8733
|
return _results1;
|
8724
8734
|
}.apply(this).reverse();
|
@@ -8759,7 +8769,7 @@ var require_heap = __commonJS({
|
|
8759
8769
|
return result.sort(cmp).reverse();
|
8760
8770
|
};
|
8761
8771
|
nsmallest = function(array, n, cmp) {
|
8762
|
-
var elem, i, los, result, _i2,
|
8772
|
+
var elem, i, los, result, _i2, _j2, _len, _ref, _ref1, _results;
|
8763
8773
|
if (cmp == null) {
|
8764
8774
|
cmp = defaultCmp;
|
8765
8775
|
}
|
@@ -8782,7 +8792,7 @@ var require_heap = __commonJS({
|
|
8782
8792
|
}
|
8783
8793
|
heapify(array, cmp);
|
8784
8794
|
_results = [];
|
8785
|
-
for (i =
|
8795
|
+
for (i = _j2 = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j2 < _ref1 : _j2 > _ref1; i = 0 <= _ref1 ? ++_j2 : --_j2) {
|
8786
8796
|
_results.push(heappop(array, cmp));
|
8787
8797
|
}
|
8788
8798
|
return _results;
|
@@ -11447,7 +11457,20 @@ var init_jsonDiffer = __esm({
|
|
11447
11457
|
});
|
11448
11458
|
|
11449
11459
|
// src/sqlgenerator.ts
|
11450
|
-
|
11460
|
+
function fromJson(statements, dialect7, action, driver2, json2) {
|
11461
|
+
const result = statements.flatMap((statement) => {
|
11462
|
+
const filtered = convertors.filter((it) => {
|
11463
|
+
return it.can(statement, dialect7, driver2);
|
11464
|
+
});
|
11465
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
11466
|
+
if (!convertor) {
|
11467
|
+
return "";
|
11468
|
+
}
|
11469
|
+
return convertor.convert(statement, json2, action);
|
11470
|
+
}).filter((it) => it !== "");
|
11471
|
+
return result;
|
11472
|
+
}
|
11473
|
+
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;
|
11451
11474
|
var init_sqlgenerator = __esm({
|
11452
11475
|
"src/sqlgenerator.ts"() {
|
11453
11476
|
"use strict";
|
@@ -11963,7 +11986,7 @@ var init_sqlgenerator = __esm({
|
|
11963
11986
|
}
|
11964
11987
|
convert(statement) {
|
11965
11988
|
const { tableName, oldColumnName, newColumnName } = statement;
|
11966
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
11989
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
|
11967
11990
|
}
|
11968
11991
|
};
|
11969
11992
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -12065,8 +12088,8 @@ var init_sqlgenerator = __esm({
|
|
12065
12088
|
}
|
12066
12089
|
};
|
12067
12090
|
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
12068
|
-
can(statement, dialect7) {
|
12069
|
-
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
12091
|
+
can(statement, dialect7, driver2) {
|
12092
|
+
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite" && !driver2;
|
12070
12093
|
}
|
12071
12094
|
convert(statement) {
|
12072
12095
|
return `/*
|
@@ -12377,6 +12400,46 @@ var init_sqlgenerator = __esm({
|
|
12377
12400
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
12378
12401
|
}
|
12379
12402
|
};
|
12403
|
+
LibSQLModifyColumn = class extends Convertor {
|
12404
|
+
can(statement, dialect7, driver2) {
|
12405
|
+
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";
|
12406
|
+
}
|
12407
|
+
convert(statement, json2) {
|
12408
|
+
const { tableName, columnName } = statement;
|
12409
|
+
let columnType = ``;
|
12410
|
+
let columnDefault = "";
|
12411
|
+
let columnNotNull = "";
|
12412
|
+
switch (statement.type) {
|
12413
|
+
case "alter_table_alter_column_set_type":
|
12414
|
+
columnType = ` ${statement.newDataType}`;
|
12415
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12416
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12417
|
+
break;
|
12418
|
+
case "alter_table_alter_column_drop_notnull":
|
12419
|
+
columnType = ` ${statement.newDataType}`;
|
12420
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12421
|
+
columnNotNull = "";
|
12422
|
+
break;
|
12423
|
+
case "alter_table_alter_column_set_notnull":
|
12424
|
+
columnType = ` ${statement.newDataType}`;
|
12425
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12426
|
+
columnNotNull = ` NOT NULL`;
|
12427
|
+
break;
|
12428
|
+
case "alter_table_alter_column_set_default":
|
12429
|
+
columnType = ` ${statement.newDataType}`;
|
12430
|
+
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
12431
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12432
|
+
break;
|
12433
|
+
case "alter_table_alter_column_drop_default":
|
12434
|
+
columnType = ` ${statement.newDataType}`;
|
12435
|
+
columnDefault = "";
|
12436
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12437
|
+
break;
|
12438
|
+
}
|
12439
|
+
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
12440
|
+
return `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`;
|
12441
|
+
}
|
12442
|
+
};
|
12380
12443
|
MySqlModifyColumn = class extends Convertor {
|
12381
12444
|
can(statement, dialect7) {
|
12382
12445
|
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";
|
@@ -12717,8 +12780,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12717
12780
|
}
|
12718
12781
|
};
|
12719
12782
|
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
12720
|
-
can(statement, dialect7) {
|
12721
|
-
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
12783
|
+
can(statement, dialect7, driver2) {
|
12784
|
+
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite" && !driver2;
|
12722
12785
|
}
|
12723
12786
|
convert(statement) {
|
12724
12787
|
return `/*
|
@@ -12732,8 +12795,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12732
12795
|
}
|
12733
12796
|
};
|
12734
12797
|
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
12735
|
-
can(statement, dialect7) {
|
12736
|
-
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
12798
|
+
can(statement, dialect7, driver2) {
|
12799
|
+
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite" && !driver2;
|
12737
12800
|
}
|
12738
12801
|
convert(statement) {
|
12739
12802
|
return `/*
|
@@ -12747,8 +12810,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12747
12810
|
}
|
12748
12811
|
};
|
12749
12812
|
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
12750
|
-
can(statement, dialect7) {
|
12751
|
-
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
12813
|
+
can(statement, dialect7, driver2) {
|
12814
|
+
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite" && !driver2;
|
12752
12815
|
}
|
12753
12816
|
convert(statement) {
|
12754
12817
|
return `/*
|
@@ -12772,8 +12835,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12772
12835
|
}
|
12773
12836
|
};
|
12774
12837
|
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12775
|
-
can(statement, dialect7) {
|
12776
|
-
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
12838
|
+
can(statement, dialect7, driver2) {
|
12839
|
+
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite" && !driver2;
|
12777
12840
|
}
|
12778
12841
|
convert(statement) {
|
12779
12842
|
return `/*
|
@@ -12817,8 +12880,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12817
12880
|
}
|
12818
12881
|
};
|
12819
12882
|
SqliteCreateForeignKeyConvertor = class extends Convertor {
|
12820
|
-
can(statement, dialect7) {
|
12821
|
-
return statement.type === "create_reference" && dialect7 === "sqlite";
|
12883
|
+
can(statement, dialect7, driver2) {
|
12884
|
+
return statement.type === "create_reference" && dialect7 === "sqlite" && !driver2;
|
12822
12885
|
}
|
12823
12886
|
convert(statement) {
|
12824
12887
|
return `/*
|
@@ -12830,6 +12893,32 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12830
12893
|
*/`;
|
12831
12894
|
}
|
12832
12895
|
};
|
12896
|
+
LibSQLCreateForeignKeyConvertor = class extends Convertor {
|
12897
|
+
can(statement, dialect7, driver2) {
|
12898
|
+
return statement.type === "create_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
12899
|
+
}
|
12900
|
+
convert(statement, json2, action) {
|
12901
|
+
const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
12902
|
+
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
12903
|
+
if (isMulticolumn) {
|
12904
|
+
return `/*
|
12905
|
+
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
|
12906
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12907
|
+
https://www.sqlite.org/lang_altertable.html
|
12908
|
+
|
12909
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12910
|
+
*/`;
|
12911
|
+
}
|
12912
|
+
const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
|
12913
|
+
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
12914
|
+
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
12915
|
+
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
12916
|
+
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
12917
|
+
const columnFrom = columnsFrom[0];
|
12918
|
+
const columnTo = columnsTo[0];
|
12919
|
+
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
|
12920
|
+
}
|
12921
|
+
};
|
12833
12922
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
12834
12923
|
can(statement, dialect7) {
|
12835
12924
|
return statement.type === "create_reference" && dialect7 === "mysql";
|
@@ -12903,8 +12992,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12903
12992
|
}
|
12904
12993
|
};
|
12905
12994
|
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
12906
|
-
can(statement, dialect7) {
|
12907
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
12995
|
+
can(statement, dialect7, driver2) {
|
12996
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite" && !driver2;
|
12908
12997
|
}
|
12909
12998
|
convert(statement) {
|
12910
12999
|
return `/*
|
@@ -12916,6 +13005,29 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12916
13005
|
*/`;
|
12917
13006
|
}
|
12918
13007
|
};
|
13008
|
+
LibSQLDeleteForeignKeyConvertor = class extends Convertor {
|
13009
|
+
can(statement, dialect7, driver2) {
|
13010
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite" && driver2 === "turso";
|
13011
|
+
}
|
13012
|
+
convert(statement, json2, action) {
|
13013
|
+
const { columnsFrom, tableFrom } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
13014
|
+
const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
|
13015
|
+
if (isMulticolumn) {
|
13016
|
+
return `/*
|
13017
|
+
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
|
13018
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
13019
|
+
https://www.sqlite.org/lang_altertable.html
|
13020
|
+
|
13021
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
13022
|
+
*/`;
|
13023
|
+
}
|
13024
|
+
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
13025
|
+
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
13026
|
+
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
13027
|
+
const columnFrom = columnsFrom[0];
|
13028
|
+
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue};`;
|
13029
|
+
}
|
13030
|
+
};
|
12919
13031
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
12920
13032
|
can(statement, dialect7) {
|
12921
13033
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -13079,10 +13191,90 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13079
13191
|
return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
|
13080
13192
|
}
|
13081
13193
|
};
|
13194
|
+
SQLiteRecreateTableConvertor = class extends Convertor {
|
13195
|
+
can(statement, dialect7, driver2) {
|
13196
|
+
return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
|
13197
|
+
}
|
13198
|
+
convert(statement) {
|
13199
|
+
const { tableName, columns, compositePKs, referenceData } = statement;
|
13200
|
+
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13201
|
+
const sqlStatements = [];
|
13202
|
+
sqlStatements.push(
|
13203
|
+
new SqliteRenameTableConvertor().convert({
|
13204
|
+
fromSchema: "",
|
13205
|
+
tableNameFrom: tableName,
|
13206
|
+
tableNameTo: `__old__generate_${tableName}`,
|
13207
|
+
toSchema: "",
|
13208
|
+
type: "rename_table"
|
13209
|
+
})
|
13210
|
+
);
|
13211
|
+
sqlStatements.push(
|
13212
|
+
new SQLiteCreateTableConvertor().convert({
|
13213
|
+
type: "sqlite_create_table",
|
13214
|
+
tableName,
|
13215
|
+
columns,
|
13216
|
+
referenceData,
|
13217
|
+
compositePKs
|
13218
|
+
})
|
13219
|
+
);
|
13220
|
+
sqlStatements.push(
|
13221
|
+
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
13222
|
+
);
|
13223
|
+
sqlStatements.push(
|
13224
|
+
new SQLiteDropTableConvertor().convert({
|
13225
|
+
type: "drop_table",
|
13226
|
+
tableName: `__old__generate_${tableName}`,
|
13227
|
+
schema: ""
|
13228
|
+
})
|
13229
|
+
);
|
13230
|
+
return sqlStatements;
|
13231
|
+
}
|
13232
|
+
};
|
13233
|
+
LibSQLRecreateTableConvertor = class extends Convertor {
|
13234
|
+
can(statement, dialect7, driver2) {
|
13235
|
+
return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
|
13236
|
+
}
|
13237
|
+
convert(statement) {
|
13238
|
+
const { tableName, columns, compositePKs, referenceData } = statement;
|
13239
|
+
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13240
|
+
const sqlStatements = [];
|
13241
|
+
sqlStatements.push(
|
13242
|
+
new SqliteRenameTableConvertor().convert({
|
13243
|
+
fromSchema: "",
|
13244
|
+
tableNameFrom: tableName,
|
13245
|
+
tableNameTo: `__old__generate_${tableName}`,
|
13246
|
+
toSchema: "",
|
13247
|
+
type: "rename_table"
|
13248
|
+
})
|
13249
|
+
);
|
13250
|
+
sqlStatements.push(
|
13251
|
+
new SQLiteCreateTableConvertor().convert({
|
13252
|
+
type: "sqlite_create_table",
|
13253
|
+
tableName,
|
13254
|
+
columns,
|
13255
|
+
referenceData,
|
13256
|
+
compositePKs
|
13257
|
+
})
|
13258
|
+
);
|
13259
|
+
sqlStatements.push(
|
13260
|
+
`INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
|
13261
|
+
);
|
13262
|
+
sqlStatements.push(
|
13263
|
+
new SQLiteDropTableConvertor().convert({
|
13264
|
+
type: "drop_table",
|
13265
|
+
tableName: `__old__generate_${tableName}`,
|
13266
|
+
schema: ""
|
13267
|
+
})
|
13268
|
+
);
|
13269
|
+
return sqlStatements;
|
13270
|
+
}
|
13271
|
+
};
|
13082
13272
|
convertors = [];
|
13083
13273
|
convertors.push(new PgCreateTableConvertor());
|
13084
13274
|
convertors.push(new MySqlCreateTableConvertor());
|
13085
13275
|
convertors.push(new SQLiteCreateTableConvertor());
|
13276
|
+
convertors.push(new SQLiteRecreateTableConvertor());
|
13277
|
+
convertors.push(new LibSQLRecreateTableConvertor());
|
13086
13278
|
convertors.push(new CreateTypeEnumConvertor());
|
13087
13279
|
convertors.push(new CreatePgSequenceConvertor());
|
13088
13280
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13130,6 +13322,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13130
13322
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
13131
13323
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
13132
13324
|
convertors.push(new MySqlModifyColumn());
|
13325
|
+
convertors.push(new LibSQLModifyColumn());
|
13133
13326
|
convertors.push(new PgCreateForeignKeyConvertor());
|
13134
13327
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
13135
13328
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -13144,7 +13337,9 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13144
13337
|
convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
13145
13338
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
13146
13339
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
13340
|
+
convertors.push(new LibSQLDeleteForeignKeyConvertor());
|
13147
13341
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
13342
|
+
convertors.push(new LibSQLCreateForeignKeyConvertor());
|
13148
13343
|
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
13149
13344
|
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
13150
13345
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
@@ -13167,19 +13362,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13167
13362
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
13168
13363
|
convertors.push(new MySqlAlterTableAddPk());
|
13169
13364
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
13170
|
-
fromJson = (statements, dialect7) => {
|
13171
|
-
const result = statements.flatMap((statement) => {
|
13172
|
-
const filtered = convertors.filter((it) => {
|
13173
|
-
return it.can(statement, dialect7);
|
13174
|
-
});
|
13175
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
13176
|
-
if (!convertor) {
|
13177
|
-
return "";
|
13178
|
-
}
|
13179
|
-
return convertor.convert(statement);
|
13180
|
-
}).filter((it) => it !== "");
|
13181
|
-
return result;
|
13182
|
-
};
|
13183
13365
|
https: `
|
13184
13366
|
create table users (
|
13185
13367
|
id int,
|
@@ -13206,12 +13388,237 @@ drop type __venum;
|
|
13206
13388
|
}
|
13207
13389
|
});
|
13208
13390
|
|
13391
|
+
// src/cli/commands/sqlitePushUtils.ts
|
13392
|
+
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
|
13393
|
+
var init_sqlitePushUtils = __esm({
|
13394
|
+
"src/cli/commands/sqlitePushUtils.ts"() {
|
13395
|
+
"use strict";
|
13396
|
+
init_source();
|
13397
|
+
init_sqliteSchema();
|
13398
|
+
init_sqlgenerator();
|
13399
|
+
init_utils();
|
13400
|
+
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
13401
|
+
const statements = [];
|
13402
|
+
statements.push(
|
13403
|
+
new SqliteRenameTableConvertor().convert({
|
13404
|
+
type: "rename_table",
|
13405
|
+
tableNameFrom: tableName,
|
13406
|
+
tableNameTo: `__old_push_${tableName}`,
|
13407
|
+
fromSchema: "",
|
13408
|
+
toSchema: ""
|
13409
|
+
})
|
13410
|
+
);
|
13411
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
13412
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
13413
|
+
const compositePKs = Object.values(
|
13414
|
+
json.tables[tableName].compositePrimaryKeys
|
13415
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
13416
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
13417
|
+
statements.push(
|
13418
|
+
new SQLiteCreateTableConvertor().convert({
|
13419
|
+
type: "sqlite_create_table",
|
13420
|
+
tableName,
|
13421
|
+
columns: tableColumns,
|
13422
|
+
referenceData: fks,
|
13423
|
+
compositePKs
|
13424
|
+
})
|
13425
|
+
);
|
13426
|
+
if (!dataLoss) {
|
13427
|
+
const columns = Object.keys(json.tables[tableName].columns).map(
|
13428
|
+
(c) => `"${c}"`
|
13429
|
+
);
|
13430
|
+
statements.push(
|
13431
|
+
`INSERT INTO \`${tableName}\`(${columns.join(
|
13432
|
+
", "
|
13433
|
+
)}) SELECT (${columns.join(", ")}) FROM \`__old_push_${tableName}\`;`
|
13434
|
+
);
|
13435
|
+
}
|
13436
|
+
statements.push(
|
13437
|
+
new SQLiteDropTableConvertor().convert({
|
13438
|
+
type: "drop_table",
|
13439
|
+
tableName: `__old_push_${tableName}`,
|
13440
|
+
schema: ""
|
13441
|
+
})
|
13442
|
+
);
|
13443
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
13444
|
+
statements.push(
|
13445
|
+
new CreateSqliteIndexConvertor().convert({
|
13446
|
+
type: "create_index",
|
13447
|
+
tableName,
|
13448
|
+
schema: "",
|
13449
|
+
data: idx
|
13450
|
+
})
|
13451
|
+
);
|
13452
|
+
}
|
13453
|
+
return statements;
|
13454
|
+
};
|
13455
|
+
getOldTableName = (tableName, meta) => {
|
13456
|
+
for (const key of Object.keys(meta.tables)) {
|
13457
|
+
const value = meta.tables[key];
|
13458
|
+
if (`"${tableName}"` === value) {
|
13459
|
+
return key.substring(1, key.length - 1);
|
13460
|
+
}
|
13461
|
+
}
|
13462
|
+
return tableName;
|
13463
|
+
};
|
13464
|
+
getNewTableName = (tableName, meta) => {
|
13465
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
13466
|
+
return meta.tables[`"${tableName}"`].substring(
|
13467
|
+
1,
|
13468
|
+
meta.tables[`"${tableName}"`].length - 1
|
13469
|
+
);
|
13470
|
+
}
|
13471
|
+
return tableName;
|
13472
|
+
};
|
13473
|
+
logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
13474
|
+
let shouldAskForApprove = false;
|
13475
|
+
const statementsToExecute = [];
|
13476
|
+
const infoToPrint = [];
|
13477
|
+
const tablesToRemove = [];
|
13478
|
+
const columnsToRemove = [];
|
13479
|
+
const schemasToRemove = [];
|
13480
|
+
const tablesToTruncate = [];
|
13481
|
+
for (const statement of statements) {
|
13482
|
+
if (statement.type === "drop_table") {
|
13483
|
+
const res = await connection.query(
|
13484
|
+
`select count(*) as count from \`${statement.tableName}\``
|
13485
|
+
);
|
13486
|
+
const count2 = Number(res[0].count);
|
13487
|
+
if (count2 > 0) {
|
13488
|
+
infoToPrint.push(
|
13489
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13490
|
+
statement.tableName
|
13491
|
+
)} table with ${count2} items`
|
13492
|
+
);
|
13493
|
+
tablesToRemove.push(statement.tableName);
|
13494
|
+
shouldAskForApprove = true;
|
13495
|
+
}
|
13496
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13497
|
+
statementsToExecute.push(
|
13498
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13499
|
+
);
|
13500
|
+
} else if (statement.type === "alter_table_drop_column") {
|
13501
|
+
const tableName = statement.tableName;
|
13502
|
+
const columnName = statement.columnName;
|
13503
|
+
const res = await connection.query(
|
13504
|
+
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
|
13505
|
+
);
|
13506
|
+
const count2 = Number(res[0].count);
|
13507
|
+
if (count2 > 0) {
|
13508
|
+
infoToPrint.push(
|
13509
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13510
|
+
columnName
|
13511
|
+
)} column in ${tableName} table with ${count2} items`
|
13512
|
+
);
|
13513
|
+
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
13514
|
+
shouldAskForApprove = true;
|
13515
|
+
}
|
13516
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13517
|
+
statementsToExecute.push(
|
13518
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13519
|
+
);
|
13520
|
+
} else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
|
13521
|
+
const tableName = statement.tableName;
|
13522
|
+
const columnName = statement.column.name;
|
13523
|
+
const res = await connection.query(
|
13524
|
+
`select count(*) as count from \`${tableName}\``
|
13525
|
+
);
|
13526
|
+
const count2 = Number(res[0].count);
|
13527
|
+
if (count2 > 0) {
|
13528
|
+
infoToPrint.push(
|
13529
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
13530
|
+
columnName
|
13531
|
+
)} column without default value, which contains ${count2} items`
|
13532
|
+
);
|
13533
|
+
tablesToTruncate.push(tableName);
|
13534
|
+
statementsToExecute.push(`delete from ${tableName};`);
|
13535
|
+
shouldAskForApprove = true;
|
13536
|
+
}
|
13537
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13538
|
+
statementsToExecute.push(
|
13539
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13540
|
+
);
|
13541
|
+
} else if (statement.type === "recreate_table") {
|
13542
|
+
const tableName = statement.tableName;
|
13543
|
+
const oldTableName = getOldTableName(tableName, meta);
|
13544
|
+
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
13545
|
+
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
13546
|
+
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
13547
|
+
prevColumnNames,
|
13548
|
+
currentColumnNames
|
13549
|
+
);
|
13550
|
+
if (removedColumns.length) {
|
13551
|
+
for (const removedColumn of removedColumns) {
|
13552
|
+
const res = await connection.query(
|
13553
|
+
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
13554
|
+
);
|
13555
|
+
const count2 = Number(res[0].count);
|
13556
|
+
if (count2 > 0) {
|
13557
|
+
infoToPrint.push(
|
13558
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13559
|
+
removedColumn
|
13560
|
+
)} column in ${tableName} table with ${count2} items`
|
13561
|
+
);
|
13562
|
+
columnsToRemove.push(removedColumn);
|
13563
|
+
shouldAskForApprove = true;
|
13564
|
+
}
|
13565
|
+
}
|
13566
|
+
}
|
13567
|
+
if (addedColumns.length) {
|
13568
|
+
for (const addedColumn of addedColumns) {
|
13569
|
+
const [res] = await connection.query(
|
13570
|
+
`select count(*) as count from \`${tableName}\``
|
13571
|
+
);
|
13572
|
+
const columnConf = json2.tables[tableName].columns[addedColumn];
|
13573
|
+
const count2 = Number(res.count);
|
13574
|
+
if (count2 > 0 && columnConf.notNull && !columnConf.default) {
|
13575
|
+
infoToPrint.push(
|
13576
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
13577
|
+
addedColumn
|
13578
|
+
)} column without default value to table, which contains ${count2} items`
|
13579
|
+
);
|
13580
|
+
shouldAskForApprove = true;
|
13581
|
+
tablesToTruncate.push(tableName);
|
13582
|
+
}
|
13583
|
+
}
|
13584
|
+
}
|
13585
|
+
statementsToExecute.push(..._moveDataStatements(tableName, json2));
|
13586
|
+
const tablesReferencingCurrent = [];
|
13587
|
+
for (const table4 of Object.values(json2.tables)) {
|
13588
|
+
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
13589
|
+
tablesReferencingCurrent.push(...tablesRefs);
|
13590
|
+
}
|
13591
|
+
const uniqueTableRefs = [...new Set(tablesReferencingCurrent)];
|
13592
|
+
for (const table4 of uniqueTableRefs) {
|
13593
|
+
statementsToExecute.push(..._moveDataStatements(table4, json2));
|
13594
|
+
}
|
13595
|
+
} else {
|
13596
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13597
|
+
statementsToExecute.push(
|
13598
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13599
|
+
);
|
13600
|
+
}
|
13601
|
+
}
|
13602
|
+
return {
|
13603
|
+
statementsToExecute,
|
13604
|
+
shouldAskForApprove,
|
13605
|
+
infoToPrint,
|
13606
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
13607
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
13608
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
13609
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
13610
|
+
};
|
13611
|
+
};
|
13612
|
+
}
|
13613
|
+
});
|
13614
|
+
|
13209
13615
|
// src/jsonStatements.ts
|
13210
|
-
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;
|
13616
|
+
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, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13211
13617
|
var init_jsonStatements = __esm({
|
13212
13618
|
"src/jsonStatements.ts"() {
|
13213
13619
|
"use strict";
|
13214
13620
|
init_source();
|
13621
|
+
init_sqlitePushUtils();
|
13215
13622
|
init_views();
|
13216
13623
|
init_mysqlSchema();
|
13217
13624
|
init_pgSchema();
|
@@ -13995,6 +14402,49 @@ var init_jsonStatements = __esm({
|
|
13995
14402
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
13996
14403
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
13997
14404
|
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
14405
|
+
if (column4.autoincrement?.type === "added") {
|
14406
|
+
statements.push({
|
14407
|
+
type: "alter_table_alter_column_set_autoincrement",
|
14408
|
+
tableName,
|
14409
|
+
columnName,
|
14410
|
+
schema: schema4,
|
14411
|
+
newDataType: columnType,
|
14412
|
+
columnDefault,
|
14413
|
+
columnOnUpdate,
|
14414
|
+
columnNotNull,
|
14415
|
+
columnAutoIncrement,
|
14416
|
+
columnPk
|
14417
|
+
});
|
14418
|
+
}
|
14419
|
+
if (column4.autoincrement?.type === "changed") {
|
14420
|
+
const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
14421
|
+
statements.push({
|
14422
|
+
type,
|
14423
|
+
tableName,
|
14424
|
+
columnName,
|
14425
|
+
schema: schema4,
|
14426
|
+
newDataType: columnType,
|
14427
|
+
columnDefault,
|
14428
|
+
columnOnUpdate,
|
14429
|
+
columnNotNull,
|
14430
|
+
columnAutoIncrement,
|
14431
|
+
columnPk
|
14432
|
+
});
|
14433
|
+
}
|
14434
|
+
if (column4.autoincrement?.type === "deleted") {
|
14435
|
+
statements.push({
|
14436
|
+
type: "alter_table_alter_column_drop_autoincrement",
|
14437
|
+
tableName,
|
14438
|
+
columnName,
|
14439
|
+
schema: schema4,
|
14440
|
+
newDataType: columnType,
|
14441
|
+
columnDefault,
|
14442
|
+
columnOnUpdate,
|
14443
|
+
columnNotNull,
|
14444
|
+
columnAutoIncrement,
|
14445
|
+
columnPk
|
14446
|
+
});
|
14447
|
+
}
|
13998
14448
|
if (typeof column4.name !== "string") {
|
13999
14449
|
statements.push({
|
14000
14450
|
type: "alter_table_rename_column",
|
@@ -14258,33 +14708,111 @@ var init_jsonStatements = __esm({
|
|
14258
14708
|
};
|
14259
14709
|
});
|
14260
14710
|
};
|
14261
|
-
|
14711
|
+
prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
|
14262
14712
|
return Object.values(foreignKeys).map((fkData) => {
|
14713
|
+
const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14714
|
+
let isMulticolumn = false;
|
14715
|
+
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14716
|
+
isMulticolumn = true;
|
14717
|
+
return {
|
14718
|
+
type: "create_reference",
|
14719
|
+
tableName,
|
14720
|
+
data: fkData,
|
14721
|
+
schema: schema4,
|
14722
|
+
isMulticolumn
|
14723
|
+
};
|
14724
|
+
}
|
14725
|
+
const columnFrom = columnsFrom[0];
|
14726
|
+
const {
|
14727
|
+
notNull: columnNotNull,
|
14728
|
+
default: columnDefault,
|
14729
|
+
type: columnType
|
14730
|
+
} = json2.tables[tableFrom].columns[columnFrom];
|
14263
14731
|
return {
|
14264
|
-
type: "
|
14732
|
+
type: "create_reference",
|
14265
14733
|
tableName,
|
14266
14734
|
data: fkData,
|
14267
|
-
schema: schema4
|
14735
|
+
schema: schema4,
|
14736
|
+
columnNotNull,
|
14737
|
+
columnDefault,
|
14738
|
+
columnType
|
14268
14739
|
};
|
14269
14740
|
});
|
14270
14741
|
};
|
14271
|
-
|
14272
|
-
|
14273
|
-
|
14274
|
-
stmts.push({
|
14742
|
+
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14743
|
+
return Object.values(foreignKeys).map((fkData) => {
|
14744
|
+
return {
|
14275
14745
|
type: "delete_reference",
|
14276
14746
|
tableName,
|
14277
|
-
|
14278
|
-
|
14279
|
-
}
|
14280
|
-
stmts.push({
|
14281
|
-
type: "create_reference",
|
14282
|
-
tableName,
|
14283
|
-
schema: schema4,
|
14284
|
-
data: val.__new
|
14285
|
-
});
|
14747
|
+
data: fkData,
|
14748
|
+
schema: schema4
|
14749
|
+
};
|
14286
14750
|
});
|
14287
|
-
|
14751
|
+
};
|
14752
|
+
prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
|
14753
|
+
const statements = Object.values(foreignKeys).map((fkData) => {
|
14754
|
+
const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14755
|
+
const keys = Object.keys(json2.tables[tableName].columns);
|
14756
|
+
const filtered = columnsFrom.filter((it) => keys.includes(it));
|
14757
|
+
const fullDrop = filtered.length === 0;
|
14758
|
+
if (fullDrop) return;
|
14759
|
+
let isMulticolumn = false;
|
14760
|
+
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14761
|
+
isMulticolumn = true;
|
14762
|
+
return {
|
14763
|
+
type: "delete_reference",
|
14764
|
+
tableName,
|
14765
|
+
data: fkData,
|
14766
|
+
schema: schema4,
|
14767
|
+
isMulticolumn
|
14768
|
+
};
|
14769
|
+
}
|
14770
|
+
const columnFrom = columnsFrom[0];
|
14771
|
+
const newTableName = getNewTableName(tableFrom, meta);
|
14772
|
+
const {
|
14773
|
+
notNull: columnNotNull,
|
14774
|
+
default: columnDefault,
|
14775
|
+
type: columnType
|
14776
|
+
} = json2.tables[newTableName].columns[columnFrom];
|
14777
|
+
const fkToSquash = {
|
14778
|
+
columnsFrom,
|
14779
|
+
columnsTo,
|
14780
|
+
name: name2,
|
14781
|
+
tableFrom: newTableName,
|
14782
|
+
tableTo,
|
14783
|
+
onDelete,
|
14784
|
+
onUpdate
|
14785
|
+
};
|
14786
|
+
const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
|
14787
|
+
return {
|
14788
|
+
type: "delete_reference",
|
14789
|
+
tableName,
|
14790
|
+
data: foreignKey,
|
14791
|
+
schema: schema4,
|
14792
|
+
columnNotNull,
|
14793
|
+
columnDefault,
|
14794
|
+
columnType
|
14795
|
+
};
|
14796
|
+
});
|
14797
|
+
return statements.filter((it) => it);
|
14798
|
+
};
|
14799
|
+
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
14800
|
+
const stmts = [];
|
14801
|
+
Object.values(foreignKeys).map((val) => {
|
14802
|
+
stmts.push({
|
14803
|
+
type: "delete_reference",
|
14804
|
+
tableName,
|
14805
|
+
schema: schema4,
|
14806
|
+
data: val.__old
|
14807
|
+
});
|
14808
|
+
stmts.push({
|
14809
|
+
type: "create_reference",
|
14810
|
+
tableName,
|
14811
|
+
schema: schema4,
|
14812
|
+
data: val.__new
|
14813
|
+
});
|
14814
|
+
});
|
14815
|
+
return stmts;
|
14288
14816
|
};
|
14289
14817
|
prepareDropIndexesJson = (tableName, schema4, indexes) => {
|
14290
14818
|
return Object.values(indexes).map((indexData) => {
|
@@ -14421,10 +14949,298 @@ var init_jsonStatements = __esm({
|
|
14421
14949
|
}
|
14422
14950
|
});
|
14423
14951
|
|
14952
|
+
// src/statementCombiner.ts
|
14953
|
+
var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
|
14954
|
+
var init_statementCombiner = __esm({
|
14955
|
+
"src/statementCombiner.ts"() {
|
14956
|
+
"use strict";
|
14957
|
+
init_jsonStatements();
|
14958
|
+
init_sqliteSchema();
|
14959
|
+
prepareLibSQLRecreateTable = (table4, action) => {
|
14960
|
+
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14961
|
+
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14962
|
+
(it) => SQLiteSquasher.unsquashPK(it)
|
14963
|
+
);
|
14964
|
+
const references2 = Object.values(table4.foreignKeys);
|
14965
|
+
const fks = references2.map(
|
14966
|
+
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14967
|
+
);
|
14968
|
+
const statements = [
|
14969
|
+
{
|
14970
|
+
type: "recreate_table",
|
14971
|
+
tableName: name2,
|
14972
|
+
columns: Object.values(columns),
|
14973
|
+
compositePKs: composites,
|
14974
|
+
referenceData: fks,
|
14975
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
14976
|
+
}
|
14977
|
+
];
|
14978
|
+
if (Object.keys(indexes).length) {
|
14979
|
+
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14980
|
+
}
|
14981
|
+
return statements;
|
14982
|
+
};
|
14983
|
+
prepareSQLiteRecreateTable = (table4, action) => {
|
14984
|
+
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14985
|
+
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14986
|
+
(it) => SQLiteSquasher.unsquashPK(it)
|
14987
|
+
);
|
14988
|
+
const references2 = Object.values(table4.foreignKeys);
|
14989
|
+
const fks = references2.map(
|
14990
|
+
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14991
|
+
);
|
14992
|
+
const statements = [
|
14993
|
+
{
|
14994
|
+
type: "recreate_table",
|
14995
|
+
tableName: name2,
|
14996
|
+
columns: Object.values(columns),
|
14997
|
+
compositePKs: composites,
|
14998
|
+
referenceData: fks,
|
14999
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
15000
|
+
}
|
15001
|
+
];
|
15002
|
+
if (Object.keys(indexes).length) {
|
15003
|
+
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
15004
|
+
}
|
15005
|
+
return statements;
|
15006
|
+
};
|
15007
|
+
libSQLCombineStatements = (statements, json2, action) => {
|
15008
|
+
const newStatements = {};
|
15009
|
+
for (const statement of statements) {
|
15010
|
+
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") {
|
15011
|
+
const tableName2 = statement.tableName;
|
15012
|
+
const statementsForTable2 = newStatements[tableName2];
|
15013
|
+
if (!statementsForTable2) {
|
15014
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15015
|
+
continue;
|
15016
|
+
}
|
15017
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15018
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15019
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15020
|
+
if (wasRename) {
|
15021
|
+
newStatements[tableName2].push(...preparedStatements);
|
15022
|
+
} else {
|
15023
|
+
newStatements[tableName2] = preparedStatements;
|
15024
|
+
}
|
15025
|
+
continue;
|
15026
|
+
}
|
15027
|
+
continue;
|
15028
|
+
}
|
15029
|
+
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") {
|
15030
|
+
const { tableName: tableName2, columnName, columnPk } = statement;
|
15031
|
+
const columnIsPartOfUniqueIndex = Object.values(
|
15032
|
+
json2.tables[tableName2].indexes
|
15033
|
+
).some((it) => {
|
15034
|
+
const unsquashIndex = SQLiteSquasher.unsquashIdx(it);
|
15035
|
+
return unsquashIndex.columns.includes(columnName) && unsquashIndex.isUnique;
|
15036
|
+
});
|
15037
|
+
const columnIsPartOfForeignKey = Object.values(
|
15038
|
+
json2.tables[tableName2].foreignKeys
|
15039
|
+
).some((it) => {
|
15040
|
+
const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
|
15041
|
+
return unsquashFk.columnsFrom.includes(columnName);
|
15042
|
+
});
|
15043
|
+
const statementsForTable2 = newStatements[tableName2];
|
15044
|
+
if (!statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15045
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15046
|
+
continue;
|
15047
|
+
}
|
15048
|
+
if (statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15049
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15050
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15051
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15052
|
+
if (wasRename) {
|
15053
|
+
newStatements[tableName2].push(...preparedStatements);
|
15054
|
+
} else {
|
15055
|
+
newStatements[tableName2] = preparedStatements;
|
15056
|
+
}
|
15057
|
+
}
|
15058
|
+
continue;
|
15059
|
+
}
|
15060
|
+
if (statementsForTable2 && !(columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
|
15061
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15062
|
+
newStatements[tableName2].push(statement);
|
15063
|
+
}
|
15064
|
+
continue;
|
15065
|
+
}
|
15066
|
+
newStatements[tableName2] = [statement];
|
15067
|
+
continue;
|
15068
|
+
}
|
15069
|
+
if (statement.type === "create_reference") {
|
15070
|
+
const tableName2 = statement.tableName;
|
15071
|
+
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
15072
|
+
const statementsForTable2 = newStatements[tableName2];
|
15073
|
+
if (!statementsForTable2) {
|
15074
|
+
newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : newStatements[tableName2] = [statement];
|
15075
|
+
continue;
|
15076
|
+
}
|
15077
|
+
if (!statement.isMulticolumn && statementsForTable2.some(
|
15078
|
+
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
15079
|
+
)) {
|
15080
|
+
continue;
|
15081
|
+
}
|
15082
|
+
if (statement.isMulticolumn) {
|
15083
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15084
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15085
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15086
|
+
if (wasRename) {
|
15087
|
+
newStatements[tableName2].push(...preparedStatements);
|
15088
|
+
} else {
|
15089
|
+
newStatements[tableName2] = preparedStatements;
|
15090
|
+
}
|
15091
|
+
continue;
|
15092
|
+
}
|
15093
|
+
continue;
|
15094
|
+
}
|
15095
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15096
|
+
newStatements[tableName2].push(statement);
|
15097
|
+
}
|
15098
|
+
continue;
|
15099
|
+
}
|
15100
|
+
if (statement.type === "delete_reference") {
|
15101
|
+
const tableName2 = statement.tableName;
|
15102
|
+
const statementsForTable2 = newStatements[tableName2];
|
15103
|
+
if (!statementsForTable2) {
|
15104
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15105
|
+
continue;
|
15106
|
+
}
|
15107
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15108
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15109
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15110
|
+
if (wasRename) {
|
15111
|
+
newStatements[tableName2].push(...preparedStatements);
|
15112
|
+
} else {
|
15113
|
+
newStatements[tableName2] = preparedStatements;
|
15114
|
+
}
|
15115
|
+
continue;
|
15116
|
+
}
|
15117
|
+
continue;
|
15118
|
+
}
|
15119
|
+
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
15120
|
+
const tableName2 = statement.tableName;
|
15121
|
+
const statementsForTable2 = newStatements[tableName2];
|
15122
|
+
if (!statementsForTable2) {
|
15123
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15124
|
+
continue;
|
15125
|
+
}
|
15126
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15127
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15128
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15129
|
+
if (wasRename) {
|
15130
|
+
newStatements[tableName2].push(...preparedStatements);
|
15131
|
+
} else {
|
15132
|
+
newStatements[tableName2] = preparedStatements;
|
15133
|
+
}
|
15134
|
+
continue;
|
15135
|
+
}
|
15136
|
+
continue;
|
15137
|
+
}
|
15138
|
+
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
15139
|
+
const statementsForTable = newStatements[tableName];
|
15140
|
+
if (!statementsForTable) {
|
15141
|
+
newStatements[tableName] = [statement];
|
15142
|
+
continue;
|
15143
|
+
}
|
15144
|
+
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
15145
|
+
newStatements[tableName].push(statement);
|
15146
|
+
}
|
15147
|
+
}
|
15148
|
+
const combinedStatements = Object.values(newStatements).flat();
|
15149
|
+
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
15150
|
+
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
15151
|
+
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
15152
|
+
return [...renamedTables, ...renamedColumns, ...rest];
|
15153
|
+
};
|
15154
|
+
sqliteCombineStatements = (statements, json2, action) => {
|
15155
|
+
const newStatements = {};
|
15156
|
+
for (const statement of statements) {
|
15157
|
+
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") {
|
15158
|
+
const tableName2 = statement.tableName;
|
15159
|
+
const statementsForTable2 = newStatements[tableName2];
|
15160
|
+
if (!statementsForTable2) {
|
15161
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15162
|
+
continue;
|
15163
|
+
}
|
15164
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15165
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15166
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15167
|
+
if (wasRename) {
|
15168
|
+
newStatements[tableName2].push(...preparedStatements);
|
15169
|
+
} else {
|
15170
|
+
newStatements[tableName2] = preparedStatements;
|
15171
|
+
}
|
15172
|
+
continue;
|
15173
|
+
}
|
15174
|
+
continue;
|
15175
|
+
}
|
15176
|
+
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
15177
|
+
const tableName2 = statement.tableName;
|
15178
|
+
const statementsForTable2 = newStatements[tableName2];
|
15179
|
+
if (!statementsForTable2) {
|
15180
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15181
|
+
continue;
|
15182
|
+
}
|
15183
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15184
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15185
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15186
|
+
if (wasRename) {
|
15187
|
+
newStatements[tableName2].push(...preparedStatements);
|
15188
|
+
} else {
|
15189
|
+
newStatements[tableName2] = preparedStatements;
|
15190
|
+
}
|
15191
|
+
continue;
|
15192
|
+
}
|
15193
|
+
continue;
|
15194
|
+
}
|
15195
|
+
if (statement.type === "create_reference") {
|
15196
|
+
const tableName2 = statement.tableName;
|
15197
|
+
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
15198
|
+
const statementsForTable2 = newStatements[tableName2];
|
15199
|
+
if (!statementsForTable2) {
|
15200
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
|
15201
|
+
continue;
|
15202
|
+
}
|
15203
|
+
if (data.columnsFrom.length === 1 && statementsForTable2.some(
|
15204
|
+
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
15205
|
+
)) {
|
15206
|
+
continue;
|
15207
|
+
}
|
15208
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
15209
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
15210
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
15211
|
+
if (wasRename) {
|
15212
|
+
newStatements[tableName2].push(...preparedStatements);
|
15213
|
+
} else {
|
15214
|
+
newStatements[tableName2] = preparedStatements;
|
15215
|
+
}
|
15216
|
+
continue;
|
15217
|
+
}
|
15218
|
+
continue;
|
15219
|
+
}
|
15220
|
+
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
15221
|
+
const statementsForTable = newStatements[tableName];
|
15222
|
+
if (!statementsForTable) {
|
15223
|
+
newStatements[tableName] = [statement];
|
15224
|
+
continue;
|
15225
|
+
}
|
15226
|
+
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
15227
|
+
newStatements[tableName].push(statement);
|
15228
|
+
}
|
15229
|
+
}
|
15230
|
+
const combinedStatements = Object.values(newStatements).flat();
|
15231
|
+
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
15232
|
+
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
15233
|
+
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
15234
|
+
return [...renamedTables, ...renamedColumns, ...rest];
|
15235
|
+
};
|
15236
|
+
}
|
15237
|
+
});
|
15238
|
+
|
14424
15239
|
// src/snapshotsDiffer.ts
|
14425
15240
|
var snapshotsDiffer_exports = {};
|
14426
15241
|
__export(snapshotsDiffer_exports, {
|
14427
15242
|
alteredTableScheme: () => alteredTableScheme,
|
15243
|
+
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
14428
15244
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
14429
15245
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
14430
15246
|
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
@@ -14434,7 +15250,7 @@ __export(snapshotsDiffer_exports, {
|
|
14434
15250
|
makePatched: () => makePatched,
|
14435
15251
|
makeSelfOrPatched: () => makeSelfOrPatched
|
14436
15252
|
});
|
14437
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
15253
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
14438
15254
|
var init_snapshotsDiffer = __esm({
|
14439
15255
|
"src/snapshotsDiffer.ts"() {
|
14440
15256
|
"use strict";
|
@@ -14446,6 +15262,7 @@ var init_snapshotsDiffer = __esm({
|
|
14446
15262
|
init_mysqlSchema();
|
14447
15263
|
init_pgSchema();
|
14448
15264
|
init_sqliteSchema();
|
15265
|
+
init_statementCombiner();
|
14449
15266
|
init_utils();
|
14450
15267
|
makeChanged = (schema4) => {
|
14451
15268
|
return objectType({
|
@@ -15363,9 +16180,308 @@ var init_snapshotsDiffer = __esm({
|
|
15363
16180
|
);
|
15364
16181
|
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
15365
16182
|
it.name,
|
15366
|
-
it.alteredCompositePKs,
|
15367
|
-
prevFull,
|
15368
|
-
curFull
|
16183
|
+
it.alteredCompositePKs,
|
16184
|
+
prevFull,
|
16185
|
+
curFull
|
16186
|
+
);
|
16187
|
+
let addedUniqueConstraints = [];
|
16188
|
+
let deletedUniqueConstraints = [];
|
16189
|
+
let alteredUniqueConstraints = [];
|
16190
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16191
|
+
it.name,
|
16192
|
+
it.schema,
|
16193
|
+
it.addedUniqueConstraints
|
16194
|
+
);
|
16195
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
16196
|
+
it.name,
|
16197
|
+
it.schema,
|
16198
|
+
it.deletedUniqueConstraints
|
16199
|
+
);
|
16200
|
+
if (it.alteredUniqueConstraints) {
|
16201
|
+
const added = {};
|
16202
|
+
const deleted = {};
|
16203
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
16204
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
16205
|
+
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
16206
|
+
}
|
16207
|
+
addedUniqueConstraints.push(
|
16208
|
+
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
16209
|
+
);
|
16210
|
+
deletedUniqueConstraints.push(
|
16211
|
+
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16212
|
+
);
|
16213
|
+
}
|
16214
|
+
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16215
|
+
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16216
|
+
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16217
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16218
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16219
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16220
|
+
});
|
16221
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16222
|
+
const tableName = it.tableName;
|
16223
|
+
const schema4 = it.schema;
|
16224
|
+
return {
|
16225
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16226
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16227
|
+
};
|
16228
|
+
});
|
16229
|
+
const jsonTableAlternations = alteredTables.map((it) => {
|
16230
|
+
return prepareAlterColumnsMysql(
|
16231
|
+
it.name,
|
16232
|
+
it.schema,
|
16233
|
+
it.altered,
|
16234
|
+
json1,
|
16235
|
+
json2,
|
16236
|
+
action
|
16237
|
+
);
|
16238
|
+
}).flat();
|
16239
|
+
const jsonCreateIndexesForAllAlteredTables = alteredTables.map((it) => {
|
16240
|
+
return prepareCreateIndexesJson(
|
16241
|
+
it.name,
|
16242
|
+
it.schema,
|
16243
|
+
it.addedIndexes || {},
|
16244
|
+
curFull.internal
|
16245
|
+
);
|
16246
|
+
}).flat();
|
16247
|
+
const jsonDropIndexesForAllAlteredTables = alteredTables.map((it) => {
|
16248
|
+
return prepareDropIndexesJson(
|
16249
|
+
it.name,
|
16250
|
+
it.schema,
|
16251
|
+
it.deletedIndexes || {}
|
16252
|
+
);
|
16253
|
+
}).flat();
|
16254
|
+
alteredTables.forEach((it) => {
|
16255
|
+
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
16256
|
+
(current, item) => {
|
16257
|
+
current[item] = it.alteredIndexes[item].__old;
|
16258
|
+
return current;
|
16259
|
+
},
|
16260
|
+
{}
|
16261
|
+
);
|
16262
|
+
const createdIndexes = Object.keys(it.alteredIndexes).reduce(
|
16263
|
+
(current, item) => {
|
16264
|
+
current[item] = it.alteredIndexes[item].__new;
|
16265
|
+
return current;
|
16266
|
+
},
|
16267
|
+
{}
|
16268
|
+
);
|
16269
|
+
jsonCreateIndexesForAllAlteredTables.push(
|
16270
|
+
...prepareCreateIndexesJson(it.name, it.schema, createdIndexes || {})
|
16271
|
+
);
|
16272
|
+
jsonDropIndexesForAllAlteredTables.push(
|
16273
|
+
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
16274
|
+
);
|
16275
|
+
});
|
16276
|
+
const jsonCreateReferencesForCreatedTables = createdTables.map((it) => {
|
16277
|
+
return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
|
16278
|
+
}).flat();
|
16279
|
+
const jsonReferencesForAllAlteredTables = alteredTables.map((it) => {
|
16280
|
+
const forAdded = prepareCreateReferencesJson(
|
16281
|
+
it.name,
|
16282
|
+
it.schema,
|
16283
|
+
it.addedForeignKeys
|
16284
|
+
);
|
16285
|
+
const forAltered = prepareDropReferencesJson(
|
16286
|
+
it.name,
|
16287
|
+
it.schema,
|
16288
|
+
it.deletedForeignKeys
|
16289
|
+
);
|
16290
|
+
const alteredFKs = prepareAlterReferencesJson(
|
16291
|
+
it.name,
|
16292
|
+
it.schema,
|
16293
|
+
it.alteredForeignKeys
|
16294
|
+
);
|
16295
|
+
return [...forAdded, ...forAltered, ...alteredFKs];
|
16296
|
+
}).flat();
|
16297
|
+
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16298
|
+
(t) => t.type === "create_reference"
|
16299
|
+
);
|
16300
|
+
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16301
|
+
(t) => t.type === "delete_reference"
|
16302
|
+
);
|
16303
|
+
const jsonMySqlCreateTables = createdTables.map((it) => {
|
16304
|
+
return prepareMySqlCreateTableJson(
|
16305
|
+
it,
|
16306
|
+
curFull,
|
16307
|
+
curFull.internal
|
16308
|
+
);
|
16309
|
+
});
|
16310
|
+
jsonStatements.push(...jsonMySqlCreateTables);
|
16311
|
+
jsonStatements.push(...jsonDropTables);
|
16312
|
+
jsonStatements.push(...jsonRenameTables);
|
16313
|
+
jsonStatements.push(...jsonRenameColumnsStatements);
|
16314
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16315
|
+
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16316
|
+
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16317
|
+
jsonStatements.push(...jsonDeletedCompositePKs);
|
16318
|
+
jsonStatements.push(...jsonTableAlternations);
|
16319
|
+
jsonStatements.push(...jsonAddedCompositePKs);
|
16320
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16321
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16322
|
+
jsonStatements.push(...jsonAddColumnsStatemets);
|
16323
|
+
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16324
|
+
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16325
|
+
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16326
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16327
|
+
jsonStatements.push(...jsonDropColumnsStatemets);
|
16328
|
+
jsonStatements.push(...jsonAlteredCompositePKs);
|
16329
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16330
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16331
|
+
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16332
|
+
const uniqueSqlStatements = [];
|
16333
|
+
sqlStatements.forEach((ss) => {
|
16334
|
+
if (!uniqueSqlStatements.includes(ss)) {
|
16335
|
+
uniqueSqlStatements.push(ss);
|
16336
|
+
}
|
16337
|
+
});
|
16338
|
+
const rTables = renamedTables.map((it) => {
|
16339
|
+
return { from: it.from, to: it.to };
|
16340
|
+
});
|
16341
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16342
|
+
return {
|
16343
|
+
statements: jsonStatements,
|
16344
|
+
sqlStatements: uniqueSqlStatements,
|
16345
|
+
_meta
|
16346
|
+
};
|
16347
|
+
};
|
16348
|
+
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16349
|
+
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16350
|
+
const {
|
16351
|
+
created: createdTables,
|
16352
|
+
deleted: deletedTables,
|
16353
|
+
renamed: renamedTables
|
16354
|
+
} = await tablesResolver2({
|
16355
|
+
created: tablesDiff.added,
|
16356
|
+
deleted: tablesDiff.deleted
|
16357
|
+
});
|
16358
|
+
const tablesPatchedSnap1 = copy(json1);
|
16359
|
+
tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
|
16360
|
+
const { name: name2 } = nameChangeFor(it, renamedTables);
|
16361
|
+
it.name = name2;
|
16362
|
+
return [name2, it];
|
16363
|
+
});
|
16364
|
+
const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
|
16365
|
+
const columnRenames = [];
|
16366
|
+
const columnCreates = [];
|
16367
|
+
const columnDeletes = [];
|
16368
|
+
for (let entry of Object.values(res)) {
|
16369
|
+
const { renamed, created, deleted } = await columnsResolver2({
|
16370
|
+
tableName: entry.name,
|
16371
|
+
schema: entry.schema,
|
16372
|
+
deleted: entry.columns.deleted,
|
16373
|
+
created: entry.columns.added
|
16374
|
+
});
|
16375
|
+
if (created.length > 0) {
|
16376
|
+
columnCreates.push({
|
16377
|
+
table: entry.name,
|
16378
|
+
columns: created
|
16379
|
+
});
|
16380
|
+
}
|
16381
|
+
if (deleted.length > 0) {
|
16382
|
+
columnDeletes.push({
|
16383
|
+
table: entry.name,
|
16384
|
+
columns: deleted
|
16385
|
+
});
|
16386
|
+
}
|
16387
|
+
if (renamed.length > 0) {
|
16388
|
+
columnRenames.push({
|
16389
|
+
table: entry.name,
|
16390
|
+
renames: renamed
|
16391
|
+
});
|
16392
|
+
}
|
16393
|
+
}
|
16394
|
+
const columnRenamesDict = columnRenames.reduce(
|
16395
|
+
(acc, it) => {
|
16396
|
+
acc[it.table] = it.renames;
|
16397
|
+
return acc;
|
16398
|
+
},
|
16399
|
+
{}
|
16400
|
+
);
|
16401
|
+
const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
|
16402
|
+
columnsPatchedSnap1.tables = mapEntries(
|
16403
|
+
columnsPatchedSnap1.tables,
|
16404
|
+
(tableKey2, tableValue) => {
|
16405
|
+
const patchedColumns = mapKeys(
|
16406
|
+
tableValue.columns,
|
16407
|
+
(columnKey, column4) => {
|
16408
|
+
const rens = columnRenamesDict[tableValue.name] || [];
|
16409
|
+
const newName = columnChangeFor(columnKey, rens);
|
16410
|
+
column4.name = newName;
|
16411
|
+
return newName;
|
16412
|
+
}
|
16413
|
+
);
|
16414
|
+
tableValue.columns = patchedColumns;
|
16415
|
+
return [tableKey2, tableValue];
|
16416
|
+
}
|
16417
|
+
);
|
16418
|
+
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
16419
|
+
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16420
|
+
const tablesMap = {};
|
16421
|
+
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
16422
|
+
tablesMap[obj.name] = obj;
|
16423
|
+
});
|
16424
|
+
const jsonCreateTables = createdTables.map((it) => {
|
16425
|
+
return prepareSQLiteCreateTable(it, action);
|
16426
|
+
});
|
16427
|
+
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
16428
|
+
return prepareCreateIndexesJson(
|
16429
|
+
it.name,
|
16430
|
+
it.schema,
|
16431
|
+
it.indexes,
|
16432
|
+
curFull.internal
|
16433
|
+
);
|
16434
|
+
}).flat();
|
16435
|
+
const jsonDropTables = deletedTables.map((it) => {
|
16436
|
+
return prepareDropTableJson(it);
|
16437
|
+
});
|
16438
|
+
const jsonRenameTables = renamedTables.map((it) => {
|
16439
|
+
return prepareRenameTableJson(it.from, it.to);
|
16440
|
+
});
|
16441
|
+
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16442
|
+
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
16443
|
+
const jsonAddColumnsStatemets = columnCreates.map((it) => {
|
16444
|
+
return _prepareSqliteAddColumns(
|
16445
|
+
it.table,
|
16446
|
+
it.columns,
|
16447
|
+
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16448
|
+
);
|
16449
|
+
}).flat();
|
16450
|
+
const allAltered = typedResult.alteredTablesWithColumns;
|
16451
|
+
const jsonAddedCompositePKs = [];
|
16452
|
+
const jsonDeletedCompositePKs = [];
|
16453
|
+
const jsonAlteredCompositePKs = [];
|
16454
|
+
const jsonAddedUniqueConstraints = [];
|
16455
|
+
const jsonDeletedUniqueConstraints = [];
|
16456
|
+
const jsonAlteredUniqueConstraints = [];
|
16457
|
+
allAltered.forEach((it) => {
|
16458
|
+
let addedColumns = [];
|
16459
|
+
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16460
|
+
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16461
|
+
addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
|
16462
|
+
}
|
16463
|
+
let deletedColumns = [];
|
16464
|
+
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16465
|
+
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16466
|
+
deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
|
16467
|
+
}
|
16468
|
+
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16469
|
+
let addedCompositePKs = [];
|
16470
|
+
let deletedCompositePKs = [];
|
16471
|
+
let alteredCompositePKs = [];
|
16472
|
+
if (doPerformDeleteAndCreate) {
|
16473
|
+
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
16474
|
+
it.name,
|
16475
|
+
it.addedCompositePKs
|
16476
|
+
);
|
16477
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
16478
|
+
it.name,
|
16479
|
+
it.deletedCompositePKs
|
16480
|
+
);
|
16481
|
+
}
|
16482
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
16483
|
+
it.name,
|
16484
|
+
it.alteredCompositePKs
|
15369
16485
|
);
|
15370
16486
|
let addedUniqueConstraints = [];
|
15371
16487
|
let deletedUniqueConstraints = [];
|
@@ -15409,17 +16525,10 @@ var init_snapshotsDiffer = __esm({
|
|
15409
16525
|
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
15410
16526
|
};
|
15411
16527
|
});
|
15412
|
-
const jsonTableAlternations =
|
15413
|
-
return
|
15414
|
-
it.name,
|
15415
|
-
it.schema,
|
15416
|
-
it.altered,
|
15417
|
-
json1,
|
15418
|
-
json2,
|
15419
|
-
action
|
15420
|
-
);
|
16528
|
+
const jsonTableAlternations = allAltered.map((it) => {
|
16529
|
+
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
15421
16530
|
}).flat();
|
15422
|
-
const jsonCreateIndexesForAllAlteredTables =
|
16531
|
+
const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
|
15423
16532
|
return prepareCreateIndexesJson(
|
15424
16533
|
it.name,
|
15425
16534
|
it.schema,
|
@@ -15427,14 +16536,14 @@ var init_snapshotsDiffer = __esm({
|
|
15427
16536
|
curFull.internal
|
15428
16537
|
);
|
15429
16538
|
}).flat();
|
15430
|
-
const jsonDropIndexesForAllAlteredTables =
|
16539
|
+
const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
|
15431
16540
|
return prepareDropIndexesJson(
|
15432
16541
|
it.name,
|
15433
16542
|
it.schema,
|
15434
16543
|
it.deletedIndexes || {}
|
15435
16544
|
);
|
15436
16545
|
}).flat();
|
15437
|
-
|
16546
|
+
allAltered.forEach((it) => {
|
15438
16547
|
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
15439
16548
|
(current, item) => {
|
15440
16549
|
current[item] = it.alteredIndexes[item].__old;
|
@@ -15450,16 +16559,18 @@ var init_snapshotsDiffer = __esm({
|
|
15450
16559
|
{}
|
15451
16560
|
);
|
15452
16561
|
jsonCreateIndexesForAllAlteredTables.push(
|
15453
|
-
...prepareCreateIndexesJson(
|
16562
|
+
...prepareCreateIndexesJson(
|
16563
|
+
it.name,
|
16564
|
+
it.schema,
|
16565
|
+
createdIndexes || {},
|
16566
|
+
curFull.internal
|
16567
|
+
)
|
15454
16568
|
);
|
15455
16569
|
jsonDropIndexesForAllAlteredTables.push(
|
15456
16570
|
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
15457
16571
|
);
|
15458
16572
|
});
|
15459
|
-
const
|
15460
|
-
return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
|
15461
|
-
}).flat();
|
15462
|
-
const jsonReferencesForAllAlteredTables = alteredTables.map((it) => {
|
16573
|
+
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
15463
16574
|
const forAdded = prepareCreateReferencesJson(
|
15464
16575
|
it.name,
|
15465
16576
|
it.schema,
|
@@ -15483,35 +16594,25 @@ var init_snapshotsDiffer = __esm({
|
|
15483
16594
|
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
15484
16595
|
(t) => t.type === "delete_reference"
|
15485
16596
|
);
|
15486
|
-
const
|
15487
|
-
|
15488
|
-
it,
|
15489
|
-
curFull,
|
15490
|
-
curFull.internal
|
15491
|
-
);
|
15492
|
-
});
|
15493
|
-
jsonStatements.push(...jsonMySqlCreateTables);
|
16597
|
+
const jsonStatements = [];
|
16598
|
+
jsonStatements.push(...jsonCreateTables);
|
15494
16599
|
jsonStatements.push(...jsonDropTables);
|
15495
16600
|
jsonStatements.push(...jsonRenameTables);
|
15496
16601
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15497
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
15498
16602
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
15499
16603
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
15500
16604
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
15501
16605
|
jsonStatements.push(...jsonTableAlternations);
|
15502
16606
|
jsonStatements.push(...jsonAddedCompositePKs);
|
15503
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15504
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
15505
16607
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
15506
|
-
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
15507
16608
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
15508
|
-
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
15509
16609
|
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16610
|
+
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
15510
16611
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
15511
16612
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15512
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15513
16613
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
15514
|
-
const
|
16614
|
+
const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json2, action);
|
16615
|
+
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
15515
16616
|
const uniqueSqlStatements = [];
|
15516
16617
|
sqlStatements.forEach((ss) => {
|
15517
16618
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -15523,12 +16624,12 @@ var init_snapshotsDiffer = __esm({
|
|
15523
16624
|
});
|
15524
16625
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
15525
16626
|
return {
|
15526
|
-
statements:
|
16627
|
+
statements: combinedJsonStatements,
|
15527
16628
|
sqlStatements: uniqueSqlStatements,
|
15528
16629
|
_meta
|
15529
16630
|
};
|
15530
16631
|
};
|
15531
|
-
|
16632
|
+
applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
15532
16633
|
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
15533
16634
|
const {
|
15534
16635
|
created: createdTables,
|
@@ -15630,6 +16731,18 @@ var init_snapshotsDiffer = __esm({
|
|
15630
16731
|
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
15631
16732
|
);
|
15632
16733
|
}).flat();
|
16734
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16735
|
+
const tableName = it.tableName;
|
16736
|
+
const schema4 = it.schema;
|
16737
|
+
return {
|
16738
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16739
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16740
|
+
};
|
16741
|
+
});
|
16742
|
+
const rTables = renamedTables.map((it) => {
|
16743
|
+
return { from: it.from, to: it.to };
|
16744
|
+
});
|
16745
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
15633
16746
|
const allAltered = typedResult.alteredTablesWithColumns;
|
15634
16747
|
const jsonAddedCompositePKs = [];
|
15635
16748
|
const jsonDeletedCompositePKs = [];
|
@@ -15700,14 +16813,6 @@ var init_snapshotsDiffer = __esm({
|
|
15700
16813
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
15701
16814
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
15702
16815
|
});
|
15703
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
15704
|
-
const tableName = it.tableName;
|
15705
|
-
const schema4 = it.schema;
|
15706
|
-
return {
|
15707
|
-
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
15708
|
-
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
15709
|
-
};
|
15710
|
-
});
|
15711
16816
|
const jsonTableAlternations = allAltered.map((it) => {
|
15712
16817
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
15713
16818
|
}).flat();
|
@@ -15754,21 +16859,22 @@ var init_snapshotsDiffer = __esm({
|
|
15754
16859
|
);
|
15755
16860
|
});
|
15756
16861
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
15757
|
-
const forAdded =
|
15758
|
-
it.name,
|
15759
|
-
it.schema,
|
15760
|
-
it.addedForeignKeys
|
15761
|
-
);
|
15762
|
-
const forAltered = prepareDropReferencesJson(
|
16862
|
+
const forAdded = prepareLibSQLCreateReferencesJson(
|
15763
16863
|
it.name,
|
15764
16864
|
it.schema,
|
15765
|
-
it.
|
16865
|
+
it.addedForeignKeys,
|
16866
|
+
json2,
|
16867
|
+
action
|
15766
16868
|
);
|
15767
|
-
const
|
16869
|
+
const forAltered = prepareLibSQLDropReferencesJson(
|
15768
16870
|
it.name,
|
15769
16871
|
it.schema,
|
15770
|
-
it.
|
16872
|
+
it.deletedForeignKeys,
|
16873
|
+
json2,
|
16874
|
+
_meta,
|
16875
|
+
action
|
15771
16876
|
);
|
16877
|
+
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
15772
16878
|
return [...forAdded, ...forAltered, ...alteredFKs];
|
15773
16879
|
}).flat();
|
15774
16880
|
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
@@ -15794,19 +16900,22 @@ var init_snapshotsDiffer = __esm({
|
|
15794
16900
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
15795
16901
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15796
16902
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
15797
|
-
const
|
16903
|
+
const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
|
16904
|
+
const sqlStatements = fromJson(
|
16905
|
+
combinedJsonStatements,
|
16906
|
+
"sqlite",
|
16907
|
+
action,
|
16908
|
+
"turso",
|
16909
|
+
json2
|
16910
|
+
);
|
15798
16911
|
const uniqueSqlStatements = [];
|
15799
16912
|
sqlStatements.forEach((ss) => {
|
15800
16913
|
if (!uniqueSqlStatements.includes(ss)) {
|
15801
16914
|
uniqueSqlStatements.push(ss);
|
15802
16915
|
}
|
15803
16916
|
});
|
15804
|
-
const rTables = renamedTables.map((it) => {
|
15805
|
-
return { from: it.from, to: it.to };
|
15806
|
-
});
|
15807
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
15808
16917
|
return {
|
15809
|
-
statements:
|
16918
|
+
statements: combinedJsonStatements,
|
15810
16919
|
sqlStatements: uniqueSqlStatements,
|
15811
16920
|
_meta
|
15812
16921
|
};
|
@@ -17477,7 +18586,7 @@ function getTableName(table4) {
|
|
17477
18586
|
function getTableUniqueName(table4) {
|
17478
18587
|
return `${table4[Schema] ?? "public"}.${table4[TableName]}`;
|
17479
18588
|
}
|
17480
|
-
var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, Table2;
|
18589
|
+
var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, Table2;
|
17481
18590
|
var init_table = __esm({
|
17482
18591
|
"../drizzle-orm/dist/table.js"() {
|
17483
18592
|
"use strict";
|
@@ -17491,32 +18600,34 @@ var init_table = __esm({
|
|
17491
18600
|
IsAlias = Symbol.for("drizzle:IsAlias");
|
17492
18601
|
ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
17493
18602
|
IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
17494
|
-
|
18603
|
+
_j = entityKind, _i = TableName, _h = OriginalName, _g = Schema, _f = Columns, _e = ExtraConfigColumns, _d = BaseName, _c = IsAlias, _b = IsDrizzleTable, _a3 = ExtraConfigBuilder;
|
17495
18604
|
Table2 = class {
|
17496
18605
|
constructor(name2, schema4, baseName) {
|
17497
18606
|
/**
|
17498
18607
|
* @internal
|
17499
18608
|
* Can be changed if the table is aliased.
|
17500
18609
|
*/
|
17501
|
-
__publicField(this,
|
18610
|
+
__publicField(this, _i);
|
17502
18611
|
/**
|
17503
18612
|
* @internal
|
17504
18613
|
* Used to store the original name of the table, before any aliasing.
|
17505
18614
|
*/
|
18615
|
+
__publicField(this, _h);
|
18616
|
+
/** @internal */
|
17506
18617
|
__publicField(this, _g);
|
17507
18618
|
/** @internal */
|
17508
18619
|
__publicField(this, _f);
|
17509
18620
|
/** @internal */
|
17510
18621
|
__publicField(this, _e);
|
17511
|
-
/** @internal */
|
17512
|
-
__publicField(this, _d);
|
17513
18622
|
/**
|
17514
18623
|
* @internal
|
17515
18624
|
* Used to store the table name before the transformation via the `tableCreator` functions.
|
17516
18625
|
*/
|
17517
|
-
__publicField(this,
|
18626
|
+
__publicField(this, _d);
|
18627
|
+
/** @internal */
|
18628
|
+
__publicField(this, _c, false);
|
17518
18629
|
/** @internal */
|
17519
|
-
__publicField(this, _b,
|
18630
|
+
__publicField(this, _b, true);
|
17520
18631
|
/** @internal */
|
17521
18632
|
__publicField(this, _a3);
|
17522
18633
|
this[TableName] = this[OriginalName] = name2;
|
@@ -17524,7 +18635,7 @@ var init_table = __esm({
|
|
17524
18635
|
this[BaseName] = baseName;
|
17525
18636
|
}
|
17526
18637
|
};
|
17527
|
-
__publicField(Table2,
|
18638
|
+
__publicField(Table2, _j, "Table");
|
17528
18639
|
/** @internal */
|
17529
18640
|
__publicField(Table2, "Symbol", {
|
17530
18641
|
Name: TableName,
|
@@ -18100,7 +19211,7 @@ var version;
|
|
18100
19211
|
var init_version = __esm({
|
18101
19212
|
"../drizzle-orm/dist/version.js"() {
|
18102
19213
|
"use strict";
|
18103
|
-
version = "0.
|
19214
|
+
version = "0.33.0";
|
18104
19215
|
}
|
18105
19216
|
});
|
18106
19217
|
|
@@ -18202,6 +19313,12 @@ function fillPlaceholders(params, values) {
|
|
18202
19313
|
}
|
18203
19314
|
return values[p.name];
|
18204
19315
|
}
|
19316
|
+
if (is(p, Param) && is(p.value, Placeholder)) {
|
19317
|
+
if (!(p.value.name in values)) {
|
19318
|
+
throw new Error(`No value for placeholder "${p.value.name}" was provided`);
|
19319
|
+
}
|
19320
|
+
return p.encoder.mapToDriverValue(values[p.value.name]);
|
19321
|
+
}
|
18205
19322
|
return p;
|
18206
19323
|
});
|
18207
19324
|
}
|
@@ -18315,6 +19432,9 @@ var init_sql = __esm({
|
|
18315
19432
|
};
|
18316
19433
|
}
|
18317
19434
|
if (is(chunk, Param)) {
|
19435
|
+
if (is(chunk.value, Placeholder)) {
|
19436
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
19437
|
+
}
|
18318
19438
|
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
18319
19439
|
if (is(mappedValue, _SQL)) {
|
18320
19440
|
return this.buildQueryFromSourceParams([mappedValue], config);
|
@@ -24636,6 +25756,30 @@ function minRangeForIdentityBasedOn(columnType) {
|
|
24636
25756
|
function stringFromDatabaseIdentityProperty(field) {
|
24637
25757
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
|
24638
25758
|
}
|
25759
|
+
function buildArrayString(array, sqlType) {
|
25760
|
+
sqlType = sqlType.split("[")[0];
|
25761
|
+
const values = array.map((value) => {
|
25762
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
25763
|
+
return value.toString();
|
25764
|
+
} else if (typeof value === "boolean") {
|
25765
|
+
return value ? "true" : "false";
|
25766
|
+
} else if (Array.isArray(value)) {
|
25767
|
+
return buildArrayString(value, sqlType);
|
25768
|
+
} else if (value instanceof Date) {
|
25769
|
+
if (sqlType === "date") {
|
25770
|
+
return `"${value.toISOString().split("T")[0]}"`;
|
25771
|
+
} else if (sqlType === "timestamp") {
|
25772
|
+
return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
|
25773
|
+
} else {
|
25774
|
+
return `"${value.toISOString()}"`;
|
25775
|
+
}
|
25776
|
+
} else if (typeof value === "object") {
|
25777
|
+
return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
|
25778
|
+
}
|
25779
|
+
return `"${value}"`;
|
25780
|
+
}).join(",");
|
25781
|
+
return `{${values}}`;
|
25782
|
+
}
|
24639
25783
|
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
|
24640
25784
|
var init_pgSerializer = __esm({
|
24641
25785
|
"src/serializer/pgSerializer.ts"() {
|
@@ -24646,6 +25790,7 @@ var init_pgSerializer = __esm({
|
|
24646
25790
|
init_pg_core();
|
24647
25791
|
init_vector3();
|
24648
25792
|
init_outputs();
|
25793
|
+
init_utils();
|
24649
25794
|
init_serializer();
|
24650
25795
|
dialect4 = new PgDialect();
|
24651
25796
|
indexName = (tableName, columns) => {
|
@@ -24752,6 +25897,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
24752
25897
|
} else {
|
24753
25898
|
columnToSet.default = `'${column4.default.toISOString()}'`;
|
24754
25899
|
}
|
25900
|
+
} else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
|
25901
|
+
columnToSet.default = `'${buildArrayString(
|
25902
|
+
column4.default,
|
25903
|
+
sqlTypeLowered
|
25904
|
+
)}'::${sqlTypeLowered}`;
|
24755
25905
|
} else {
|
24756
25906
|
columnToSet.default = column4.default;
|
24757
25907
|
}
|
@@ -29031,7 +30181,7 @@ The unique constraint ${source_default.underline.blue(
|
|
29031
30181
|
primaryKeys.forEach((it) => {
|
29032
30182
|
if (it.columns.length > 1) {
|
29033
30183
|
primaryKeysObject[it.getName()] = {
|
29034
|
-
columns: it.columns.map((it2) => it2.name)
|
30184
|
+
columns: it.columns.map((it2) => it2.name),
|
29035
30185
|
name: it.getName()
|
29036
30186
|
};
|
29037
30187
|
} else {
|
@@ -29156,7 +30306,6 @@ The unique constraint ${source_default.underline.blue(
|
|
29156
30306
|
}
|
29157
30307
|
for (const [key, value] of Object.entries(tableToPk)) {
|
29158
30308
|
if (value.length > 1) {
|
29159
|
-
value.sort();
|
29160
30309
|
result[key].compositePrimaryKeys = {
|
29161
30310
|
[`${key}_${value.join("_")}_pk`]: {
|
29162
30311
|
columns: value,
|
@@ -33600,7 +34749,7 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
33600
34749
|
onUpdate = true;
|
33601
34750
|
}
|
33602
34751
|
const newColumn = {
|
33603
|
-
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith(
|
34752
|
+
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
|
33604
34753
|
autoincrement: isAutoincrement,
|
33605
34754
|
name: columnName,
|
33606
34755
|
type: changedType,
|
@@ -33828,7 +34977,8 @@ var init_cli = __esm({
|
|
33828
34977
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
33829
34978
|
extensionsFilters: literalType("postgis").array().optional(),
|
33830
34979
|
verbose: booleanType().optional(),
|
33831
|
-
strict: booleanType().optional()
|
34980
|
+
strict: booleanType().optional(),
|
34981
|
+
driver: driver.optional()
|
33832
34982
|
}).passthrough();
|
33833
34983
|
pullParams = objectType({
|
33834
34984
|
config: stringType().optional(),
|
@@ -34817,6 +35967,37 @@ var updateUpToV6 = (json) => {
|
|
34817
35967
|
enums
|
34818
35968
|
};
|
34819
35969
|
};
|
35970
|
+
var updateUpToV7 = (json) => {
|
35971
|
+
const schema4 = pgSchemaV6.parse(json);
|
35972
|
+
const tables = Object.fromEntries(
|
35973
|
+
Object.entries(schema4.tables).map((it) => {
|
35974
|
+
const table4 = it[1];
|
35975
|
+
const mappedIndexes = Object.fromEntries(
|
35976
|
+
Object.entries(table4.indexes).map((idx) => {
|
35977
|
+
const { columns, ...rest } = idx[1];
|
35978
|
+
const mappedColumns = columns.map((it2) => {
|
35979
|
+
return {
|
35980
|
+
expression: it2,
|
35981
|
+
isExpression: false,
|
35982
|
+
asc: true,
|
35983
|
+
nulls: "last",
|
35984
|
+
opClass: void 0
|
35985
|
+
};
|
35986
|
+
});
|
35987
|
+
return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
|
35988
|
+
})
|
35989
|
+
);
|
35990
|
+
return [it[0], { ...table4, indexes: mappedIndexes }];
|
35991
|
+
})
|
35992
|
+
);
|
35993
|
+
return {
|
35994
|
+
...schema4,
|
35995
|
+
version: "7",
|
35996
|
+
dialect: "postgresql",
|
35997
|
+
sequences: {},
|
35998
|
+
tables
|
35999
|
+
};
|
36000
|
+
};
|
34820
36001
|
|
34821
36002
|
// src/cli/commands/sqliteIntrospect.ts
|
34822
36003
|
var import_hanji6 = __toESM(require_hanji());
|
@@ -34963,284 +36144,8 @@ var sqlitePushIntrospect = async (db, filters) => {
|
|
34963
36144
|
return { schema: schema4 };
|
34964
36145
|
};
|
34965
36146
|
|
34966
|
-
// src/cli/commands/sqlitePushUtils.ts
|
34967
|
-
init_source();
|
34968
|
-
init_sqliteSchema();
|
34969
|
-
init_sqlgenerator();
|
34970
|
-
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
34971
|
-
const statements = [];
|
34972
|
-
statements.push(
|
34973
|
-
new SqliteRenameTableConvertor().convert({
|
34974
|
-
type: "rename_table",
|
34975
|
-
tableNameFrom: tableName,
|
34976
|
-
tableNameTo: `__old_push_${tableName}`,
|
34977
|
-
fromSchema: "",
|
34978
|
-
toSchema: ""
|
34979
|
-
})
|
34980
|
-
);
|
34981
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
34982
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
34983
|
-
const compositePKs = Object.values(
|
34984
|
-
json.tables[tableName].compositePrimaryKeys
|
34985
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
34986
|
-
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
34987
|
-
statements.push(
|
34988
|
-
new SQLiteCreateTableConvertor().convert({
|
34989
|
-
type: "sqlite_create_table",
|
34990
|
-
tableName,
|
34991
|
-
columns: tableColumns,
|
34992
|
-
referenceData: fks,
|
34993
|
-
compositePKs
|
34994
|
-
})
|
34995
|
-
);
|
34996
|
-
if (!dataLoss) {
|
34997
|
-
statements.push(
|
34998
|
-
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
34999
|
-
);
|
35000
|
-
}
|
35001
|
-
statements.push(
|
35002
|
-
new SQLiteDropTableConvertor().convert({
|
35003
|
-
type: "drop_table",
|
35004
|
-
tableName: `__old_push_${tableName}`,
|
35005
|
-
schema: ""
|
35006
|
-
})
|
35007
|
-
);
|
35008
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
35009
|
-
statements.push(
|
35010
|
-
new CreateSqliteIndexConvertor().convert({
|
35011
|
-
type: "create_index",
|
35012
|
-
tableName,
|
35013
|
-
schema: "",
|
35014
|
-
data: idx
|
35015
|
-
})
|
35016
|
-
);
|
35017
|
-
}
|
35018
|
-
return statements;
|
35019
|
-
};
|
35020
|
-
var getOldTableName = (tableName, meta) => {
|
35021
|
-
for (const key of Object.keys(meta.tables)) {
|
35022
|
-
const value = meta.tables[key];
|
35023
|
-
if (`"${tableName}"` === value) {
|
35024
|
-
return key.substring(1, key.length - 1);
|
35025
|
-
}
|
35026
|
-
}
|
35027
|
-
return tableName;
|
35028
|
-
};
|
35029
|
-
var getNewTableName = (tableName, meta) => {
|
35030
|
-
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
35031
|
-
return meta.tables[`"${tableName}"`].substring(
|
35032
|
-
1,
|
35033
|
-
meta.tables[`"${tableName}"`].length - 1
|
35034
|
-
);
|
35035
|
-
}
|
35036
|
-
return tableName;
|
35037
|
-
};
|
35038
|
-
var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
35039
|
-
let shouldAskForApprove = false;
|
35040
|
-
const statementsToExecute = [];
|
35041
|
-
const infoToPrint = [];
|
35042
|
-
const tablesToRemove = [];
|
35043
|
-
const columnsToRemove = [];
|
35044
|
-
const schemasToRemove = [];
|
35045
|
-
const tablesToTruncate = [];
|
35046
|
-
const tablesContext = {};
|
35047
|
-
for (const statement of statements) {
|
35048
|
-
if (statement.type === "drop_table") {
|
35049
|
-
const res = await connection.query(
|
35050
|
-
`select count(*) as count from \`${statement.tableName}\``
|
35051
|
-
);
|
35052
|
-
const count2 = Number(res[0].count);
|
35053
|
-
if (count2 > 0) {
|
35054
|
-
infoToPrint.push(
|
35055
|
-
`\xB7 You're about to delete ${source_default.underline(
|
35056
|
-
statement.tableName
|
35057
|
-
)} table with ${count2} items`
|
35058
|
-
);
|
35059
|
-
tablesToRemove.push(statement.tableName);
|
35060
|
-
shouldAskForApprove = true;
|
35061
|
-
}
|
35062
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35063
|
-
statementsToExecute.push(stmnt);
|
35064
|
-
} else if (statement.type === "alter_table_drop_column") {
|
35065
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35066
|
-
const columnIsPartOfPk = Object.values(
|
35067
|
-
json1.tables[newTableName].compositePrimaryKeys
|
35068
|
-
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
35069
|
-
const columnIsPartOfIndex = Object.values(
|
35070
|
-
json1.tables[newTableName].indexes
|
35071
|
-
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
35072
|
-
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
35073
|
-
const columnIsPartOfFk = Object.values(
|
35074
|
-
json1.tables[newTableName].foreignKeys
|
35075
|
-
).find(
|
35076
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
|
35077
|
-
statement.columnName
|
35078
|
-
)
|
35079
|
-
);
|
35080
|
-
const res = await connection.query(
|
35081
|
-
`select count(*) as count from \`${newTableName}\``
|
35082
|
-
);
|
35083
|
-
const count2 = Number(res[0].count);
|
35084
|
-
if (count2 > 0) {
|
35085
|
-
infoToPrint.push(
|
35086
|
-
`\xB7 You're about to delete ${source_default.underline(
|
35087
|
-
statement.columnName
|
35088
|
-
)} column in ${newTableName} table with ${count2} items`
|
35089
|
-
);
|
35090
|
-
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
35091
|
-
shouldAskForApprove = true;
|
35092
|
-
}
|
35093
|
-
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
35094
|
-
tablesContext[newTableName] = [
|
35095
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
35096
|
-
];
|
35097
|
-
const tablesReferncingCurrent = [];
|
35098
|
-
for (const table4 of Object.values(json1.tables)) {
|
35099
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35100
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35101
|
-
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35102
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35103
|
-
}
|
35104
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35105
|
-
for (const table4 of uniqueTableRefs) {
|
35106
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35107
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35108
|
-
}
|
35109
|
-
}
|
35110
|
-
} else {
|
35111
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35112
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35113
|
-
statementsToExecute.push(stmnt);
|
35114
|
-
}
|
35115
|
-
}
|
35116
|
-
} else if (statement.type === "sqlite_alter_table_add_column") {
|
35117
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35118
|
-
if (statement.column.notNull && !statement.column.default) {
|
35119
|
-
const res = await connection.query(
|
35120
|
-
`select count(*) as count from \`${newTableName}\``
|
35121
|
-
);
|
35122
|
-
const count2 = Number(res[0].count);
|
35123
|
-
if (count2 > 0) {
|
35124
|
-
infoToPrint.push(
|
35125
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
35126
|
-
statement.column.name
|
35127
|
-
)} column without default value, which contains ${count2} items`
|
35128
|
-
);
|
35129
|
-
tablesToTruncate.push(newTableName);
|
35130
|
-
statementsToExecute.push(`delete from ${newTableName};`);
|
35131
|
-
shouldAskForApprove = true;
|
35132
|
-
}
|
35133
|
-
}
|
35134
|
-
if (statement.column.primaryKey) {
|
35135
|
-
tablesContext[newTableName] = [
|
35136
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
35137
|
-
];
|
35138
|
-
const tablesReferncingCurrent = [];
|
35139
|
-
for (const table4 of Object.values(json1.tables)) {
|
35140
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35141
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35142
|
-
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35143
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35144
|
-
}
|
35145
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35146
|
-
for (const table4 of uniqueTableRefs) {
|
35147
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35148
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35149
|
-
}
|
35150
|
-
}
|
35151
|
-
} else {
|
35152
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35153
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35154
|
-
statementsToExecute.push(stmnt);
|
35155
|
-
}
|
35156
|
-
}
|
35157
|
-
} 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") {
|
35158
|
-
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
35159
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35160
|
-
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
35161
|
-
const res = await connection.query(
|
35162
|
-
`select count(*) as count from \`${newTableName}\``
|
35163
|
-
);
|
35164
|
-
const count2 = Number(res[0].count);
|
35165
|
-
if (count2 > 0) {
|
35166
|
-
infoToPrint.push(
|
35167
|
-
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
35168
|
-
statement.columnName
|
35169
|
-
)} column without default value, which contains ${count2} items`
|
35170
|
-
);
|
35171
|
-
tablesToTruncate.push(newTableName);
|
35172
|
-
shouldAskForApprove = true;
|
35173
|
-
}
|
35174
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35175
|
-
statement.tableName,
|
35176
|
-
json1,
|
35177
|
-
true
|
35178
|
-
);
|
35179
|
-
} else {
|
35180
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35181
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35182
|
-
statement.tableName,
|
35183
|
-
json1
|
35184
|
-
);
|
35185
|
-
}
|
35186
|
-
}
|
35187
|
-
const tablesReferncingCurrent = [];
|
35188
|
-
for (const table4 of Object.values(json1.tables)) {
|
35189
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35190
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35191
|
-
).map((t) => {
|
35192
|
-
return getNewTableName(
|
35193
|
-
SQLiteSquasher.unsquashPushFK(t).tableFrom,
|
35194
|
-
meta
|
35195
|
-
);
|
35196
|
-
});
|
35197
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35198
|
-
}
|
35199
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35200
|
-
for (const table4 of uniqueTableRefs) {
|
35201
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35202
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
35203
|
-
}
|
35204
|
-
}
|
35205
|
-
}
|
35206
|
-
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
35207
|
-
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
35208
|
-
if (typeof tablesContext[statement.tableName] === "undefined") {
|
35209
|
-
tablesContext[statement.tableName] = _moveDataStatements(
|
35210
|
-
statement.tableName,
|
35211
|
-
json2
|
35212
|
-
);
|
35213
|
-
}
|
35214
|
-
} 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") {
|
35215
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35216
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35217
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35218
|
-
statement.tableName,
|
35219
|
-
json2
|
35220
|
-
);
|
35221
|
-
}
|
35222
|
-
} else {
|
35223
|
-
const stmnt = fromJson([statement], "sqlite");
|
35224
|
-
if (typeof stmnt !== "undefined") {
|
35225
|
-
statementsToExecute.push(...stmnt);
|
35226
|
-
}
|
35227
|
-
}
|
35228
|
-
}
|
35229
|
-
for (const context of Object.values(tablesContext)) {
|
35230
|
-
statementsToExecute.push(...context);
|
35231
|
-
}
|
35232
|
-
return {
|
35233
|
-
statementsToExecute,
|
35234
|
-
shouldAskForApprove,
|
35235
|
-
infoToPrint,
|
35236
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
35237
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
35238
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
35239
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
35240
|
-
};
|
35241
|
-
};
|
35242
|
-
|
35243
36147
|
// src/api.ts
|
36148
|
+
init_sqlitePushUtils();
|
35244
36149
|
init_global();
|
35245
36150
|
init_migrationPreparator();
|
35246
36151
|
init_mysqlSchema();
|
@@ -35473,7 +36378,13 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
|
|
35473
36378
|
};
|
35474
36379
|
};
|
35475
36380
|
var upPgSnapshot = (snapshot) => {
|
35476
|
-
|
36381
|
+
if (snapshot.version === "5") {
|
36382
|
+
return updateUpToV7(updateUpToV6(snapshot));
|
36383
|
+
}
|
36384
|
+
if (snapshot.version === "6") {
|
36385
|
+
return updateUpToV7(snapshot);
|
36386
|
+
}
|
36387
|
+
return snapshot;
|
35477
36388
|
};
|
35478
36389
|
// Annotate the CommonJS export names for ESM import in node:
|
35479
36390
|
0 && (module.exports = {
|