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.
Files changed (8) hide show
  1. package/api.d.mts +10 -0
  2. package/api.d.ts +10 -0
  3. package/api.js +842 -1353
  4. package/api.mjs +842 -1353
  5. package/bin.cjs +1732 -2167
  6. package/package.json +3 -3
  7. package/utils.js +2 -10
  8. package/utils.mjs +2 -9
package/api.js CHANGED
@@ -7464,11 +7464,30 @@ var init_mysqlSchema = __esm({
7464
7464
  }
7465
7465
  });
7466
7466
 
7467
+ // src/extensions/vector.ts
7468
+ var vectorOps;
7469
+ var init_vector = __esm({
7470
+ "src/extensions/vector.ts"() {
7471
+ "use strict";
7472
+ vectorOps = [
7473
+ "vector_l2_ops",
7474
+ "vector_ip_ops",
7475
+ "vector_cosine_ops",
7476
+ "vector_l1_ops",
7477
+ "bit_hamming_ops",
7478
+ "bit_jaccard_ops",
7479
+ "halfvec_l2_ops",
7480
+ "sparsevec_l2_ops"
7481
+ ];
7482
+ }
7483
+ });
7484
+
7467
7485
  // src/serializer/pgSchema.ts
7468
7486
  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;
7469
7487
  var init_pgSchema = __esm({
7470
7488
  "src/serializer/pgSchema.ts"() {
7471
7489
  "use strict";
7490
+ init_vector();
7472
7491
  init_global();
7473
7492
  init_lib();
7474
7493
  indexV2 = objectType({
@@ -7715,7 +7734,8 @@ var init_pgSchema = __esm({
7715
7734
  objectType({
7716
7735
  isArray: booleanType().optional(),
7717
7736
  dimensions: numberType().optional(),
7718
- rawType: stringType().optional()
7737
+ rawType: stringType().optional(),
7738
+ isDefaultAnExpression: booleanType().optional()
7719
7739
  }).optional()
7720
7740
  )
7721
7741
  }).optional()
@@ -7853,7 +7873,7 @@ var init_pgSchema = __esm({
7853
7873
  squashIdx: (idx) => {
7854
7874
  index2.parse(idx);
7855
7875
  return `${idx.name};${idx.columns.map(
7856
- (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
7876
+ (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
7857
7877
  ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
7858
7878
  },
7859
7879
  unsquashIdx: (input) => {
@@ -8341,13 +8361,6 @@ var init_sqliteSchema = __esm({
8341
8361
  function isPgArrayType(sqlType) {
8342
8362
  return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
8343
8363
  }
8344
- function findAddedAndRemoved(columnNames1, columnNames2) {
8345
- const set1 = new Set(columnNames1);
8346
- const set2 = new Set(columnNames2);
8347
- const addedColumns = columnNames2.filter((it) => !set1.has(it));
8348
- const removedColumns = columnNames1.filter((it) => !set2.has(it));
8349
- return { addedColumns, removedColumns };
8350
- }
8351
8364
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8352
8365
  var init_utils = __esm({
8353
8366
  "src/utils.ts"() {
@@ -11457,20 +11470,7 @@ var init_jsonDiffer = __esm({
11457
11470
  });
11458
11471
 
11459
11472
  // src/sqlgenerator.ts
11460
- function fromJson(statements, dialect7, action, driver2, json2) {
11461
- const result = statements.flatMap((statement) => {
11462
- const filtered = convertors.filter((it) => {
11463
- return it.can(statement, dialect7, driver2);
11464
- });
11465
- const convertor = filtered.length === 1 ? filtered[0] : void 0;
11466
- if (!convertor) {
11467
- return "";
11468
- }
11469
- return convertor.convert(statement, json2, action);
11470
- }).filter((it) => it !== "");
11471
- return result;
11472
- }
11473
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, 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;
11473
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
11474
11474
  var init_sqlgenerator = __esm({
11475
11475
  "src/sqlgenerator.ts"() {
11476
11476
  "use strict";
@@ -11522,7 +11522,7 @@ var init_sqlgenerator = __esm({
11522
11522
  isPgNativeType = (it) => {
11523
11523
  if (pgNativeTypes.has(it)) return true;
11524
11524
  const toCheck = it.replace(/ /g, "");
11525
- 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);
11525
+ 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);
11526
11526
  };
11527
11527
  Convertor = class {
11528
11528
  };
@@ -11792,6 +11792,32 @@ var init_sqlgenerator = __esm({
11792
11792
  return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
11793
11793
  }
11794
11794
  };
11795
+ SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
11796
+ can(statement, dialect7) {
11797
+ return statement.type === "create_unique_constraint" && dialect7 === "sqlite";
11798
+ }
11799
+ convert(statement) {
11800
+ return `/*
11801
+ 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
11802
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
11803
+
11804
+ Due to that we don't generate migration automatically and it has to be done manually
11805
+ */`;
11806
+ }
11807
+ };
11808
+ SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
11809
+ can(statement, dialect7) {
11810
+ return statement.type === "delete_unique_constraint" && dialect7 === "sqlite";
11811
+ }
11812
+ convert(statement) {
11813
+ return `/*
11814
+ 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
11815
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
11816
+
11817
+ Due to that we don't generate migration automatically and it has to be done manually
11818
+ */`;
11819
+ }
11820
+ };
11795
11821
  CreatePgSequenceConvertor = class extends Convertor {
11796
11822
  can(statement, dialect7) {
11797
11823
  return statement.type === "create_sequence" && dialect7 === "postgresql";
@@ -11960,7 +11986,7 @@ var init_sqlgenerator = __esm({
11960
11986
  }
11961
11987
  convert(statement) {
11962
11988
  const { tableName, oldColumnName, newColumnName } = statement;
11963
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
11989
+ return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
11964
11990
  }
11965
11991
  };
11966
11992
  PgAlterTableDropColumnConvertor = class extends Convertor {
@@ -12061,6 +12087,21 @@ var init_sqlgenerator = __esm({
12061
12087
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DATA TYPE ${newDataType};`;
12062
12088
  }
12063
12089
  };
12090
+ SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
12091
+ can(statement, dialect7) {
12092
+ return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
12093
+ }
12094
+ convert(statement) {
12095
+ return `/*
12096
+ 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
12097
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12098
+ https://www.sqlite.org/lang_altertable.html
12099
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12100
+
12101
+ Due to that we don't generate migration automatically and it has to be done manually
12102
+ */`;
12103
+ }
12104
+ };
12064
12105
  PgAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
12065
12106
  can(statement, dialect7) {
12066
12107
  return statement.type === "alter_table_alter_column_set_default" && dialect7 === "postgresql";
@@ -12071,6 +12112,21 @@ var init_sqlgenerator = __esm({
12071
12112
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DEFAULT ${statement.newDefaultValue};`;
12072
12113
  }
12073
12114
  };
12115
+ SqliteAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
12116
+ can(statement, dialect7) {
12117
+ return statement.type === "alter_table_alter_column_set_default" && dialect7 === "sqlite";
12118
+ }
12119
+ convert(statement) {
12120
+ return `/*
12121
+ 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
12122
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12123
+ https://www.sqlite.org/lang_altertable.html
12124
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12125
+
12126
+ Due to that we don't generate migration automatically and it has to be done manually
12127
+ */`;
12128
+ }
12129
+ };
12074
12130
  PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
12075
12131
  can(statement, dialect7) {
12076
12132
  return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "postgresql";
@@ -12344,67 +12400,6 @@ var init_sqlgenerator = __esm({
12344
12400
  return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
12345
12401
  }
12346
12402
  };
12347
- LibSQLModifyColumn = class extends Convertor {
12348
- can(statement, dialect7, driver2) {
12349
- 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";
12350
- }
12351
- convert(statement, json2, action) {
12352
- const { tableName, columnName } = statement;
12353
- let columnType = ``;
12354
- let columnDefault = "";
12355
- let columnNotNull = "";
12356
- const sqlStatements = [];
12357
- const indexes = [];
12358
- for (const table4 of Object.values(json2.tables)) {
12359
- for (const index4 of Object.values(table4.indexes)) {
12360
- const unsquashed = SQLiteSquasher.unsquashIdx(index4);
12361
- sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
12362
- indexes.push({ ...unsquashed, tableName: table4.name });
12363
- }
12364
- }
12365
- switch (statement.type) {
12366
- case "alter_table_alter_column_set_type":
12367
- columnType = ` ${statement.newDataType}`;
12368
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12369
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12370
- break;
12371
- case "alter_table_alter_column_drop_notnull":
12372
- columnType = ` ${statement.newDataType}`;
12373
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12374
- columnNotNull = "";
12375
- break;
12376
- case "alter_table_alter_column_set_notnull":
12377
- columnType = ` ${statement.newDataType}`;
12378
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12379
- columnNotNull = ` NOT NULL`;
12380
- break;
12381
- case "alter_table_alter_column_set_default":
12382
- columnType = ` ${statement.newDataType}`;
12383
- columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
12384
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12385
- break;
12386
- case "alter_table_alter_column_drop_default":
12387
- columnType = ` ${statement.newDataType}`;
12388
- columnDefault = "";
12389
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12390
- break;
12391
- }
12392
- columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
12393
- sqlStatements.push(
12394
- `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`
12395
- );
12396
- for (const index4 of indexes) {
12397
- const indexPart = index4.isUnique ? "UNIQUE INDEX" : "INDEX";
12398
- const whereStatement = index4.where ? ` WHERE ${index4.where}` : "";
12399
- const uniqueString = index4.columns.map((it) => `\`${it}\``).join(",");
12400
- const tableName2 = index4.tableName;
12401
- sqlStatements.push(
12402
- `CREATE ${indexPart} \`${index4.name}\` ON \`${tableName2}\` (${uniqueString})${whereStatement};`
12403
- );
12404
- }
12405
- return sqlStatements;
12406
- }
12407
- };
12408
12403
  MySqlModifyColumn = class extends Convertor {
12409
12404
  can(statement, dialect7) {
12410
12405
  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";
@@ -12542,6 +12537,21 @@ var init_sqlgenerator = __esm({
12542
12537
  return `ALTER TABLE \`${tableName}\` MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnNotNull}${columnDefault}${columnOnUpdate}${columnGenerated};`;
12543
12538
  }
12544
12539
  };
12540
+ SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
12541
+ can(statement, dialect7) {
12542
+ return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "sqlite";
12543
+ }
12544
+ convert(statement) {
12545
+ return `/*
12546
+ 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
12547
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12548
+ https://www.sqlite.org/lang_altertable.html
12549
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12550
+
12551
+ Due to that we don't generate migration automatically and it has to be done manually
12552
+ */`;
12553
+ }
12554
+ };
12545
12555
  PgAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
12546
12556
  can(statement, dialect7) {
12547
12557
  return statement.type === "create_composite_pk" && dialect7 === "postgresql";
@@ -12606,6 +12616,85 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12606
12616
  return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY, ADD PRIMARY KEY(\`${newColumns.join("`,`")}\`);`;
12607
12617
  }
12608
12618
  };
12619
+ SqliteAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
12620
+ can(statement, dialect7) {
12621
+ return statement.type === "create_composite_pk" && dialect7 === "sqlite";
12622
+ }
12623
+ convert(statement) {
12624
+ let msg = "/*\n";
12625
+ msg += `You're trying to add PRIMARY KEY(${statement.data}) to '${statement.tableName}' table
12626
+ `;
12627
+ msg += "SQLite does not support adding primary key to an already created table\n";
12628
+ msg += "You can do it in 3 steps with drizzle orm:\n";
12629
+ msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
12630
+ msg += " - migrate old data from one table to another\n";
12631
+ msg += " - delete old_table in schema, generate sql\n\n";
12632
+ msg += "or create manual migration like below:\n\n";
12633
+ msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12634
+ msg += "CREATE TABLE table_name (\n";
12635
+ msg += " column1 datatype [ NULL | NOT NULL ],\n";
12636
+ msg += " column2 datatype [ NULL | NOT NULL ],\n";
12637
+ msg += " ...\n";
12638
+ msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12639
+ msg += " );\n";
12640
+ msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12641
+ msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12642
+ msg += "*/\n";
12643
+ return msg;
12644
+ }
12645
+ };
12646
+ SqliteAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
12647
+ can(statement, dialect7) {
12648
+ return statement.type === "delete_composite_pk" && dialect7 === "sqlite";
12649
+ }
12650
+ convert(statement) {
12651
+ let msg = "/*\n";
12652
+ msg += `You're trying to delete PRIMARY KEY(${statement.data}) from '${statement.tableName}' table
12653
+ `;
12654
+ msg += "SQLite does not supportprimary key deletion from existing table\n";
12655
+ msg += "You can do it in 3 steps with drizzle orm:\n";
12656
+ msg += " - create new mirror table table without pk, rename current table to old_table, generate SQL\n";
12657
+ msg += " - migrate old data from one table to another\n";
12658
+ msg += " - delete old_table in schema, generate sql\n\n";
12659
+ msg += "or create manual migration like below:\n\n";
12660
+ msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12661
+ msg += "CREATE TABLE table_name (\n";
12662
+ msg += " column1 datatype [ NULL | NOT NULL ],\n";
12663
+ msg += " column2 datatype [ NULL | NOT NULL ],\n";
12664
+ msg += " ...\n";
12665
+ msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12666
+ msg += " );\n";
12667
+ msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12668
+ msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12669
+ msg += "*/\n";
12670
+ return msg;
12671
+ }
12672
+ };
12673
+ SqliteAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
12674
+ can(statement, dialect7) {
12675
+ return statement.type === "alter_composite_pk" && dialect7 === "sqlite";
12676
+ }
12677
+ convert(statement) {
12678
+ let msg = "/*\n";
12679
+ msg += "SQLite does not support altering primary key\n";
12680
+ msg += "You can do it in 3 steps with drizzle orm:\n";
12681
+ msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
12682
+ msg += " - migrate old data from one table to another\n";
12683
+ msg += " - delete old_table in schema, generate sql\n\n";
12684
+ msg += "or create manual migration like below:\n\n";
12685
+ msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12686
+ msg += "CREATE TABLE table_name (\n";
12687
+ msg += " column1 datatype [ NULL | NOT NULL ],\n";
12688
+ msg += " column2 datatype [ NULL | NOT NULL ],\n";
12689
+ msg += " ...\n";
12690
+ msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12691
+ msg += " );\n";
12692
+ msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12693
+ msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12694
+ msg += "*/\n";
12695
+ return msg;
12696
+ }
12697
+ };
12609
12698
  PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
12610
12699
  can(statement, dialect7) {
12611
12700
  return statement.type === "alter_table_alter_column_set_pk" && dialect7 === "postgresql";
@@ -12650,6 +12739,51 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12650
12739
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET NOT NULL;`;
12651
12740
  }
12652
12741
  };
12742
+ SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
12743
+ can(statement, dialect7) {
12744
+ return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
12745
+ }
12746
+ convert(statement) {
12747
+ return `/*
12748
+ 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
12749
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12750
+ https://www.sqlite.org/lang_altertable.html
12751
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12752
+
12753
+ Due to that we don't generate migration automatically and it has to be done manually
12754
+ */`;
12755
+ }
12756
+ };
12757
+ SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
12758
+ can(statement, dialect7) {
12759
+ return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
12760
+ }
12761
+ convert(statement) {
12762
+ return `/*
12763
+ 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
12764
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12765
+ https://www.sqlite.org/lang_altertable.html
12766
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12767
+
12768
+ Due to that we don't generate migration automatically and it has to be done manually
12769
+ */`;
12770
+ }
12771
+ };
12772
+ SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
12773
+ can(statement, dialect7) {
12774
+ return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
12775
+ }
12776
+ convert(statement) {
12777
+ return `/*
12778
+ 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
12779
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12780
+ https://www.sqlite.org/lang_altertable.html
12781
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12782
+
12783
+ Due to that we don't generate migration automatically and it has to be done manually
12784
+ */`;
12785
+ }
12786
+ };
12653
12787
  PgAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
12654
12788
  can(statement, dialect7) {
12655
12789
  return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "postgresql";
@@ -12660,6 +12794,21 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12660
12794
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP NOT NULL;`;
12661
12795
  }
12662
12796
  };
