drizzle-kit 0.24.0-38d6dab → 0.24.0-6386ea9
Sign up to get free protection for your applications and to get access to all the features.
- package/api.js +411 -1242
- package/api.mjs +411 -1242
- package/bin.cjs +950 -1796
- package/package.json +3 -3
- package/utils.js +0 -9
- package/utils.mjs +0 -8
package/api.js
CHANGED
@@ -8341,13 +8341,6 @@ var init_sqliteSchema = __esm({
|
|
8341
8341
|
function isPgArrayType(sqlType) {
|
8342
8342
|
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8343
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
|
-
}
|
8351
8344
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8352
8345
|
var init_utils = __esm({
|
8353
8346
|
"src/utils.ts"() {
|
@@ -11457,20 +11450,7 @@ var init_jsonDiffer = __esm({
|
|
11457
11450
|
});
|
11458
11451
|
|
11459
11452
|
// src/sqlgenerator.ts
|
11460
|
-
|
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;
|
11453
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
11474
11454
|
var init_sqlgenerator = __esm({
|
11475
11455
|
"src/sqlgenerator.ts"() {
|
11476
11456
|
"use strict";
|
@@ -11986,7 +11966,7 @@ var init_sqlgenerator = __esm({
|
|
11986
11966
|
}
|
11987
11967
|
convert(statement) {
|
11988
11968
|
const { tableName, oldColumnName, newColumnName } = statement;
|
11989
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
11969
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
|
11990
11970
|
}
|
11991
11971
|
};
|
11992
11972
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -12088,8 +12068,8 @@ var init_sqlgenerator = __esm({
|
|
12088
12068
|
}
|
12089
12069
|
};
|
12090
12070
|
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
12091
|
-
can(statement, dialect7
|
12092
|
-
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite"
|
12071
|
+
can(statement, dialect7) {
|
12072
|
+
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
12093
12073
|
}
|
12094
12074
|
convert(statement) {
|
12095
12075
|
return `/*
|
@@ -12400,46 +12380,6 @@ var init_sqlgenerator = __esm({
|
|
12400
12380
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
12401
12381
|
}
|
12402
12382
|
};
|
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
|
-
};
|
12443
12383
|
MySqlModifyColumn = class extends Convertor {
|
12444
12384
|
can(statement, dialect7) {
|
12445
12385
|
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";
|
@@ -12780,8 +12720,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12780
12720
|
}
|
12781
12721
|
};
|
12782
12722
|
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
12783
|
-
can(statement, dialect7
|
12784
|
-
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite"
|
12723
|
+
can(statement, dialect7) {
|
12724
|
+
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
12785
12725
|
}
|
12786
12726
|
convert(statement) {
|
12787
12727
|
return `/*
|
@@ -12795,8 +12735,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12795
12735
|
}
|
12796
12736
|
};
|
12797
12737
|
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
12798
|
-
can(statement, dialect7
|
12799
|
-
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite"
|
12738
|
+
can(statement, dialect7) {
|
12739
|
+
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
12800
12740
|
}
|
12801
12741
|
convert(statement) {
|
12802
12742
|
return `/*
|
@@ -12810,8 +12750,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12810
12750
|
}
|
12811
12751
|
};
|
12812
12752
|
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
12813
|
-
can(statement, dialect7
|
12814
|
-
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite"
|
12753
|
+
can(statement, dialect7) {
|
12754
|
+
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
12815
12755
|
}
|
12816
12756
|
convert(statement) {
|
12817
12757
|
return `/*
|
@@ -12835,8 +12775,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12835
12775
|
}
|
12836
12776
|
};
|
12837
12777
|
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12838
|
-
can(statement, dialect7
|
12839
|
-
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite"
|
12778
|
+
can(statement, dialect7) {
|
12779
|
+
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
12840
12780
|
}
|
12841
12781
|
convert(statement) {
|
12842
12782
|
return `/*
|
@@ -12880,8 +12820,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12880
12820
|
}
|
12881
12821
|
};
|
12882
12822
|
SqliteCreateForeignKeyConvertor = class extends Convertor {
|
12883
|
-
can(statement, dialect7
|
12884
|
-
return statement.type === "create_reference" && dialect7 === "sqlite"
|
12823
|
+
can(statement, dialect7) {
|
12824
|
+
return statement.type === "create_reference" && dialect7 === "sqlite";
|
12885
12825
|
}
|
12886
12826
|
convert(statement) {
|
12887
12827
|
return `/*
|
@@ -12893,32 +12833,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12893
12833
|
*/`;
|
12894
12834
|
}
|
12895
12835
|
};
|
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
|
-
};
|
12922
12836
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
12923
12837
|
can(statement, dialect7) {
|
12924
12838
|
return statement.type === "create_reference" && dialect7 === "mysql";
|
@@ -12992,8 +12906,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12992
12906
|
}
|
12993
12907
|
};
|
12994
12908
|
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
12995
|
-
can(statement, dialect7
|
12996
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite"
|
12909
|
+
can(statement, dialect7) {
|
12910
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
12997
12911
|
}
|
12998
12912
|
convert(statement) {
|
12999
12913
|
return `/*
|
@@ -13005,29 +12919,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13005
12919
|
*/`;
|
13006
12920
|
}
|
13007
12921
|
};
|
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
|
-
};
|
13031
12922
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
13032
12923
|
can(statement, dialect7) {
|
13033
12924
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -13191,90 +13082,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13191
13082
|
return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
|
13192
13083
|
}
|
13193
13084
|
};
|
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
|
-
};
|
13272
13085
|
convertors = [];
|
13273
13086
|
convertors.push(new PgCreateTableConvertor());
|
13274
13087
|
convertors.push(new MySqlCreateTableConvertor());
|
13275
13088
|
convertors.push(new SQLiteCreateTableConvertor());
|
13276
|
-
convertors.push(new SQLiteRecreateTableConvertor());
|
13277
|
-
convertors.push(new LibSQLRecreateTableConvertor());
|
13278
13089
|
convertors.push(new CreateTypeEnumConvertor());
|
13279
13090
|
convertors.push(new CreatePgSequenceConvertor());
|
13280
13091
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13322,7 +13133,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13322
13133
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
13323
13134
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
13324
13135
|
convertors.push(new MySqlModifyColumn());
|
13325
|
-
convertors.push(new LibSQLModifyColumn());
|
13326
13136
|
convertors.push(new PgCreateForeignKeyConvertor());
|
13327
13137
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
13328
13138
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -13337,9 +13147,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13337
13147
|
convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
13338
13148
|
convertors.push(new SqliteAlterForeignKeyConvertor());
|
13339
13149
|
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
13340
|
-
convertors.push(new LibSQLDeleteForeignKeyConvertor());
|
13341
13150
|
convertors.push(new SqliteCreateForeignKeyConvertor());
|
13342
|
-
convertors.push(new LibSQLCreateForeignKeyConvertor());
|
13343
13151
|
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
13344
13152
|
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
13345
13153
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
@@ -13362,6 +13170,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13362
13170
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
13363
13171
|
convertors.push(new MySqlAlterTableAddPk());
|
13364
13172
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
13173
|
+
fromJson = (statements, dialect7) => {
|
13174
|
+
const result = statements.flatMap((statement) => {
|
13175
|
+
const filtered = convertors.filter((it) => {
|
13176
|
+
return it.can(statement, dialect7);
|
13177
|
+
});
|
13178
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
13179
|
+
if (!convertor) {
|
13180
|
+
return "";
|
13181
|
+
}
|
13182
|
+
return convertor.convert(statement);
|
13183
|
+
}).filter((it) => it !== "");
|
13184
|
+
return result;
|
13185
|
+
};
|
13365
13186
|
https: `
|
13366
13187
|
create table users (
|
13367
13188
|
id int,
|
@@ -13388,237 +13209,12 @@ drop type __venum;
|
|
13388
13209
|
}
|
13389
13210
|
});
|
13390
13211
|
|
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
|
-
|
13615
13212
|
// src/jsonStatements.ts
|
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,
|
13213
|
+
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;
|
13617
13214
|
var init_jsonStatements = __esm({
|
13618
13215
|
"src/jsonStatements.ts"() {
|
13619
13216
|
"use strict";
|
13620
13217
|
init_source();
|
13621
|
-
init_sqlitePushUtils();
|
13622
13218
|
init_views();
|
13623
13219
|
init_mysqlSchema();
|
13624
13220
|
init_pgSchema();
|
@@ -14402,49 +13998,6 @@ var init_jsonStatements = __esm({
|
|
14402
13998
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
14403
13999
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
14404
14000
|
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
|
-
}
|
14448
14001
|
if (typeof column4.name !== "string") {
|
14449
14002
|
statements.push({
|
14450
14003
|
type: "alter_table_rename_column",
|
@@ -14708,111 +14261,33 @@ var init_jsonStatements = __esm({
|
|
14708
14261
|
};
|
14709
14262
|
});
|
14710
14263
|
};
|
14711
|
-
|
14264
|
+
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14712
14265
|
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];
|
14731
14266
|
return {
|
14732
|
-
type: "
|
14267
|
+
type: "delete_reference",
|
14733
14268
|
tableName,
|
14734
14269
|
data: fkData,
|
14735
|
-
schema: schema4
|
14736
|
-
columnNotNull,
|
14737
|
-
columnDefault,
|
14738
|
-
columnType
|
14270
|
+
schema: schema4
|
14739
14271
|
};
|
14740
14272
|
});
|
14741
14273
|
};
|
14742
|
-
|
14743
|
-
|
14744
|
-
|
14274
|
+
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
14275
|
+
const stmts = [];
|
14276
|
+
Object.values(foreignKeys).map((val) => {
|
14277
|
+
stmts.push({
|
14745
14278
|
type: "delete_reference",
|
14746
14279
|
tableName,
|
14747
|
-
|
14748
|
-
|
14749
|
-
};
|
14280
|
+
schema: schema4,
|
14281
|
+
data: val.__old
|
14282
|
+
});
|
14283
|
+
stmts.push({
|
14284
|
+
type: "create_reference",
|
14285
|
+
tableName,
|
14286
|
+
schema: schema4,
|
14287
|
+
data: val.__new
|
14288
|
+
});
|
14750
14289
|
});
|
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;
|
14290
|
+
return stmts;
|
14816
14291
|
};
|
14817
14292
|
prepareDropIndexesJson = (tableName, schema4, indexes) => {
|
14818
14293
|
return Object.values(indexes).map((indexData) => {
|
@@ -14949,298 +14424,10 @@ var init_jsonStatements = __esm({
|
|
14949
14424
|
}
|
14950
14425
|
});
|
14951
14426
|
|
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
|
-
|
15239
14427
|
// src/snapshotsDiffer.ts
|
15240
14428
|
var snapshotsDiffer_exports = {};
|
15241
14429
|
__export(snapshotsDiffer_exports, {
|
15242
14430
|
alteredTableScheme: () => alteredTableScheme,
|
15243
|
-
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
15244
14431
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
15245
14432
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
15246
14433
|
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
@@ -15250,7 +14437,7 @@ __export(snapshotsDiffer_exports, {
|
|
15250
14437
|
makePatched: () => makePatched,
|
15251
14438
|
makeSelfOrPatched: () => makeSelfOrPatched
|
15252
14439
|
});
|
15253
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff
|
14440
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
15254
14441
|
var init_snapshotsDiffer = __esm({
|
15255
14442
|
"src/snapshotsDiffer.ts"() {
|
15256
14443
|
"use strict";
|
@@ -15262,7 +14449,6 @@ var init_snapshotsDiffer = __esm({
|
|
15262
14449
|
init_mysqlSchema();
|
15263
14450
|
init_pgSchema();
|
15264
14451
|
init_sqliteSchema();
|
15265
|
-
init_statementCombiner();
|
15266
14452
|
init_utils();
|
15267
14453
|
makeChanged = (schema4) => {
|
15268
14454
|
return objectType({
|
@@ -16136,352 +15322,53 @@ var init_snapshotsDiffer = __esm({
|
|
16136
15322
|
curFull.internal
|
16137
15323
|
);
|
16138
15324
|
}).flat();
|
16139
|
-
const jsonDropTables = deletedTables.map((it) => {
|
16140
|
-
return prepareDropTableJson(it);
|
16141
|
-
});
|
16142
|
-
const jsonRenameTables = renamedTables.map((it) => {
|
16143
|
-
return prepareRenameTableJson(it.from, it.to);
|
16144
|
-
});
|
16145
|
-
const alteredTables = typedResult.alteredTablesWithColumns;
|
16146
|
-
const jsonAddedCompositePKs = [];
|
16147
|
-
const jsonDeletedCompositePKs = [];
|
16148
|
-
const jsonAlteredCompositePKs = [];
|
16149
|
-
const jsonAddedUniqueConstraints = [];
|
16150
|
-
const jsonDeletedUniqueConstraints = [];
|
16151
|
-
const jsonAlteredUniqueConstraints = [];
|
16152
|
-
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16153
|
-
const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
|
16154
|
-
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
16155
|
-
alteredTables.forEach((it) => {
|
16156
|
-
let addedColumns = [];
|
16157
|
-
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16158
|
-
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16159
|
-
addedColumns = MySqlSquasher.unsquashPK(addedPkColumns).columns;
|
16160
|
-
}
|
16161
|
-
let deletedColumns = [];
|
16162
|
-
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16163
|
-
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16164
|
-
deletedColumns = MySqlSquasher.unsquashPK(deletedPkColumns).columns;
|
16165
|
-
}
|
16166
|
-
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16167
|
-
let addedCompositePKs = [];
|
16168
|
-
let deletedCompositePKs = [];
|
16169
|
-
let alteredCompositePKs = [];
|
16170
|
-
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
16171
|
-
it.name,
|
16172
|
-
it.addedCompositePKs,
|
16173
|
-
prevFull,
|
16174
|
-
curFull
|
16175
|
-
);
|
16176
|
-
deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
|
16177
|
-
it.name,
|
16178
|
-
it.deletedCompositePKs,
|
16179
|
-
prevFull
|
16180
|
-
);
|
16181
|
-
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
16182
|
-
it.name,
|
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;
|
15325
|
+
const jsonDropTables = deletedTables.map((it) => {
|
15326
|
+
return prepareDropTableJson(it);
|
15327
|
+
});
|
15328
|
+
const jsonRenameTables = renamedTables.map((it) => {
|
15329
|
+
return prepareRenameTableJson(it.from, it.to);
|
15330
|
+
});
|
15331
|
+
const alteredTables = typedResult.alteredTablesWithColumns;
|
16451
15332
|
const jsonAddedCompositePKs = [];
|
16452
15333
|
const jsonDeletedCompositePKs = [];
|
16453
15334
|
const jsonAlteredCompositePKs = [];
|
16454
15335
|
const jsonAddedUniqueConstraints = [];
|
16455
15336
|
const jsonDeletedUniqueConstraints = [];
|
16456
15337
|
const jsonAlteredUniqueConstraints = [];
|
16457
|
-
|
15338
|
+
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
15339
|
+
const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
|
15340
|
+
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
15341
|
+
alteredTables.forEach((it) => {
|
16458
15342
|
let addedColumns = [];
|
16459
15343
|
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16460
15344
|
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16461
|
-
addedColumns =
|
15345
|
+
addedColumns = MySqlSquasher.unsquashPK(addedPkColumns).columns;
|
16462
15346
|
}
|
16463
15347
|
let deletedColumns = [];
|
16464
15348
|
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16465
15349
|
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16466
|
-
deletedColumns =
|
15350
|
+
deletedColumns = MySqlSquasher.unsquashPK(deletedPkColumns).columns;
|
16467
15351
|
}
|
16468
15352
|
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16469
15353
|
let addedCompositePKs = [];
|
16470
15354
|
let deletedCompositePKs = [];
|
16471
15355
|
let alteredCompositePKs = [];
|
16472
|
-
|
16473
|
-
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
16474
|
-
it.name,
|
16475
|
-
it.addedCompositePKs
|
16476
|
-
);
|
16477
|
-
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
16478
|
-
it.name,
|
16479
|
-
it.deletedCompositePKs
|
16480
|
-
);
|
16481
|
-
}
|
16482
|
-
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
15356
|
+
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
16483
15357
|
it.name,
|
16484
|
-
it.
|
15358
|
+
it.addedCompositePKs,
|
15359
|
+
prevFull,
|
15360
|
+
curFull
|
15361
|
+
);
|
15362
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeyMySql(
|
15363
|
+
it.name,
|
15364
|
+
it.deletedCompositePKs,
|
15365
|
+
prevFull
|
15366
|
+
);
|
15367
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeyMySql(
|
15368
|
+
it.name,
|
15369
|
+
it.alteredCompositePKs,
|
15370
|
+
prevFull,
|
15371
|
+
curFull
|
16485
15372
|
);
|
16486
15373
|
let addedUniqueConstraints = [];
|
16487
15374
|
let deletedUniqueConstraints = [];
|
@@ -16525,10 +15412,17 @@ var init_snapshotsDiffer = __esm({
|
|
16525
15412
|
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16526
15413
|
};
|
16527
15414
|
});
|
16528
|
-
const jsonTableAlternations =
|
16529
|
-
return
|
15415
|
+
const jsonTableAlternations = alteredTables.map((it) => {
|
15416
|
+
return prepareAlterColumnsMysql(
|
15417
|
+
it.name,
|
15418
|
+
it.schema,
|
15419
|
+
it.altered,
|
15420
|
+
json1,
|
15421
|
+
json2,
|
15422
|
+
action
|
15423
|
+
);
|
16530
15424
|
}).flat();
|
16531
|
-
const jsonCreateIndexesForAllAlteredTables =
|
15425
|
+
const jsonCreateIndexesForAllAlteredTables = alteredTables.map((it) => {
|
16532
15426
|
return prepareCreateIndexesJson(
|
16533
15427
|
it.name,
|
16534
15428
|
it.schema,
|
@@ -16536,14 +15430,14 @@ var init_snapshotsDiffer = __esm({
|
|
16536
15430
|
curFull.internal
|
16537
15431
|
);
|
16538
15432
|
}).flat();
|
16539
|
-
const jsonDropIndexesForAllAlteredTables =
|
15433
|
+
const jsonDropIndexesForAllAlteredTables = alteredTables.map((it) => {
|
16540
15434
|
return prepareDropIndexesJson(
|
16541
15435
|
it.name,
|
16542
15436
|
it.schema,
|
16543
15437
|
it.deletedIndexes || {}
|
16544
15438
|
);
|
16545
15439
|
}).flat();
|
16546
|
-
|
15440
|
+
alteredTables.forEach((it) => {
|
16547
15441
|
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
16548
15442
|
(current, item) => {
|
16549
15443
|
current[item] = it.alteredIndexes[item].__old;
|
@@ -16559,18 +15453,16 @@ var init_snapshotsDiffer = __esm({
|
|
16559
15453
|
{}
|
16560
15454
|
);
|
16561
15455
|
jsonCreateIndexesForAllAlteredTables.push(
|
16562
|
-
...prepareCreateIndexesJson(
|
16563
|
-
it.name,
|
16564
|
-
it.schema,
|
16565
|
-
createdIndexes || {},
|
16566
|
-
curFull.internal
|
16567
|
-
)
|
15456
|
+
...prepareCreateIndexesJson(it.name, it.schema, createdIndexes || {})
|
16568
15457
|
);
|
16569
15458
|
jsonDropIndexesForAllAlteredTables.push(
|
16570
15459
|
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
16571
15460
|
);
|
16572
15461
|
});
|
16573
|
-
const
|
15462
|
+
const jsonCreateReferencesForCreatedTables = createdTables.map((it) => {
|
15463
|
+
return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
|
15464
|
+
}).flat();
|
15465
|
+
const jsonReferencesForAllAlteredTables = alteredTables.map((it) => {
|
16574
15466
|
const forAdded = prepareCreateReferencesJson(
|
16575
15467
|
it.name,
|
16576
15468
|
it.schema,
|
@@ -16594,25 +15486,35 @@ var init_snapshotsDiffer = __esm({
|
|
16594
15486
|
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16595
15487
|
(t) => t.type === "delete_reference"
|
16596
15488
|
);
|
16597
|
-
const
|
16598
|
-
|
15489
|
+
const jsonMySqlCreateTables = createdTables.map((it) => {
|
15490
|
+
return prepareMySqlCreateTableJson(
|
15491
|
+
it,
|
15492
|
+
curFull,
|
15493
|
+
curFull.internal
|
15494
|
+
);
|
15495
|
+
});
|
15496
|
+
jsonStatements.push(...jsonMySqlCreateTables);
|
16599
15497
|
jsonStatements.push(...jsonDropTables);
|
16600
15498
|
jsonStatements.push(...jsonRenameTables);
|
16601
15499
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15500
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16602
15501
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16603
15502
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16604
15503
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16605
15504
|
jsonStatements.push(...jsonTableAlternations);
|
16606
15505
|
jsonStatements.push(...jsonAddedCompositePKs);
|
15506
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15507
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16607
15508
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
15509
|
+
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16608
15510
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16609
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16610
15511
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
15512
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16611
15513
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16612
15514
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15515
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16613
15516
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16614
|
-
const
|
16615
|
-
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
15517
|
+
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16616
15518
|
const uniqueSqlStatements = [];
|
16617
15519
|
sqlStatements.forEach((ss) => {
|
16618
15520
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -16624,12 +15526,12 @@ var init_snapshotsDiffer = __esm({
|
|
16624
15526
|
});
|
16625
15527
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16626
15528
|
return {
|
16627
|
-
statements:
|
15529
|
+
statements: jsonStatements,
|
16628
15530
|
sqlStatements: uniqueSqlStatements,
|
16629
15531
|
_meta
|
16630
15532
|
};
|
16631
15533
|
};
|
16632
|
-
|
15534
|
+
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16633
15535
|
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16634
15536
|
const {
|
16635
15537
|
created: createdTables,
|
@@ -16731,18 +15633,6 @@ var init_snapshotsDiffer = __esm({
|
|
16731
15633
|
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16732
15634
|
);
|
16733
15635
|
}).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);
|
16746
15636
|
const allAltered = typedResult.alteredTablesWithColumns;
|
16747
15637
|
const jsonAddedCompositePKs = [];
|
16748
15638
|
const jsonDeletedCompositePKs = [];
|
@@ -16813,6 +15703,14 @@ var init_snapshotsDiffer = __esm({
|
|
16813
15703
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16814
15704
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16815
15705
|
});
|
15706
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
15707
|
+
const tableName = it.tableName;
|
15708
|
+
const schema4 = it.schema;
|
15709
|
+
return {
|
15710
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
15711
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
15712
|
+
};
|
15713
|
+
});
|
16816
15714
|
const jsonTableAlternations = allAltered.map((it) => {
|
16817
15715
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16818
15716
|
}).flat();
|
@@ -16859,22 +15757,21 @@ var init_snapshotsDiffer = __esm({
|
|
16859
15757
|
);
|
16860
15758
|
});
|
16861
15759
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16862
|
-
const forAdded =
|
15760
|
+
const forAdded = prepareCreateReferencesJson(
|
16863
15761
|
it.name,
|
16864
15762
|
it.schema,
|
16865
|
-
it.addedForeignKeys
|
16866
|
-
json2,
|
16867
|
-
action
|
15763
|
+
it.addedForeignKeys
|
16868
15764
|
);
|
16869
|
-
const forAltered =
|
15765
|
+
const forAltered = prepareDropReferencesJson(
|
16870
15766
|
it.name,
|
16871
15767
|
it.schema,
|
16872
|
-
it.deletedForeignKeys
|
16873
|
-
|
16874
|
-
|
16875
|
-
|
15768
|
+
it.deletedForeignKeys
|
15769
|
+
);
|
15770
|
+
const alteredFKs = prepareAlterReferencesJson(
|
15771
|
+
it.name,
|
15772
|
+
it.schema,
|
15773
|
+
it.alteredForeignKeys
|
16876
15774
|
);
|
16877
|
-
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
16878
15775
|
return [...forAdded, ...forAltered, ...alteredFKs];
|
16879
15776
|
}).flat();
|
16880
15777
|
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
@@ -16900,22 +15797,19 @@ var init_snapshotsDiffer = __esm({
|
|
16900
15797
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16901
15798
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16902
15799
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16903
|
-
const
|
16904
|
-
const sqlStatements = fromJson(
|
16905
|
-
combinedJsonStatements,
|
16906
|
-
"sqlite",
|
16907
|
-
action,
|
16908
|
-
"turso",
|
16909
|
-
json2
|
16910
|
-
);
|
15800
|
+
const sqlStatements = fromJson(jsonStatements, "sqlite");
|
16911
15801
|
const uniqueSqlStatements = [];
|
16912
15802
|
sqlStatements.forEach((ss) => {
|
16913
15803
|
if (!uniqueSqlStatements.includes(ss)) {
|
16914
15804
|
uniqueSqlStatements.push(ss);
|
16915
15805
|
}
|
16916
15806
|
});
|
15807
|
+
const rTables = renamedTables.map((it) => {
|
15808
|
+
return { from: it.from, to: it.to };
|
15809
|
+
});
|
15810
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16917
15811
|
return {
|
16918
|
-
statements:
|
15812
|
+
statements: jsonStatements,
|
16919
15813
|
sqlStatements: uniqueSqlStatements,
|
16920
15814
|
_meta
|
16921
15815
|
};
|
@@ -34977,8 +33871,7 @@ var init_cli = __esm({
|
|
34977
33871
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34978
33872
|
extensionsFilters: literalType("postgis").array().optional(),
|
34979
33873
|
verbose: booleanType().optional(),
|
34980
|
-
strict: booleanType().optional()
|
34981
|
-
driver: driver.optional()
|
33874
|
+
strict: booleanType().optional()
|
34982
33875
|
}).passthrough();
|
34983
33876
|
pullParams = objectType({
|
34984
33877
|
config: stringType().optional(),
|
@@ -36144,8 +35037,284 @@ var sqlitePushIntrospect = async (db, filters) => {
|
|
36144
35037
|
return { schema: schema4 };
|
36145
35038
|
};
|
36146
35039
|
|
35040
|
+
// src/cli/commands/sqlitePushUtils.ts
|
35041
|
+
init_source();
|
35042
|
+
init_sqliteSchema();
|
35043
|
+
init_sqlgenerator();
|
35044
|
+
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
35045
|
+
const statements = [];
|
35046
|
+
statements.push(
|
35047
|
+
new SqliteRenameTableConvertor().convert({
|
35048
|
+
type: "rename_table",
|
35049
|
+
tableNameFrom: tableName,
|
35050
|
+
tableNameTo: `__old_push_${tableName}`,
|
35051
|
+
fromSchema: "",
|
35052
|
+
toSchema: ""
|
35053
|
+
})
|
35054
|
+
);
|
35055
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
35056
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
35057
|
+
const compositePKs = Object.values(
|
35058
|
+
json.tables[tableName].compositePrimaryKeys
|
35059
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
35060
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
35061
|
+
statements.push(
|
35062
|
+
new SQLiteCreateTableConvertor().convert({
|
35063
|
+
type: "sqlite_create_table",
|
35064
|
+
tableName,
|
35065
|
+
columns: tableColumns,
|
35066
|
+
referenceData: fks,
|
35067
|
+
compositePKs
|
35068
|
+
})
|
35069
|
+
);
|
35070
|
+
if (!dataLoss) {
|
35071
|
+
statements.push(
|
35072
|
+
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
35073
|
+
);
|
35074
|
+
}
|
35075
|
+
statements.push(
|
35076
|
+
new SQLiteDropTableConvertor().convert({
|
35077
|
+
type: "drop_table",
|
35078
|
+
tableName: `__old_push_${tableName}`,
|
35079
|
+
schema: ""
|
35080
|
+
})
|
35081
|
+
);
|
35082
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
35083
|
+
statements.push(
|
35084
|
+
new CreateSqliteIndexConvertor().convert({
|
35085
|
+
type: "create_index",
|
35086
|
+
tableName,
|
35087
|
+
schema: "",
|
35088
|
+
data: idx
|
35089
|
+
})
|
35090
|
+
);
|
35091
|
+
}
|
35092
|
+
return statements;
|
35093
|
+
};
|
35094
|
+
var getOldTableName = (tableName, meta) => {
|
35095
|
+
for (const key of Object.keys(meta.tables)) {
|
35096
|
+
const value = meta.tables[key];
|
35097
|
+
if (`"${tableName}"` === value) {
|
35098
|
+
return key.substring(1, key.length - 1);
|
35099
|
+
}
|
35100
|
+
}
|
35101
|
+
return tableName;
|
35102
|
+
};
|
35103
|
+
var getNewTableName = (tableName, meta) => {
|
35104
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
35105
|
+
return meta.tables[`"${tableName}"`].substring(
|
35106
|
+
1,
|
35107
|
+
meta.tables[`"${tableName}"`].length - 1
|
35108
|
+
);
|
35109
|
+
}
|
35110
|
+
return tableName;
|
35111
|
+
};
|
35112
|
+
var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
35113
|
+
let shouldAskForApprove = false;
|
35114
|
+
const statementsToExecute = [];
|
35115
|
+
const infoToPrint = [];
|
35116
|
+
const tablesToRemove = [];
|
35117
|
+
const columnsToRemove = [];
|
35118
|
+
const schemasToRemove = [];
|
35119
|
+
const tablesToTruncate = [];
|
35120
|
+
const tablesContext = {};
|
35121
|
+
for (const statement of statements) {
|
35122
|
+
if (statement.type === "drop_table") {
|
35123
|
+
const res = await connection.query(
|
35124
|
+
`select count(*) as count from \`${statement.tableName}\``
|
35125
|
+
);
|
35126
|
+
const count2 = Number(res[0].count);
|
35127
|
+
if (count2 > 0) {
|
35128
|
+
infoToPrint.push(
|
35129
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35130
|
+
statement.tableName
|
35131
|
+
)} table with ${count2} items`
|
35132
|
+
);
|
35133
|
+
tablesToRemove.push(statement.tableName);
|
35134
|
+
shouldAskForApprove = true;
|
35135
|
+
}
|
35136
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35137
|
+
statementsToExecute.push(stmnt);
|
35138
|
+
} else if (statement.type === "alter_table_drop_column") {
|
35139
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35140
|
+
const columnIsPartOfPk = Object.values(
|
35141
|
+
json1.tables[newTableName].compositePrimaryKeys
|
35142
|
+
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
35143
|
+
const columnIsPartOfIndex = Object.values(
|
35144
|
+
json1.tables[newTableName].indexes
|
35145
|
+
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
35146
|
+
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
35147
|
+
const columnIsPartOfFk = Object.values(
|
35148
|
+
json1.tables[newTableName].foreignKeys
|
35149
|
+
).find(
|
35150
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
|
35151
|
+
statement.columnName
|
35152
|
+
)
|
35153
|
+
);
|
35154
|
+
const res = await connection.query(
|
35155
|
+
`select count(*) as count from \`${newTableName}\``
|
35156
|
+
);
|
35157
|
+
const count2 = Number(res[0].count);
|
35158
|
+
if (count2 > 0) {
|
35159
|
+
infoToPrint.push(
|
35160
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35161
|
+
statement.columnName
|
35162
|
+
)} column in ${newTableName} table with ${count2} items`
|
35163
|
+
);
|
35164
|
+
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
35165
|
+
shouldAskForApprove = true;
|
35166
|
+
}
|
35167
|
+
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
35168
|
+
tablesContext[newTableName] = [
|
35169
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35170
|
+
];
|
35171
|
+
const tablesReferncingCurrent = [];
|
35172
|
+
for (const table4 of Object.values(json1.tables)) {
|
35173
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35174
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35175
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35176
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35177
|
+
}
|
35178
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35179
|
+
for (const table4 of uniqueTableRefs) {
|
35180
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35181
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35182
|
+
}
|
35183
|
+
}
|
35184
|
+
} else {
|
35185
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35186
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35187
|
+
statementsToExecute.push(stmnt);
|
35188
|
+
}
|
35189
|
+
}
|
35190
|
+
} else if (statement.type === "sqlite_alter_table_add_column") {
|
35191
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35192
|
+
if (statement.column.notNull && !statement.column.default) {
|
35193
|
+
const res = await connection.query(
|
35194
|
+
`select count(*) as count from \`${newTableName}\``
|
35195
|
+
);
|
35196
|
+
const count2 = Number(res[0].count);
|
35197
|
+
if (count2 > 0) {
|
35198
|
+
infoToPrint.push(
|
35199
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
35200
|
+
statement.column.name
|
35201
|
+
)} column without default value, which contains ${count2} items`
|
35202
|
+
);
|
35203
|
+
tablesToTruncate.push(newTableName);
|
35204
|
+
statementsToExecute.push(`delete from ${newTableName};`);
|
35205
|
+
shouldAskForApprove = true;
|
35206
|
+
}
|
35207
|
+
}
|
35208
|
+
if (statement.column.primaryKey) {
|
35209
|
+
tablesContext[newTableName] = [
|
35210
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35211
|
+
];
|
35212
|
+
const tablesReferncingCurrent = [];
|
35213
|
+
for (const table4 of Object.values(json1.tables)) {
|
35214
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35215
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35216
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35217
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35218
|
+
}
|
35219
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35220
|
+
for (const table4 of uniqueTableRefs) {
|
35221
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35222
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35223
|
+
}
|
35224
|
+
}
|
35225
|
+
} else {
|
35226
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35227
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35228
|
+
statementsToExecute.push(stmnt);
|
35229
|
+
}
|
35230
|
+
}
|
35231
|
+
} 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") {
|
35232
|
+
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
35233
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35234
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
35235
|
+
const res = await connection.query(
|
35236
|
+
`select count(*) as count from \`${newTableName}\``
|
35237
|
+
);
|
35238
|
+
const count2 = Number(res[0].count);
|
35239
|
+
if (count2 > 0) {
|
35240
|
+
infoToPrint.push(
|
35241
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
35242
|
+
statement.columnName
|
35243
|
+
)} column without default value, which contains ${count2} items`
|
35244
|
+
);
|
35245
|
+
tablesToTruncate.push(newTableName);
|
35246
|
+
shouldAskForApprove = true;
|
35247
|
+
}
|
35248
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35249
|
+
statement.tableName,
|
35250
|
+
json1,
|
35251
|
+
true
|
35252
|
+
);
|
35253
|
+
} else {
|
35254
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35255
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35256
|
+
statement.tableName,
|
35257
|
+
json1
|
35258
|
+
);
|
35259
|
+
}
|
35260
|
+
}
|
35261
|
+
const tablesReferncingCurrent = [];
|
35262
|
+
for (const table4 of Object.values(json1.tables)) {
|
35263
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35264
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35265
|
+
).map((t) => {
|
35266
|
+
return getNewTableName(
|
35267
|
+
SQLiteSquasher.unsquashPushFK(t).tableFrom,
|
35268
|
+
meta
|
35269
|
+
);
|
35270
|
+
});
|
35271
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35272
|
+
}
|
35273
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35274
|
+
for (const table4 of uniqueTableRefs) {
|
35275
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35276
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
35277
|
+
}
|
35278
|
+
}
|
35279
|
+
}
|
35280
|
+
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
35281
|
+
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
35282
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
35283
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
35284
|
+
statement.tableName,
|
35285
|
+
json2
|
35286
|
+
);
|
35287
|
+
}
|
35288
|
+
} 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") {
|
35289
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35290
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35291
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35292
|
+
statement.tableName,
|
35293
|
+
json2
|
35294
|
+
);
|
35295
|
+
}
|
35296
|
+
} else {
|
35297
|
+
const stmnt = fromJson([statement], "sqlite");
|
35298
|
+
if (typeof stmnt !== "undefined") {
|
35299
|
+
statementsToExecute.push(...stmnt);
|
35300
|
+
}
|
35301
|
+
}
|
35302
|
+
}
|
35303
|
+
for (const context of Object.values(tablesContext)) {
|
35304
|
+
statementsToExecute.push(...context);
|
35305
|
+
}
|
35306
|
+
return {
|
35307
|
+
statementsToExecute,
|
35308
|
+
shouldAskForApprove,
|
35309
|
+
infoToPrint,
|
35310
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
35311
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
35312
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
35313
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
35314
|
+
};
|
35315
|
+
};
|
35316
|
+
|
36147
35317
|
// src/api.ts
|
36148
|
-
init_sqlitePushUtils();
|
36149
35318
|
init_global();
|
36150
35319
|
init_migrationPreparator();
|
36151
35320
|
init_mysqlSchema();
|