drizzle-kit 0.24.0-f71baf7 → 0.24.1-781dea0
Sign up to get free protection for your applications and to get access to all the features.
- package/api.d.mts +10 -0
- package/api.d.ts +10 -0
- package/api.js +842 -1353
- package/api.mjs +842 -1353
- package/bin.cjs +1732 -2167
- package/package.json +3 -3
- package/utils.js +2 -10
- package/utils.mjs +2 -9
package/api.mjs
CHANGED
@@ -7469,11 +7469,30 @@ var init_mysqlSchema = __esm({
|
|
7469
7469
|
}
|
7470
7470
|
});
|
7471
7471
|
|
7472
|
+
// src/extensions/vector.ts
|
7473
|
+
var vectorOps;
|
7474
|
+
var init_vector = __esm({
|
7475
|
+
"src/extensions/vector.ts"() {
|
7476
|
+
"use strict";
|
7477
|
+
vectorOps = [
|
7478
|
+
"vector_l2_ops",
|
7479
|
+
"vector_ip_ops",
|
7480
|
+
"vector_cosine_ops",
|
7481
|
+
"vector_l1_ops",
|
7482
|
+
"bit_hamming_ops",
|
7483
|
+
"bit_jaccard_ops",
|
7484
|
+
"halfvec_l2_ops",
|
7485
|
+
"sparsevec_l2_ops"
|
7486
|
+
];
|
7487
|
+
}
|
7488
|
+
});
|
7489
|
+
|
7472
7490
|
// src/serializer/pgSchema.ts
|
7473
7491
|
var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
|
7474
7492
|
var init_pgSchema = __esm({
|
7475
7493
|
"src/serializer/pgSchema.ts"() {
|
7476
7494
|
"use strict";
|
7495
|
+
init_vector();
|
7477
7496
|
init_global();
|
7478
7497
|
init_lib();
|
7479
7498
|
indexV2 = objectType({
|
@@ -7720,7 +7739,8 @@ var init_pgSchema = __esm({
|
|
7720
7739
|
objectType({
|
7721
7740
|
isArray: booleanType().optional(),
|
7722
7741
|
dimensions: numberType().optional(),
|
7723
|
-
rawType: stringType().optional()
|
7742
|
+
rawType: stringType().optional(),
|
7743
|
+
isDefaultAnExpression: booleanType().optional()
|
7724
7744
|
}).optional()
|
7725
7745
|
)
|
7726
7746
|
}).optional()
|
@@ -7858,7 +7878,7 @@ var init_pgSchema = __esm({
|
|
7858
7878
|
squashIdx: (idx) => {
|
7859
7879
|
index2.parse(idx);
|
7860
7880
|
return `${idx.name};${idx.columns.map(
|
7861
|
-
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
|
7881
|
+
(c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
|
7862
7882
|
).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
|
7863
7883
|
},
|
7864
7884
|
unsquashIdx: (input) => {
|
@@ -8346,13 +8366,6 @@ var init_sqliteSchema = __esm({
|
|
8346
8366
|
function isPgArrayType(sqlType) {
|
8347
8367
|
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8348
8368
|
}
|
8349
|
-
function findAddedAndRemoved(columnNames1, columnNames2) {
|
8350
|
-
const set1 = new Set(columnNames1);
|
8351
|
-
const set2 = new Set(columnNames2);
|
8352
|
-
const addedColumns = columnNames2.filter((it) => !set1.has(it));
|
8353
|
-
const removedColumns = columnNames1.filter((it) => !set2.has(it));
|
8354
|
-
return { addedColumns, removedColumns };
|
8355
|
-
}
|
8356
8369
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8357
8370
|
var init_utils = __esm({
|
8358
8371
|
"src/utils.ts"() {
|
@@ -11462,20 +11475,7 @@ var init_jsonDiffer = __esm({
|
|
11462
11475
|
});
|
11463
11476
|
|
11464
11477
|
// src/sqlgenerator.ts
|
11465
|
-
|
11466
|
-
const result = statements.flatMap((statement) => {
|
11467
|
-
const filtered = convertors.filter((it) => {
|
11468
|
-
return it.can(statement, dialect7, driver2);
|
11469
|
-
});
|
11470
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
11471
|
-
if (!convertor) {
|
11472
|
-
return "";
|
11473
|
-
}
|
11474
|
-
return convertor.convert(statement, json2, action);
|
11475
|
-
}).filter((it) => it !== "");
|
11476
|
-
return result;
|
11477
|
-
}
|
11478
|
-
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
|
11478
|
+
var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
|
11479
11479
|
var init_sqlgenerator = __esm({
|
11480
11480
|
"src/sqlgenerator.ts"() {
|
11481
11481
|
"use strict";
|
@@ -11527,7 +11527,7 @@ var init_sqlgenerator = __esm({
|
|
11527
11527
|
isPgNativeType = (it) => {
|
11528
11528
|
if (pgNativeTypes.has(it)) return true;
|
11529
11529
|
const toCheck = it.replace(/ /g, "");
|
11530
|
-
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11530
|
+
return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("doubleprecision[") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
|
11531
11531
|
};
|
11532
11532
|
Convertor = class {
|
11533
11533
|
};
|
@@ -11797,6 +11797,32 @@ var init_sqlgenerator = __esm({
|
|
11797
11797
|
return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
|
11798
11798
|
}
|
11799
11799
|
};
|
11800
|
+
SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
11801
|
+
can(statement, dialect7) {
|
11802
|
+
return statement.type === "create_unique_constraint" && dialect7 === "sqlite";
|
11803
|
+
}
|
11804
|
+
convert(statement) {
|
11805
|
+
return `/*
|
11806
|
+
SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
11807
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
11808
|
+
|
11809
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
11810
|
+
*/`;
|
11811
|
+
}
|
11812
|
+
};
|
11813
|
+
SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
11814
|
+
can(statement, dialect7) {
|
11815
|
+
return statement.type === "delete_unique_constraint" && dialect7 === "sqlite";
|
11816
|
+
}
|
11817
|
+
convert(statement) {
|
11818
|
+
return `/*
|
11819
|
+
SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
11820
|
+
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
11821
|
+
|
11822
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
11823
|
+
*/`;
|
11824
|
+
}
|
11825
|
+
};
|
11800
11826
|
CreatePgSequenceConvertor = class extends Convertor {
|
11801
11827
|
can(statement, dialect7) {
|
11802
11828
|
return statement.type === "create_sequence" && dialect7 === "postgresql";
|
@@ -11965,7 +11991,7 @@ var init_sqlgenerator = __esm({
|
|
11965
11991
|
}
|
11966
11992
|
convert(statement) {
|
11967
11993
|
const { tableName, oldColumnName, newColumnName } = statement;
|
11968
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
11994
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
|
11969
11995
|
}
|
11970
11996
|
};
|
11971
11997
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -12066,6 +12092,21 @@ var init_sqlgenerator = __esm({
|
|
12066
12092
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DATA TYPE ${newDataType};`;
|
12067
12093
|
}
|
12068
12094
|
};
|
12095
|
+
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
12096
|
+
can(statement, dialect7) {
|
12097
|
+
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
12098
|
+
}
|
12099
|
+
convert(statement) {
|
12100
|
+
return `/*
|
12101
|
+
SQLite does not support "Changing existing column type" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12102
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12103
|
+
https://www.sqlite.org/lang_altertable.html
|
12104
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12105
|
+
|
12106
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12107
|
+
*/`;
|
12108
|
+
}
|
12109
|
+
};
|
12069
12110
|
PgAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
12070
12111
|
can(statement, dialect7) {
|
12071
12112
|
return statement.type === "alter_table_alter_column_set_default" && dialect7 === "postgresql";
|
@@ -12076,6 +12117,21 @@ var init_sqlgenerator = __esm({
|
|
12076
12117
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DEFAULT ${statement.newDefaultValue};`;
|
12077
12118
|
}
|
12078
12119
|
};
|
12120
|
+
SqliteAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
12121
|
+
can(statement, dialect7) {
|
12122
|
+
return statement.type === "alter_table_alter_column_set_default" && dialect7 === "sqlite";
|
12123
|
+
}
|
12124
|
+
convert(statement) {
|
12125
|
+
return `/*
|
12126
|
+
SQLite does not support "Set default to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12127
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12128
|
+
https://www.sqlite.org/lang_altertable.html
|
12129
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12130
|
+
|
12131
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12132
|
+
*/`;
|
12133
|
+
}
|
12134
|
+
};
|
12079
12135
|
PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
12080
12136
|
can(statement, dialect7) {
|
12081
12137
|
return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "postgresql";
|
@@ -12349,67 +12405,6 @@ var init_sqlgenerator = __esm({
|
|
12349
12405
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
12350
12406
|
}
|
12351
12407
|
};
|
12352
|
-
LibSQLModifyColumn = class extends Convertor {
|
12353
|
-
can(statement, dialect7, driver2) {
|
12354
|
-
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";
|
12355
|
-
}
|
12356
|
-
convert(statement, json2, action) {
|
12357
|
-
const { tableName, columnName } = statement;
|
12358
|
-
let columnType = ``;
|
12359
|
-
let columnDefault = "";
|
12360
|
-
let columnNotNull = "";
|
12361
|
-
const sqlStatements = [];
|
12362
|
-
const indexes = [];
|
12363
|
-
for (const table4 of Object.values(json2.tables)) {
|
12364
|
-
for (const index4 of Object.values(table4.indexes)) {
|
12365
|
-
const unsquashed = SQLiteSquasher.unsquashIdx(index4);
|
12366
|
-
sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
|
12367
|
-
indexes.push({ ...unsquashed, tableName: table4.name });
|
12368
|
-
}
|
12369
|
-
}
|
12370
|
-
switch (statement.type) {
|
12371
|
-
case "alter_table_alter_column_set_type":
|
12372
|
-
columnType = ` ${statement.newDataType}`;
|
12373
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12374
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12375
|
-
break;
|
12376
|
-
case "alter_table_alter_column_drop_notnull":
|
12377
|
-
columnType = ` ${statement.newDataType}`;
|
12378
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12379
|
-
columnNotNull = "";
|
12380
|
-
break;
|
12381
|
-
case "alter_table_alter_column_set_notnull":
|
12382
|
-
columnType = ` ${statement.newDataType}`;
|
12383
|
-
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12384
|
-
columnNotNull = ` NOT NULL`;
|
12385
|
-
break;
|
12386
|
-
case "alter_table_alter_column_set_default":
|
12387
|
-
columnType = ` ${statement.newDataType}`;
|
12388
|
-
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
12389
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12390
|
-
break;
|
12391
|
-
case "alter_table_alter_column_drop_default":
|
12392
|
-
columnType = ` ${statement.newDataType}`;
|
12393
|
-
columnDefault = "";
|
12394
|
-
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12395
|
-
break;
|
12396
|
-
}
|
12397
|
-
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
12398
|
-
sqlStatements.push(
|
12399
|
-
`ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`
|
12400
|
-
);
|
12401
|
-
for (const index4 of indexes) {
|
12402
|
-
const indexPart = index4.isUnique ? "UNIQUE INDEX" : "INDEX";
|
12403
|
-
const whereStatement = index4.where ? ` WHERE ${index4.where}` : "";
|
12404
|
-
const uniqueString = index4.columns.map((it) => `\`${it}\``).join(",");
|
12405
|
-
const tableName2 = index4.tableName;
|
12406
|
-
sqlStatements.push(
|
12407
|
-
`CREATE ${indexPart} \`${index4.name}\` ON \`${tableName2}\` (${uniqueString})${whereStatement};`
|
12408
|
-
);
|
12409
|
-
}
|
12410
|
-
return sqlStatements;
|
12411
|
-
}
|
12412
|
-
};
|
12413
12408
|
MySqlModifyColumn = class extends Convertor {
|
12414
12409
|
can(statement, dialect7) {
|
12415
12410
|
return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_generated" || statement.type === "alter_table_alter_column_drop_generated") && dialect7 === "mysql";
|
@@ -12547,6 +12542,21 @@ var init_sqlgenerator = __esm({
|
|
12547
12542
|
return `ALTER TABLE \`${tableName}\` MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate}${columnGenerated};`;
|
12548
12543
|
}
|
12549
12544
|
};
|
12545
|
+
SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
12546
|
+
can(statement, dialect7) {
|
12547
|
+
return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "sqlite";
|
12548
|
+
}
|
12549
|
+
convert(statement) {
|
12550
|
+
return `/*
|
12551
|
+
SQLite does not support "Drop default from column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12552
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12553
|
+
https://www.sqlite.org/lang_altertable.html
|
12554
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12555
|
+
|
12556
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12557
|
+
*/`;
|
12558
|
+
}
|
12559
|
+
};
|
12550
12560
|
PgAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
12551
12561
|
can(statement, dialect7) {
|
12552
12562
|
return statement.type === "create_composite_pk" && dialect7 === "postgresql";
|
@@ -12611,6 +12621,85 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12611
12621
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY, ADD PRIMARY KEY(\`${newColumns.join("`,`")}\`);`;
|
12612
12622
|
}
|
12613
12623
|
};
|
12624
|
+
SqliteAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
12625
|
+
can(statement, dialect7) {
|
12626
|
+
return statement.type === "create_composite_pk" && dialect7 === "sqlite";
|
12627
|
+
}
|
12628
|
+
convert(statement) {
|
12629
|
+
let msg = "/*\n";
|
12630
|
+
msg += `You're trying to add PRIMARY KEY(${statement.data}) to '${statement.tableName}' table
|
12631
|
+
`;
|
12632
|
+
msg += "SQLite does not support adding primary key to an already created table\n";
|
12633
|
+
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12634
|
+
msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
|
12635
|
+
msg += " - migrate old data from one table to another\n";
|
12636
|
+
msg += " - delete old_table in schema, generate sql\n\n";
|
12637
|
+
msg += "or create manual migration like below:\n\n";
|
12638
|
+
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12639
|
+
msg += "CREATE TABLE table_name (\n";
|
12640
|
+
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12641
|
+
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12642
|
+
msg += " ...\n";
|
12643
|
+
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12644
|
+
msg += " );\n";
|
12645
|
+
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12646
|
+
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12647
|
+
msg += "*/\n";
|
12648
|
+
return msg;
|
12649
|
+
}
|
12650
|
+
};
|
12651
|
+
SqliteAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
|
12652
|
+
can(statement, dialect7) {
|
12653
|
+
return statement.type === "delete_composite_pk" && dialect7 === "sqlite";
|
12654
|
+
}
|
12655
|
+
convert(statement) {
|
12656
|
+
let msg = "/*\n";
|
12657
|
+
msg += `You're trying to delete PRIMARY KEY(${statement.data}) from '${statement.tableName}' table
|
12658
|
+
`;
|
12659
|
+
msg += "SQLite does not supportprimary key deletion from existing table\n";
|
12660
|
+
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12661
|
+
msg += " - create new mirror table table without pk, rename current table to old_table, generate SQL\n";
|
12662
|
+
msg += " - migrate old data from one table to another\n";
|
12663
|
+
msg += " - delete old_table in schema, generate sql\n\n";
|
12664
|
+
msg += "or create manual migration like below:\n\n";
|
12665
|
+
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12666
|
+
msg += "CREATE TABLE table_name (\n";
|
12667
|
+
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12668
|
+
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12669
|
+
msg += " ...\n";
|
12670
|
+
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12671
|
+
msg += " );\n";
|
12672
|
+
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12673
|
+
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12674
|
+
msg += "*/\n";
|
12675
|
+
return msg;
|
12676
|
+
}
|
12677
|
+
};
|
12678
|
+
SqliteAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
|
12679
|
+
can(statement, dialect7) {
|
12680
|
+
return statement.type === "alter_composite_pk" && dialect7 === "sqlite";
|
12681
|
+
}
|
12682
|
+
convert(statement) {
|
12683
|
+
let msg = "/*\n";
|
12684
|
+
msg += "SQLite does not support altering primary key\n";
|
12685
|
+
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12686
|
+
msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
|
12687
|
+
msg += " - migrate old data from one table to another\n";
|
12688
|
+
msg += " - delete old_table in schema, generate sql\n\n";
|
12689
|
+
msg += "or create manual migration like below:\n\n";
|
12690
|
+
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12691
|
+
msg += "CREATE TABLE table_name (\n";
|
12692
|
+
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12693
|
+
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12694
|
+
msg += " ...\n";
|
12695
|
+
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12696
|
+
msg += " );\n";
|
12697
|
+
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12698
|
+
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12699
|
+
msg += "*/\n";
|
12700
|
+
return msg;
|
12701
|
+
}
|
12702
|
+
};
|
12614
12703
|
PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
|
12615
12704
|
can(statement, dialect7) {
|
12616
12705
|
return statement.type === "alter_table_alter_column_set_pk" && dialect7 === "postgresql";
|
@@ -12655,6 +12744,51 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12655
12744
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET NOT NULL;`;
|
12656
12745
|
}
|
12657
12746
|
};
|
12747
|
+
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
12748
|
+
can(statement, dialect7) {
|
12749
|
+
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
12750
|
+
}
|
12751
|
+
convert(statement) {
|
12752
|
+
return `/*
|
12753
|
+
SQLite does not support "Set not null to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12754
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12755
|
+
https://www.sqlite.org/lang_altertable.html
|
12756
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12757
|
+
|
12758
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12759
|
+
*/`;
|
12760
|
+
}
|
12761
|
+
};
|
12762
|
+
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
12763
|
+
can(statement, dialect7) {
|
12764
|
+
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
12765
|
+
}
|
12766
|
+
convert(statement) {
|
12767
|
+
return `/*
|
12768
|
+
SQLite does not support "Set autoincrement to a column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12769
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12770
|
+
https://www.sqlite.org/lang_altertable.html
|
12771
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12772
|
+
|
12773
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12774
|
+
*/`;
|
12775
|
+
}
|
12776
|
+
};
|
12777
|
+
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
12778
|
+
can(statement, dialect7) {
|
12779
|
+
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
12780
|
+
}
|
12781
|
+
convert(statement) {
|
12782
|
+
return `/*
|
12783
|
+
SQLite does not support "Drop autoincrement from a column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12784
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12785
|
+
https://www.sqlite.org/lang_altertable.html
|
12786
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12787
|
+
|
12788
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12789
|
+
*/`;
|
12790
|
+
}
|
12791
|
+
};
|
12658
12792
|
PgAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12659
12793
|
can(statement, dialect7) {
|
12660
12794
|
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "postgresql";
|
@@ -12665,6 +12799,21 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12665
12799
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP NOT NULL;`;
|
12666
12800
|
}
|
12667
12801
|
};
|
12802
|
+
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12803
|
+
can(statement, dialect7) {
|
12804
|
+
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
12805
|
+
}
|
12806
|
+
convert(statement) {
|
12807
|
+
return `/*
|
12808
|
+
SQLite does not support "Drop not null from column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12809
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12810
|
+
https://www.sqlite.org/lang_altertable.html
|
12811
|
+
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12812
|
+
|
12813
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12814
|
+
*/`;
|
12815
|
+
}
|
12816
|
+
};
|
12668
12817
|
PgCreateForeignKeyConvertor = class extends Convertor {
|
12669
12818
|
can(statement, dialect7) {
|
12670
12819
|
return statement.type === "create_reference" && dialect7 === "postgresql";
|
@@ -12695,21 +12844,18 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12695
12844
|
return sql2;
|
12696
12845
|
}
|
12697
12846
|
};
|
12698
|
-
|
12699
|
-
can(statement, dialect7
|
12700
|
-
return statement.type === "create_reference" && dialect7 === "sqlite"
|
12847
|
+
SqliteCreateForeignKeyConvertor = class extends Convertor {
|
12848
|
+
can(statement, dialect7) {
|
12849
|
+
return statement.type === "create_reference" && dialect7 === "sqlite";
|
12701
12850
|
}
|
12702
|
-
convert(statement
|
12703
|
-
|
12704
|
-
|
12705
|
-
|
12706
|
-
|
12707
|
-
|
12708
|
-
|
12709
|
-
|
12710
|
-
const columnFrom = columnsFrom[0];
|
12711
|
-
const columnTo = columnsTo[0];
|
12712
|
-
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
|
12851
|
+
convert(statement) {
|
12852
|
+
return `/*
|
12853
|
+
SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12854
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12855
|
+
https://www.sqlite.org/lang_altertable.html
|
12856
|
+
|
12857
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12858
|
+
*/`;
|
12713
12859
|
}
|
12714
12860
|
};
|
12715
12861
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
@@ -12758,6 +12904,20 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12758
12904
|
return sql2;
|
12759
12905
|
}
|
12760
12906
|
};
|
12907
|
+
SqliteAlterForeignKeyConvertor = class extends Convertor {
|
12908
|
+
can(statement, dialect7) {
|
12909
|
+
return statement.type === "alter_reference" && dialect7 === "sqlite";
|
12910
|
+
}
|
12911
|
+
convert(statement) {
|
12912
|
+
return `/*
|
12913
|
+
SQLite does not support "Changing existing foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12914
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12915
|
+
https://www.sqlite.org/lang_altertable.html
|
12916
|
+
|
12917
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12918
|
+
*/`;
|
12919
|
+
}
|
12920
|
+
};
|
12761
12921
|
PgDeleteForeignKeyConvertor = class extends Convertor {
|
12762
12922
|
can(statement, dialect7) {
|
12763
12923
|
return statement.type === "delete_reference" && dialect7 === "postgresql";
|
@@ -12770,6 +12930,20 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12770
12930
|
`;
|
12771
12931
|
}
|
12772
12932
|
};
|
12933
|
+
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
12934
|
+
can(statement, dialect7) {
|
12935
|
+
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
12936
|
+
}
|
12937
|
+
convert(statement) {
|
12938
|
+
return `/*
|
12939
|
+
SQLite does not support "Dropping foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually
|
12940
|
+
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12941
|
+
https://www.sqlite.org/lang_altertable.html
|
12942
|
+
|
12943
|
+
Due to that we don't generate migration automatically and it has to be done manually
|
12944
|
+
*/`;
|
12945
|
+
}
|
12946
|
+
};
|
12773
12947
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
12774
12948
|
can(statement, dialect7) {
|
12775
12949
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -12933,96 +13107,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12933
13107
|
return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
|
12934
13108
|
}
|
12935
13109
|
};
|
12936
|
-
SQLiteRecreateTableConvertor = class extends Convertor {
|
12937
|
-
can(statement, dialect7, driver2) {
|
12938
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
|
12939
|
-
}
|
12940
|
-
convert(statement) {
|
12941
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
12942
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
12943
|
-
const newTableName = `__new_${tableName}`;
|
12944
|
-
const sqlStatements = [];
|
12945
|
-
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
12946
|
-
sqlStatements.push(
|
12947
|
-
new SQLiteCreateTableConvertor().convert({
|
12948
|
-
type: "sqlite_create_table",
|
12949
|
-
tableName: newTableName,
|
12950
|
-
columns,
|
12951
|
-
referenceData,
|
12952
|
-
compositePKs
|
12953
|
-
})
|
12954
|
-
);
|
12955
|
-
sqlStatements.push(
|
12956
|
-
`INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
|
12957
|
-
);
|
12958
|
-
sqlStatements.push(
|
12959
|
-
new SQLiteDropTableConvertor().convert({
|
12960
|
-
type: "drop_table",
|
12961
|
-
tableName,
|
12962
|
-
schema: ""
|
12963
|
-
})
|
12964
|
-
);
|
12965
|
-
sqlStatements.push(
|
12966
|
-
new SqliteRenameTableConvertor().convert({
|
12967
|
-
fromSchema: "",
|
12968
|
-
tableNameFrom: newTableName,
|
12969
|
-
tableNameTo: tableName,
|
12970
|
-
toSchema: "",
|
12971
|
-
type: "rename_table"
|
12972
|
-
})
|
12973
|
-
);
|
12974
|
-
sqlStatements.push(`PRAGMA foreign_keys=ON;`);
|
12975
|
-
return sqlStatements;
|
12976
|
-
}
|
12977
|
-
};
|
12978
|
-
LibSQLRecreateTableConvertor = class extends Convertor {
|
12979
|
-
can(statement, dialect7, driver2) {
|
12980
|
-
return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
|
12981
|
-
}
|
12982
|
-
convert(statement) {
|
12983
|
-
const { tableName, columns, compositePKs, referenceData } = statement;
|
12984
|
-
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
12985
|
-
const newTableName = `__new_${tableName}`;
|
12986
|
-
const sqlStatements = [];
|
12987
|
-
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
12988
|
-
sqlStatements.push(
|
12989
|
-
new SQLiteCreateTableConvertor().convert({
|
12990
|
-
type: "sqlite_create_table",
|
12991
|
-
tableName: newTableName,
|
12992
|
-
columns,
|
12993
|
-
referenceData,
|
12994
|
-
compositePKs
|
12995
|
-
})
|
12996
|
-
);
|
12997
|
-
sqlStatements.push(
|
12998
|
-
`INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
|
12999
|
-
);
|
13000
|
-
sqlStatements.push(
|
13001
|
-
new SQLiteDropTableConvertor().convert({
|
13002
|
-
type: "drop_table",
|
13003
|
-
tableName,
|
13004
|
-
schema: ""
|
13005
|
-
})
|
13006
|
-
);
|
13007
|
-
sqlStatements.push(
|
13008
|
-
new SqliteRenameTableConvertor().convert({
|
13009
|
-
fromSchema: "",
|
13010
|
-
tableNameFrom: newTableName,
|
13011
|
-
tableNameTo: tableName,
|
13012
|
-
toSchema: "",
|
13013
|
-
type: "rename_table"
|
13014
|
-
})
|
13015
|
-
);
|
13016
|
-
sqlStatements.push(`PRAGMA foreign_keys=ON;`);
|
13017
|
-
return sqlStatements;
|
13018
|
-
}
|
13019
|
-
};
|
13020
13110
|
convertors = [];
|
13021
13111
|
convertors.push(new PgCreateTableConvertor());
|
13022
13112
|
convertors.push(new MySqlCreateTableConvertor());
|
13023
13113
|
convertors.push(new SQLiteCreateTableConvertor());
|
13024
|
-
convertors.push(new SQLiteRecreateTableConvertor());
|
13025
|
-
convertors.push(new LibSQLRecreateTableConvertor());
|
13026
13114
|
convertors.push(new CreateTypeEnumConvertor());
|
13027
13115
|
convertors.push(new CreatePgSequenceConvertor());
|
13028
13116
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13070,7 +13158,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13070
13158
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
13071
13159
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
13072
13160
|
convertors.push(new MySqlModifyColumn());
|
13073
|
-
convertors.push(new LibSQLModifyColumn());
|
13074
13161
|
convertors.push(new PgCreateForeignKeyConvertor());
|
13075
13162
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
13076
13163
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -13082,10 +13169,24 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13082
13169
|
convertors.push(new PgAlterTableSetSchemaConvertor());
|
13083
13170
|
convertors.push(new PgAlterTableSetNewSchemaConvertor());
|
13084
13171
|
convertors.push(new PgAlterTableRemoveFromSchemaConvertor());
|
13085
|
-
convertors.push(new
|
13172
|
+
convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
|
13173
|
+
convertors.push(new SqliteAlterForeignKeyConvertor());
|
13174
|
+
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
13175
|
+
convertors.push(new SqliteCreateForeignKeyConvertor());
|
13176
|
+
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
13177
|
+
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
13086
13178
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
13087
13179
|
convertors.push(new PgAlterTableAlterColumnSetGenerated());
|
13088
13180
|
convertors.push(new PgAlterTableAlterColumnAlterGenerated());
|
13181
|
+
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
13182
|
+
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
13183
|
+
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
13184
|
+
convertors.push(new SqliteAlterTableAlterColumnDropDefaultConvertor());
|
13185
|
+
convertors.push(new SqliteAlterTableAlterColumnSetAutoincrementConvertor());
|
13186
|
+
convertors.push(new SqliteAlterTableAlterColumnDropAutoincrementConvertor());
|
13187
|
+
convertors.push(new SqliteAlterTableCreateCompositePrimaryKeyConvertor());
|
13188
|
+
convertors.push(new SqliteAlterTableDeleteCompositePrimaryKeyConvertor());
|
13189
|
+
convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
|
13089
13190
|
convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
|
13090
13191
|
convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
|
13091
13192
|
convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
|
@@ -13094,6 +13195,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13094
13195
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
13095
13196
|
convertors.push(new MySqlAlterTableAddPk());
|
13096
13197
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
13198
|
+
fromJson = (statements, dialect7) => {
|
13199
|
+
const result = statements.flatMap((statement) => {
|
13200
|
+
const filtered = convertors.filter((it) => {
|
13201
|
+
return it.can(statement, dialect7);
|
13202
|
+
});
|
13203
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
13204
|
+
if (!convertor) {
|
13205
|
+
return "";
|
13206
|
+
}
|
13207
|
+
return convertor.convert(statement);
|
13208
|
+
}).filter((it) => it !== "");
|
13209
|
+
return result;
|
13210
|
+
};
|
13097
13211
|
https: `
|
13098
13212
|
create table users (
|
13099
13213
|
id int,
|
@@ -13120,312 +13234,76 @@ drop type __venum;
|
|
13120
13234
|
}
|
13121
13235
|
});
|
13122
13236
|
|
13123
|
-
// src/
|
13124
|
-
var
|
13125
|
-
var
|
13126
|
-
"src/
|
13237
|
+
// src/jsonStatements.ts
|
13238
|
+
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13239
|
+
var init_jsonStatements = __esm({
|
13240
|
+
"src/jsonStatements.ts"() {
|
13127
13241
|
"use strict";
|
13128
13242
|
init_source();
|
13243
|
+
init_views();
|
13244
|
+
init_mysqlSchema();
|
13245
|
+
init_pgSchema();
|
13129
13246
|
init_sqliteSchema();
|
13130
|
-
|
13131
|
-
|
13132
|
-
|
13133
|
-
const
|
13134
|
-
|
13135
|
-
|
13136
|
-
|
13137
|
-
|
13138
|
-
|
13139
|
-
|
13140
|
-
|
13141
|
-
|
13142
|
-
|
13143
|
-
|
13144
|
-
|
13145
|
-
|
13146
|
-
|
13147
|
-
|
13148
|
-
|
13149
|
-
|
13150
|
-
|
13151
|
-
|
13152
|
-
|
13153
|
-
)
|
13154
|
-
|
13155
|
-
|
13156
|
-
|
13157
|
-
|
13158
|
-
|
13159
|
-
|
13160
|
-
|
13161
|
-
|
13162
|
-
type: "drop_table",
|
13163
|
-
tableName,
|
13164
|
-
schema: ""
|
13165
|
-
})
|
13247
|
+
preparePgCreateTableJson = (table4, json2) => {
|
13248
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13249
|
+
const tableKey2 = `${schema4 || "public"}.${name2}`;
|
13250
|
+
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
13251
|
+
return {
|
13252
|
+
type: "create_table",
|
13253
|
+
tableName: name2,
|
13254
|
+
schema: schema4,
|
13255
|
+
columns: Object.values(columns),
|
13256
|
+
compositePKs: Object.values(compositePrimaryKeys),
|
13257
|
+
compositePkName,
|
13258
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
13259
|
+
};
|
13260
|
+
};
|
13261
|
+
prepareMySqlCreateTableJson = (table4, json2, internals) => {
|
13262
|
+
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13263
|
+
return {
|
13264
|
+
type: "create_table",
|
13265
|
+
tableName: name2,
|
13266
|
+
schema: schema4,
|
13267
|
+
columns: Object.values(columns),
|
13268
|
+
compositePKs: Object.values(compositePrimaryKeys),
|
13269
|
+
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
|
13270
|
+
uniqueConstraints: Object.values(uniqueConstraints),
|
13271
|
+
internals
|
13272
|
+
};
|
13273
|
+
};
|
13274
|
+
prepareSQLiteCreateTable = (table4, action) => {
|
13275
|
+
const { name: name2, columns, uniqueConstraints } = table4;
|
13276
|
+
const references2 = Object.values(table4.foreignKeys);
|
13277
|
+
const composites = Object.values(table4.compositePrimaryKeys).map(
|
13278
|
+
(it) => SQLiteSquasher.unsquashPK(it)
|
13166
13279
|
);
|
13167
|
-
|
13168
|
-
|
13169
|
-
fromSchema: "",
|
13170
|
-
tableNameFrom: newTableName,
|
13171
|
-
tableNameTo: tableName,
|
13172
|
-
toSchema: "",
|
13173
|
-
type: "rename_table"
|
13174
|
-
})
|
13280
|
+
const fks = references2.map(
|
13281
|
+
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
13175
13282
|
);
|
13176
|
-
|
13177
|
-
|
13178
|
-
|
13179
|
-
|
13180
|
-
|
13181
|
-
|
13182
|
-
|
13183
|
-
|
13184
|
-
);
|
13185
|
-
}
|
13186
|
-
return statements;
|
13283
|
+
return {
|
13284
|
+
type: "sqlite_create_table",
|
13285
|
+
tableName: name2,
|
13286
|
+
columns: Object.values(columns),
|
13287
|
+
referenceData: fks,
|
13288
|
+
compositePKs: composites,
|
13289
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
13290
|
+
};
|
13187
13291
|
};
|
13188
|
-
|
13189
|
-
|
13190
|
-
|
13191
|
-
|
13192
|
-
|
13193
|
-
|
13194
|
-
}
|
13195
|
-
return tableName;
|
13292
|
+
prepareDropTableJson = (table4) => {
|
13293
|
+
return {
|
13294
|
+
type: "drop_table",
|
13295
|
+
tableName: table4.name,
|
13296
|
+
schema: table4.schema
|
13297
|
+
};
|
13196
13298
|
};
|
13197
|
-
|
13198
|
-
|
13199
|
-
|
13200
|
-
|
13201
|
-
|
13202
|
-
|
13203
|
-
|
13204
|
-
|
13205
|
-
};
|
13206
|
-
logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
13207
|
-
let shouldAskForApprove = false;
|
13208
|
-
const statementsToExecute = [];
|
13209
|
-
const infoToPrint = [];
|
13210
|
-
const tablesToRemove = [];
|
13211
|
-
const columnsToRemove = [];
|
13212
|
-
const schemasToRemove = [];
|
13213
|
-
const tablesToTruncate = [];
|
13214
|
-
for (const statement of statements) {
|
13215
|
-
if (statement.type === "drop_table") {
|
13216
|
-
const res = await connection.query(
|
13217
|
-
`select count(*) as count from \`${statement.tableName}\``
|
13218
|
-
);
|
13219
|
-
const count2 = Number(res[0].count);
|
13220
|
-
if (count2 > 0) {
|
13221
|
-
infoToPrint.push(
|
13222
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13223
|
-
statement.tableName
|
13224
|
-
)} table with ${count2} items`
|
13225
|
-
);
|
13226
|
-
tablesToRemove.push(statement.tableName);
|
13227
|
-
shouldAskForApprove = true;
|
13228
|
-
}
|
13229
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13230
|
-
statementsToExecute.push(
|
13231
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13232
|
-
);
|
13233
|
-
} else if (statement.type === "alter_table_drop_column") {
|
13234
|
-
const tableName = statement.tableName;
|
13235
|
-
const columnName = statement.columnName;
|
13236
|
-
const res = await connection.query(
|
13237
|
-
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
|
13238
|
-
);
|
13239
|
-
const count2 = Number(res[0].count);
|
13240
|
-
if (count2 > 0) {
|
13241
|
-
infoToPrint.push(
|
13242
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13243
|
-
columnName
|
13244
|
-
)} column in ${tableName} table with ${count2} items`
|
13245
|
-
);
|
13246
|
-
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
13247
|
-
shouldAskForApprove = true;
|
13248
|
-
}
|
13249
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13250
|
-
statementsToExecute.push(
|
13251
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13252
|
-
);
|
13253
|
-
} else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
|
13254
|
-
const tableName = statement.tableName;
|
13255
|
-
const columnName = statement.column.name;
|
13256
|
-
const res = await connection.query(
|
13257
|
-
`select count(*) as count from \`${tableName}\``
|
13258
|
-
);
|
13259
|
-
const count2 = Number(res[0].count);
|
13260
|
-
if (count2 > 0) {
|
13261
|
-
infoToPrint.push(
|
13262
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
13263
|
-
columnName
|
13264
|
-
)} column without default value, which contains ${count2} items`
|
13265
|
-
);
|
13266
|
-
tablesToTruncate.push(tableName);
|
13267
|
-
statementsToExecute.push(`delete from ${tableName};`);
|
13268
|
-
shouldAskForApprove = true;
|
13269
|
-
}
|
13270
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13271
|
-
statementsToExecute.push(
|
13272
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13273
|
-
);
|
13274
|
-
} else if (statement.type === "recreate_table") {
|
13275
|
-
const tableName = statement.tableName;
|
13276
|
-
const oldTableName = getOldTableName(tableName, meta);
|
13277
|
-
let dataLoss = false;
|
13278
|
-
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
13279
|
-
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
13280
|
-
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
13281
|
-
prevColumnNames,
|
13282
|
-
currentColumnNames
|
13283
|
-
);
|
13284
|
-
if (removedColumns.length) {
|
13285
|
-
for (const removedColumn of removedColumns) {
|
13286
|
-
const res = await connection.query(
|
13287
|
-
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
13288
|
-
);
|
13289
|
-
const count2 = Number(res[0].count);
|
13290
|
-
if (count2 > 0) {
|
13291
|
-
infoToPrint.push(
|
13292
|
-
`\xB7 You're about to delete ${source_default.underline(
|
13293
|
-
removedColumn
|
13294
|
-
)} column in ${tableName} table with ${count2} items`
|
13295
|
-
);
|
13296
|
-
columnsToRemove.push(removedColumn);
|
13297
|
-
shouldAskForApprove = true;
|
13298
|
-
}
|
13299
|
-
}
|
13300
|
-
}
|
13301
|
-
if (addedColumns.length) {
|
13302
|
-
for (const addedColumn of addedColumns) {
|
13303
|
-
const [res] = await connection.query(
|
13304
|
-
`select count(*) as count from \`${tableName}\``
|
13305
|
-
);
|
13306
|
-
const columnConf = json2.tables[tableName].columns[addedColumn];
|
13307
|
-
const count2 = Number(res.count);
|
13308
|
-
if (count2 > 0 && columnConf.notNull && !columnConf.default) {
|
13309
|
-
dataLoss = true;
|
13310
|
-
infoToPrint.push(
|
13311
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
13312
|
-
addedColumn
|
13313
|
-
)} column without default value to table, which contains ${count2} items`
|
13314
|
-
);
|
13315
|
-
shouldAskForApprove = true;
|
13316
|
-
tablesToTruncate.push(tableName);
|
13317
|
-
statementsToExecute.push(`DELETE FROM \`${tableName}\`;`);
|
13318
|
-
}
|
13319
|
-
}
|
13320
|
-
}
|
13321
|
-
const tablesReferencingCurrent = [];
|
13322
|
-
for (const table4 of Object.values(json2.tables)) {
|
13323
|
-
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
13324
|
-
tablesReferencingCurrent.push(...tablesRefs);
|
13325
|
-
}
|
13326
|
-
if (!tablesReferencingCurrent.length) {
|
13327
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
13328
|
-
continue;
|
13329
|
-
}
|
13330
|
-
const [{ foreign_keys: pragmaState }] = await connection.query(`PRAGMA foreign_keys;`);
|
13331
|
-
if (pragmaState) {
|
13332
|
-
statementsToExecute.push(`PRAGMA foreign_keys=OFF;`);
|
13333
|
-
}
|
13334
|
-
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
13335
|
-
if (pragmaState) {
|
13336
|
-
statementsToExecute.push(`PRAGMA foreign_keys=ON;`);
|
13337
|
-
}
|
13338
|
-
} else {
|
13339
|
-
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13340
|
-
statementsToExecute.push(
|
13341
|
-
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13342
|
-
);
|
13343
|
-
}
|
13344
|
-
}
|
13345
|
-
return {
|
13346
|
-
statementsToExecute,
|
13347
|
-
shouldAskForApprove,
|
13348
|
-
infoToPrint,
|
13349
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
13350
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
13351
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
13352
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
13353
|
-
};
|
13354
|
-
};
|
13355
|
-
}
|
13356
|
-
});
|
13357
|
-
|
13358
|
-
// src/jsonStatements.ts
|
13359
|
-
var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
|
13360
|
-
var init_jsonStatements = __esm({
|
13361
|
-
"src/jsonStatements.ts"() {
|
13362
|
-
"use strict";
|
13363
|
-
init_source();
|
13364
|
-
init_sqlitePushUtils();
|
13365
|
-
init_views();
|
13366
|
-
init_mysqlSchema();
|
13367
|
-
init_pgSchema();
|
13368
|
-
init_sqliteSchema();
|
13369
|
-
preparePgCreateTableJson = (table4, json2) => {
|
13370
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13371
|
-
const tableKey2 = `${schema4 || "public"}.${name2}`;
|
13372
|
-
const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
|
13373
|
-
return {
|
13374
|
-
type: "create_table",
|
13375
|
-
tableName: name2,
|
13376
|
-
schema: schema4,
|
13377
|
-
columns: Object.values(columns),
|
13378
|
-
compositePKs: Object.values(compositePrimaryKeys),
|
13379
|
-
compositePkName,
|
13380
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
13381
|
-
};
|
13382
|
-
};
|
13383
|
-
prepareMySqlCreateTableJson = (table4, json2, internals) => {
|
13384
|
-
const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
|
13385
|
-
return {
|
13386
|
-
type: "create_table",
|
13387
|
-
tableName: name2,
|
13388
|
-
schema: schema4,
|
13389
|
-
columns: Object.values(columns),
|
13390
|
-
compositePKs: Object.values(compositePrimaryKeys),
|
13391
|
-
compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
|
13392
|
-
uniqueConstraints: Object.values(uniqueConstraints),
|
13393
|
-
internals
|
13394
|
-
};
|
13395
|
-
};
|
13396
|
-
prepareSQLiteCreateTable = (table4, action) => {
|
13397
|
-
const { name: name2, columns, uniqueConstraints } = table4;
|
13398
|
-
const references2 = Object.values(table4.foreignKeys);
|
13399
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
13400
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
13401
|
-
);
|
13402
|
-
const fks = references2.map(
|
13403
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
13404
|
-
);
|
13405
|
-
return {
|
13406
|
-
type: "sqlite_create_table",
|
13407
|
-
tableName: name2,
|
13408
|
-
columns: Object.values(columns),
|
13409
|
-
referenceData: fks,
|
13410
|
-
compositePKs: composites,
|
13411
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
13412
|
-
};
|
13413
|
-
};
|
13414
|
-
prepareDropTableJson = (table4) => {
|
13415
|
-
return {
|
13416
|
-
type: "drop_table",
|
13417
|
-
tableName: table4.name,
|
13418
|
-
schema: table4.schema
|
13419
|
-
};
|
13420
|
-
};
|
13421
|
-
prepareRenameTableJson = (tableFrom, tableTo) => {
|
13422
|
-
return {
|
13423
|
-
type: "rename_table",
|
13424
|
-
fromSchema: tableTo.schema,
|
13425
|
-
toSchema: tableTo.schema,
|
13426
|
-
tableNameFrom: tableFrom.name,
|
13427
|
-
tableNameTo: tableTo.name
|
13428
|
-
};
|
13299
|
+
prepareRenameTableJson = (tableFrom, tableTo) => {
|
13300
|
+
return {
|
13301
|
+
type: "rename_table",
|
13302
|
+
fromSchema: tableTo.schema,
|
13303
|
+
toSchema: tableTo.schema,
|
13304
|
+
tableNameFrom: tableFrom.name,
|
13305
|
+
tableNameTo: tableTo.name
|
13306
|
+
};
|
13429
13307
|
};
|
13430
13308
|
prepareCreateEnumJson = (name2, schema4, values) => {
|
13431
13309
|
return {
|
@@ -14145,49 +14023,6 @@ var init_jsonStatements = __esm({
|
|
14145
14023
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
14146
14024
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
14147
14025
|
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
14148
|
-
if (column4.autoincrement?.type === "added") {
|
14149
|
-
statements.push({
|
14150
|
-
type: "alter_table_alter_column_set_autoincrement",
|
14151
|
-
tableName,
|
14152
|
-
columnName,
|
14153
|
-
schema: schema4,
|
14154
|
-
newDataType: columnType,
|
14155
|
-
columnDefault,
|
14156
|
-
columnOnUpdate,
|
14157
|
-
columnNotNull,
|
14158
|
-
columnAutoIncrement,
|
14159
|
-
columnPk
|
14160
|
-
});
|
14161
|
-
}
|
14162
|
-
if (column4.autoincrement?.type === "changed") {
|
14163
|
-
const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
14164
|
-
statements.push({
|
14165
|
-
type,
|
14166
|
-
tableName,
|
14167
|
-
columnName,
|
14168
|
-
schema: schema4,
|
14169
|
-
newDataType: columnType,
|
14170
|
-
columnDefault,
|
14171
|
-
columnOnUpdate,
|
14172
|
-
columnNotNull,
|
14173
|
-
columnAutoIncrement,
|
14174
|
-
columnPk
|
14175
|
-
});
|
14176
|
-
}
|
14177
|
-
if (column4.autoincrement?.type === "deleted") {
|
14178
|
-
statements.push({
|
14179
|
-
type: "alter_table_alter_column_drop_autoincrement",
|
14180
|
-
tableName,
|
14181
|
-
columnName,
|
14182
|
-
schema: schema4,
|
14183
|
-
newDataType: columnType,
|
14184
|
-
columnDefault,
|
14185
|
-
columnOnUpdate,
|
14186
|
-
columnNotNull,
|
14187
|
-
columnAutoIncrement,
|
14188
|
-
columnPk
|
14189
|
-
});
|
14190
|
-
}
|
14191
14026
|
if (typeof column4.name !== "string") {
|
14192
14027
|
statements.push({
|
14193
14028
|
type: "alter_table_rename_column",
|
@@ -14451,37 +14286,6 @@ var init_jsonStatements = __esm({
|
|
14451
14286
|
};
|
14452
14287
|
});
|
14453
14288
|
};
|
14454
|
-
prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
|
14455
|
-
return Object.values(foreignKeys).map((fkData) => {
|
14456
|
-
const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14457
|
-
let isMulticolumn = false;
|
14458
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14459
|
-
isMulticolumn = true;
|
14460
|
-
return {
|
14461
|
-
type: "create_reference",
|
14462
|
-
tableName,
|
14463
|
-
data: fkData,
|
14464
|
-
schema: schema4,
|
14465
|
-
isMulticolumn
|
14466
|
-
};
|
14467
|
-
}
|
14468
|
-
const columnFrom = columnsFrom[0];
|
14469
|
-
const {
|
14470
|
-
notNull: columnNotNull,
|
14471
|
-
default: columnDefault,
|
14472
|
-
type: columnType
|
14473
|
-
} = json2.tables[tableFrom].columns[columnFrom];
|
14474
|
-
return {
|
14475
|
-
type: "create_reference",
|
14476
|
-
tableName,
|
14477
|
-
data: fkData,
|
14478
|
-
schema: schema4,
|
14479
|
-
columnNotNull,
|
14480
|
-
columnDefault,
|
14481
|
-
columnType
|
14482
|
-
};
|
14483
|
-
});
|
14484
|
-
};
|
14485
14289
|
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14486
14290
|
return Object.values(foreignKeys).map((fkData) => {
|
14487
14291
|
return {
|
@@ -14492,53 +14296,6 @@ var init_jsonStatements = __esm({
|
|
14492
14296
|
};
|
14493
14297
|
});
|
14494
14298
|
};
|
14495
|
-
prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
|
14496
|
-
const statements = Object.values(foreignKeys).map((fkData) => {
|
14497
|
-
const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14498
|
-
const keys = Object.keys(json2.tables[tableName].columns);
|
14499
|
-
const filtered = columnsFrom.filter((it) => keys.includes(it));
|
14500
|
-
const fullDrop = filtered.length === 0;
|
14501
|
-
if (fullDrop) return;
|
14502
|
-
let isMulticolumn = false;
|
14503
|
-
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14504
|
-
isMulticolumn = true;
|
14505
|
-
return {
|
14506
|
-
type: "delete_reference",
|
14507
|
-
tableName,
|
14508
|
-
data: fkData,
|
14509
|
-
schema: schema4,
|
14510
|
-
isMulticolumn
|
14511
|
-
};
|
14512
|
-
}
|
14513
|
-
const columnFrom = columnsFrom[0];
|
14514
|
-
const newTableName = getNewTableName(tableFrom, meta);
|
14515
|
-
const {
|
14516
|
-
notNull: columnNotNull,
|
14517
|
-
default: columnDefault,
|
14518
|
-
type: columnType
|
14519
|
-
} = json2.tables[newTableName].columns[columnFrom];
|
14520
|
-
const fkToSquash = {
|
14521
|
-
columnsFrom,
|
14522
|
-
columnsTo,
|
14523
|
-
name: name2,
|
14524
|
-
tableFrom: newTableName,
|
14525
|
-
tableTo,
|
14526
|
-
onDelete,
|
14527
|
-
onUpdate
|
14528
|
-
};
|
14529
|
-
const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
|
14530
|
-
return {
|
14531
|
-
type: "delete_reference",
|
14532
|
-
tableName,
|
14533
|
-
data: foreignKey,
|
14534
|
-
schema: schema4,
|
14535
|
-
columnNotNull,
|
14536
|
-
columnDefault,
|
14537
|
-
columnType
|
14538
|
-
};
|
14539
|
-
});
|
14540
|
-
return statements.filter((it) => it);
|
14541
|
-
};
|
14542
14299
|
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
14543
14300
|
const stmts = [];
|
14544
14301
|
Object.values(foreignKeys).map((val) => {
|
@@ -14692,321 +14449,38 @@ var init_jsonStatements = __esm({
|
|
14692
14449
|
}
|
14693
14450
|
});
|
14694
14451
|
|
14695
|
-
// src/
|
14696
|
-
var
|
14697
|
-
|
14698
|
-
|
14452
|
+
// src/snapshotsDiffer.ts
|
14453
|
+
var snapshotsDiffer_exports = {};
|
14454
|
+
__export(snapshotsDiffer_exports, {
|
14455
|
+
alteredTableScheme: () => alteredTableScheme,
|
14456
|
+
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
14457
|
+
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
14458
|
+
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
14459
|
+
diffResultScheme: () => diffResultScheme,
|
14460
|
+
diffResultSchemeMysql: () => diffResultSchemeMysql,
|
14461
|
+
diffResultSchemeSQLite: () => diffResultSchemeSQLite,
|
14462
|
+
makePatched: () => makePatched,
|
14463
|
+
makeSelfOrPatched: () => makeSelfOrPatched
|
14464
|
+
});
|
14465
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
14466
|
+
var init_snapshotsDiffer = __esm({
|
14467
|
+
"src/snapshotsDiffer.ts"() {
|
14699
14468
|
"use strict";
|
14469
|
+
init_lib();
|
14470
|
+
init_jsonDiffer();
|
14471
|
+
init_sqlgenerator();
|
14700
14472
|
init_jsonStatements();
|
14473
|
+
init_global();
|
14474
|
+
init_mysqlSchema();
|
14475
|
+
init_pgSchema();
|
14701
14476
|
init_sqliteSchema();
|
14702
|
-
|
14703
|
-
|
14704
|
-
|
14705
|
-
|
14706
|
-
|
14707
|
-
|
14708
|
-
|
14709
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14710
|
-
);
|
14711
|
-
const statements = [
|
14712
|
-
{
|
14713
|
-
type: "recreate_table",
|
14714
|
-
tableName: name2,
|
14715
|
-
columns: Object.values(columns),
|
14716
|
-
compositePKs: composites,
|
14717
|
-
referenceData: fks,
|
14718
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
14719
|
-
}
|
14720
|
-
];
|
14721
|
-
if (Object.keys(indexes).length) {
|
14722
|
-
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14723
|
-
}
|
14724
|
-
return statements;
|
14725
|
-
};
|
14726
|
-
prepareSQLiteRecreateTable = (table4, action) => {
|
14727
|
-
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14728
|
-
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14729
|
-
(it) => SQLiteSquasher.unsquashPK(it)
|
14730
|
-
);
|
14731
|
-
const references2 = Object.values(table4.foreignKeys);
|
14732
|
-
const fks = references2.map(
|
14733
|
-
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14734
|
-
);
|
14735
|
-
const statements = [
|
14736
|
-
{
|
14737
|
-
type: "recreate_table",
|
14738
|
-
tableName: name2,
|
14739
|
-
columns: Object.values(columns),
|
14740
|
-
compositePKs: composites,
|
14741
|
-
referenceData: fks,
|
14742
|
-
uniqueConstraints: Object.values(uniqueConstraints)
|
14743
|
-
}
|
14744
|
-
];
|
14745
|
-
if (Object.keys(indexes).length) {
|
14746
|
-
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14747
|
-
}
|
14748
|
-
return statements;
|
14749
|
-
};
|
14750
|
-
libSQLCombineStatements = (statements, json2, action) => {
|
14751
|
-
const newStatements = {};
|
14752
|
-
for (const statement of statements) {
|
14753
|
-
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") {
|
14754
|
-
const tableName2 = statement.tableName;
|
14755
|
-
const statementsForTable2 = newStatements[tableName2];
|
14756
|
-
if (!statementsForTable2) {
|
14757
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14758
|
-
continue;
|
14759
|
-
}
|
14760
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14761
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14762
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14763
|
-
if (wasRename) {
|
14764
|
-
newStatements[tableName2].push(...preparedStatements);
|
14765
|
-
} else {
|
14766
|
-
newStatements[tableName2] = preparedStatements;
|
14767
|
-
}
|
14768
|
-
continue;
|
14769
|
-
}
|
14770
|
-
continue;
|
14771
|
-
}
|
14772
|
-
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") {
|
14773
|
-
const { tableName: tableName2, columnName, columnPk } = statement;
|
14774
|
-
const columnIsPartOfForeignKey = Object.values(
|
14775
|
-
json2.tables[tableName2].foreignKeys
|
14776
|
-
).some((it) => {
|
14777
|
-
const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
|
14778
|
-
return unsquashFk.columnsFrom.includes(columnName);
|
14779
|
-
});
|
14780
|
-
const statementsForTable2 = newStatements[tableName2];
|
14781
|
-
if (!statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
|
14782
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14783
|
-
continue;
|
14784
|
-
}
|
14785
|
-
if (statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
|
14786
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14787
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14788
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14789
|
-
if (wasRename) {
|
14790
|
-
newStatements[tableName2].push(...preparedStatements);
|
14791
|
-
} else {
|
14792
|
-
newStatements[tableName2] = preparedStatements;
|
14793
|
-
}
|
14794
|
-
}
|
14795
|
-
continue;
|
14796
|
-
}
|
14797
|
-
if (statementsForTable2 && !(columnIsPartOfForeignKey || columnPk)) {
|
14798
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14799
|
-
newStatements[tableName2].push(statement);
|
14800
|
-
}
|
14801
|
-
continue;
|
14802
|
-
}
|
14803
|
-
newStatements[tableName2] = [statement];
|
14804
|
-
continue;
|
14805
|
-
}
|
14806
|
-
if (statement.type === "create_reference") {
|
14807
|
-
const tableName2 = statement.tableName;
|
14808
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
14809
|
-
const statementsForTable2 = newStatements[tableName2];
|
14810
|
-
if (!statementsForTable2) {
|
14811
|
-
newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : [statement];
|
14812
|
-
continue;
|
14813
|
-
}
|
14814
|
-
if (!statement.isMulticolumn && statementsForTable2.some(
|
14815
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
14816
|
-
)) {
|
14817
|
-
continue;
|
14818
|
-
}
|
14819
|
-
if (statement.isMulticolumn) {
|
14820
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14821
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14822
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14823
|
-
if (wasRename) {
|
14824
|
-
newStatements[tableName2].push(...preparedStatements);
|
14825
|
-
} else {
|
14826
|
-
newStatements[tableName2] = preparedStatements;
|
14827
|
-
}
|
14828
|
-
continue;
|
14829
|
-
}
|
14830
|
-
continue;
|
14831
|
-
}
|
14832
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14833
|
-
newStatements[tableName2].push(statement);
|
14834
|
-
}
|
14835
|
-
continue;
|
14836
|
-
}
|
14837
|
-
if (statement.type === "delete_reference") {
|
14838
|
-
const tableName2 = statement.tableName;
|
14839
|
-
const statementsForTable2 = newStatements[tableName2];
|
14840
|
-
if (!statementsForTable2) {
|
14841
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14842
|
-
continue;
|
14843
|
-
}
|
14844
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14845
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14846
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14847
|
-
if (wasRename) {
|
14848
|
-
newStatements[tableName2].push(...preparedStatements);
|
14849
|
-
} else {
|
14850
|
-
newStatements[tableName2] = preparedStatements;
|
14851
|
-
}
|
14852
|
-
continue;
|
14853
|
-
}
|
14854
|
-
continue;
|
14855
|
-
}
|
14856
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
14857
|
-
const tableName2 = statement.tableName;
|
14858
|
-
const statementsForTable2 = newStatements[tableName2];
|
14859
|
-
if (!statementsForTable2) {
|
14860
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14861
|
-
continue;
|
14862
|
-
}
|
14863
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14864
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14865
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14866
|
-
if (wasRename) {
|
14867
|
-
newStatements[tableName2].push(...preparedStatements);
|
14868
|
-
} else {
|
14869
|
-
newStatements[tableName2] = preparedStatements;
|
14870
|
-
}
|
14871
|
-
continue;
|
14872
|
-
}
|
14873
|
-
continue;
|
14874
|
-
}
|
14875
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
14876
|
-
const statementsForTable = newStatements[tableName];
|
14877
|
-
if (!statementsForTable) {
|
14878
|
-
newStatements[tableName] = [statement];
|
14879
|
-
continue;
|
14880
|
-
}
|
14881
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
14882
|
-
newStatements[tableName].push(statement);
|
14883
|
-
}
|
14884
|
-
}
|
14885
|
-
const combinedStatements = Object.values(newStatements).flat();
|
14886
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
14887
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
14888
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
14889
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
14890
|
-
};
|
14891
|
-
sqliteCombineStatements = (statements, json2, action) => {
|
14892
|
-
const newStatements = {};
|
14893
|
-
for (const statement of statements) {
|
14894
|
-
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") {
|
14895
|
-
const tableName2 = statement.tableName;
|
14896
|
-
const statementsForTable2 = newStatements[tableName2];
|
14897
|
-
if (!statementsForTable2) {
|
14898
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14899
|
-
continue;
|
14900
|
-
}
|
14901
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14902
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14903
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14904
|
-
if (wasRename) {
|
14905
|
-
newStatements[tableName2].push(...preparedStatements);
|
14906
|
-
} else {
|
14907
|
-
newStatements[tableName2] = preparedStatements;
|
14908
|
-
}
|
14909
|
-
continue;
|
14910
|
-
}
|
14911
|
-
continue;
|
14912
|
-
}
|
14913
|
-
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
14914
|
-
const tableName2 = statement.tableName;
|
14915
|
-
const statementsForTable2 = newStatements[tableName2];
|
14916
|
-
if (!statementsForTable2) {
|
14917
|
-
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14918
|
-
continue;
|
14919
|
-
}
|
14920
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14921
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14922
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14923
|
-
if (wasRename) {
|
14924
|
-
newStatements[tableName2].push(...preparedStatements);
|
14925
|
-
} else {
|
14926
|
-
newStatements[tableName2] = preparedStatements;
|
14927
|
-
}
|
14928
|
-
continue;
|
14929
|
-
}
|
14930
|
-
continue;
|
14931
|
-
}
|
14932
|
-
if (statement.type === "create_reference") {
|
14933
|
-
const tableName2 = statement.tableName;
|
14934
|
-
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
14935
|
-
const statementsForTable2 = newStatements[tableName2];
|
14936
|
-
if (!statementsForTable2) {
|
14937
|
-
newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
|
14938
|
-
continue;
|
14939
|
-
}
|
14940
|
-
if (data.columnsFrom.length === 1 && statementsForTable2.some(
|
14941
|
-
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
14942
|
-
)) {
|
14943
|
-
continue;
|
14944
|
-
}
|
14945
|
-
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14946
|
-
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14947
|
-
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14948
|
-
if (wasRename) {
|
14949
|
-
newStatements[tableName2].push(...preparedStatements);
|
14950
|
-
} else {
|
14951
|
-
newStatements[tableName2] = preparedStatements;
|
14952
|
-
}
|
14953
|
-
continue;
|
14954
|
-
}
|
14955
|
-
continue;
|
14956
|
-
}
|
14957
|
-
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
14958
|
-
const statementsForTable = newStatements[tableName];
|
14959
|
-
if (!statementsForTable) {
|
14960
|
-
newStatements[tableName] = [statement];
|
14961
|
-
continue;
|
14962
|
-
}
|
14963
|
-
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
14964
|
-
newStatements[tableName].push(statement);
|
14965
|
-
}
|
14966
|
-
}
|
14967
|
-
const combinedStatements = Object.values(newStatements).flat();
|
14968
|
-
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
14969
|
-
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
14970
|
-
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
14971
|
-
return [...renamedTables, ...renamedColumns, ...rest];
|
14972
|
-
};
|
14973
|
-
}
|
14974
|
-
});
|
14975
|
-
|
14976
|
-
// src/snapshotsDiffer.ts
|
14977
|
-
var snapshotsDiffer_exports = {};
|
14978
|
-
__export(snapshotsDiffer_exports, {
|
14979
|
-
alteredTableScheme: () => alteredTableScheme,
|
14980
|
-
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
14981
|
-
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
14982
|
-
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
14983
|
-
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
14984
|
-
diffResultScheme: () => diffResultScheme,
|
14985
|
-
diffResultSchemeMysql: () => diffResultSchemeMysql,
|
14986
|
-
diffResultSchemeSQLite: () => diffResultSchemeSQLite,
|
14987
|
-
makePatched: () => makePatched,
|
14988
|
-
makeSelfOrPatched: () => makeSelfOrPatched
|
14989
|
-
});
|
14990
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
14991
|
-
var init_snapshotsDiffer = __esm({
|
14992
|
-
"src/snapshotsDiffer.ts"() {
|
14993
|
-
"use strict";
|
14994
|
-
init_lib();
|
14995
|
-
init_jsonDiffer();
|
14996
|
-
init_sqlgenerator();
|
14997
|
-
init_jsonStatements();
|
14998
|
-
init_global();
|
14999
|
-
init_mysqlSchema();
|
15000
|
-
init_pgSchema();
|
15001
|
-
init_sqliteSchema();
|
15002
|
-
init_statementCombiner();
|
15003
|
-
init_utils();
|
15004
|
-
makeChanged = (schema4) => {
|
15005
|
-
return objectType({
|
15006
|
-
type: enumType(["changed"]),
|
15007
|
-
old: schema4,
|
15008
|
-
new: schema4
|
15009
|
-
});
|
14477
|
+
init_utils();
|
14478
|
+
makeChanged = (schema4) => {
|
14479
|
+
return objectType({
|
14480
|
+
type: enumType(["changed"]),
|
14481
|
+
old: schema4,
|
14482
|
+
new: schema4
|
14483
|
+
});
|
15010
14484
|
};
|
15011
14485
|
makeSelfOrChanged = (schema4) => {
|
15012
14486
|
return unionType([
|
@@ -16043,313 +15517,29 @@ var init_snapshotsDiffer = __esm({
|
|
16043
15517
|
curFull,
|
16044
15518
|
curFull.internal
|
16045
15519
|
);
|
16046
|
-
});
|
16047
|
-
jsonStatements.push(...jsonMySqlCreateTables);
|
16048
|
-
jsonStatements.push(...jsonDropTables);
|
16049
|
-
jsonStatements.push(...jsonRenameTables);
|
16050
|
-
jsonStatements.push(...jsonRenameColumnsStatements);
|
16051
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16052
|
-
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16053
|
-
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16054
|
-
jsonStatements.push(...jsonDeletedCompositePKs);
|
16055
|
-
jsonStatements.push(...jsonTableAlternations);
|
16056
|
-
jsonStatements.push(...jsonAddedCompositePKs);
|
16057
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16058
|
-
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16059
|
-
jsonStatements.push(...jsonAddColumnsStatemets);
|
16060
|
-
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16061
|
-
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16062
|
-
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16063
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16064
|
-
jsonStatements.push(...jsonDropColumnsStatemets);
|
16065
|
-
jsonStatements.push(...jsonAlteredCompositePKs);
|
16066
|
-
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16067
|
-
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16068
|
-
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16069
|
-
const uniqueSqlStatements = [];
|
16070
|
-
sqlStatements.forEach((ss) => {
|
16071
|
-
if (!uniqueSqlStatements.includes(ss)) {
|
16072
|
-
uniqueSqlStatements.push(ss);
|
16073
|
-
}
|
16074
|
-
});
|
16075
|
-
const rTables = renamedTables.map((it) => {
|
16076
|
-
return { from: it.from, to: it.to };
|
16077
|
-
});
|
16078
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16079
|
-
return {
|
16080
|
-
statements: jsonStatements,
|
16081
|
-
sqlStatements: uniqueSqlStatements,
|
16082
|
-
_meta
|
16083
|
-
};
|
16084
|
-
};
|
16085
|
-
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16086
|
-
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16087
|
-
const {
|
16088
|
-
created: createdTables,
|
16089
|
-
deleted: deletedTables,
|
16090
|
-
renamed: renamedTables
|
16091
|
-
} = await tablesResolver2({
|
16092
|
-
created: tablesDiff.added,
|
16093
|
-
deleted: tablesDiff.deleted
|
16094
|
-
});
|
16095
|
-
const tablesPatchedSnap1 = copy(json1);
|
16096
|
-
tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
|
16097
|
-
const { name: name2 } = nameChangeFor(it, renamedTables);
|
16098
|
-
it.name = name2;
|
16099
|
-
return [name2, it];
|
16100
|
-
});
|
16101
|
-
const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
|
16102
|
-
const columnRenames = [];
|
16103
|
-
const columnCreates = [];
|
16104
|
-
const columnDeletes = [];
|
16105
|
-
for (let entry of Object.values(res)) {
|
16106
|
-
const { renamed, created, deleted } = await columnsResolver2({
|
16107
|
-
tableName: entry.name,
|
16108
|
-
schema: entry.schema,
|
16109
|
-
deleted: entry.columns.deleted,
|
16110
|
-
created: entry.columns.added
|
16111
|
-
});
|
16112
|
-
if (created.length > 0) {
|
16113
|
-
columnCreates.push({
|
16114
|
-
table: entry.name,
|
16115
|
-
columns: created
|
16116
|
-
});
|
16117
|
-
}
|
16118
|
-
if (deleted.length > 0) {
|
16119
|
-
columnDeletes.push({
|
16120
|
-
table: entry.name,
|
16121
|
-
columns: deleted
|
16122
|
-
});
|
16123
|
-
}
|
16124
|
-
if (renamed.length > 0) {
|
16125
|
-
columnRenames.push({
|
16126
|
-
table: entry.name,
|
16127
|
-
renames: renamed
|
16128
|
-
});
|
16129
|
-
}
|
16130
|
-
}
|
16131
|
-
const columnRenamesDict = columnRenames.reduce(
|
16132
|
-
(acc, it) => {
|
16133
|
-
acc[it.table] = it.renames;
|
16134
|
-
return acc;
|
16135
|
-
},
|
16136
|
-
{}
|
16137
|
-
);
|
16138
|
-
const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
|
16139
|
-
columnsPatchedSnap1.tables = mapEntries(
|
16140
|
-
columnsPatchedSnap1.tables,
|
16141
|
-
(tableKey2, tableValue) => {
|
16142
|
-
const patchedColumns = mapKeys(
|
16143
|
-
tableValue.columns,
|
16144
|
-
(columnKey, column4) => {
|
16145
|
-
const rens = columnRenamesDict[tableValue.name] || [];
|
16146
|
-
const newName = columnChangeFor(columnKey, rens);
|
16147
|
-
column4.name = newName;
|
16148
|
-
return newName;
|
16149
|
-
}
|
16150
|
-
);
|
16151
|
-
tableValue.columns = patchedColumns;
|
16152
|
-
return [tableKey2, tableValue];
|
16153
|
-
}
|
16154
|
-
);
|
16155
|
-
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
16156
|
-
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16157
|
-
const tablesMap = {};
|
16158
|
-
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
16159
|
-
tablesMap[obj.name] = obj;
|
16160
|
-
});
|
16161
|
-
const jsonCreateTables = createdTables.map((it) => {
|
16162
|
-
return prepareSQLiteCreateTable(it, action);
|
16163
|
-
});
|
16164
|
-
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
16165
|
-
return prepareCreateIndexesJson(
|
16166
|
-
it.name,
|
16167
|
-
it.schema,
|
16168
|
-
it.indexes,
|
16169
|
-
curFull.internal
|
16170
|
-
);
|
16171
|
-
}).flat();
|
16172
|
-
const jsonDropTables = deletedTables.map((it) => {
|
16173
|
-
return prepareDropTableJson(it);
|
16174
|
-
});
|
16175
|
-
const jsonRenameTables = renamedTables.map((it) => {
|
16176
|
-
return prepareRenameTableJson(it.from, it.to);
|
16177
|
-
});
|
16178
|
-
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16179
|
-
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
16180
|
-
const jsonAddColumnsStatemets = columnCreates.map((it) => {
|
16181
|
-
return _prepareSqliteAddColumns(
|
16182
|
-
it.table,
|
16183
|
-
it.columns,
|
16184
|
-
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16185
|
-
);
|
16186
|
-
}).flat();
|
16187
|
-
const allAltered = typedResult.alteredTablesWithColumns;
|
16188
|
-
const jsonAddedCompositePKs = [];
|
16189
|
-
const jsonDeletedCompositePKs = [];
|
16190
|
-
const jsonAlteredCompositePKs = [];
|
16191
|
-
const jsonAddedUniqueConstraints = [];
|
16192
|
-
const jsonDeletedUniqueConstraints = [];
|
16193
|
-
const jsonAlteredUniqueConstraints = [];
|
16194
|
-
allAltered.forEach((it) => {
|
16195
|
-
let addedColumns = [];
|
16196
|
-
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16197
|
-
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16198
|
-
addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
|
16199
|
-
}
|
16200
|
-
let deletedColumns = [];
|
16201
|
-
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16202
|
-
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16203
|
-
deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
|
16204
|
-
}
|
16205
|
-
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16206
|
-
let addedCompositePKs = [];
|
16207
|
-
let deletedCompositePKs = [];
|
16208
|
-
let alteredCompositePKs = [];
|
16209
|
-
if (doPerformDeleteAndCreate) {
|
16210
|
-
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
16211
|
-
it.name,
|
16212
|
-
it.addedCompositePKs
|
16213
|
-
);
|
16214
|
-
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
16215
|
-
it.name,
|
16216
|
-
it.deletedCompositePKs
|
16217
|
-
);
|
16218
|
-
}
|
16219
|
-
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
16220
|
-
it.name,
|
16221
|
-
it.alteredCompositePKs
|
16222
|
-
);
|
16223
|
-
let addedUniqueConstraints = [];
|
16224
|
-
let deletedUniqueConstraints = [];
|
16225
|
-
let alteredUniqueConstraints = [];
|
16226
|
-
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16227
|
-
it.name,
|
16228
|
-
it.schema,
|
16229
|
-
it.addedUniqueConstraints
|
16230
|
-
);
|
16231
|
-
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
16232
|
-
it.name,
|
16233
|
-
it.schema,
|
16234
|
-
it.deletedUniqueConstraints
|
16235
|
-
);
|
16236
|
-
if (it.alteredUniqueConstraints) {
|
16237
|
-
const added = {};
|
16238
|
-
const deleted = {};
|
16239
|
-
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
16240
|
-
added[k] = it.alteredUniqueConstraints[k].__new;
|
16241
|
-
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
16242
|
-
}
|
16243
|
-
addedUniqueConstraints.push(
|
16244
|
-
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
16245
|
-
);
|
16246
|
-
deletedUniqueConstraints.push(
|
16247
|
-
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16248
|
-
);
|
16249
|
-
}
|
16250
|
-
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16251
|
-
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16252
|
-
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16253
|
-
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16254
|
-
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16255
|
-
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16256
|
-
});
|
16257
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16258
|
-
const tableName = it.tableName;
|
16259
|
-
const schema4 = it.schema;
|
16260
|
-
return {
|
16261
|
-
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16262
|
-
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16263
|
-
};
|
16264
|
-
});
|
16265
|
-
const jsonTableAlternations = allAltered.map((it) => {
|
16266
|
-
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16267
|
-
}).flat();
|
16268
|
-
const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
|
16269
|
-
return prepareCreateIndexesJson(
|
16270
|
-
it.name,
|
16271
|
-
it.schema,
|
16272
|
-
it.addedIndexes || {},
|
16273
|
-
curFull.internal
|
16274
|
-
);
|
16275
|
-
}).flat();
|
16276
|
-
const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
|
16277
|
-
return prepareDropIndexesJson(
|
16278
|
-
it.name,
|
16279
|
-
it.schema,
|
16280
|
-
it.deletedIndexes || {}
|
16281
|
-
);
|
16282
|
-
}).flat();
|
16283
|
-
allAltered.forEach((it) => {
|
16284
|
-
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
16285
|
-
(current, item) => {
|
16286
|
-
current[item] = it.alteredIndexes[item].__old;
|
16287
|
-
return current;
|
16288
|
-
},
|
16289
|
-
{}
|
16290
|
-
);
|
16291
|
-
const createdIndexes = Object.keys(it.alteredIndexes).reduce(
|
16292
|
-
(current, item) => {
|
16293
|
-
current[item] = it.alteredIndexes[item].__new;
|
16294
|
-
return current;
|
16295
|
-
},
|
16296
|
-
{}
|
16297
|
-
);
|
16298
|
-
jsonCreateIndexesForAllAlteredTables.push(
|
16299
|
-
...prepareCreateIndexesJson(
|
16300
|
-
it.name,
|
16301
|
-
it.schema,
|
16302
|
-
createdIndexes || {},
|
16303
|
-
curFull.internal
|
16304
|
-
)
|
16305
|
-
);
|
16306
|
-
jsonDropIndexesForAllAlteredTables.push(
|
16307
|
-
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
16308
|
-
);
|
16309
|
-
});
|
16310
|
-
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16311
|
-
const forAdded = prepareCreateReferencesJson(
|
16312
|
-
it.name,
|
16313
|
-
it.schema,
|
16314
|
-
it.addedForeignKeys
|
16315
|
-
);
|
16316
|
-
const forAltered = prepareDropReferencesJson(
|
16317
|
-
it.name,
|
16318
|
-
it.schema,
|
16319
|
-
it.deletedForeignKeys
|
16320
|
-
);
|
16321
|
-
const alteredFKs = prepareAlterReferencesJson(
|
16322
|
-
it.name,
|
16323
|
-
it.schema,
|
16324
|
-
it.alteredForeignKeys
|
16325
|
-
);
|
16326
|
-
return [...forAdded, ...forAltered, ...alteredFKs];
|
16327
|
-
}).flat();
|
16328
|
-
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16329
|
-
(t) => t.type === "create_reference"
|
16330
|
-
);
|
16331
|
-
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16332
|
-
(t) => t.type === "delete_reference"
|
16333
|
-
);
|
16334
|
-
const jsonStatements = [];
|
16335
|
-
jsonStatements.push(...jsonCreateTables);
|
15520
|
+
});
|
15521
|
+
jsonStatements.push(...jsonMySqlCreateTables);
|
16336
15522
|
jsonStatements.push(...jsonDropTables);
|
16337
15523
|
jsonStatements.push(...jsonRenameTables);
|
16338
15524
|
jsonStatements.push(...jsonRenameColumnsStatements);
|
15525
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16339
15526
|
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16340
15527
|
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16341
15528
|
jsonStatements.push(...jsonDeletedCompositePKs);
|
16342
15529
|
jsonStatements.push(...jsonTableAlternations);
|
16343
15530
|
jsonStatements.push(...jsonAddedCompositePKs);
|
15531
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
15532
|
+
jsonStatements.push(...jsonDeletedUniqueConstraints);
|
16344
15533
|
jsonStatements.push(...jsonAddColumnsStatemets);
|
15534
|
+
jsonStatements.push(...jsonCreateReferencesForCreatedTables);
|
16345
15535
|
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16346
|
-
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16347
15536
|
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
15537
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16348
15538
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16349
15539
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15540
|
+
jsonStatements.push(...jsonAddedUniqueConstraints);
|
16350
15541
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16351
|
-
const
|
16352
|
-
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
15542
|
+
const sqlStatements = fromJson(jsonStatements, "mysql");
|
16353
15543
|
const uniqueSqlStatements = [];
|
16354
15544
|
sqlStatements.forEach((ss) => {
|
16355
15545
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -16361,12 +15551,12 @@ var init_snapshotsDiffer = __esm({
|
|
16361
15551
|
});
|
16362
15552
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16363
15553
|
return {
|
16364
|
-
statements:
|
15554
|
+
statements: jsonStatements,
|
16365
15555
|
sqlStatements: uniqueSqlStatements,
|
16366
15556
|
_meta
|
16367
15557
|
};
|
16368
15558
|
};
|
16369
|
-
|
15559
|
+
applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16370
15560
|
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16371
15561
|
const {
|
16372
15562
|
created: createdTables,
|
@@ -16468,18 +15658,6 @@ var init_snapshotsDiffer = __esm({
|
|
16468
15658
|
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16469
15659
|
);
|
16470
15660
|
}).flat();
|
16471
|
-
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16472
|
-
const tableName = it.tableName;
|
16473
|
-
const schema4 = it.schema;
|
16474
|
-
return {
|
16475
|
-
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16476
|
-
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16477
|
-
};
|
16478
|
-
});
|
16479
|
-
const rTables = renamedTables.map((it) => {
|
16480
|
-
return { from: it.from, to: it.to };
|
16481
|
-
});
|
16482
|
-
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16483
15661
|
const allAltered = typedResult.alteredTablesWithColumns;
|
16484
15662
|
const jsonAddedCompositePKs = [];
|
16485
15663
|
const jsonDeletedCompositePKs = [];
|
@@ -16550,6 +15728,14 @@ var init_snapshotsDiffer = __esm({
|
|
16550
15728
|
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16551
15729
|
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16552
15730
|
});
|
15731
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
15732
|
+
const tableName = it.tableName;
|
15733
|
+
const schema4 = it.schema;
|
15734
|
+
return {
|
15735
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
15736
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
15737
|
+
};
|
15738
|
+
});
|
16553
15739
|
const jsonTableAlternations = allAltered.map((it) => {
|
16554
15740
|
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16555
15741
|
}).flat();
|
@@ -16596,22 +15782,21 @@ var init_snapshotsDiffer = __esm({
|
|
16596
15782
|
);
|
16597
15783
|
});
|
16598
15784
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16599
|
-
const forAdded =
|
15785
|
+
const forAdded = prepareCreateReferencesJson(
|
16600
15786
|
it.name,
|
16601
15787
|
it.schema,
|
16602
|
-
it.addedForeignKeys
|
16603
|
-
json2,
|
16604
|
-
action
|
15788
|
+
it.addedForeignKeys
|
16605
15789
|
);
|
16606
|
-
const forAltered =
|
15790
|
+
const forAltered = prepareDropReferencesJson(
|
16607
15791
|
it.name,
|
16608
15792
|
it.schema,
|
16609
|
-
it.deletedForeignKeys
|
16610
|
-
|
16611
|
-
|
16612
|
-
|
15793
|
+
it.deletedForeignKeys
|
15794
|
+
);
|
15795
|
+
const alteredFKs = prepareAlterReferencesJson(
|
15796
|
+
it.name,
|
15797
|
+
it.schema,
|
15798
|
+
it.alteredForeignKeys
|
16613
15799
|
);
|
16614
|
-
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
16615
15800
|
return [...forAdded, ...forAltered, ...alteredFKs];
|
16616
15801
|
}).flat();
|
16617
15802
|
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
@@ -16637,22 +15822,19 @@ var init_snapshotsDiffer = __esm({
|
|
16637
15822
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
16638
15823
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
16639
15824
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16640
|
-
const
|
16641
|
-
const sqlStatements = fromJson(
|
16642
|
-
combinedJsonStatements,
|
16643
|
-
"sqlite",
|
16644
|
-
action,
|
16645
|
-
"turso",
|
16646
|
-
json2
|
16647
|
-
);
|
15825
|
+
const sqlStatements = fromJson(jsonStatements, "sqlite");
|
16648
15826
|
const uniqueSqlStatements = [];
|
16649
15827
|
sqlStatements.forEach((ss) => {
|
16650
15828
|
if (!uniqueSqlStatements.includes(ss)) {
|
16651
15829
|
uniqueSqlStatements.push(ss);
|
16652
15830
|
}
|
16653
15831
|
});
|
15832
|
+
const rTables = renamedTables.map((it) => {
|
15833
|
+
return { from: it.from, to: it.to };
|
15834
|
+
});
|
15835
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16654
15836
|
return {
|
16655
|
-
statements:
|
15837
|
+
statements: jsonStatements,
|
16656
15838
|
sqlStatements: uniqueSqlStatements,
|
16657
15839
|
_meta
|
16658
15840
|
};
|
@@ -20216,7 +19398,7 @@ function jaccardDistance(column4, value) {
|
|
20216
19398
|
}
|
20217
19399
|
return sql`${column4} <%> ${value}`;
|
20218
19400
|
}
|
20219
|
-
var
|
19401
|
+
var init_vector2 = __esm({
|
20220
19402
|
"../drizzle-orm/dist/sql/functions/vector.js"() {
|
20221
19403
|
"use strict";
|
20222
19404
|
init_sql();
|
@@ -20228,7 +19410,7 @@ var init_functions = __esm({
|
|
20228
19410
|
"../drizzle-orm/dist/sql/functions/index.js"() {
|
20229
19411
|
"use strict";
|
20230
19412
|
init_aggregate();
|
20231
|
-
|
19413
|
+
init_vector2();
|
20232
19414
|
}
|
20233
19415
|
});
|
20234
19416
|
|
@@ -21892,7 +21074,7 @@ var init_sparsevec = __esm({
|
|
21892
21074
|
|
21893
21075
|
// ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
|
21894
21076
|
var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
|
21895
|
-
var
|
21077
|
+
var init_vector3 = __esm({
|
21896
21078
|
"../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
|
21897
21079
|
"use strict";
|
21898
21080
|
init_entity();
|
@@ -21964,7 +21146,7 @@ var init_columns = __esm({
|
|
21964
21146
|
init_bit();
|
21965
21147
|
init_halfvec();
|
21966
21148
|
init_sparsevec();
|
21967
|
-
|
21149
|
+
init_vector3();
|
21968
21150
|
}
|
21969
21151
|
});
|
21970
21152
|
|
@@ -25462,24 +24644,6 @@ var init_pg_core = __esm({
|
|
25462
24644
|
}
|
25463
24645
|
});
|
25464
24646
|
|
25465
|
-
// src/extensions/vector.ts
|
25466
|
-
var vectorOps;
|
25467
|
-
var init_vector3 = __esm({
|
25468
|
-
"src/extensions/vector.ts"() {
|
25469
|
-
"use strict";
|
25470
|
-
vectorOps = [
|
25471
|
-
"vector_l2_ops",
|
25472
|
-
"vector_ip_ops",
|
25473
|
-
"vector_cosine_ops",
|
25474
|
-
"vector_l1_ops",
|
25475
|
-
"bit_hamming_ops",
|
25476
|
-
"bit_jaccard_ops",
|
25477
|
-
"halfvec_l2_ops",
|
25478
|
-
"sparsevec_l2_ops"
|
25479
|
-
];
|
25480
|
-
}
|
25481
|
-
});
|
25482
|
-
|
25483
24647
|
// src/serializer/pgSerializer.ts
|
25484
24648
|
function stringFromIdentityProperty(field) {
|
25485
24649
|
return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
|
@@ -25517,7 +24681,7 @@ function buildArrayString(array, sqlType) {
|
|
25517
24681
|
}).join(",");
|
25518
24682
|
return `{${values}}`;
|
25519
24683
|
}
|
25520
|
-
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase,
|
24684
|
+
var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
|
25521
24685
|
var init_pgSerializer = __esm({
|
25522
24686
|
"src/serializer/pgSerializer.ts"() {
|
25523
24687
|
"use strict";
|
@@ -25525,7 +24689,7 @@ var init_pgSerializer = __esm({
|
|
25525
24689
|
init_dist();
|
25526
24690
|
init_pg_core();
|
25527
24691
|
init_pg_core();
|
25528
|
-
|
24692
|
+
init_vector();
|
25529
24693
|
init_outputs();
|
25530
24694
|
init_utils();
|
25531
24695
|
init_serializer();
|
@@ -25638,7 +24802,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
|
|
25638
24802
|
columnToSet.default = `'${buildArrayString(
|
25639
24803
|
column4.default,
|
25640
24804
|
sqlTypeLowered
|
25641
|
-
)}'
|
24805
|
+
)}'`;
|
25642
24806
|
} else {
|
25643
24807
|
columnToSet.default = column4.default;
|
25644
24808
|
}
|
@@ -25985,7 +25149,7 @@ ${withStyle.errorWarning(
|
|
25985
25149
|
WHEN 'int2'::regtype THEN 'smallserial'
|
25986
25150
|
END
|
25987
25151
|
ELSE format_type(a.atttypid, a.atttypmod)
|
25988
|
-
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
|
25152
|
+
END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
|
25989
25153
|
pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
|
25990
25154
|
INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
|
25991
25155
|
INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
|
@@ -25996,6 +25160,7 @@ ${withStyle.errorWarning(
|
|
25996
25160
|
INFORMATION_SCHEMA.COLUMNS.identity_cycle
|
25997
25161
|
FROM pg_attribute a
|
25998
25162
|
JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
|
25163
|
+
JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
|
25999
25164
|
WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
|
26000
25165
|
AND a.attnum > 0
|
26001
25166
|
AND NOT a.attisdropped
|
@@ -26015,30 +25180,42 @@ ${withStyle.errorWarning(
|
|
26015
25180
|
}
|
26016
25181
|
const tableForeignKeys = await db.query(
|
26017
25182
|
`SELECT
|
26018
|
-
|
26019
|
-
|
26020
|
-
|
26021
|
-
|
26022
|
-
|
26023
|
-
|
26024
|
-
|
26025
|
-
|
26026
|
-
|
26027
|
-
|
26028
|
-
|
26029
|
-
|
26030
|
-
|
26031
|
-
|
26032
|
-
|
26033
|
-
|
26034
|
-
|
26035
|
-
|
26036
|
-
|
26037
|
-
|
26038
|
-
|
26039
|
-
|
26040
|
-
|
26041
|
-
|
25183
|
+
con.contype AS constraint_type,
|
25184
|
+
nsp.nspname AS constraint_schema,
|
25185
|
+
con.conname AS constraint_name,
|
25186
|
+
rel.relname AS table_name,
|
25187
|
+
att.attname AS column_name,
|
25188
|
+
fnsp.nspname AS foreign_table_schema,
|
25189
|
+
frel.relname AS foreign_table_name,
|
25190
|
+
fatt.attname AS foreign_column_name,
|
25191
|
+
CASE con.confupdtype
|
25192
|
+
WHEN 'a' THEN 'NO ACTION'
|
25193
|
+
WHEN 'r' THEN 'RESTRICT'
|
25194
|
+
WHEN 'n' THEN 'SET NULL'
|
25195
|
+
WHEN 'c' THEN 'CASCADE'
|
25196
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25197
|
+
END AS update_rule,
|
25198
|
+
CASE con.confdeltype
|
25199
|
+
WHEN 'a' THEN 'NO ACTION'
|
25200
|
+
WHEN 'r' THEN 'RESTRICT'
|
25201
|
+
WHEN 'n' THEN 'SET NULL'
|
25202
|
+
WHEN 'c' THEN 'CASCADE'
|
25203
|
+
WHEN 'd' THEN 'SET DEFAULT'
|
25204
|
+
END AS delete_rule
|
25205
|
+
FROM
|
25206
|
+
pg_catalog.pg_constraint con
|
25207
|
+
JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
|
25208
|
+
JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
|
25209
|
+
LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
|
25210
|
+
AND att.attrelid = con.conrelid
|
25211
|
+
LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
|
25212
|
+
LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
|
25213
|
+
LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
|
25214
|
+
AND fatt.attrelid = con.confrelid
|
25215
|
+
WHERE
|
25216
|
+
nsp.nspname = '${tableSchema}'
|
25217
|
+
AND rel.relname = '${tableName}'
|
25218
|
+
AND con.contype IN ('f');`
|
26042
25219
|
);
|
26043
25220
|
foreignKeysCount += tableForeignKeys.length;
|
26044
25221
|
if (progressCallback) {
|
@@ -26050,8 +25227,8 @@ ${withStyle.errorWarning(
|
|
26050
25227
|
const columnTo = fk4.foreign_column_name;
|
26051
25228
|
const schemaTo = fk4.foreign_table_schema;
|
26052
25229
|
const foreignKeyName = fk4.constraint_name;
|
26053
|
-
const onUpdate = fk4.update_rule
|
26054
|
-
const onDelete = fk4.delete_rule
|
25230
|
+
const onUpdate = fk4.update_rule?.toLowerCase();
|
25231
|
+
const onDelete = fk4.delete_rule?.toLowerCase();
|
26055
25232
|
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
26056
25233
|
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
26057
25234
|
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
@@ -26096,6 +25273,8 @@ ${withStyle.errorWarning(
|
|
26096
25273
|
const columnDimensions = columnResponse.array_dimensions;
|
26097
25274
|
const enumType2 = columnResponse.enum_name;
|
26098
25275
|
let columnType = columnResponse.data_type;
|
25276
|
+
const typeSchema = columnResponse.type_schema;
|
25277
|
+
const defaultValueRes = columnResponse.column_default;
|
26099
25278
|
const isGenerated = columnResponse.is_generated === "ALWAYS";
|
26100
25279
|
const generationExpression = columnResponse.generation_expression;
|
26101
25280
|
const isIdentity = columnResponse.is_identity === "YES";
|
@@ -26126,12 +25305,7 @@ ${withStyle.errorWarning(
|
|
26126
25305
|
columns: cprimaryKey.map((c) => c.column_name)
|
26127
25306
|
};
|
26128
25307
|
}
|
26129
|
-
const defaultValue = defaultForColumn(columnResponse);
|
26130
|
-
const isSerial = columnType === "serial";
|
26131
25308
|
let columnTypeMapped = columnType;
|
26132
|
-
if (columnTypeMapped.startsWith("numeric(")) {
|
26133
|
-
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
26134
|
-
}
|
26135
25309
|
if (columnAdditionalDT === "ARRAY") {
|
26136
25310
|
if (typeof internals.tables[tableName] === "undefined") {
|
26137
25311
|
internals.tables[tableName] = {
|
@@ -26159,6 +25333,34 @@ ${withStyle.errorWarning(
|
|
26159
25333
|
}
|
26160
25334
|
}
|
26161
25335
|
}
|
25336
|
+
const defaultValue = defaultForColumn(
|
25337
|
+
columnResponse,
|
25338
|
+
internals,
|
25339
|
+
tableName
|
25340
|
+
);
|
25341
|
+
if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
|
25342
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25343
|
+
internals.tables[tableName] = {
|
25344
|
+
columns: {
|
25345
|
+
[columnName]: {
|
25346
|
+
isDefaultAnExpression: true
|
25347
|
+
}
|
25348
|
+
}
|
25349
|
+
};
|
25350
|
+
} else {
|
25351
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25352
|
+
internals.tables[tableName].columns[columnName] = {
|
25353
|
+
isDefaultAnExpression: true
|
25354
|
+
};
|
25355
|
+
} else {
|
25356
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25357
|
+
}
|
25358
|
+
}
|
25359
|
+
}
|
25360
|
+
const isSerial = columnType === "serial";
|
25361
|
+
if (columnTypeMapped.startsWith("numeric(")) {
|
25362
|
+
columnTypeMapped = columnTypeMapped.replace(",", ", ");
|
25363
|
+
}
|
26162
25364
|
if (columnAdditionalDT === "ARRAY") {
|
26163
25365
|
for (let i = 1; i < Number(columnDimensions); i++) {
|
26164
25366
|
columnTypeMapped += "[]";
|
@@ -26172,7 +25374,7 @@ ${withStyle.errorWarning(
|
|
26172
25374
|
// filter vectors, but in future we should filter any extension that was installed by user
|
26173
25375
|
columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
|
26174
25376
|
),
|
26175
|
-
typeSchema: enumsToReturn[`${
|
25377
|
+
typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
|
26176
25378
|
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
26177
25379
|
// default: isSerial ? undefined : defaultValue,
|
26178
25380
|
notNull: columnResponse.is_nullable === "NO",
|
@@ -26190,7 +25392,7 @@ ${withStyle.errorWarning(
|
|
26190
25392
|
} : void 0
|
26191
25393
|
};
|
26192
25394
|
if (identityName) {
|
26193
|
-
delete sequencesToReturn[`${tableSchema}.${identityName}`];
|
25395
|
+
delete sequencesToReturn[`${tableSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
|
26194
25396
|
delete sequencesToReturn[identityName];
|
26195
25397
|
}
|
26196
25398
|
if (!isSerial && typeof defaultValue !== "undefined") {
|
@@ -26343,59 +25545,71 @@ ${withStyle.errorWarning(
|
|
26343
25545
|
internal: internals
|
26344
25546
|
};
|
26345
25547
|
};
|
26346
|
-
|
26347
|
-
|
26348
|
-
|
26349
|
-
// "character varying": "::character varying",
|
26350
|
-
// "double precision": "::double precision",
|
26351
|
-
// "time with time zone": "::time with time zone",
|
26352
|
-
"time without time zone": "::time without time zone",
|
26353
|
-
// "timestamp with time zone": "::timestamp with time zone",
|
26354
|
-
"timestamp without time zone": "::timestamp without time zone",
|
26355
|
-
"timestamp(": "::timestamp without time zone",
|
26356
|
-
// date: "::date",
|
26357
|
-
// interval: "::interval",
|
26358
|
-
// character: "::bpchar",
|
26359
|
-
// macaddr8: "::macaddr8",
|
26360
|
-
// macaddr: "::macaddr",
|
26361
|
-
// inet: "::inet",
|
26362
|
-
// cidr: "::cidr",
|
26363
|
-
// jsonb: "::jsonb",
|
26364
|
-
// json: "::json",
|
26365
|
-
"character(": "::bpchar"
|
26366
|
-
};
|
26367
|
-
defaultForColumn = (column4) => {
|
25548
|
+
defaultForColumn = (column4, internals, tableName) => {
|
25549
|
+
const columnName = column4.attname;
|
25550
|
+
const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
|
26368
25551
|
if (column4.column_default === null) {
|
26369
25552
|
return void 0;
|
26370
25553
|
}
|
26371
25554
|
if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
|
26372
25555
|
return void 0;
|
26373
25556
|
}
|
26374
|
-
|
25557
|
+
if (column4.column_default.endsWith("[]")) {
|
25558
|
+
column4.column_default = column4.column_default.slice(0, -2);
|
25559
|
+
}
|
25560
|
+
column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
|
26375
25561
|
const columnDefaultAsString = column4.column_default.toString();
|
26376
|
-
if (
|
26377
|
-
|
26378
|
-
|
26379
|
-
|
26380
|
-
|
26381
|
-
|
26382
|
-
|
26383
|
-
|
26384
|
-
|
26385
|
-
|
26386
|
-
|
26387
|
-
|
26388
|
-
|
26389
|
-
|
26390
|
-
|
26391
|
-
|
26392
|
-
|
25562
|
+
if (isArray) {
|
25563
|
+
return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
|
25564
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
|
25565
|
+
return value;
|
25566
|
+
} else if (column4.data_type.startsWith("timestamp")) {
|
25567
|
+
return `${value}`;
|
25568
|
+
} else if (column4.data_type.slice(0, -2) === "interval") {
|
25569
|
+
return value.replaceAll('"', `"`);
|
25570
|
+
} else if (column4.data_type.slice(0, -2) === "boolean") {
|
25571
|
+
return value === "t" ? "true" : "false";
|
25572
|
+
} else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
|
25573
|
+
return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
|
25574
|
+
} else {
|
25575
|
+
return `"${value}"`;
|
25576
|
+
}
|
25577
|
+
}).join(",")}}'`;
|
25578
|
+
}
|
25579
|
+
if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
|
25580
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
|
26393
25581
|
return Number(columnDefaultAsString);
|
26394
|
-
} else if (column4.data_type === "boolean") {
|
26395
|
-
return column4.column_default === "true";
|
26396
25582
|
} else {
|
26397
|
-
|
25583
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
25584
|
+
internals.tables[tableName] = {
|
25585
|
+
columns: {
|
25586
|
+
[columnName]: {
|
25587
|
+
isDefaultAnExpression: true
|
25588
|
+
}
|
25589
|
+
}
|
25590
|
+
};
|
25591
|
+
} else {
|
25592
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
25593
|
+
internals.tables[tableName].columns[columnName] = {
|
25594
|
+
isDefaultAnExpression: true
|
25595
|
+
};
|
25596
|
+
} else {
|
25597
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
25598
|
+
}
|
25599
|
+
}
|
25600
|
+
return columnDefaultAsString;
|
26398
25601
|
}
|
25602
|
+
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
25603
|
+
const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
|
25604
|
+
return `'${jsonWithoutSpaces}'::${column4.data_type}`;
|
25605
|
+
} else if (column4.data_type === "boolean") {
|
25606
|
+
return column4.column_default === "true";
|
25607
|
+
} else if (columnDefaultAsString === "NULL") {
|
25608
|
+
return `NULL`;
|
25609
|
+
} else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
|
25610
|
+
return columnDefaultAsString;
|
25611
|
+
} else {
|
25612
|
+
return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
|
26399
25613
|
}
|
26400
25614
|
};
|
26401
25615
|
}
|
@@ -34714,8 +33928,7 @@ var init_cli = __esm({
|
|
34714
33928
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34715
33929
|
extensionsFilters: literalType("postgis").array().optional(),
|
34716
33930
|
verbose: booleanType().optional(),
|
34717
|
-
strict: booleanType().optional()
|
34718
|
-
driver: driver.optional()
|
33931
|
+
strict: booleanType().optional()
|
34719
33932
|
}).passthrough();
|
34720
33933
|
pullParams = objectType({
|
34721
33934
|
config: stringType().optional(),
|
@@ -34724,9 +33937,9 @@ var init_cli = __esm({
|
|
34724
33937
|
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
34725
33938
|
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34726
33939
|
extensionsFilters: literalType("postgis").array().optional(),
|
34727
|
-
|
33940
|
+
casing,
|
34728
33941
|
breakpoints: booleanType().optional().default(true),
|
34729
|
-
|
33942
|
+
migrations: objectType({
|
34730
33943
|
prefix: prefix.optional().default("index")
|
34731
33944
|
}).optional()
|
34732
33945
|
}).passthrough();
|
@@ -35867,8 +35080,284 @@ var sqlitePushIntrospect = async (db, filters) => {
|
|
35867
35080
|
return { schema: schema4 };
|
35868
35081
|
};
|
35869
35082
|
|
35083
|
+
// src/cli/commands/sqlitePushUtils.ts
|
35084
|
+
init_source();
|
35085
|
+
init_sqliteSchema();
|
35086
|
+
init_sqlgenerator();
|
35087
|
+
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
35088
|
+
const statements = [];
|
35089
|
+
statements.push(
|
35090
|
+
new SqliteRenameTableConvertor().convert({
|
35091
|
+
type: "rename_table",
|
35092
|
+
tableNameFrom: tableName,
|
35093
|
+
tableNameTo: `__old_push_${tableName}`,
|
35094
|
+
fromSchema: "",
|
35095
|
+
toSchema: ""
|
35096
|
+
})
|
35097
|
+
);
|
35098
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
35099
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
35100
|
+
const compositePKs = Object.values(
|
35101
|
+
json.tables[tableName].compositePrimaryKeys
|
35102
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
35103
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
35104
|
+
statements.push(
|
35105
|
+
new SQLiteCreateTableConvertor().convert({
|
35106
|
+
type: "sqlite_create_table",
|
35107
|
+
tableName,
|
35108
|
+
columns: tableColumns,
|
35109
|
+
referenceData: fks,
|
35110
|
+
compositePKs
|
35111
|
+
})
|
35112
|
+
);
|
35113
|
+
if (!dataLoss) {
|
35114
|
+
statements.push(
|
35115
|
+
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
35116
|
+
);
|
35117
|
+
}
|
35118
|
+
statements.push(
|
35119
|
+
new SQLiteDropTableConvertor().convert({
|
35120
|
+
type: "drop_table",
|
35121
|
+
tableName: `__old_push_${tableName}`,
|
35122
|
+
schema: ""
|
35123
|
+
})
|
35124
|
+
);
|
35125
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
35126
|
+
statements.push(
|
35127
|
+
new CreateSqliteIndexConvertor().convert({
|
35128
|
+
type: "create_index",
|
35129
|
+
tableName,
|
35130
|
+
schema: "",
|
35131
|
+
data: idx
|
35132
|
+
})
|
35133
|
+
);
|
35134
|
+
}
|
35135
|
+
return statements;
|
35136
|
+
};
|
35137
|
+
var getOldTableName = (tableName, meta) => {
|
35138
|
+
for (const key of Object.keys(meta.tables)) {
|
35139
|
+
const value = meta.tables[key];
|
35140
|
+
if (`"${tableName}"` === value) {
|
35141
|
+
return key.substring(1, key.length - 1);
|
35142
|
+
}
|
35143
|
+
}
|
35144
|
+
return tableName;
|
35145
|
+
};
|
35146
|
+
var getNewTableName = (tableName, meta) => {
|
35147
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
35148
|
+
return meta.tables[`"${tableName}"`].substring(
|
35149
|
+
1,
|
35150
|
+
meta.tables[`"${tableName}"`].length - 1
|
35151
|
+
);
|
35152
|
+
}
|
35153
|
+
return tableName;
|
35154
|
+
};
|
35155
|
+
var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
35156
|
+
let shouldAskForApprove = false;
|
35157
|
+
const statementsToExecute = [];
|
35158
|
+
const infoToPrint = [];
|
35159
|
+
const tablesToRemove = [];
|
35160
|
+
const columnsToRemove = [];
|
35161
|
+
const schemasToRemove = [];
|
35162
|
+
const tablesToTruncate = [];
|
35163
|
+
const tablesContext = {};
|
35164
|
+
for (const statement of statements) {
|
35165
|
+
if (statement.type === "drop_table") {
|
35166
|
+
const res = await connection.query(
|
35167
|
+
`select count(*) as count from \`${statement.tableName}\``
|
35168
|
+
);
|
35169
|
+
const count2 = Number(res[0].count);
|
35170
|
+
if (count2 > 0) {
|
35171
|
+
infoToPrint.push(
|
35172
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35173
|
+
statement.tableName
|
35174
|
+
)} table with ${count2} items`
|
35175
|
+
);
|
35176
|
+
tablesToRemove.push(statement.tableName);
|
35177
|
+
shouldAskForApprove = true;
|
35178
|
+
}
|
35179
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35180
|
+
statementsToExecute.push(stmnt);
|
35181
|
+
} else if (statement.type === "alter_table_drop_column") {
|
35182
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35183
|
+
const columnIsPartOfPk = Object.values(
|
35184
|
+
json1.tables[newTableName].compositePrimaryKeys
|
35185
|
+
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
35186
|
+
const columnIsPartOfIndex = Object.values(
|
35187
|
+
json1.tables[newTableName].indexes
|
35188
|
+
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
35189
|
+
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
35190
|
+
const columnIsPartOfFk = Object.values(
|
35191
|
+
json1.tables[newTableName].foreignKeys
|
35192
|
+
).find(
|
35193
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
|
35194
|
+
statement.columnName
|
35195
|
+
)
|
35196
|
+
);
|
35197
|
+
const res = await connection.query(
|
35198
|
+
`select count(*) as count from \`${newTableName}\``
|
35199
|
+
);
|
35200
|
+
const count2 = Number(res[0].count);
|
35201
|
+
if (count2 > 0) {
|
35202
|
+
infoToPrint.push(
|
35203
|
+
`\xB7 You're about to delete ${source_default.underline(
|
35204
|
+
statement.columnName
|
35205
|
+
)} column in ${newTableName} table with ${count2} items`
|
35206
|
+
);
|
35207
|
+
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
35208
|
+
shouldAskForApprove = true;
|
35209
|
+
}
|
35210
|
+
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
35211
|
+
tablesContext[newTableName] = [
|
35212
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35213
|
+
];
|
35214
|
+
const tablesReferncingCurrent = [];
|
35215
|
+
for (const table4 of Object.values(json1.tables)) {
|
35216
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35217
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35218
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35219
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35220
|
+
}
|
35221
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35222
|
+
for (const table4 of uniqueTableRefs) {
|
35223
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35224
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35225
|
+
}
|
35226
|
+
}
|
35227
|
+
} else {
|
35228
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35229
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35230
|
+
statementsToExecute.push(stmnt);
|
35231
|
+
}
|
35232
|
+
}
|
35233
|
+
} else if (statement.type === "sqlite_alter_table_add_column") {
|
35234
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35235
|
+
if (statement.column.notNull && !statement.column.default) {
|
35236
|
+
const res = await connection.query(
|
35237
|
+
`select count(*) as count from \`${newTableName}\``
|
35238
|
+
);
|
35239
|
+
const count2 = Number(res[0].count);
|
35240
|
+
if (count2 > 0) {
|
35241
|
+
infoToPrint.push(
|
35242
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
35243
|
+
statement.column.name
|
35244
|
+
)} column without default value, which contains ${count2} items`
|
35245
|
+
);
|
35246
|
+
tablesToTruncate.push(newTableName);
|
35247
|
+
statementsToExecute.push(`delete from ${newTableName};`);
|
35248
|
+
shouldAskForApprove = true;
|
35249
|
+
}
|
35250
|
+
}
|
35251
|
+
if (statement.column.primaryKey) {
|
35252
|
+
tablesContext[newTableName] = [
|
35253
|
+
..._moveDataStatements(statement.tableName, json2, true)
|
35254
|
+
];
|
35255
|
+
const tablesReferncingCurrent = [];
|
35256
|
+
for (const table4 of Object.values(json1.tables)) {
|
35257
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35258
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35259
|
+
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35260
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35261
|
+
}
|
35262
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35263
|
+
for (const table4 of uniqueTableRefs) {
|
35264
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35265
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35266
|
+
}
|
35267
|
+
}
|
35268
|
+
} else {
|
35269
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35270
|
+
const stmnt = fromJson([statement], "sqlite")[0];
|
35271
|
+
statementsToExecute.push(stmnt);
|
35272
|
+
}
|
35273
|
+
}
|
35274
|
+
} else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
|
35275
|
+
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
35276
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35277
|
+
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
35278
|
+
const res = await connection.query(
|
35279
|
+
`select count(*) as count from \`${newTableName}\``
|
35280
|
+
);
|
35281
|
+
const count2 = Number(res[0].count);
|
35282
|
+
if (count2 > 0) {
|
35283
|
+
infoToPrint.push(
|
35284
|
+
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
35285
|
+
statement.columnName
|
35286
|
+
)} column without default value, which contains ${count2} items`
|
35287
|
+
);
|
35288
|
+
tablesToTruncate.push(newTableName);
|
35289
|
+
shouldAskForApprove = true;
|
35290
|
+
}
|
35291
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35292
|
+
statement.tableName,
|
35293
|
+
json1,
|
35294
|
+
true
|
35295
|
+
);
|
35296
|
+
} else {
|
35297
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35298
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35299
|
+
statement.tableName,
|
35300
|
+
json1
|
35301
|
+
);
|
35302
|
+
}
|
35303
|
+
}
|
35304
|
+
const tablesReferncingCurrent = [];
|
35305
|
+
for (const table4 of Object.values(json1.tables)) {
|
35306
|
+
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35307
|
+
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35308
|
+
).map((t) => {
|
35309
|
+
return getNewTableName(
|
35310
|
+
SQLiteSquasher.unsquashPushFK(t).tableFrom,
|
35311
|
+
meta
|
35312
|
+
);
|
35313
|
+
});
|
35314
|
+
tablesReferncingCurrent.push(...tablesRefs);
|
35315
|
+
}
|
35316
|
+
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35317
|
+
for (const table4 of uniqueTableRefs) {
|
35318
|
+
if (typeof tablesContext[table4] === "undefined") {
|
35319
|
+
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
35320
|
+
}
|
35321
|
+
}
|
35322
|
+
}
|
35323
|
+
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
35324
|
+
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
35325
|
+
if (typeof tablesContext[statement.tableName] === "undefined") {
|
35326
|
+
tablesContext[statement.tableName] = _moveDataStatements(
|
35327
|
+
statement.tableName,
|
35328
|
+
json2
|
35329
|
+
);
|
35330
|
+
}
|
35331
|
+
} else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
|
35332
|
+
const newTableName = getOldTableName(statement.tableName, meta);
|
35333
|
+
if (typeof tablesContext[newTableName] === "undefined") {
|
35334
|
+
tablesContext[newTableName] = _moveDataStatements(
|
35335
|
+
statement.tableName,
|
35336
|
+
json2
|
35337
|
+
);
|
35338
|
+
}
|
35339
|
+
} else {
|
35340
|
+
const stmnt = fromJson([statement], "sqlite");
|
35341
|
+
if (typeof stmnt !== "undefined") {
|
35342
|
+
statementsToExecute.push(...stmnt);
|
35343
|
+
}
|
35344
|
+
}
|
35345
|
+
}
|
35346
|
+
for (const context of Object.values(tablesContext)) {
|
35347
|
+
statementsToExecute.push(...context);
|
35348
|
+
}
|
35349
|
+
return {
|
35350
|
+
statementsToExecute,
|
35351
|
+
shouldAskForApprove,
|
35352
|
+
infoToPrint,
|
35353
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
35354
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
35355
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
35356
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
35357
|
+
};
|
35358
|
+
};
|
35359
|
+
|
35870
35360
|
// src/api.ts
|
35871
|
-
init_sqlitePushUtils();
|
35872
35361
|
init_global();
|
35873
35362
|
init_migrationPreparator();
|
35874
35363
|
init_mysqlSchema();
|