12797
+ SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
12798
+ can(statement, dialect7) {
12799
+ return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
12800
+ }
12801
+ convert(statement) {
12802
+ return `/*
12803
+ 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
12804
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12805
+ https://www.sqlite.org/lang_altertable.html
12806
+ https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12807
+
12808
+ Due to that we don't generate migration automatically and it has to be done manually
12809
+ */`;
12810
+ }
12811
+ };
12663
12812
  PgCreateForeignKeyConvertor = class extends Convertor {
12664
12813
  can(statement, dialect7) {
12665
12814
  return statement.type === "create_reference" && dialect7 === "postgresql";
@@ -12690,21 +12839,18 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12690
12839
  return sql2;
12691
12840
  }
12692
12841
  };
12693
- LibSQLCreateForeignKeyConvertor = class extends Convertor {
12694
- can(statement, dialect7, driver2) {
12695
- return statement.type === "create_reference" && dialect7 === "sqlite" && driver2 === "turso";
12842
+ SqliteCreateForeignKeyConvertor = class extends Convertor {
12843
+ can(statement, dialect7) {
12844
+ return statement.type === "create_reference" && dialect7 === "sqlite";
12696
12845
  }
12697
- convert(statement, json2, action) {
12698
- const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
12699
- const { columnDefault, columnNotNull, columnType } = statement;
12700
- const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
12701
- const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
12702
- const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
12703
- const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
12704
- const columnTypeValue = columnType ? ` ${columnType}` : "";
12705
- const columnFrom = columnsFrom[0];
12706
- const columnTo = columnsTo[0];
12707
- return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
12846
+ convert(statement) {
12847
+ return `/*
12848
+ 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
12849
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12850
+ https://www.sqlite.org/lang_altertable.html
12851
+
12852
+ Due to that we don't generate migration automatically and it has to be done manually
12853
+ */`;
12708
12854
  }
12709
12855
  };
12710
12856
  MySqlCreateForeignKeyConvertor = class extends Convertor {
@@ -12753,6 +12899,20 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12753
12899
  return sql2;
12754
12900
  }
12755
12901
  };
12902
+ SqliteAlterForeignKeyConvertor = class extends Convertor {
12903
+ can(statement, dialect7) {
12904
+ return statement.type === "alter_reference" && dialect7 === "sqlite";
12905
+ }
12906
+ convert(statement) {
12907
+ return `/*
12908
+ 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
12909
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12910
+ https://www.sqlite.org/lang_altertable.html
12911
+
12912
+ Due to that we don't generate migration automatically and it has to be done manually
12913
+ */`;
12914
+ }
12915
+ };
12756
12916
  PgDeleteForeignKeyConvertor = class extends Convertor {
12757
12917
  can(statement, dialect7) {
12758
12918
  return statement.type === "delete_reference" && dialect7 === "postgresql";
@@ -12765,6 +12925,20 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12765
12925
  `;
12766
12926
  }
12767
12927
  };
12928
+ SqliteDeleteForeignKeyConvertor = class extends Convertor {
12929
+ can(statement, dialect7) {
12930
+ return statement.type === "delete_reference" && dialect7 === "sqlite";
12931
+ }
12932
+ convert(statement) {
12933
+ return `/*
12934
+ 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
12935
+ Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12936
+ https://www.sqlite.org/lang_altertable.html
12937
+
12938
+ Due to that we don't generate migration automatically and it has to be done manually
12939
+ */`;
12940
+ }
12941
+ };
12768
12942
  MySqlDeleteForeignKeyConvertor = class extends Convertor {
12769
12943
  can(statement, dialect7) {
12770
12944
  return statement.type === "delete_reference" && dialect7 === "mysql";
@@ -12928,96 +13102,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12928
13102
  return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
12929
13103
  }
12930
13104
  };
12931
- SQLiteRecreateTableConvertor = class extends Convertor {
12932
- can(statement, dialect7, driver2) {
12933
- return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
12934
- }
12935
- convert(statement) {
12936
- const { tableName, columns, compositePKs, referenceData } = statement;
12937
- const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
12938
- const newTableName = `__new_${tableName}`;
12939
- const sqlStatements = [];
12940
- sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
12941
- sqlStatements.push(
12942
- new SQLiteCreateTableConvertor().convert({
12943
- type: "sqlite_create_table",
12944
- tableName: newTableName,
12945
- columns,
12946
- referenceData,
12947
- compositePKs
12948
- })
12949
- );
12950
- sqlStatements.push(
12951
- `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
12952
- );
12953
- sqlStatements.push(
12954
- new SQLiteDropTableConvertor().convert({
12955
- type: "drop_table",
12956
- tableName,
12957
- schema: ""
12958
- })
12959
- );
12960
- sqlStatements.push(
12961
- new SqliteRenameTableConvertor().convert({
12962
- fromSchema: "",
12963
- tableNameFrom: newTableName,
12964
- tableNameTo: tableName,
12965
- toSchema: "",
12966
- type: "rename_table"
12967
- })
12968
- );
12969
- sqlStatements.push(`PRAGMA foreign_keys=ON;`);
12970
- return sqlStatements;
12971
- }
12972
- };
12973
- LibSQLRecreateTableConvertor = class extends Convertor {
12974
- can(statement, dialect7, driver2) {
12975
- return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
12976
- }
12977
- convert(statement) {
12978
- const { tableName, columns, compositePKs, referenceData } = statement;
12979
- const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
12980
- const newTableName = `__new_${tableName}`;
12981
- const sqlStatements = [];
12982
- sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
12983
- sqlStatements.push(
12984
- new SQLiteCreateTableConvertor().convert({
12985
- type: "sqlite_create_table",
12986
- tableName: newTableName,
12987
- columns,
12988
- referenceData,
12989
- compositePKs
12990
- })
12991
- );
12992
- sqlStatements.push(
12993
- `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
12994
- );
12995
- sqlStatements.push(
12996
- new SQLiteDropTableConvertor().convert({
12997
- type: "drop_table",
12998
- tableName,
12999
- schema: ""
13000
- })
13001
- );
13002
- sqlStatements.push(
13003
- new SqliteRenameTableConvertor().convert({
13004
- fromSchema: "",
13005
- tableNameFrom: newTableName,
13006
- tableNameTo: tableName,
13007
- toSchema: "",
13008
- type: "rename_table"
13009
- })
13010
- );
13011
- sqlStatements.push(`PRAGMA foreign_keys=ON;`);
13012
- return sqlStatements;
13013
- }
13014
- };
13015
13105
  convertors = [];
13016
13106
  convertors.push(new PgCreateTableConvertor());
13017
13107
  convertors.push(new MySqlCreateTableConvertor());
13018
13108
  convertors.push(new SQLiteCreateTableConvertor());
13019
- convertors.push(new SQLiteRecreateTableConvertor());
13020
- convertors.push(new LibSQLRecreateTableConvertor());
13021
13109
  convertors.push(new CreateTypeEnumConvertor());
13022
13110
  convertors.push(new CreatePgSequenceConvertor());
13023
13111
  convertors.push(new DropPgSequenceConvertor());
@@ -13065,7 +13153,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13065
13153
  convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
13066
13154
  convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
13067
13155
  convertors.push(new MySqlModifyColumn());
13068
- convertors.push(new LibSQLModifyColumn());
13069
13156
  convertors.push(new PgCreateForeignKeyConvertor());
13070
13157
  convertors.push(new MySqlCreateForeignKeyConvertor());
13071
13158
  convertors.push(new PgAlterForeignKeyConvertor());
@@ -13077,10 +13164,24 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13077
13164
  convertors.push(new PgAlterTableSetSchemaConvertor());
13078
13165
  convertors.push(new PgAlterTableSetNewSchemaConvertor());
13079
13166
  convertors.push(new PgAlterTableRemoveFromSchemaConvertor());
13080
- convertors.push(new LibSQLCreateForeignKeyConvertor());
13167
+ convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
13168
+ convertors.push(new SqliteAlterForeignKeyConvertor());
13169
+ convertors.push(new SqliteDeleteForeignKeyConvertor());
13170
+ convertors.push(new SqliteCreateForeignKeyConvertor());
13171
+ convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
13172
+ convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
13081
13173
  convertors.push(new PgAlterTableAlterColumnDropGenerated());
13082
13174
  convertors.push(new PgAlterTableAlterColumnSetGenerated());
13083
13175
  convertors.push(new PgAlterTableAlterColumnAlterGenerated());
13176
+ convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
13177
+ convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
13178
+ convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
13179
+ convertors.push(new SqliteAlterTableAlterColumnDropDefaultConvertor());
13180
+ convertors.push(new SqliteAlterTableAlterColumnSetAutoincrementConvertor());
13181
+ convertors.push(new SqliteAlterTableAlterColumnDropAutoincrementConvertor());
13182
+ convertors.push(new SqliteAlterTableCreateCompositePrimaryKeyConvertor());
13183
+ convertors.push(new SqliteAlterTableDeleteCompositePrimaryKeyConvertor());
13184
+ convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
13084
13185
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
13085
13186
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
13086
13187
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
@@ -13089,6 +13190,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13089
13190
  convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
13090
13191
  convertors.push(new MySqlAlterTableAddPk());
13091
13192
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
13193
+ fromJson = (statements, dialect7) => {
13194
+ const result = statements.flatMap((statement) => {
13195
+ const filtered = convertors.filter((it) => {
13196
+ return it.can(statement, dialect7);
13197
+ });
13198
+ const convertor = filtered.length === 1 ? filtered[0] : void 0;
13199
+ if (!convertor) {
13200
+ return "";
13201
+ }
13202
+ return convertor.convert(statement);
13203
+ }).filter((it) => it !== "");
13204
+ return result;
13205
+ };
13092
13206
  https: `
13093
13207
  create table users (
13094
13208
  id int,
@@ -13115,312 +13229,76 @@ drop type __venum;
13115
13229
  }
13116
13230
  });
13117
13231
 
13118
- // src/cli/commands/sqlitePushUtils.ts
13119
- var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
13120
- var init_sqlitePushUtils = __esm({
13121
- "src/cli/commands/sqlitePushUtils.ts"() {
13232
+ // src/jsonStatements.ts
13233
+ 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;
13234
+ var init_jsonStatements = __esm({
13235
+ "src/jsonStatements.ts"() {
13122
13236
  "use strict";
13123
13237
  init_source();
13238
+ init_views();
13239
+ init_mysqlSchema();
13240
+ init_pgSchema();
13124
13241
  init_sqliteSchema();
13125
- init_sqlgenerator();
13126
- init_utils();
13127
- _moveDataStatements = (tableName, json, dataLoss = false) => {
13128
- const statements = [];
13129
- const newTableName = `__new_${tableName}`;
13130
- const tableColumns = Object.values(json.tables[tableName].columns);
13131
- const referenceData = Object.values(json.tables[tableName].foreignKeys);
13132
- const compositePKs = Object.values(
13133
- json.tables[tableName].compositePrimaryKeys
13134
- ).map((it) => SQLiteSquasher.unsquashPK(it));
13135
- const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
13136
- statements.push(
13137
- new SQLiteCreateTableConvertor().convert({
13138
- type: "sqlite_create_table",
13139
- tableName: newTableName,
13140
- columns: tableColumns,
13141
- referenceData: fks,
13142
- compositePKs
13143
- })
13144
- );
13145
- if (!dataLoss) {
13146
- const columns = Object.keys(json.tables[tableName].columns).map(
13147
- (c) => `"${c}"`
13148
- );
13149
- statements.push(
13150
- `INSERT INTO \`${newTableName}\`(${columns.join(
13151
- ", "
13152
- )}) SELECT ${columns.join(", ")} FROM \`${tableName}\`;`
13153
- );
13154
- }
13155
- statements.push(
13156
- new SQLiteDropTableConvertor().convert({
13157
- type: "drop_table",
13158
- tableName,
13159
- schema: ""
13160
- })
13242
+ preparePgCreateTableJson = (table4, json2) => {
13243
+ const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
13244
+ const tableKey2 = `${schema4 || "public"}.${name2}`;
13245
+ const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
13246
+ return {
13247
+ type: "create_table",
13248
+ tableName: name2,
13249
+ schema: schema4,
13250
+ columns: Object.values(columns),
13251
+ compositePKs: Object.values(compositePrimaryKeys),
13252
+ compositePkName,
13253
+ uniqueConstraints: Object.values(uniqueConstraints)
13254
+ };
13255
+ };
13256
+ prepareMySqlCreateTableJson = (table4, json2, internals) => {
13257
+ const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
13258
+ return {
13259
+ type: "create_table",
13260
+ tableName: name2,
13261
+ schema: schema4,
13262
+ columns: Object.values(columns),
13263
+ compositePKs: Object.values(compositePrimaryKeys),
13264
+ compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
13265
+ uniqueConstraints: Object.values(uniqueConstraints),
13266
+ internals
13267
+ };
13268
+ };
13269
+ prepareSQLiteCreateTable = (table4, action) => {
13270
+ const { name: name2, columns, uniqueConstraints } = table4;
13271
+ const references2 = Object.values(table4.foreignKeys);
13272
+ const composites = Object.values(table4.compositePrimaryKeys).map(
13273
+ (it) => SQLiteSquasher.unsquashPK(it)
13161
13274
  );
13162
- statements.push(
13163
- new SqliteRenameTableConvertor().convert({
13164
- fromSchema: "",
13165
- tableNameFrom: newTableName,
13166
- tableNameTo: tableName,
13167
- toSchema: "",
13168
- type: "rename_table"
13169
- })
13275
+ const fks = references2.map(
13276
+ (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
13170
13277
  );
13171
- for (const idx of Object.values(json.tables[tableName].indexes)) {
13172
- statements.push(
13173
- new CreateSqliteIndexConvertor().convert({
13174
- type: "create_index",
13175
- tableName,
13176
- schema: "",
13177
- data: idx
13178
- })
13179
- );
13180
- }
13181
- return statements;
13278
+ return {
13279
+ type: "sqlite_create_table",
13280
+ tableName: name2,
13281
+ columns: Object.values(columns),
13282
+ referenceData: fks,
13283
+ compositePKs: composites,
13284
+ uniqueConstraints: Object.values(uniqueConstraints)
13285
+ };
13182
13286
  };
13183
- getOldTableName = (tableName, meta) => {
13184
- for (const key of Object.keys(meta.tables)) {
13185
- const value = meta.tables[key];
13186
- if (`"${tableName}"` === value) {
13187
- return key.substring(1, key.length - 1);
13188
- }
13189
- }
13190
- return tableName;
13287
+ prepareDropTableJson = (table4) => {
13288
+ return {
13289
+ type: "drop_table",
13290
+ tableName: table4.name,
13291
+ schema: table4.schema
13292
+ };
13191
13293
  };
13192
- getNewTableName = (tableName, meta) => {
13193
- if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
13194
- return meta.tables[`"${tableName}"`].substring(
13195
- 1,
13196
- meta.tables[`"${tableName}"`].length - 1
13197
- );
13198
- }
13199
- return tableName;
13200
- };
13201
- logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
13202
- let shouldAskForApprove = false;
13203
- const statementsToExecute = [];
13204
- const infoToPrint = [];
13205
- const tablesToRemove = [];
13206
- const columnsToRemove = [];
13207
- const schemasToRemove = [];
13208
- const tablesToTruncate = [];
13209
- for (const statement of statements) {
13210
- if (statement.type === "drop_table") {
13211
- const res = await connection.query(
13212
- `select count(*) as count from \`${statement.tableName}\``
13213
- );
13214
- const count2 = Number(res[0].count);
13215
- if (count2 > 0) {
13216
- infoToPrint.push(
13217
- `\xB7 You're about to delete ${source_default.underline(
13218
- statement.tableName
13219
- )} table with ${count2} items`
13220
- );
13221
- tablesToRemove.push(statement.tableName);
13222
- shouldAskForApprove = true;
13223
- }
13224
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13225
- statementsToExecute.push(
13226
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13227
- );
13228
- } else if (statement.type === "alter_table_drop_column") {
13229
- const tableName = statement.tableName;
13230
- const columnName = statement.columnName;
13231
- const res = await connection.query(
13232
- `select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
13233
- );
13234
- const count2 = Number(res[0].count);
13235
- if (count2 > 0) {
13236
- infoToPrint.push(
13237
- `\xB7 You're about to delete ${source_default.underline(
13238
- columnName
13239
- )} column in ${tableName} table with ${count2} items`
13240
- );
13241
- columnsToRemove.push(`${tableName}_${statement.columnName}`);
13242
- shouldAskForApprove = true;
13243
- }
13244
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13245
- statementsToExecute.push(
13246
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13247
- );
13248
- } else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
13249
- const tableName = statement.tableName;
13250
- const columnName = statement.column.name;
13251
- const res = await connection.query(
13252
- `select count(*) as count from \`${tableName}\``
13253
- );
13254
- const count2 = Number(res[0].count);
13255
- if (count2 > 0) {
13256
- infoToPrint.push(
13257
- `\xB7 You're about to add not-null ${source_default.underline(
13258
- columnName
13259
- )} column without default value, which contains ${count2} items`
13260
- );
13261
- tablesToTruncate.push(tableName);
13262
- statementsToExecute.push(`delete from ${tableName};`);
13263
- shouldAskForApprove = true;
13264
- }
13265
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13266
- statementsToExecute.push(
13267
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13268
- );
13269
- } else if (statement.type === "recreate_table") {
13270
- const tableName = statement.tableName;
13271
- const oldTableName = getOldTableName(tableName, meta);
13272
- let dataLoss = false;
13273
- const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
13274
- const currentColumnNames = Object.keys(json2.tables[tableName].columns);
13275
- const { removedColumns, addedColumns } = findAddedAndRemoved(
13276
- prevColumnNames,
13277
- currentColumnNames
13278
- );
13279
- if (removedColumns.length) {
13280
- for (const removedColumn of removedColumns) {
13281
- const res = await connection.query(
13282
- `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
13283
- );
13284
- const count2 = Number(res[0].count);
13285
- if (count2 > 0) {
13286
- infoToPrint.push(
13287
- `\xB7 You're about to delete ${source_default.underline(
13288
- removedColumn
13289
- )} column in ${tableName} table with ${count2} items`
13290
- );
13291
- columnsToRemove.push(removedColumn);
13292
- shouldAskForApprove = true;
13293
- }
13294
- }
13295
- }
13296
- if (addedColumns.length) {
13297
- for (const addedColumn of addedColumns) {
13298
- const [res] = await connection.query(
13299
- `select count(*) as count from \`${tableName}\``
13300
- );
13301
- const columnConf = json2.tables[tableName].columns[addedColumn];
13302
- const count2 = Number(res.count);
13303
- if (count2 > 0 && columnConf.notNull && !columnConf.default) {
13304
- dataLoss = true;
13305
- infoToPrint.push(
13306
- `\xB7 You're about to add not-null ${source_default.underline(
13307
- addedColumn
13308
- )} column without default value to table, which contains ${count2} items`
13309
- );
13310
- shouldAskForApprove = true;
13311
- tablesToTruncate.push(tableName);
13312
- statementsToExecute.push(`DELETE FROM \`${tableName}\`;`);
13313
- }
13314
- }
13315
- }
13316
- const tablesReferencingCurrent = [];
13317
- for (const table4 of Object.values(json2.tables)) {
13318
- const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
13319
- tablesReferencingCurrent.push(...tablesRefs);
13320
- }
13321
- if (!tablesReferencingCurrent.length) {
13322
- statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
13323
- continue;
13324
- }
13325
- const [{ foreign_keys: pragmaState }] = await connection.query(`PRAGMA foreign_keys;`);
13326
- if (pragmaState) {
13327
- statementsToExecute.push(`PRAGMA foreign_keys=OFF;`);
13328
- }
13329
- statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
13330
- if (pragmaState) {
13331
- statementsToExecute.push(`PRAGMA foreign_keys=ON;`);
13332
- }
13333
- } else {
13334
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13335
- statementsToExecute.push(
13336
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13337
- );
13338
- }
13339
- }
13340
- return {
13341
- statementsToExecute,
13342
- shouldAskForApprove,
13343
- infoToPrint,
13344
- columnsToRemove: [...new Set(columnsToRemove)],
13345
- schemasToRemove: [...new Set(schemasToRemove)],
13346
- tablesToTruncate: [...new Set(tablesToTruncate)],
13347
- tablesToRemove: [...new Set(tablesToRemove)]
13348
- };
13349
- };
13350
- }
13351
- });
13352
-
13353
- // src/jsonStatements.ts
13354
- 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;
13355
- var init_jsonStatements = __esm({
13356
- "src/jsonStatements.ts"() {
13357
- "use strict";
13358
- init_source();
13359
- init_sqlitePushUtils();
13360
- init_views();
13361
- init_mysqlSchema();
13362
- init_pgSchema();
13363
- init_sqliteSchema();
13364
- preparePgCreateTableJson = (table4, json2) => {
13365
- const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
13366
- const tableKey2 = `${schema4 || "public"}.${name2}`;
13367
- const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
13368
- return {
13369
- type: "create_table",
13370
- tableName: name2,
13371
- schema: schema4,
13372
- columns: Object.values(columns),
13373
- compositePKs: Object.values(compositePrimaryKeys),
13374
- compositePkName,
13375
- uniqueConstraints: Object.values(uniqueConstraints)
13376
- };
13377
- };
13378
- prepareMySqlCreateTableJson = (table4, json2, internals) => {
13379
- const { name: name2, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
13380
- return {
13381
- type: "create_table",
13382
- tableName: name2,
13383
- schema: schema4,
13384
- columns: Object.values(columns),
13385
- compositePKs: Object.values(compositePrimaryKeys),
13386
- compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name2].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
13387
- uniqueConstraints: Object.values(uniqueConstraints),
13388
- internals
13389
- };
13390
- };
13391
- prepareSQLiteCreateTable = (table4, action) => {
13392
- const { name: name2, columns, uniqueConstraints } = table4;
13393
- const references2 = Object.values(table4.foreignKeys);
13394
- const composites = Object.values(table4.compositePrimaryKeys).map(
13395
- (it) => SQLiteSquasher.unsquashPK(it)
13396
- );
13397
- const fks = references2.map(
13398
- (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
13399
- );
13400
- return {
13401
- type: "sqlite_create_table",
13402
- tableName: name2,
13403
- columns: Object.values(columns),
13404
- referenceData: fks,
13405
- compositePKs: composites,
13406
- uniqueConstraints: Object.values(uniqueConstraints)
13407
- };
13408
- };
13409
- prepareDropTableJson = (table4) => {
13410
- return {
13411
- type: "drop_table",
13412
- tableName: table4.name,
13413
- schema: table4.schema
13414
- };
13415
- };
13416
- prepareRenameTableJson = (tableFrom, tableTo) => {
13417
- return {
13418
- type: "rename_table",
13419
- fromSchema: tableTo.schema,
13420
- toSchema: tableTo.schema,
13421
- tableNameFrom: tableFrom.name,
13422
- tableNameTo: tableTo.name
13423
- };
13294
+ prepareRenameTableJson = (tableFrom, tableTo) => {
13295
+ return {
13296
+ type: "rename_table",
13297
+ fromSchema: tableTo.schema,
13298
+ toSchema: tableTo.schema,
13299
+ tableNameFrom: tableFrom.name,
13300
+ tableNameTo: tableTo.name
13301
+ };
13424
13302
  };
13425
13303
  prepareCreateEnumJson = (name2, schema4, values) => {
13426
13304
  return {
@@ -14140,49 +14018,6 @@ var init_jsonStatements = __esm({
14140
14018
  const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
14141
14019
  const columnGenerated = json2.tables[tableName].columns[columnName].generated;
14142
14020
  const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
14143
- if (column4.autoincrement?.type === "added") {
14144
- statements.push({
14145
- type: "alter_table_alter_column_set_autoincrement",
14146
- tableName,
14147
- columnName,
14148
- schema: schema4,
14149
- newDataType: columnType,
14150
- columnDefault,
14151
- columnOnUpdate,
14152
- columnNotNull,
14153
- columnAutoIncrement,
14154
- columnPk
14155
- });
14156
- }
14157
- if (column4.autoincrement?.type === "changed") {
14158
- const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
14159
- statements.push({
14160
- type,
14161
- tableName,
14162
- columnName,
14163
- schema: schema4,
14164
- newDataType: columnType,
14165
- columnDefault,
14166
- columnOnUpdate,
14167
- columnNotNull,
14168
- columnAutoIncrement,
14169
- columnPk
14170
- });
14171
- }
14172
- if (column4.autoincrement?.type === "deleted") {
14173
- statements.push({
14174
- type: "alter_table_alter_column_drop_autoincrement",
14175
- tableName,
14176
- columnName,
14177
- schema: schema4,
14178
- newDataType: columnType,
14179
- columnDefault,
14180
- columnOnUpdate,
14181
- columnNotNull,
14182
- columnAutoIncrement,
14183
- columnPk
14184
- });
14185
- }
14186
14021
  if (typeof column4.name !== "string") {
14187
14022
  statements.push({
14188
14023
  type: "alter_table_rename_column",
@@ -14446,37 +14281,6 @@ var init_jsonStatements = __esm({
14446
14281
  };
14447
14282
  });
14448
14283
  };
14449
- prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
14450
- return Object.values(foreignKeys).map((fkData) => {
14451
- const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14452
- let isMulticolumn = false;
14453
- if (columnsFrom.length > 1 || columnsTo.length > 1) {
14454
- isMulticolumn = true;
14455
- return {
14456
- type: "create_reference",
14457
- tableName,
14458
- data: fkData,
14459
- schema: schema4,
14460
- isMulticolumn
14461
- };
14462
- }
14463
- const columnFrom = columnsFrom[0];
14464
- const {
14465
- notNull: columnNotNull,
14466
- default: columnDefault,
14467
- type: columnType
14468
- } = json2.tables[tableFrom].columns[columnFrom];
14469
- return {
14470
- type: "create_reference",
14471
- tableName,
14472
- data: fkData,
14473
- schema: schema4,
14474
- columnNotNull,
14475
- columnDefault,
14476
- columnType
14477
- };
14478
- });
14479
- };
14480
14284
  prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
14481
14285
  return Object.values(foreignKeys).map((fkData) => {
14482
14286
  return {
@@ -14487,53 +14291,6 @@ var init_jsonStatements = __esm({
14487
14291
  };
14488
14292
  });
14489
14293
  };
14490
- prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
14491
- const statements = Object.values(foreignKeys).map((fkData) => {
14492
- const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14493
- const keys = Object.keys(json2.tables[tableName].columns);
14494
- const filtered = columnsFrom.filter((it) => keys.includes(it));
14495
- const fullDrop = filtered.length === 0;
14496
- if (fullDrop) return;
14497
- let isMulticolumn = false;
14498
- if (columnsFrom.length > 1 || columnsTo.length > 1) {
14499
- isMulticolumn = true;
14500
- return {
14501
- type: "delete_reference",
14502
- tableName,
14503
- data: fkData,
14504
- schema: schema4,
14505
- isMulticolumn
14506
- };
14507
- }
14508
- const columnFrom = columnsFrom[0];
14509
- const newTableName = getNewTableName(tableFrom, meta);
14510
- const {
14511
- notNull: columnNotNull,
14512
- default: columnDefault,
14513
- type: columnType
14514
- } = json2.tables[newTableName].columns[columnFrom];
14515
- const fkToSquash = {
14516
- columnsFrom,
14517
- columnsTo,
14518
- name: name2,
14519
- tableFrom: newTableName,
14520
- tableTo,
14521
- onDelete,
14522
- onUpdate
14523
- };
14524
- const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
14525
- return {
14526
- type: "delete_reference",
14527
- tableName,
14528
- data: foreignKey,
14529
- schema: schema4,
14530
- columnNotNull,
14531
- columnDefault,
14532
- columnType
14533
- };
14534
- });
14535
- return statements.filter((it) => it);
14536
- };
14537
14294
  prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
14538
14295
  const stmts = [];
14539
14296
  Object.values(foreignKeys).map((val) => {
@@ -14687,321 +14444,38 @@ var init_jsonStatements = __esm({
14687
14444
  }
14688
14445
  });
14689
14446
 
14690
- // src/statementCombiner.ts
14691
- var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
14692
- var init_statementCombiner = __esm({
14693
- "src/statementCombiner.ts"() {
14447
+ // src/snapshotsDiffer.ts
14448
+ var snapshotsDiffer_exports = {};
14449
+ __export(snapshotsDiffer_exports, {
14450
+ alteredTableScheme: () => alteredTableScheme,
14451
+ applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
14452
+ applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
14453
+ applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
14454
+ diffResultScheme: () => diffResultScheme,
14455
+ diffResultSchemeMysql: () => diffResultSchemeMysql,
14456
+ diffResultSchemeSQLite: () => diffResultSchemeSQLite,
14457
+ makePatched: () => makePatched,
14458
+ makeSelfOrPatched: () => makeSelfOrPatched
14459
+ });
14460
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
14461
+ var init_snapshotsDiffer = __esm({
14462
+ "src/snapshotsDiffer.ts"() {
14694
14463
  "use strict";
14464
+ init_lib();
14465
+ init_jsonDiffer();
14466
+ init_sqlgenerator();
14695
14467
  init_jsonStatements();
14468
+ init_global();
14469
+ init_mysqlSchema();
14470
+ init_pgSchema();
14696
14471
  init_sqliteSchema();
14697
- prepareLibSQLRecreateTable = (table4, action) => {
14698
- const { name: name2, columns, uniqueConstraints, indexes } = table4;
14699
- const composites = Object.values(table4.compositePrimaryKeys).map(
14700
- (it) => SQLiteSquasher.unsquashPK(it)
14701
- );
14702
- const references2 = Object.values(table4.foreignKeys);
14703
- const fks = references2.map(
14704
- (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14705
- );
14706
- const statements = [
14707
- {
14708
- type: "recreate_table",
14709
- tableName: name2,
14710
- columns: Object.values(columns),
14711
- compositePKs: composites,
14712
- referenceData: fks,
14713
- uniqueConstraints: Object.values(uniqueConstraints)
14714
- }
14715
- ];
14716
- if (Object.keys(indexes).length) {
14717
- statements.push(...prepareCreateIndexesJson(name2, "", indexes));
14718
- }
14719
- return statements;
14720
- };
14721
- prepareSQLiteRecreateTable = (table4, action) => {
14722
- const { name: name2, columns, uniqueConstraints, indexes } = table4;
14723
- const composites = Object.values(table4.compositePrimaryKeys).map(
14724
- (it) => SQLiteSquasher.unsquashPK(it)
14725
- );
14726
- const references2 = Object.values(table4.foreignKeys);
14727
- const fks = references2.map(
14728
- (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14729
- );
14730
- const statements = [
14731
- {
14732
- type: "recreate_table",
14733
- tableName: name2,
14734
- columns: Object.values(columns),
14735
- compositePKs: composites,
14736
- referenceData: fks,
14737
- uniqueConstraints: Object.values(uniqueConstraints)
14738
- }
14739
- ];
14740
- if (Object.keys(indexes).length) {
14741
- statements.push(...prepareCreateIndexesJson(name2, "", indexes));
14742
- }
14743
- return statements;
14744
- };
14745
- libSQLCombineStatements = (statements, json2, action) => {
14746
- const newStatements = {};
14747
- for (const statement of statements) {
14748
- 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") {
14749
- const tableName2 = statement.tableName;
14750
- const statementsForTable2 = newStatements[tableName2];
14751
- if (!statementsForTable2) {
14752
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14753
- continue;
14754
- }
14755
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14756
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14757
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14758
- if (wasRename) {
14759
- newStatements[tableName2].push(...preparedStatements);
14760
- } else {
14761
- newStatements[tableName2] = preparedStatements;
14762
- }
14763
- continue;
14764
- }
14765
- continue;
14766
- }
14767
- 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") {
14768
- const { tableName: tableName2, columnName, columnPk } = statement;
14769
- const columnIsPartOfForeignKey = Object.values(
14770
- json2.tables[tableName2].foreignKeys
14771
- ).some((it) => {
14772
- const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
14773
- return unsquashFk.columnsFrom.includes(columnName);
14774
- });
14775
- const statementsForTable2 = newStatements[tableName2];
14776
- if (!statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
14777
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14778
- continue;
14779
- }
14780
- if (statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
14781
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14782
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14783
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14784
- if (wasRename) {
14785
- newStatements[tableName2].push(...preparedStatements);
14786
- } else {
14787
- newStatements[tableName2] = preparedStatements;
14788
- }
14789
- }
14790
- continue;
14791
- }
14792
- if (statementsForTable2 && !(columnIsPartOfForeignKey || columnPk)) {
14793
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14794
- newStatements[tableName2].push(statement);
14795
- }
14796
- continue;
14797
- }
14798
- newStatements[tableName2] = [statement];
14799
- continue;
14800
- }
14801
- if (statement.type === "create_reference") {
14802
- const tableName2 = statement.tableName;
14803
- const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
14804
- const statementsForTable2 = newStatements[tableName2];
14805
- if (!statementsForTable2) {
14806
- newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : [statement];
14807
- continue;
14808
- }
14809
- if (!statement.isMulticolumn && statementsForTable2.some(
14810
- (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
14811
- )) {
14812
- continue;
14813
- }
14814
- if (statement.isMulticolumn) {
14815
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14816
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14817
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14818
- if (wasRename) {
14819
- newStatements[tableName2].push(...preparedStatements);
14820
- } else {
14821
- newStatements[tableName2] = preparedStatements;
14822
- }
14823
- continue;
14824
- }
14825
- continue;
14826
- }
14827
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14828
- newStatements[tableName2].push(statement);
14829
- }
14830
- continue;
14831
- }
14832
- if (statement.type === "delete_reference") {
14833
- const tableName2 = statement.tableName;
14834
- const statementsForTable2 = newStatements[tableName2];
14835
- if (!statementsForTable2) {
14836
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14837
- continue;
14838
- }
14839
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14840
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14841
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14842
- if (wasRename) {
14843
- newStatements[tableName2].push(...preparedStatements);
14844
- } else {
14845
- newStatements[tableName2] = preparedStatements;
14846
- }
14847
- continue;
14848
- }
14849
- continue;
14850
- }
14851
- if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
14852
- const tableName2 = statement.tableName;
14853
- const statementsForTable2 = newStatements[tableName2];
14854
- if (!statementsForTable2) {
14855
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14856
- continue;
14857
- }
14858
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14859
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14860
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14861
- if (wasRename) {
14862
- newStatements[tableName2].push(...preparedStatements);
14863
- } else {
14864
- newStatements[tableName2] = preparedStatements;
14865
- }
14866
- continue;
14867
- }
14868
- continue;
14869
- }
14870
- const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
14871
- const statementsForTable = newStatements[tableName];
14872
- if (!statementsForTable) {
14873
- newStatements[tableName] = [statement];
14874
- continue;
14875
- }
14876
- if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
14877
- newStatements[tableName].push(statement);
14878
- }
14879
- }
14880
- const combinedStatements = Object.values(newStatements).flat();
14881
- const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
14882
- const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
14883
- const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
14884
- return [...renamedTables, ...renamedColumns, ...rest];
14885
- };
14886
- sqliteCombineStatements = (statements, json2, action) => {
14887
- const newStatements = {};
14888
- for (const statement of statements) {
14889
- 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") {
14890
- const tableName2 = statement.tableName;
14891
- const statementsForTable2 = newStatements[tableName2];
14892
- if (!statementsForTable2) {
14893
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14894
- continue;
14895
- }
14896
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14897
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14898
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14899
- if (wasRename) {
14900
- newStatements[tableName2].push(...preparedStatements);
14901
- } else {
14902
- newStatements[tableName2] = preparedStatements;
14903
- }
14904
- continue;
14905
- }
14906
- continue;
14907
- }
14908
- if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
14909
- const tableName2 = statement.tableName;
14910
- const statementsForTable2 = newStatements[tableName2];
14911
- if (!statementsForTable2) {
14912
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14913
- continue;
14914
- }
14915
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14916
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14917
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14918
- if (wasRename) {
14919
- newStatements[tableName2].push(...preparedStatements);
14920
- } else {
14921
- newStatements[tableName2] = preparedStatements;
14922
- }
14923
- continue;
14924
- }
14925
- continue;
14926
- }
14927
- if (statement.type === "create_reference") {
14928
- const tableName2 = statement.tableName;
14929
- const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
14930
- const statementsForTable2 = newStatements[tableName2];
14931
- if (!statementsForTable2) {
14932
- newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
14933
- continue;
14934
- }
14935
- if (data.columnsFrom.length === 1 && statementsForTable2.some(
14936
- (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
14937
- )) {
14938
- continue;
14939
- }
14940
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14941
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14942
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14943
- if (wasRename) {
14944
- newStatements[tableName2].push(...preparedStatements);
14945
- } else {
14946
- newStatements[tableName2] = preparedStatements;
14947
- }
14948
- continue;
14949
- }
14950
- continue;
14951
- }
14952
- const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
14953
- const statementsForTable = newStatements[tableName];
14954
- if (!statementsForTable) {
14955
- newStatements[tableName] = [statement];
14956
- continue;
14957
- }
14958
- if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
14959
- newStatements[tableName].push(statement);
14960
- }
14961
- }
14962
- const combinedStatements = Object.values(newStatements).flat();
14963
- const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
14964
- const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
14965
- const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
14966
- return [...renamedTables, ...renamedColumns, ...rest];
14967
- };
14968
- }
14969
- });
14970
-
14971
- // src/snapshotsDiffer.ts
14972
- var snapshotsDiffer_exports = {};
14973
- __export(snapshotsDiffer_exports, {
14974
- alteredTableScheme: () => alteredTableScheme,
14975
- applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
14976
- applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
14977
- applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
14978
- applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
14979
- diffResultScheme: () => diffResultScheme,
14980
- diffResultSchemeMysql: () => diffResultSchemeMysql,
14981
- diffResultSchemeSQLite: () => diffResultSchemeSQLite,
14982
- makePatched: () => makePatched,
14983
- makeSelfOrPatched: () => makeSelfOrPatched
14984
- });
14985
- var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
14986
- var init_snapshotsDiffer = __esm({
14987
- "src/snapshotsDiffer.ts"() {
14988
- "use strict";
14989
- init_lib();
14990
- init_jsonDiffer();
14991
- init_sqlgenerator();
14992
- init_jsonStatements();
14993
- init_global();
14994
- init_mysqlSchema();
14995
- init_pgSchema();
14996
- init_sqliteSchema();
14997
- init_statementCombiner();
14998
- init_utils();
14999
- makeChanged = (schema4) => {
15000
- return objectType({
15001
- type: enumType(["changed"]),
15002
- old: schema4,
15003
- new: schema4
15004
- });
14472
+ init_utils();
14473
+ makeChanged = (schema4) => {
14474
+ return objectType({
14475
+ type: enumType(["changed"]),
14476
+ old: schema4,
14477
+ new: schema4
14478
+ });
15005
14479
  };
15006
14480
  makeSelfOrChanged = (schema4) => {
15007
14481
  return unionType([
@@ -16038,313 +15512,29 @@ var init_snapshotsDiffer = __esm({
16038
15512
  curFull,
16039
15513
  curFull.internal
16040
15514
  );
16041
- });
16042
- jsonStatements.push(...jsonMySqlCreateTables);
16043
- jsonStatements.push(...jsonDropTables);
16044
- jsonStatements.push(...jsonRenameTables);
16045
- jsonStatements.push(...jsonRenameColumnsStatements);
16046
- jsonStatements.push(...jsonDeletedUniqueConstraints);
16047
- jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16048
- jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16049
- jsonStatements.push(...jsonDeletedCompositePKs);
16050
- jsonStatements.push(...jsonTableAlternations);
16051
- jsonStatements.push(...jsonAddedCompositePKs);
16052
- jsonStatements.push(...jsonAddedUniqueConstraints);
16053
- jsonStatements.push(...jsonDeletedUniqueConstraints);
16054
- jsonStatements.push(...jsonAddColumnsStatemets);
16055
- jsonStatements.push(...jsonCreateReferencesForCreatedTables);
16056
- jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16057
- jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
16058
- jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16059
- jsonStatements.push(...jsonDropColumnsStatemets);
16060
- jsonStatements.push(...jsonAlteredCompositePKs);
16061
- jsonStatements.push(...jsonAddedUniqueConstraints);
16062
- jsonStatements.push(...jsonAlteredUniqueConstraints);
16063
- const sqlStatements = fromJson(jsonStatements, "mysql");
16064
- const uniqueSqlStatements = [];
16065
- sqlStatements.forEach((ss) => {
16066
- if (!uniqueSqlStatements.includes(ss)) {
16067
- uniqueSqlStatements.push(ss);
16068
- }
16069
- });
16070
- const rTables = renamedTables.map((it) => {
16071
- return { from: it.from, to: it.to };
16072
- });
16073
- const _meta = prepareMigrationMeta([], rTables, rColumns);
16074
- return {
16075
- statements: jsonStatements,
16076
- sqlStatements: uniqueSqlStatements,
16077
- _meta
16078
- };
16079
- };
16080
- applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
16081
- const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
16082
- const {
16083
- created: createdTables,
16084
- deleted: deletedTables,
16085
- renamed: renamedTables
16086
- } = await tablesResolver2({
16087
- created: tablesDiff.added,
16088
- deleted: tablesDiff.deleted
16089
- });
16090
- const tablesPatchedSnap1 = copy(json1);
16091
- tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
16092
- const { name: name2 } = nameChangeFor(it, renamedTables);
16093
- it.name = name2;
16094
- return [name2, it];
16095
- });
16096
- const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
16097
- const columnRenames = [];
16098
- const columnCreates = [];
16099
- const columnDeletes = [];
16100
- for (let entry of Object.values(res)) {
16101
- const { renamed, created, deleted } = await columnsResolver2({
16102
- tableName: entry.name,
16103
- schema: entry.schema,
16104
- deleted: entry.columns.deleted,
16105
- created: entry.columns.added
16106
- });
16107
- if (created.length > 0) {
16108
- columnCreates.push({
16109
- table: entry.name,
16110
- columns: created
16111
- });
16112
- }
16113
- if (deleted.length > 0) {
16114
- columnDeletes.push({
16115
- table: entry.name,
16116
- columns: deleted
16117
- });
16118
- }
16119
- if (renamed.length > 0) {
16120
- columnRenames.push({
16121
- table: entry.name,
16122
- renames: renamed
16123
- });
16124
- }
16125
- }
16126
- const columnRenamesDict = columnRenames.reduce(
16127
- (acc, it) => {
16128
- acc[it.table] = it.renames;
16129
- return acc;
16130
- },
16131
- {}
16132
- );
16133
- const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
16134
- columnsPatchedSnap1.tables = mapEntries(
16135
- columnsPatchedSnap1.tables,
16136
- (tableKey2, tableValue) => {
16137
- const patchedColumns = mapKeys(
16138
- tableValue.columns,
16139
- (columnKey, column4) => {
16140
- const rens = columnRenamesDict[tableValue.name] || [];
16141
- const newName = columnChangeFor(columnKey, rens);
16142
- column4.name = newName;
16143
- return newName;
16144
- }
16145
- );
16146
- tableValue.columns = patchedColumns;
16147
- return [tableKey2, tableValue];
16148
- }
16149
- );
16150
- const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
16151
- const typedResult = diffResultSchemeSQLite.parse(diffResult);
16152
- const tablesMap = {};
16153
- typedResult.alteredTablesWithColumns.forEach((obj) => {
16154
- tablesMap[obj.name] = obj;
16155
- });
16156
- const jsonCreateTables = createdTables.map((it) => {
16157
- return prepareSQLiteCreateTable(it, action);
16158
- });
16159
- const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
16160
- return prepareCreateIndexesJson(
16161
- it.name,
16162
- it.schema,
16163
- it.indexes,
16164
- curFull.internal
16165
- );
16166
- }).flat();
16167
- const jsonDropTables = deletedTables.map((it) => {
16168
- return prepareDropTableJson(it);
16169
- });
16170
- const jsonRenameTables = renamedTables.map((it) => {
16171
- return prepareRenameTableJson(it.from, it.to);
16172
- });
16173
- const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
16174
- const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
16175
- const jsonAddColumnsStatemets = columnCreates.map((it) => {
16176
- return _prepareSqliteAddColumns(
16177
- it.table,
16178
- it.columns,
16179
- tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
16180
- );
16181
- }).flat();
16182
- const allAltered = typedResult.alteredTablesWithColumns;
16183
- const jsonAddedCompositePKs = [];
16184
- const jsonDeletedCompositePKs = [];
16185
- const jsonAlteredCompositePKs = [];
16186
- const jsonAddedUniqueConstraints = [];
16187
- const jsonDeletedUniqueConstraints = [];
16188
- const jsonAlteredUniqueConstraints = [];
16189
- allAltered.forEach((it) => {
16190
- let addedColumns = [];
16191
- for (const addedPkName of Object.keys(it.addedCompositePKs)) {
16192
- const addedPkColumns = it.addedCompositePKs[addedPkName];
16193
- addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
16194
- }
16195
- let deletedColumns = [];
16196
- for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
16197
- const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
16198
- deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
16199
- }
16200
- const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
16201
- let addedCompositePKs = [];
16202
- let deletedCompositePKs = [];
16203
- let alteredCompositePKs = [];
16204
- if (doPerformDeleteAndCreate) {
16205
- addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
16206
- it.name,
16207
- it.addedCompositePKs
16208
- );
16209
- deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
16210
- it.name,
16211
- it.deletedCompositePKs
16212
- );
16213
- }
16214
- alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
16215
- it.name,
16216
- it.alteredCompositePKs
16217
- );
16218
- let addedUniqueConstraints = [];
16219
- let deletedUniqueConstraints = [];
16220
- let alteredUniqueConstraints = [];
16221
- addedUniqueConstraints = prepareAddUniqueConstraintPg(
16222
- it.name,
16223
- it.schema,
16224
- it.addedUniqueConstraints
16225
- );
16226
- deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
16227
- it.name,
16228
- it.schema,
16229
- it.deletedUniqueConstraints
16230
- );
16231
- if (it.alteredUniqueConstraints) {
16232
- const added = {};
16233
- const deleted = {};
16234
- for (const k of Object.keys(it.alteredUniqueConstraints)) {
16235
- added[k] = it.alteredUniqueConstraints[k].__new;
16236
- deleted[k] = it.alteredUniqueConstraints[k].__old;
16237
- }
16238
- addedUniqueConstraints.push(
16239
- ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
16240
- );
16241
- deletedUniqueConstraints.push(
16242
- ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
16243
- );
16244
- }
16245
- jsonAddedCompositePKs.push(...addedCompositePKs);
16246
- jsonDeletedCompositePKs.push(...deletedCompositePKs);
16247
- jsonAlteredCompositePKs.push(...alteredCompositePKs);
16248
- jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
16249
- jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
16250
- jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
16251
- });
16252
- const rColumns = jsonRenameColumnsStatements.map((it) => {
16253
- const tableName = it.tableName;
16254
- const schema4 = it.schema;
16255
- return {
16256
- from: { schema: schema4, table: tableName, column: it.oldColumnName },
16257
- to: { schema: schema4, table: tableName, column: it.newColumnName }
16258
- };
16259
- });
16260
- const jsonTableAlternations = allAltered.map((it) => {
16261
- return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
16262
- }).flat();
16263
- const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
16264
- return prepareCreateIndexesJson(
16265
- it.name,
16266
- it.schema,
16267
- it.addedIndexes || {},
16268
- curFull.internal
16269
- );
16270
- }).flat();
16271
- const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
16272
- return prepareDropIndexesJson(
16273
- it.name,
16274
- it.schema,
16275
- it.deletedIndexes || {}
16276
- );
16277
- }).flat();
16278
- allAltered.forEach((it) => {
16279
- const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
16280
- (current, item) => {
16281
- current[item] = it.alteredIndexes[item].__old;
16282
- return current;
16283
- },
16284
- {}
16285
- );
16286
- const createdIndexes = Object.keys(it.alteredIndexes).reduce(
16287
- (current, item) => {
16288
- current[item] = it.alteredIndexes[item].__new;
16289
- return current;
16290
- },
16291
- {}
16292
- );
16293
- jsonCreateIndexesForAllAlteredTables.push(
16294
- ...prepareCreateIndexesJson(
16295
- it.name,
16296
- it.schema,
16297
- createdIndexes || {},
16298
- curFull.internal
16299
- )
16300
- );
16301
- jsonDropIndexesForAllAlteredTables.push(
16302
- ...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
16303
- );
16304
- });
16305
- const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
16306
- const forAdded = prepareCreateReferencesJson(
16307
- it.name,
16308
- it.schema,
16309
- it.addedForeignKeys
16310
- );
16311
- const forAltered = prepareDropReferencesJson(
16312
- it.name,
16313
- it.schema,
16314
- it.deletedForeignKeys
16315
- );
16316
- const alteredFKs = prepareAlterReferencesJson(
16317
- it.name,
16318
- it.schema,
16319
- it.alteredForeignKeys
16320
- );
16321
- return [...forAdded, ...forAltered, ...alteredFKs];
16322
- }).flat();
16323
- const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16324
- (t) => t.type === "create_reference"
16325
- );
16326
- const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16327
- (t) => t.type === "delete_reference"
16328
- );
16329
- const jsonStatements = [];
16330
- jsonStatements.push(...jsonCreateTables);
15515
+ });
15516
+ jsonStatements.push(...jsonMySqlCreateTables);
16331
15517
  jsonStatements.push(...jsonDropTables);
16332
15518
  jsonStatements.push(...jsonRenameTables);
16333
15519
  jsonStatements.push(...jsonRenameColumnsStatements);
15520
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16334
15521
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16335
15522
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16336
15523
  jsonStatements.push(...jsonDeletedCompositePKs);
16337
15524
  jsonStatements.push(...jsonTableAlternations);
16338
15525
  jsonStatements.push(...jsonAddedCompositePKs);
15526
+ jsonStatements.push(...jsonAddedUniqueConstraints);
15527
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16339
15528
  jsonStatements.push(...jsonAddColumnsStatemets);
15529
+ jsonStatements.push(...jsonCreateReferencesForCreatedTables);
16340
15530
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16341
- jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16342
15531
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
15532
+ jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16343
15533
  jsonStatements.push(...jsonDropColumnsStatemets);
16344
15534
  jsonStatements.push(...jsonAlteredCompositePKs);
15535
+ jsonStatements.push(...jsonAddedUniqueConstraints);
16345
15536
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16346
- const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json2, action);
16347
- const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
15537
+ const sqlStatements = fromJson(jsonStatements, "mysql");
16348
15538
  const uniqueSqlStatements = [];
16349
15539
  sqlStatements.forEach((ss) => {
16350
15540
  if (!uniqueSqlStatements.includes(ss)) {
@@ -16356,12 +15546,12 @@ var init_snapshotsDiffer = __esm({
16356
15546
  });
16357
15547
  const _meta = prepareMigrationMeta([], rTables, rColumns);
16358
15548
  return {
16359
- statements: combinedJsonStatements,
15549
+ statements: jsonStatements,
16360
15550
  sqlStatements: uniqueSqlStatements,
16361
15551
  _meta
16362
15552
  };
16363
15553
  };
16364
- applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
15554
+ applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
16365
15555
  const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
16366
15556
  const {
16367
15557
  created: createdTables,
@@ -16463,18 +15653,6 @@ var init_snapshotsDiffer = __esm({
16463
15653
  tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
16464
15654
  );
16465
15655
  }).flat();
16466
- const rColumns = jsonRenameColumnsStatements.map((it) => {
16467
- const tableName = it.tableName;
16468
- const schema4 = it.schema;
16469
- return {
16470
- from: { schema: schema4, table: tableName, column: it.oldColumnName },
16471
- to: { schema: schema4, table: tableName, column: it.newColumnName }
16472
- };
16473
- });
16474
- const rTables = renamedTables.map((it) => {
16475
- return { from: it.from, to: it.to };
16476
- });
16477
- const _meta = prepareMigrationMeta([], rTables, rColumns);
16478
15656
  const allAltered = typedResult.alteredTablesWithColumns;
16479
15657
  const jsonAddedCompositePKs = [];
16480
15658
  const jsonDeletedCompositePKs = [];
@@ -16545,6 +15723,14 @@ var init_snapshotsDiffer = __esm({
16545
15723
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
16546
15724
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
16547
15725
  });
15726
+ const rColumns = jsonRenameColumnsStatements.map((it) => {
15727
+ const tableName = it.tableName;
15728
+ const schema4 = it.schema;
15729
+ return {
15730
+ from: { schema: schema4, table: tableName, column: it.oldColumnName },
15731
+ to: { schema: schema4, table: tableName, column: it.newColumnName }
15732
+ };
15733
+ });
16548
15734
  const jsonTableAlternations = allAltered.map((it) => {
16549
15735
  return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
16550
15736
  }).flat();
@@ -16591,22 +15777,21 @@ var init_snapshotsDiffer = __esm({
16591
15777
  );
16592
15778
  });
16593
15779
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
16594
- const forAdded = prepareLibSQLCreateReferencesJson(
15780
+ const forAdded = prepareCreateReferencesJson(
16595
15781
  it.name,
16596
15782
  it.schema,
16597
- it.addedForeignKeys,
16598
- json2,
16599
- action
15783
+ it.addedForeignKeys
16600
15784
  );
16601
- const forAltered = prepareLibSQLDropReferencesJson(
15785
+ const forAltered = prepareDropReferencesJson(
16602
15786
  it.name,
16603
15787
  it.schema,
16604
- it.deletedForeignKeys,
16605
- json2,
16606
- _meta,
16607
- action
15788
+ it.deletedForeignKeys
15789
+ );
15790
+ const alteredFKs = prepareAlterReferencesJson(
15791
+ it.name,
15792
+ it.schema,
15793
+ it.alteredForeignKeys
16608
15794
  );
16609
- const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
16610
15795
  return [...forAdded, ...forAltered, ...alteredFKs];
16611
15796
  }).flat();
16612
15797
  const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
@@ -16632,22 +15817,19 @@ var init_snapshotsDiffer = __esm({
16632
15817
  jsonStatements.push(...jsonDropColumnsStatemets);
16633
15818
  jsonStatements.push(...jsonAlteredCompositePKs);
16634
15819
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16635
- const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
16636
- const sqlStatements = fromJson(
16637
- combinedJsonStatements,
16638
- "sqlite",
16639
- action,
16640
- "turso",
16641
- json2
16642
- );
15820
+ const sqlStatements = fromJson(jsonStatements, "sqlite");
16643
15821
  const uniqueSqlStatements = [];
16644
15822
  sqlStatements.forEach((ss) => {
16645
15823
  if (!uniqueSqlStatements.includes(ss)) {
16646
15824
  uniqueSqlStatements.push(ss);
16647
15825
  }
16648
15826
  });
15827
+ const rTables = renamedTables.map((it) => {
15828
+ return { from: it.from, to: it.to };
15829
+ });
15830
+ const _meta = prepareMigrationMeta([], rTables, rColumns);
16649
15831
  return {
16650
- statements: combinedJsonStatements,
15832
+ statements: jsonStatements,
16651
15833
  sqlStatements: uniqueSqlStatements,
16652
15834
  _meta
16653
15835
  };
@@ -20211,7 +19393,7 @@ function jaccardDistance(column4, value) {
20211
19393
  }
20212
19394
  return sql`${column4} <%> ${value}`;
20213
19395
  }
20214
- var init_vector = __esm({
19396
+ var init_vector2 = __esm({
20215
19397
  "../drizzle-orm/dist/sql/functions/vector.js"() {
20216
19398
  "use strict";
20217
19399
  init_sql();
@@ -20223,7 +19405,7 @@ var init_functions = __esm({
20223
19405
  "../drizzle-orm/dist/sql/functions/index.js"() {
20224
19406
  "use strict";
20225
19407
  init_aggregate();
20226
- init_vector();
19408
+ init_vector2();
20227
19409
  }
20228
19410
  });
20229
19411
 
@@ -21887,7 +21069,7 @@ var init_sparsevec = __esm({
21887
21069
 
21888
21070
  // ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
21889
21071
  var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
21890
- var init_vector2 = __esm({
21072
+ var init_vector3 = __esm({
21891
21073
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
21892
21074
  "use strict";
21893
21075
  init_entity();
@@ -21959,7 +21141,7 @@ var init_columns = __esm({
21959
21141
  init_bit();
21960
21142
  init_halfvec();
21961
21143
  init_sparsevec();
21962
- init_vector2();
21144
+ init_vector3();
21963
21145
  }
21964
21146
  });
21965
21147
 
@@ -25457,24 +24639,6 @@ var init_pg_core = __esm({
25457
24639
  }
25458
24640
  });
25459
24641
 
25460
- // src/extensions/vector.ts
25461
- var vectorOps;
25462
- var init_vector3 = __esm({
25463
- "src/extensions/vector.ts"() {
25464
- "use strict";
25465
- vectorOps = [
25466
- "vector_l2_ops",
25467
- "vector_ip_ops",
25468
- "vector_cosine_ops",
25469
- "vector_l1_ops",
25470
- "bit_hamming_ops",
25471
- "bit_jaccard_ops",
25472
- "halfvec_l2_ops",
25473
- "sparsevec_l2_ops"
25474
- ];
25475
- }
25476
- });
25477
-
25478
24642
  // src/serializer/pgSerializer.ts
25479
24643
  function stringFromIdentityProperty(field) {
25480
24644
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
@@ -25512,7 +24676,7 @@ function buildArrayString(array, sqlType) {
25512
24676
  }).join(",");
25513
24677
  return `{${values}}`;
25514
24678
  }
25515
- var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24679
+ var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
25516
24680
  var init_pgSerializer = __esm({
25517
24681
  "src/serializer/pgSerializer.ts"() {
25518
24682
  "use strict";
@@ -25520,7 +24684,7 @@ var init_pgSerializer = __esm({
25520
24684
  init_dist();
25521
24685
  init_pg_core();
25522
24686
  init_pg_core();
25523
- init_vector3();
24687
+ init_vector();
25524
24688
  init_outputs();
25525
24689
  init_utils();
25526
24690
  init_serializer();
@@ -25633,7 +24797,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
25633
24797
  columnToSet.default = `'${buildArrayString(
25634
24798
  column4.default,
25635
24799
  sqlTypeLowered
25636
- )}'::${sqlTypeLowered}`;
24800
+ )}'`;
25637
24801
  } else {
25638
24802
  columnToSet.default = column4.default;
25639
24803
  }
@@ -25980,7 +25144,7 @@ ${withStyle.errorWarning(
25980
25144
  WHEN 'int2'::regtype THEN 'smallserial'
25981
25145
  END
25982
25146
  ELSE format_type(a.atttypid, a.atttypmod)
25983
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
25147
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
25984
25148
  pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
25985
25149
  INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
25986
25150
  INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
@@ -25991,6 +25155,7 @@ ${withStyle.errorWarning(
25991
25155
  INFORMATION_SCHEMA.COLUMNS.identity_cycle
25992
25156
  FROM pg_attribute a
25993
25157
  JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
25158
+ JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
25994
25159
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
25995
25160
  AND a.attnum > 0
25996
25161
  AND NOT a.attisdropped
@@ -26010,30 +25175,42 @@ ${withStyle.errorWarning(
26010
25175
  }
26011
25176
  const tableForeignKeys = await db.query(
26012
25177
  `SELECT
26013
- tc.table_schema,
26014
- tc.constraint_name,
26015
- tc.table_name,
26016
- kcu.column_name,
26017
- (
26018
- SELECT ccu.table_schema
26019
- FROM information_schema.constraint_column_usage ccu
26020
- WHERE ccu.constraint_name = tc.constraint_name
26021
- LIMIT 1
26022
- ) AS foreign_table_schema,
26023
- ccu.table_name AS foreign_table_name,
26024
- ccu.column_name AS foreign_column_name,
26025
- rc.delete_rule,
26026
- rc.update_rule
26027
- FROM
26028
- information_schema.table_constraints AS tc
26029
- JOIN information_schema.key_column_usage AS kcu
26030
- ON tc.constraint_name = kcu.constraint_name
26031
- AND tc.table_schema = kcu.table_schema
26032
- JOIN information_schema.constraint_column_usage AS ccu
26033
- ON ccu.constraint_name = tc.constraint_name
26034
- JOIN information_schema.referential_constraints AS rc
26035
- ON ccu.constraint_name = rc.constraint_name
26036
- WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
25178
+ con.contype AS constraint_type,
25179
+ nsp.nspname AS constraint_schema,
25180
+ con.conname AS constraint_name,
25181
+ rel.relname AS table_name,
25182
+ att.attname AS column_name,
25183
+ fnsp.nspname AS foreign_table_schema,
25184
+ frel.relname AS foreign_table_name,
25185
+ fatt.attname AS foreign_column_name,
25186
+ CASE con.confupdtype
25187
+ WHEN 'a' THEN 'NO ACTION'
25188
+ WHEN 'r' THEN 'RESTRICT'
25189
+ WHEN 'n' THEN 'SET NULL'
25190
+ WHEN 'c' THEN 'CASCADE'
25191
+ WHEN 'd' THEN 'SET DEFAULT'
25192
+ END AS update_rule,
25193
+ CASE con.confdeltype
25194
+ WHEN 'a' THEN 'NO ACTION'
25195
+ WHEN 'r' THEN 'RESTRICT'
25196
+ WHEN 'n' THEN 'SET NULL'
25197
+ WHEN 'c' THEN 'CASCADE'
25198
+ WHEN 'd' THEN 'SET DEFAULT'
25199
+ END AS delete_rule
25200
+ FROM
25201
+ pg_catalog.pg_constraint con
25202
+ JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
25203
+ JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
25204
+ LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
25205
+ AND att.attrelid = con.conrelid
25206
+ LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
25207
+ LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
25208
+ LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
25209
+ AND fatt.attrelid = con.confrelid
25210
+ WHERE
25211
+ nsp.nspname = '${tableSchema}'
25212
+ AND rel.relname = '${tableName}'
25213
+ AND con.contype IN ('f');`
26037
25214
  );
26038
25215
  foreignKeysCount += tableForeignKeys.length;
26039
25216
  if (progressCallback) {
@@ -26045,8 +25222,8 @@ ${withStyle.errorWarning(
26045
25222
  const columnTo = fk4.foreign_column_name;
26046
25223
  const schemaTo = fk4.foreign_table_schema;
26047
25224
  const foreignKeyName = fk4.constraint_name;
26048
- const onUpdate = fk4.update_rule.toLowerCase();
26049
- const onDelete = fk4.delete_rule.toLowerCase();
25225
+ const onUpdate = fk4.update_rule?.toLowerCase();
25226
+ const onDelete = fk4.delete_rule?.toLowerCase();
26050
25227
  if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
26051
25228
  foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
26052
25229
  foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
@@ -26091,6 +25268,8 @@ ${withStyle.errorWarning(
26091
25268
  const columnDimensions = columnResponse.array_dimensions;
26092
25269
  const enumType2 = columnResponse.enum_name;
26093
25270
  let columnType = columnResponse.data_type;
25271
+ const typeSchema = columnResponse.type_schema;
25272
+ const defaultValueRes = columnResponse.column_default;
26094
25273
  const isGenerated = columnResponse.is_generated === "ALWAYS";
26095
25274
  const generationExpression = columnResponse.generation_expression;
26096
25275
  const isIdentity = columnResponse.is_identity === "YES";
@@ -26121,12 +25300,7 @@ ${withStyle.errorWarning(
26121
25300
  columns: cprimaryKey.map((c) => c.column_name)
26122
25301
  };
26123
25302
  }
26124
- const defaultValue = defaultForColumn(columnResponse);
26125
- const isSerial = columnType === "serial";
26126
25303
  let columnTypeMapped = columnType;
26127
- if (columnTypeMapped.startsWith("numeric(")) {
26128
- columnTypeMapped = columnTypeMapped.replace(",", ", ");
26129
- }
26130
25304
  if (columnAdditionalDT === "ARRAY") {
26131
25305
  if (typeof internals.tables[tableName] === "undefined") {
26132
25306
  internals.tables[tableName] = {
@@ -26154,6 +25328,34 @@ ${withStyle.errorWarning(
26154
25328
  }
26155
25329
  }
26156
25330
  }
25331
+ const defaultValue = defaultForColumn(
25332
+ columnResponse,
25333
+ internals,
25334
+ tableName
25335
+ );
25336
+ if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
25337
+ if (typeof internals.tables[tableName] === "undefined") {
25338
+ internals.tables[tableName] = {
25339
+ columns: {
25340
+ [columnName]: {
25341
+ isDefaultAnExpression: true
25342
+ }
25343
+ }
25344
+ };
25345
+ } else {
25346
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25347
+ internals.tables[tableName].columns[columnName] = {
25348
+ isDefaultAnExpression: true
25349
+ };
25350
+ } else {
25351
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25352
+ }
25353
+ }
25354
+ }
25355
+ const isSerial = columnType === "serial";
25356
+ if (columnTypeMapped.startsWith("numeric(")) {
25357
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
25358
+ }
26157
25359
  if (columnAdditionalDT === "ARRAY") {
26158
25360
  for (let i = 1; i < Number(columnDimensions); i++) {
26159
25361
  columnTypeMapped += "[]";
@@ -26167,7 +25369,7 @@ ${withStyle.errorWarning(
26167
25369
  // filter vectors, but in future we should filter any extension that was installed by user
26168
25370
  columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
26169
25371
  ),
26170
- typeSchema: enumsToReturn[`${tableSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${tableSchema}.${enumType2}`].schema : void 0,
25372
+ typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
26171
25373
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
26172
25374
  // default: isSerial ? undefined : defaultValue,
26173
25375
  notNull: columnResponse.is_nullable === "NO",
@@ -26185,7 +25387,7 @@ ${withStyle.errorWarning(
26185
25387
  } : void 0
26186
25388
  };
26187
25389
  if (identityName) {
26188
- delete sequencesToReturn[`${tableSchema}.${identityName}`];
25390
+ delete sequencesToReturn[`${tableSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
26189
25391
  delete sequencesToReturn[identityName];
26190
25392
  }
26191
25393
  if (!isSerial && typeof defaultValue !== "undefined") {
@@ -26338,59 +25540,71 @@ ${withStyle.errorWarning(
26338
25540
  internal: internals
26339
25541
  };
26340
25542
  };
26341
- columnToDefault = {
26342
- "numeric(": "::numeric",
26343
- // text: "::text",
26344
- // "character varying": "::character varying",
26345
- // "double precision": "::double precision",
26346
- // "time with time zone": "::time with time zone",
26347
- "time without time zone": "::time without time zone",
26348
- // "timestamp with time zone": "::timestamp with time zone",
26349
- "timestamp without time zone": "::timestamp without time zone",
26350
- "timestamp(": "::timestamp without time zone",
26351
- // date: "::date",
26352
- // interval: "::interval",
26353
- // character: "::bpchar",
26354
- // macaddr8: "::macaddr8",
26355
- // macaddr: "::macaddr",
26356
- // inet: "::inet",
26357
- // cidr: "::cidr",
26358
- // jsonb: "::jsonb",
26359
- // json: "::json",
26360
- "character(": "::bpchar"
26361
- };
26362
- defaultForColumn = (column4) => {
25543
+ defaultForColumn = (column4, internals, tableName) => {
25544
+ const columnName = column4.attname;
25545
+ const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
26363
25546
  if (column4.column_default === null) {
26364
25547
  return void 0;
26365
25548
  }
26366
25549
  if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
26367
25550
  return void 0;
26368
25551
  }
26369
- const hasDifferentDefaultCast = Object.keys(columnToDefault).find((it) => column4.data_type.startsWith(it));
25552
+ if (column4.column_default.endsWith("[]")) {
25553
+ column4.column_default = column4.column_default.slice(0, -2);
25554
+ }
25555
+ column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
26370
25556
  const columnDefaultAsString = column4.column_default.toString();
26371
- if (columnDefaultAsString.endsWith(
26372
- hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
26373
- )) {
26374
- const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
26375
- const rt = column4.column_default.toString().substring(1, nonPrefixPart);
26376
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
26377
- return Number(rt);
26378
- } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
26379
- const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
26380
- return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
26381
- } else if (column4.data_type === "boolean") {
26382
- return column4.column_default === "true";
26383
- } else {
26384
- return `'${rt}'`;
26385
- }
26386
- } else {
26387
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column4.data_type.startsWith("numeric")) {
25557
+ if (isArray) {
25558
+ return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
25559
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
25560
+ return value;
25561
+ } else if (column4.data_type.startsWith("timestamp")) {
25562
+ return `${value}`;
25563
+ } else if (column4.data_type.slice(0, -2) === "interval") {
25564
+ return value.replaceAll('"', `"`);
25565
+ } else if (column4.data_type.slice(0, -2) === "boolean") {
25566
+ return value === "t" ? "true" : "false";
25567
+ } else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
25568
+ return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
25569
+ } else {
25570
+ return `"${value}"`;
25571
+ }
25572
+ }).join(",")}}'`;
25573
+ }
25574
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
25575
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
26388
25576
  return Number(columnDefaultAsString);
26389
- } else if (column4.data_type === "boolean") {
26390
- return column4.column_default === "true";
26391
25577
  } else {
26392
- return `${columnDefaultAsString}`;
25578
+ if (typeof internals.tables[tableName] === "undefined") {
25579
+ internals.tables[tableName] = {
25580
+ columns: {
25581
+ [columnName]: {
25582
+ isDefaultAnExpression: true
25583
+ }
25584
+ }
25585
+ };
25586
+ } else {
25587
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25588
+ internals.tables[tableName].columns[columnName] = {
25589
+ isDefaultAnExpression: true
25590
+ };
25591
+ } else {
25592
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25593
+ }
25594
+ }
25595
+ return columnDefaultAsString;
26393
25596
  }
25597
+ } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25598
+ const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
25599
+ return `'${jsonWithoutSpaces}'::${column4.data_type}`;
25600
+ } else if (column4.data_type === "boolean") {
25601
+ return column4.column_default === "true";
25602
+ } else if (columnDefaultAsString === "NULL") {
25603
+ return `NULL`;
25604
+ } else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
25605
+ return columnDefaultAsString;
25606
+ } else {
25607
+ return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
26394
25608
  }
26395
25609
  };
26396
25610
  }
@@ -34709,8 +33923,7 @@ var init_cli = __esm({
34709
33923
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
34710
33924
  extensionsFilters: literalType("postgis").array().optional(),
34711
33925
  verbose: booleanType().optional(),
34712
- strict: booleanType().optional(),
34713
- driver: driver.optional()
33926
+ strict: booleanType().optional()
34714
33927
  }).passthrough();
34715
33928
  pullParams = objectType({
34716
33929
  config: stringType().optional(),
@@ -34719,9 +33932,9 @@ var init_cli = __esm({
34719
33932
  tablesFilter: unionType([stringType(), stringType().array()]).optional(),
34720
33933
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
34721
33934
  extensionsFilters: literalType("postgis").array().optional(),
34722
- introspectCasing: casing,
33935
+ casing,
34723
33936
  breakpoints: booleanType().optional().default(true),
34724
- database: objectType({
33937
+ migrations: objectType({
34725
33938
  prefix: prefix.optional().default("index")
34726
33939
  }).optional()
34727
33940
  }).passthrough();
@@ -35876,8 +35089,284 @@ var sqlitePushIntrospect = async (db, filters) => {
35876
35089
  return { schema: schema4 };
35877
35090
  };
35878
35091
 
35092
+ // src/cli/commands/sqlitePushUtils.ts
35093
+ init_source();
35094
+ init_sqliteSchema();
35095
+ init_sqlgenerator();
35096
+ var _moveDataStatements = (tableName, json, dataLoss = false) => {
35097
+ const statements = [];
35098
+ statements.push(
35099
+ new SqliteRenameTableConvertor().convert({
35100
+ type: "rename_table",
35101
+ tableNameFrom: tableName,
35102
+ tableNameTo: `__old_push_${tableName}`,
35103
+ fromSchema: "",
35104
+ toSchema: ""
35105
+ })
35106
+ );
35107
+ const tableColumns = Object.values(json.tables[tableName].columns);
35108
+ const referenceData = Object.values(json.tables[tableName].foreignKeys);
35109
+ const compositePKs = Object.values(
35110
+ json.tables[tableName].compositePrimaryKeys
35111
+ ).map((it) => SQLiteSquasher.unsquashPK(it));
35112
+ const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
35113
+ statements.push(
35114
+ new SQLiteCreateTableConvertor().convert({
35115
+ type: "sqlite_create_table",
35116
+ tableName,
35117
+ columns: tableColumns,
35118
+ referenceData: fks,
35119
+ compositePKs
35120
+ })
35121
+ );
35122
+ if (!dataLoss) {
35123
+ statements.push(
35124
+ `INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
35125
+ );
35126
+ }
35127
+ statements.push(
35128
+ new SQLiteDropTableConvertor().convert({
35129
+ type: "drop_table",
35130
+ tableName: `__old_push_${tableName}`,
35131
+ schema: ""
35132
+ })
35133
+ );
35134
+ for (const idx of Object.values(json.tables[tableName].indexes)) {
35135
+ statements.push(
35136
+ new CreateSqliteIndexConvertor().convert({
35137
+ type: "create_index",
35138
+ tableName,
35139
+ schema: "",
35140
+ data: idx
35141
+ })
35142
+ );
35143
+ }
35144
+ return statements;
35145
+ };
35146
+ var getOldTableName = (tableName, meta) => {
35147
+ for (const key of Object.keys(meta.tables)) {
35148
+ const value = meta.tables[key];
35149
+ if (`"${tableName}"` === value) {
35150
+ return key.substring(1, key.length - 1);
35151
+ }
35152
+ }
35153
+ return tableName;
35154
+ };
35155
+ var getNewTableName = (tableName, meta) => {
35156
+ if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
35157
+ return meta.tables[`"${tableName}"`].substring(
35158
+ 1,
35159
+ meta.tables[`"${tableName}"`].length - 1
35160
+ );
35161
+ }
35162
+ return tableName;
35163
+ };
35164
+ var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
35165
+ let shouldAskForApprove = false;
35166
+ const statementsToExecute = [];
35167
+ const infoToPrint = [];
35168
+ const tablesToRemove = [];
35169
+ const columnsToRemove = [];
35170
+ const schemasToRemove = [];
35171
+ const tablesToTruncate = [];
35172
+ const tablesContext = {};
35173
+ for (const statement of statements) {
35174
+ if (statement.type === "drop_table") {
35175
+ const res = await connection.query(
35176
+ `select count(*) as count from \`${statement.tableName}\``
35177
+ );
35178
+ const count2 = Number(res[0].count);
35179
+ if (count2 > 0) {
35180
+ infoToPrint.push(
35181
+ `\xB7 You're about to delete ${source_default.underline(
35182
+ statement.tableName
35183
+ )} table with ${count2} items`
35184
+ );
35185
+ tablesToRemove.push(statement.tableName);
35186
+ shouldAskForApprove = true;
35187
+ }
35188
+ const stmnt = fromJson([statement], "sqlite")[0];
35189
+ statementsToExecute.push(stmnt);
35190
+ } else if (statement.type === "alter_table_drop_column") {
35191
+ const newTableName = getOldTableName(statement.tableName, meta);
35192
+ const columnIsPartOfPk = Object.values(
35193
+ json1.tables[newTableName].compositePrimaryKeys
35194
+ ).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
35195
+ const columnIsPartOfIndex = Object.values(
35196
+ json1.tables[newTableName].indexes
35197
+ ).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
35198
+ const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
35199
+ const columnIsPartOfFk = Object.values(
35200
+ json1.tables[newTableName].foreignKeys
35201
+ ).find(
35202
+ (t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
35203
+ statement.columnName
35204
+ )
35205
+ );
35206
+ const res = await connection.query(
35207
+ `select count(*) as count from \`${newTableName}\``
35208
+ );
35209
+ const count2 = Number(res[0].count);
35210
+ if (count2 > 0) {
35211
+ infoToPrint.push(
35212
+ `\xB7 You're about to delete ${source_default.underline(
35213
+ statement.columnName
35214
+ )} column in ${newTableName} table with ${count2} items`
35215
+ );
35216
+ columnsToRemove.push(`${newTableName}_${statement.columnName}`);
35217
+ shouldAskForApprove = true;
35218
+ }
35219
+ if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
35220
+ tablesContext[newTableName] = [
35221
+ ..._moveDataStatements(statement.tableName, json2, true)
35222
+ ];
35223
+ const tablesReferncingCurrent = [];
35224
+ for (const table4 of Object.values(json1.tables)) {
35225
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35226
+ (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35227
+ ).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
35228
+ tablesReferncingCurrent.push(...tablesRefs);
35229
+ }
35230
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35231
+ for (const table4 of uniqueTableRefs) {
35232
+ if (typeof tablesContext[table4] === "undefined") {
35233
+ tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35234
+ }
35235
+ }
35236
+ } else {
35237
+ if (typeof tablesContext[newTableName] === "undefined") {
35238
+ const stmnt = fromJson([statement], "sqlite")[0];
35239
+ statementsToExecute.push(stmnt);
35240
+ }
35241
+ }
35242
+ } else if (statement.type === "sqlite_alter_table_add_column") {
35243
+ const newTableName = getOldTableName(statement.tableName, meta);
35244
+ if (statement.column.notNull && !statement.column.default) {
35245
+ const res = await connection.query(
35246
+ `select count(*) as count from \`${newTableName}\``
35247
+ );
35248
+ const count2 = Number(res[0].count);
35249
+ if (count2 > 0) {
35250
+ infoToPrint.push(
35251
+ `\xB7 You're about to add not-null ${source_default.underline(
35252
+ statement.column.name
35253
+ )} column without default value, which contains ${count2} items`
35254
+ );
35255
+ tablesToTruncate.push(newTableName);
35256
+ statementsToExecute.push(`delete from ${newTableName};`);
35257
+ shouldAskForApprove = true;
35258
+ }
35259
+ }
35260
+ if (statement.column.primaryKey) {
35261
+ tablesContext[newTableName] = [
35262
+ ..._moveDataStatements(statement.tableName, json2, true)
35263
+ ];
35264
+ const tablesReferncingCurrent = [];
35265
+ for (const table4 of Object.values(json1.tables)) {
35266
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35267
+ (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35268
+ ).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
35269
+ tablesReferncingCurrent.push(...tablesRefs);
35270
+ }
35271
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35272
+ for (const table4 of uniqueTableRefs) {
35273
+ if (typeof tablesContext[table4] === "undefined") {
35274
+ tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35275
+ }
35276
+ }
35277
+ } else {
35278
+ if (typeof tablesContext[newTableName] === "undefined") {
35279
+ const stmnt = fromJson([statement], "sqlite")[0];
35280
+ statementsToExecute.push(stmnt);
35281
+ }
35282
+ }
35283
+ } 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") {
35284
+ if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
35285
+ const newTableName = getOldTableName(statement.tableName, meta);
35286
+ if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
35287
+ const res = await connection.query(
35288
+ `select count(*) as count from \`${newTableName}\``
35289
+ );
35290
+ const count2 = Number(res[0].count);
35291
+ if (count2 > 0) {
35292
+ infoToPrint.push(
35293
+ `\xB7 You're about to add not-null constraint to ${source_default.underline(
35294
+ statement.columnName
35295
+ )} column without default value, which contains ${count2} items`
35296
+ );
35297
+ tablesToTruncate.push(newTableName);
35298
+ shouldAskForApprove = true;
35299
+ }
35300
+ tablesContext[newTableName] = _moveDataStatements(
35301
+ statement.tableName,
35302
+ json1,
35303
+ true
35304
+ );
35305
+ } else {
35306
+ if (typeof tablesContext[newTableName] === "undefined") {
35307
+ tablesContext[newTableName] = _moveDataStatements(
35308
+ statement.tableName,
35309
+ json1
35310
+ );
35311
+ }
35312
+ }
35313
+ const tablesReferncingCurrent = [];
35314
+ for (const table4 of Object.values(json1.tables)) {
35315
+ const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35316
+ (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35317
+ ).map((t) => {
35318
+ return getNewTableName(
35319
+ SQLiteSquasher.unsquashPushFK(t).tableFrom,
35320
+ meta
35321
+ );
35322
+ });
35323
+ tablesReferncingCurrent.push(...tablesRefs);
35324
+ }
35325
+ const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35326
+ for (const table4 of uniqueTableRefs) {
35327
+ if (typeof tablesContext[table4] === "undefined") {
35328
+ tablesContext[table4] = [..._moveDataStatements(table4, json1)];
35329
+ }
35330
+ }
35331
+ }
35332
+ } else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
35333
+ const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
35334
+ if (typeof tablesContext[statement.tableName] === "undefined") {
35335
+ tablesContext[statement.tableName] = _moveDataStatements(
35336
+ statement.tableName,
35337
+ json2
35338
+ );
35339
+ }
35340
+ } 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") {
35341
+ const newTableName = getOldTableName(statement.tableName, meta);
35342
+ if (typeof tablesContext[newTableName] === "undefined") {
35343
+ tablesContext[newTableName] = _moveDataStatements(
35344
+ statement.tableName,
35345
+ json2
35346
+ );
35347
+ }
35348
+ } else {
35349
+ const stmnt = fromJson([statement], "sqlite");
35350
+ if (typeof stmnt !== "undefined") {
35351
+ statementsToExecute.push(...stmnt);
35352
+ }
35353
+ }
35354
+ }
35355
+ for (const context of Object.values(tablesContext)) {
35356
+ statementsToExecute.push(...context);
35357
+ }
35358
+ return {
35359
+ statementsToExecute,
35360
+ shouldAskForApprove,
35361
+ infoToPrint,
35362
+ columnsToRemove: [...new Set(columnsToRemove)],
35363
+ schemasToRemove: [...new Set(schemasToRemove)],
35364
+ tablesToTruncate: [...new Set(tablesToTruncate)],
35365
+ tablesToRemove: [...new Set(tablesToRemove)]
35366
+ };
35367
+ };
35368
+
35879
35369
  // src/api.ts
35880
- init_sqlitePushUtils();
35881
35370
  init_global();
35882
35371
  init_migrationPreparator();
35883
35372
  init_mysqlSchema();