drizzle-kit 0.24.0-38d6dab → 0.24.0-5df8253

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. package/api.d.mts +10 -0
  2. package/api.d.ts +10 -0
  3. package/api.js +501 -1280
  4. package/api.mjs +501 -1280
  5. package/bin.cjs +756 -1832
  6. package/package.json +2 -1
  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, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, LibSQLDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
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
  };
@@ -11986,7 +11986,7 @@ var init_sqlgenerator = __esm({
11986
11986
  }
11987
11987
  convert(statement) {
11988
11988
  const { tableName, oldColumnName, newColumnName } = statement;
11989
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
11989
+ return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
11990
11990
  }
11991
11991
  };
11992
11992
  PgAlterTableDropColumnConvertor = class extends Convertor {
@@ -12088,8 +12088,8 @@ var init_sqlgenerator = __esm({
12088
12088
  }
12089
12089
  };
12090
12090
  SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
12091
- can(statement, dialect7, driver2) {
12092
- return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite" && !driver2;
12091
+ can(statement, dialect7) {
12092
+ return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
12093
12093
  }
12094
12094
  convert(statement) {
12095
12095
  return `/*
@@ -12400,46 +12400,6 @@ var init_sqlgenerator = __esm({
12400
12400
  return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
12401
12401
  }
12402
12402
  };
12403
- LibSQLModifyColumn = class extends Convertor {
12404
- can(statement, dialect7, driver2) {
12405
- return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect7 === "sqlite" && driver2 === "turso";
12406
- }
12407
- convert(statement, json2) {
12408
- const { tableName, columnName } = statement;
12409
- let columnType = ``;
12410
- let columnDefault = "";
12411
- let columnNotNull = "";
12412
- switch (statement.type) {
12413
- case "alter_table_alter_column_set_type":
12414
- columnType = ` ${statement.newDataType}`;
12415
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12416
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12417
- break;
12418
- case "alter_table_alter_column_drop_notnull":
12419
- columnType = ` ${statement.newDataType}`;
12420
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12421
- columnNotNull = "";
12422
- break;
12423
- case "alter_table_alter_column_set_notnull":
12424
- columnType = ` ${statement.newDataType}`;
12425
- columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12426
- columnNotNull = ` NOT NULL`;
12427
- break;
12428
- case "alter_table_alter_column_set_default":
12429
- columnType = ` ${statement.newDataType}`;
12430
- columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
12431
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12432
- break;
12433
- case "alter_table_alter_column_drop_default":
12434
- columnType = ` ${statement.newDataType}`;
12435
- columnDefault = "";
12436
- columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12437
- break;
12438
- }
12439
- columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
12440
- return `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`;
12441
- }
12442
- };
12443
12403
  MySqlModifyColumn = class extends Convertor {
12444
12404
  can(statement, dialect7) {
12445
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";
@@ -12780,8 +12740,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12780
12740
  }
12781
12741
  };
12782
12742
  SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
12783
- can(statement, dialect7, driver2) {
12784
- return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite" && !driver2;
12743
+ can(statement, dialect7) {
12744
+ return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
12785
12745
  }
12786
12746
  convert(statement) {
12787
12747
  return `/*
@@ -12795,8 +12755,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12795
12755
  }
12796
12756
  };
12797
12757
  SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
12798
- can(statement, dialect7, driver2) {
12799
- return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite" && !driver2;
12758
+ can(statement, dialect7) {
12759
+ return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
12800
12760
  }
12801
12761
  convert(statement) {
12802
12762
  return `/*
@@ -12810,8 +12770,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12810
12770
  }
12811
12771
  };
12812
12772
  SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
12813
- can(statement, dialect7, driver2) {
12814
- return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite" && !driver2;
12773
+ can(statement, dialect7) {
12774
+ return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
12815
12775
  }
12816
12776
  convert(statement) {
12817
12777
  return `/*
@@ -12835,8 +12795,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12835
12795
  }
12836
12796
  };
12837
12797
  SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
12838
- can(statement, dialect7, driver2) {
12839
- return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite" && !driver2;
12798
+ can(statement, dialect7) {
12799
+ return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
12840
12800
  }
12841
12801
  convert(statement) {
12842
12802
  return `/*
@@ -12880,8 +12840,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12880
12840
  }
12881
12841
  };
12882
12842
  SqliteCreateForeignKeyConvertor = class extends Convertor {
12883
- can(statement, dialect7, driver2) {
12884
- return statement.type === "create_reference" && dialect7 === "sqlite" && !driver2;
12843
+ can(statement, dialect7) {
12844
+ return statement.type === "create_reference" && dialect7 === "sqlite";
12885
12845
  }
12886
12846
  convert(statement) {
12887
12847
  return `/*
@@ -12893,32 +12853,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12893
12853
  */`;
12894
12854
  }
12895
12855
  };
12896
- LibSQLCreateForeignKeyConvertor = class extends Convertor {
12897
- can(statement, dialect7, driver2) {
12898
- return statement.type === "create_reference" && dialect7 === "sqlite" && driver2 === "turso";
12899
- }
12900
- convert(statement, json2, action) {
12901
- const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
12902
- const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
12903
- if (isMulticolumn) {
12904
- return `/*
12905
- LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
12906
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12907
- https://www.sqlite.org/lang_altertable.html
12908
-
12909
- Due to that we don't generate migration automatically and it has to be done manually
12910
- */`;
12911
- }
12912
- const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
12913
- const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
12914
- const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
12915
- const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
12916
- const columnTypeValue = columnType ? ` ${columnType}` : "";
12917
- const columnFrom = columnsFrom[0];
12918
- const columnTo = columnsTo[0];
12919
- return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
12920
- }
12921
- };
12922
12856
  MySqlCreateForeignKeyConvertor = class extends Convertor {
12923
12857
  can(statement, dialect7) {
12924
12858
  return statement.type === "create_reference" && dialect7 === "mysql";
@@ -12992,8 +12926,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12992
12926
  }
12993
12927
  };
12994
12928
  SqliteDeleteForeignKeyConvertor = class extends Convertor {
12995
- can(statement, dialect7, driver2) {
12996
- return statement.type === "delete_reference" && dialect7 === "sqlite" && !driver2;
12929
+ can(statement, dialect7) {
12930
+ return statement.type === "delete_reference" && dialect7 === "sqlite";
12997
12931
  }
12998
12932
  convert(statement) {
12999
12933
  return `/*
@@ -13005,29 +12939,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13005
12939
  */`;
13006
12940
  }
13007
12941
  };
13008
- LibSQLDeleteForeignKeyConvertor = class extends Convertor {
13009
- can(statement, dialect7, driver2) {
13010
- return statement.type === "delete_reference" && dialect7 === "sqlite" && driver2 === "turso";
13011
- }
13012
- convert(statement, json2, action) {
13013
- const { columnsFrom, tableFrom } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
13014
- const { columnDefault, columnNotNull, columnType, isMulticolumn } = statement;
13015
- if (isMulticolumn) {
13016
- return `/*
13017
- LibSQL does not support "Creating foreign key on multiple columns" out of the box, we do not generate automatic migration for that, so it has to be done manually
13018
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
13019
- https://www.sqlite.org/lang_altertable.html
13020
-
13021
- Due to that we don't generate migration automatically and it has to be done manually
13022
- */`;
13023
- }
13024
- const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
13025
- const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
13026
- const columnTypeValue = columnType ? ` ${columnType}` : "";
13027
- const columnFrom = columnsFrom[0];
13028
- return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue};`;
13029
- }
13030
- };
13031
12942
  MySqlDeleteForeignKeyConvertor = class extends Convertor {
13032
12943
  can(statement, dialect7) {
13033
12944
  return statement.type === "delete_reference" && dialect7 === "mysql";
@@ -13191,90 +13102,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13191
13102
  return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
13192
13103
  }
13193
13104
  };
13194
- SQLiteRecreateTableConvertor = class extends Convertor {
13195
- can(statement, dialect7, driver2) {
13196
- return statement.type === "recreate_table" && dialect7 === "sqlite" && !driver2;
13197
- }
13198
- convert(statement) {
13199
- const { tableName, columns, compositePKs, referenceData } = statement;
13200
- const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
13201
- const sqlStatements = [];
13202
- sqlStatements.push(
13203
- new SqliteRenameTableConvertor().convert({
13204
- fromSchema: "",
13205
- tableNameFrom: tableName,
13206
- tableNameTo: `__old__generate_${tableName}`,
13207
- toSchema: "",
13208
- type: "rename_table"
13209
- })
13210
- );
13211
- sqlStatements.push(
13212
- new SQLiteCreateTableConvertor().convert({
13213
- type: "sqlite_create_table",
13214
- tableName,
13215
- columns,
13216
- referenceData,
13217
- compositePKs
13218
- })
13219
- );
13220
- sqlStatements.push(
13221
- `INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
13222
- );
13223
- sqlStatements.push(
13224
- new SQLiteDropTableConvertor().convert({
13225
- type: "drop_table",
13226
- tableName: `__old__generate_${tableName}`,
13227
- schema: ""
13228
- })
13229
- );
13230
- return sqlStatements;
13231
- }
13232
- };
13233
- LibSQLRecreateTableConvertor = class extends Convertor {
13234
- can(statement, dialect7, driver2) {
13235
- return statement.type === "recreate_table" && dialect7 === "sqlite" && driver2 === "turso";
13236
- }
13237
- convert(statement) {
13238
- const { tableName, columns, compositePKs, referenceData } = statement;
13239
- const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
13240
- const sqlStatements = [];
13241
- sqlStatements.push(
13242
- new SqliteRenameTableConvertor().convert({
13243
- fromSchema: "",
13244
- tableNameFrom: tableName,
13245
- tableNameTo: `__old__generate_${tableName}`,
13246
- toSchema: "",
13247
- type: "rename_table"
13248
- })
13249
- );
13250
- sqlStatements.push(
13251
- new SQLiteCreateTableConvertor().convert({
13252
- type: "sqlite_create_table",
13253
- tableName,
13254
- columns,
13255
- referenceData,
13256
- compositePKs
13257
- })
13258
- );
13259
- sqlStatements.push(
13260
- `INSERT INTO \`${tableName}\`(${columnNames}) SELECT ${columnNames} FROM \`__old__generate_${tableName}\`;`
13261
- );
13262
- sqlStatements.push(
13263
- new SQLiteDropTableConvertor().convert({
13264
- type: "drop_table",
13265
- tableName: `__old__generate_${tableName}`,
13266
- schema: ""
13267
- })
13268
- );
13269
- return sqlStatements;
13270
- }
13271
- };
13272
13105
  convertors = [];
13273
13106
  convertors.push(new PgCreateTableConvertor());
13274
13107
  convertors.push(new MySqlCreateTableConvertor());
13275
13108
  convertors.push(new SQLiteCreateTableConvertor());
13276
- convertors.push(new SQLiteRecreateTableConvertor());
13277
- convertors.push(new LibSQLRecreateTableConvertor());
13278
13109
  convertors.push(new CreateTypeEnumConvertor());
13279
13110
  convertors.push(new CreatePgSequenceConvertor());
13280
13111
  convertors.push(new DropPgSequenceConvertor());
@@ -13322,7 +13153,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13322
13153
  convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
13323
13154
  convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
13324
13155
  convertors.push(new MySqlModifyColumn());
13325
- convertors.push(new LibSQLModifyColumn());
13326
13156
  convertors.push(new PgCreateForeignKeyConvertor());
13327
13157
  convertors.push(new MySqlCreateForeignKeyConvertor());
13328
13158
  convertors.push(new PgAlterForeignKeyConvertor());
@@ -13337,9 +13167,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13337
13167
  convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
13338
13168
  convertors.push(new SqliteAlterForeignKeyConvertor());
13339
13169
  convertors.push(new SqliteDeleteForeignKeyConvertor());
13340
- convertors.push(new LibSQLDeleteForeignKeyConvertor());
13341
13170
  convertors.push(new SqliteCreateForeignKeyConvertor());
13342
- convertors.push(new LibSQLCreateForeignKeyConvertor());
13343
13171
  convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
13344
13172
  convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
13345
13173
  convertors.push(new PgAlterTableAlterColumnDropGenerated());
@@ -13362,6 +13190,19 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13362
13190
  convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
13363
13191
  convertors.push(new MySqlAlterTableAddPk());
13364
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
+ };
13365
13206
  https: `
13366
13207
  create table users (
13367
13208
  id int,
@@ -13388,237 +13229,12 @@ drop type __venum;
13388
13229
  }
13389
13230
  });
13390
13231
 
13391
- // src/cli/commands/sqlitePushUtils.ts
13392
- var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
13393
- var init_sqlitePushUtils = __esm({
13394
- "src/cli/commands/sqlitePushUtils.ts"() {
13395
- "use strict";
13396
- init_source();
13397
- init_sqliteSchema();
13398
- init_sqlgenerator();
13399
- init_utils();
13400
- _moveDataStatements = (tableName, json, dataLoss = false) => {
13401
- const statements = [];
13402
- statements.push(
13403
- new SqliteRenameTableConvertor().convert({
13404
- type: "rename_table",
13405
- tableNameFrom: tableName,
13406
- tableNameTo: `__old_push_${tableName}`,
13407
- fromSchema: "",
13408
- toSchema: ""
13409
- })
13410
- );
13411
- const tableColumns = Object.values(json.tables[tableName].columns);
13412
- const referenceData = Object.values(json.tables[tableName].foreignKeys);
13413
- const compositePKs = Object.values(
13414
- json.tables[tableName].compositePrimaryKeys
13415
- ).map((it) => SQLiteSquasher.unsquashPK(it));
13416
- const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
13417
- statements.push(
13418
- new SQLiteCreateTableConvertor().convert({
13419
- type: "sqlite_create_table",
13420
- tableName,
13421
- columns: tableColumns,
13422
- referenceData: fks,
13423
- compositePKs
13424
- })
13425
- );
13426
- if (!dataLoss) {
13427
- const columns = Object.keys(json.tables[tableName].columns).map(
13428
- (c) => `"${c}"`
13429
- );
13430
- statements.push(
13431
- `INSERT INTO \`${tableName}\`(${columns.join(
13432
- ", "
13433
- )}) SELECT (${columns.join(", ")}) FROM \`__old_push_${tableName}\`;`
13434
- );
13435
- }
13436
- statements.push(
13437
- new SQLiteDropTableConvertor().convert({
13438
- type: "drop_table",
13439
- tableName: `__old_push_${tableName}`,
13440
- schema: ""
13441
- })
13442
- );
13443
- for (const idx of Object.values(json.tables[tableName].indexes)) {
13444
- statements.push(
13445
- new CreateSqliteIndexConvertor().convert({
13446
- type: "create_index",
13447
- tableName,
13448
- schema: "",
13449
- data: idx
13450
- })
13451
- );
13452
- }
13453
- return statements;
13454
- };
13455
- getOldTableName = (tableName, meta) => {
13456
- for (const key of Object.keys(meta.tables)) {
13457
- const value = meta.tables[key];
13458
- if (`"${tableName}"` === value) {
13459
- return key.substring(1, key.length - 1);
13460
- }
13461
- }
13462
- return tableName;
13463
- };
13464
- getNewTableName = (tableName, meta) => {
13465
- if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
13466
- return meta.tables[`"${tableName}"`].substring(
13467
- 1,
13468
- meta.tables[`"${tableName}"`].length - 1
13469
- );
13470
- }
13471
- return tableName;
13472
- };
13473
- logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
13474
- let shouldAskForApprove = false;
13475
- const statementsToExecute = [];
13476
- const infoToPrint = [];
13477
- const tablesToRemove = [];
13478
- const columnsToRemove = [];
13479
- const schemasToRemove = [];
13480
- const tablesToTruncate = [];
13481
- for (const statement of statements) {
13482
- if (statement.type === "drop_table") {
13483
- const res = await connection.query(
13484
- `select count(*) as count from \`${statement.tableName}\``
13485
- );
13486
- const count2 = Number(res[0].count);
13487
- if (count2 > 0) {
13488
- infoToPrint.push(
13489
- `\xB7 You're about to delete ${source_default.underline(
13490
- statement.tableName
13491
- )} table with ${count2} items`
13492
- );
13493
- tablesToRemove.push(statement.tableName);
13494
- shouldAskForApprove = true;
13495
- }
13496
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13497
- statementsToExecute.push(
13498
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13499
- );
13500
- } else if (statement.type === "alter_table_drop_column") {
13501
- const tableName = statement.tableName;
13502
- const columnName = statement.columnName;
13503
- const res = await connection.query(
13504
- `select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
13505
- );
13506
- const count2 = Number(res[0].count);
13507
- if (count2 > 0) {
13508
- infoToPrint.push(
13509
- `\xB7 You're about to delete ${source_default.underline(
13510
- columnName
13511
- )} column in ${tableName} table with ${count2} items`
13512
- );
13513
- columnsToRemove.push(`${tableName}_${statement.columnName}`);
13514
- shouldAskForApprove = true;
13515
- }
13516
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13517
- statementsToExecute.push(
13518
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13519
- );
13520
- } else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
13521
- const tableName = statement.tableName;
13522
- const columnName = statement.column.name;
13523
- const res = await connection.query(
13524
- `select count(*) as count from \`${tableName}\``
13525
- );
13526
- const count2 = Number(res[0].count);
13527
- if (count2 > 0) {
13528
- infoToPrint.push(
13529
- `\xB7 You're about to add not-null ${source_default.underline(
13530
- columnName
13531
- )} column without default value, which contains ${count2} items`
13532
- );
13533
- tablesToTruncate.push(tableName);
13534
- statementsToExecute.push(`delete from ${tableName};`);
13535
- shouldAskForApprove = true;
13536
- }
13537
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13538
- statementsToExecute.push(
13539
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13540
- );
13541
- } else if (statement.type === "recreate_table") {
13542
- const tableName = statement.tableName;
13543
- const oldTableName = getOldTableName(tableName, meta);
13544
- const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
13545
- const currentColumnNames = Object.keys(json2.tables[tableName].columns);
13546
- const { removedColumns, addedColumns } = findAddedAndRemoved(
13547
- prevColumnNames,
13548
- currentColumnNames
13549
- );
13550
- if (removedColumns.length) {
13551
- for (const removedColumn of removedColumns) {
13552
- const res = await connection.query(
13553
- `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
13554
- );
13555
- const count2 = Number(res[0].count);
13556
- if (count2 > 0) {
13557
- infoToPrint.push(
13558
- `\xB7 You're about to delete ${source_default.underline(
13559
- removedColumn
13560
- )} column in ${tableName} table with ${count2} items`
13561
- );
13562
- columnsToRemove.push(removedColumn);
13563
- shouldAskForApprove = true;
13564
- }
13565
- }
13566
- }
13567
- if (addedColumns.length) {
13568
- for (const addedColumn of addedColumns) {
13569
- const [res] = await connection.query(
13570
- `select count(*) as count from \`${tableName}\``
13571
- );
13572
- const columnConf = json2.tables[tableName].columns[addedColumn];
13573
- const count2 = Number(res.count);
13574
- if (count2 > 0 && columnConf.notNull && !columnConf.default) {
13575
- infoToPrint.push(
13576
- `\xB7 You're about to add not-null ${source_default.underline(
13577
- addedColumn
13578
- )} column without default value to table, which contains ${count2} items`
13579
- );
13580
- shouldAskForApprove = true;
13581
- tablesToTruncate.push(tableName);
13582
- }
13583
- }
13584
- }
13585
- statementsToExecute.push(..._moveDataStatements(tableName, json2));
13586
- const tablesReferencingCurrent = [];
13587
- for (const table4 of Object.values(json2.tables)) {
13588
- const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
13589
- tablesReferencingCurrent.push(...tablesRefs);
13590
- }
13591
- const uniqueTableRefs = [...new Set(tablesReferencingCurrent)];
13592
- for (const table4 of uniqueTableRefs) {
13593
- statementsToExecute.push(..._moveDataStatements(table4, json2));
13594
- }
13595
- } else {
13596
- const fromJsonStatement = fromJson([statement], "sqlite", "push");
13597
- statementsToExecute.push(
13598
- ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13599
- );
13600
- }
13601
- }
13602
- return {
13603
- statementsToExecute,
13604
- shouldAskForApprove,
13605
- infoToPrint,
13606
- columnsToRemove: [...new Set(columnsToRemove)],
13607
- schemasToRemove: [...new Set(schemasToRemove)],
13608
- tablesToTruncate: [...new Set(tablesToTruncate)],
13609
- tablesToRemove: [...new Set(tablesToRemove)]
13610
- };
13611
- };
13612
- }
13613
- });
13614
-
13615
13232
  // src/jsonStatements.ts
13616
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
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;
13617
13234
  var init_jsonStatements = __esm({
13618
13235
  "src/jsonStatements.ts"() {
13619
13236
  "use strict";
13620
13237
  init_source();
13621
- init_sqlitePushUtils();
13622
13238
  init_views();
13623
13239
  init_mysqlSchema();
13624
13240
  init_pgSchema();
@@ -14402,49 +14018,6 @@ var init_jsonStatements = __esm({
14402
14018
  const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
14403
14019
  const columnGenerated = json2.tables[tableName].columns[columnName].generated;
14404
14020
  const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
14405
- if (column4.autoincrement?.type === "added") {
14406
- statements.push({
14407
- type: "alter_table_alter_column_set_autoincrement",
14408
- tableName,
14409
- columnName,
14410
- schema: schema4,
14411
- newDataType: columnType,
14412
- columnDefault,
14413
- columnOnUpdate,
14414
- columnNotNull,
14415
- columnAutoIncrement,
14416
- columnPk
14417
- });
14418
- }
14419
- if (column4.autoincrement?.type === "changed") {
14420
- const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
14421
- statements.push({
14422
- type,
14423
- tableName,
14424
- columnName,
14425
- schema: schema4,
14426
- newDataType: columnType,
14427
- columnDefault,
14428
- columnOnUpdate,
14429
- columnNotNull,
14430
- columnAutoIncrement,
14431
- columnPk
14432
- });
14433
- }
14434
- if (column4.autoincrement?.type === "deleted") {
14435
- statements.push({
14436
- type: "alter_table_alter_column_drop_autoincrement",
14437
- tableName,
14438
- columnName,
14439
- schema: schema4,
14440
- newDataType: columnType,
14441
- columnDefault,
14442
- columnOnUpdate,
14443
- columnNotNull,
14444
- columnAutoIncrement,
14445
- columnPk
14446
- });
14447
- }
14448
14021
  if (typeof column4.name !== "string") {
14449
14022
  statements.push({
14450
14023
  type: "alter_table_rename_column",
@@ -14708,94 +14281,16 @@ var init_jsonStatements = __esm({
14708
14281
  };
14709
14282
  });
14710
14283
  };
14711
- prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
14284
+ prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
14712
14285
  return Object.values(foreignKeys).map((fkData) => {
14713
- const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14714
- let isMulticolumn = false;
14715
- if (columnsFrom.length > 1 || columnsTo.length > 1) {
14716
- isMulticolumn = true;
14717
- return {
14718
- type: "create_reference",
14719
- tableName,
14720
- data: fkData,
14721
- schema: schema4,
14722
- isMulticolumn
14723
- };
14724
- }
14725
- const columnFrom = columnsFrom[0];
14726
- const {
14727
- notNull: columnNotNull,
14728
- default: columnDefault,
14729
- type: columnType
14730
- } = json2.tables[tableFrom].columns[columnFrom];
14731
14286
  return {
14732
- type: "create_reference",
14287
+ type: "delete_reference",
14733
14288
  tableName,
14734
14289
  data: fkData,
14735
- schema: schema4,
14736
- columnNotNull,
14737
- columnDefault,
14738
- columnType
14290
+ schema: schema4
14739
14291
  };
14740
14292
  });
14741
14293
  };
14742
- prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
14743
- return Object.values(foreignKeys).map((fkData) => {
14744
- return {
14745
- type: "delete_reference",
14746
- tableName,
14747
- data: fkData,
14748
- schema: schema4
14749
- };
14750
- });
14751
- };
14752
- prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
14753
- const statements = Object.values(foreignKeys).map((fkData) => {
14754
- const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14755
- const keys = Object.keys(json2.tables[tableName].columns);
14756
- const filtered = columnsFrom.filter((it) => keys.includes(it));
14757
- const fullDrop = filtered.length === 0;
14758
- if (fullDrop) return;
14759
- let isMulticolumn = false;
14760
- if (columnsFrom.length > 1 || columnsTo.length > 1) {
14761
- isMulticolumn = true;
14762
- return {
14763
- type: "delete_reference",
14764
- tableName,
14765
- data: fkData,
14766
- schema: schema4,
14767
- isMulticolumn
14768
- };
14769
- }
14770
- const columnFrom = columnsFrom[0];
14771
- const newTableName = getNewTableName(tableFrom, meta);
14772
- const {
14773
- notNull: columnNotNull,
14774
- default: columnDefault,
14775
- type: columnType
14776
- } = json2.tables[newTableName].columns[columnFrom];
14777
- const fkToSquash = {
14778
- columnsFrom,
14779
- columnsTo,
14780
- name: name2,
14781
- tableFrom: newTableName,
14782
- tableTo,
14783
- onDelete,
14784
- onUpdate
14785
- };
14786
- const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
14787
- return {
14788
- type: "delete_reference",
14789
- tableName,
14790
- data: foreignKey,
14791
- schema: schema4,
14792
- columnNotNull,
14793
- columnDefault,
14794
- columnType
14795
- };
14796
- });
14797
- return statements.filter((it) => it);
14798
- };
14799
14294
  prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
14800
14295
  const stmts = [];
14801
14296
  Object.values(foreignKeys).map((val) => {
@@ -14949,298 +14444,10 @@ var init_jsonStatements = __esm({
14949
14444
  }
14950
14445
  });
14951
14446
 
14952
- // src/statementCombiner.ts
14953
- var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
14954
- var init_statementCombiner = __esm({
14955
- "src/statementCombiner.ts"() {
14956
- "use strict";
14957
- init_jsonStatements();
14958
- init_sqliteSchema();
14959
- prepareLibSQLRecreateTable = (table4, action) => {
14960
- const { name: name2, columns, uniqueConstraints, indexes } = table4;
14961
- const composites = Object.values(table4.compositePrimaryKeys).map(
14962
- (it) => SQLiteSquasher.unsquashPK(it)
14963
- );
14964
- const references2 = Object.values(table4.foreignKeys);
14965
- const fks = references2.map(
14966
- (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14967
- );
14968
- const statements = [
14969
- {
14970
- type: "recreate_table",
14971
- tableName: name2,
14972
- columns: Object.values(columns),
14973
- compositePKs: composites,
14974
- referenceData: fks,
14975
- uniqueConstraints: Object.values(uniqueConstraints)
14976
- }
14977
- ];
14978
- if (Object.keys(indexes).length) {
14979
- statements.push(...prepareCreateIndexesJson(name2, "", indexes));
14980
- }
14981
- return statements;
14982
- };
14983
- prepareSQLiteRecreateTable = (table4, action) => {
14984
- const { name: name2, columns, uniqueConstraints, indexes } = table4;
14985
- const composites = Object.values(table4.compositePrimaryKeys).map(
14986
- (it) => SQLiteSquasher.unsquashPK(it)
14987
- );
14988
- const references2 = Object.values(table4.foreignKeys);
14989
- const fks = references2.map(
14990
- (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14991
- );
14992
- const statements = [
14993
- {
14994
- type: "recreate_table",
14995
- tableName: name2,
14996
- columns: Object.values(columns),
14997
- compositePKs: composites,
14998
- referenceData: fks,
14999
- uniqueConstraints: Object.values(uniqueConstraints)
15000
- }
15001
- ];
15002
- if (Object.keys(indexes).length) {
15003
- statements.push(...prepareCreateIndexesJson(name2, "", indexes));
15004
- }
15005
- return statements;
15006
- };
15007
- libSQLCombineStatements = (statements, json2, action) => {
15008
- const newStatements = {};
15009
- for (const statement of statements) {
15010
- if (statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
15011
- const tableName2 = statement.tableName;
15012
- const statementsForTable2 = newStatements[tableName2];
15013
- if (!statementsForTable2) {
15014
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15015
- continue;
15016
- }
15017
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15018
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15019
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15020
- if (wasRename) {
15021
- newStatements[tableName2].push(...preparedStatements);
15022
- } else {
15023
- newStatements[tableName2] = preparedStatements;
15024
- }
15025
- continue;
15026
- }
15027
- continue;
15028
- }
15029
- if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") {
15030
- const { tableName: tableName2, columnName, columnPk } = statement;
15031
- const columnIsPartOfUniqueIndex = Object.values(
15032
- json2.tables[tableName2].indexes
15033
- ).some((it) => {
15034
- const unsquashIndex = SQLiteSquasher.unsquashIdx(it);
15035
- return unsquashIndex.columns.includes(columnName) && unsquashIndex.isUnique;
15036
- });
15037
- const columnIsPartOfForeignKey = Object.values(
15038
- json2.tables[tableName2].foreignKeys
15039
- ).some((it) => {
15040
- const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
15041
- return unsquashFk.columnsFrom.includes(columnName);
15042
- });
15043
- const statementsForTable2 = newStatements[tableName2];
15044
- if (!statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
15045
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15046
- continue;
15047
- }
15048
- if (statementsForTable2 && (columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
15049
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15050
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15051
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15052
- if (wasRename) {
15053
- newStatements[tableName2].push(...preparedStatements);
15054
- } else {
15055
- newStatements[tableName2] = preparedStatements;
15056
- }
15057
- }
15058
- continue;
15059
- }
15060
- if (statementsForTable2 && !(columnIsPartOfUniqueIndex || columnIsPartOfForeignKey || columnPk)) {
15061
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15062
- newStatements[tableName2].push(statement);
15063
- }
15064
- continue;
15065
- }
15066
- newStatements[tableName2] = [statement];
15067
- continue;
15068
- }
15069
- if (statement.type === "create_reference") {
15070
- const tableName2 = statement.tableName;
15071
- const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
15072
- const statementsForTable2 = newStatements[tableName2];
15073
- if (!statementsForTable2) {
15074
- newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : newStatements[tableName2] = [statement];
15075
- continue;
15076
- }
15077
- if (!statement.isMulticolumn && statementsForTable2.some(
15078
- (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
15079
- )) {
15080
- continue;
15081
- }
15082
- if (statement.isMulticolumn) {
15083
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15084
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15085
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15086
- if (wasRename) {
15087
- newStatements[tableName2].push(...preparedStatements);
15088
- } else {
15089
- newStatements[tableName2] = preparedStatements;
15090
- }
15091
- continue;
15092
- }
15093
- continue;
15094
- }
15095
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15096
- newStatements[tableName2].push(statement);
15097
- }
15098
- continue;
15099
- }
15100
- if (statement.type === "delete_reference") {
15101
- const tableName2 = statement.tableName;
15102
- const statementsForTable2 = newStatements[tableName2];
15103
- if (!statementsForTable2) {
15104
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15105
- continue;
15106
- }
15107
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15108
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15109
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15110
- if (wasRename) {
15111
- newStatements[tableName2].push(...preparedStatements);
15112
- } else {
15113
- newStatements[tableName2] = preparedStatements;
15114
- }
15115
- continue;
15116
- }
15117
- continue;
15118
- }
15119
- if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
15120
- const tableName2 = statement.tableName;
15121
- const statementsForTable2 = newStatements[tableName2];
15122
- if (!statementsForTable2) {
15123
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15124
- continue;
15125
- }
15126
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15127
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15128
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15129
- if (wasRename) {
15130
- newStatements[tableName2].push(...preparedStatements);
15131
- } else {
15132
- newStatements[tableName2] = preparedStatements;
15133
- }
15134
- continue;
15135
- }
15136
- continue;
15137
- }
15138
- const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
15139
- const statementsForTable = newStatements[tableName];
15140
- if (!statementsForTable) {
15141
- newStatements[tableName] = [statement];
15142
- continue;
15143
- }
15144
- if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
15145
- newStatements[tableName].push(statement);
15146
- }
15147
- }
15148
- const combinedStatements = Object.values(newStatements).flat();
15149
- const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
15150
- const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
15151
- const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
15152
- return [...renamedTables, ...renamedColumns, ...rest];
15153
- };
15154
- sqliteCombineStatements = (statements, json2, action) => {
15155
- const newStatements = {};
15156
- for (const statement of statements) {
15157
- if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "delete_reference" || statement.type === "alter_reference" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
15158
- const tableName2 = statement.tableName;
15159
- const statementsForTable2 = newStatements[tableName2];
15160
- if (!statementsForTable2) {
15161
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15162
- continue;
15163
- }
15164
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15165
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15166
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15167
- if (wasRename) {
15168
- newStatements[tableName2].push(...preparedStatements);
15169
- } else {
15170
- newStatements[tableName2] = preparedStatements;
15171
- }
15172
- continue;
15173
- }
15174
- continue;
15175
- }
15176
- if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
15177
- const tableName2 = statement.tableName;
15178
- const statementsForTable2 = newStatements[tableName2];
15179
- if (!statementsForTable2) {
15180
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15181
- continue;
15182
- }
15183
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15184
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15185
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15186
- if (wasRename) {
15187
- newStatements[tableName2].push(...preparedStatements);
15188
- } else {
15189
- newStatements[tableName2] = preparedStatements;
15190
- }
15191
- continue;
15192
- }
15193
- continue;
15194
- }
15195
- if (statement.type === "create_reference") {
15196
- const tableName2 = statement.tableName;
15197
- const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
15198
- const statementsForTable2 = newStatements[tableName2];
15199
- if (!statementsForTable2) {
15200
- newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
15201
- continue;
15202
- }
15203
- if (data.columnsFrom.length === 1 && statementsForTable2.some(
15204
- (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
15205
- )) {
15206
- continue;
15207
- }
15208
- if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
15209
- const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
15210
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
15211
- if (wasRename) {
15212
- newStatements[tableName2].push(...preparedStatements);
15213
- } else {
15214
- newStatements[tableName2] = preparedStatements;
15215
- }
15216
- continue;
15217
- }
15218
- continue;
15219
- }
15220
- const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
15221
- const statementsForTable = newStatements[tableName];
15222
- if (!statementsForTable) {
15223
- newStatements[tableName] = [statement];
15224
- continue;
15225
- }
15226
- if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
15227
- newStatements[tableName].push(statement);
15228
- }
15229
- }
15230
- const combinedStatements = Object.values(newStatements).flat();
15231
- const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
15232
- const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
15233
- const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
15234
- return [...renamedTables, ...renamedColumns, ...rest];
15235
- };
15236
- }
15237
- });
15238
-
15239
14447
  // src/snapshotsDiffer.ts
15240
14448
  var snapshotsDiffer_exports = {};
15241
14449
  __export(snapshotsDiffer_exports, {
15242
14450
  alteredTableScheme: () => alteredTableScheme,
15243
- applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
15244
14451
  applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
15245
14452
  applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
15246
14453
  applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
@@ -15250,7 +14457,7 @@ __export(snapshotsDiffer_exports, {
15250
14457
  makePatched: () => makePatched,
15251
14458
  makeSelfOrPatched: () => makeSelfOrPatched
15252
14459
  });
15253
- var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
14460
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
15254
14461
  var init_snapshotsDiffer = __esm({
15255
14462
  "src/snapshotsDiffer.ts"() {
15256
14463
  "use strict";
@@ -15262,7 +14469,6 @@ var init_snapshotsDiffer = __esm({
15262
14469
  init_mysqlSchema();
15263
14470
  init_pgSchema();
15264
14471
  init_sqliteSchema();
15265
- init_statementCombiner();
15266
14472
  init_utils();
15267
14473
  makeChanged = (schema4) => {
15268
14474
  return objectType({
@@ -16306,313 +15512,29 @@ var init_snapshotsDiffer = __esm({
16306
15512
  curFull,
16307
15513
  curFull.internal
16308
15514
  );
16309
- });
16310
- jsonStatements.push(...jsonMySqlCreateTables);
16311
- jsonStatements.push(...jsonDropTables);
16312
- jsonStatements.push(...jsonRenameTables);
16313
- jsonStatements.push(...jsonRenameColumnsStatements);
16314
- jsonStatements.push(...jsonDeletedUniqueConstraints);
16315
- jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16316
- jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16317
- jsonStatements.push(...jsonDeletedCompositePKs);
16318
- jsonStatements.push(...jsonTableAlternations);
16319
- jsonStatements.push(...jsonAddedCompositePKs);
16320
- jsonStatements.push(...jsonAddedUniqueConstraints);
16321
- jsonStatements.push(...jsonDeletedUniqueConstraints);
16322
- jsonStatements.push(...jsonAddColumnsStatemets);
16323
- jsonStatements.push(...jsonCreateReferencesForCreatedTables);
16324
- jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16325
- jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
16326
- jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16327
- jsonStatements.push(...jsonDropColumnsStatemets);
16328
- jsonStatements.push(...jsonAlteredCompositePKs);
16329
- jsonStatements.push(...jsonAddedUniqueConstraints);
16330
- jsonStatements.push(...jsonAlteredUniqueConstraints);
16331
- const sqlStatements = fromJson(jsonStatements, "mysql");
16332
- const uniqueSqlStatements = [];
16333
- sqlStatements.forEach((ss) => {
16334
- if (!uniqueSqlStatements.includes(ss)) {
16335
- uniqueSqlStatements.push(ss);
16336
- }
16337
- });
16338
- const rTables = renamedTables.map((it) => {
16339
- return { from: it.from, to: it.to };
16340
- });
16341
- const _meta = prepareMigrationMeta([], rTables, rColumns);
16342
- return {
16343
- statements: jsonStatements,
16344
- sqlStatements: uniqueSqlStatements,
16345
- _meta
16346
- };
16347
- };
16348
- applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
16349
- const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
16350
- const {
16351
- created: createdTables,
16352
- deleted: deletedTables,
16353
- renamed: renamedTables
16354
- } = await tablesResolver2({
16355
- created: tablesDiff.added,
16356
- deleted: tablesDiff.deleted
16357
- });
16358
- const tablesPatchedSnap1 = copy(json1);
16359
- tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
16360
- const { name: name2 } = nameChangeFor(it, renamedTables);
16361
- it.name = name2;
16362
- return [name2, it];
16363
- });
16364
- const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
16365
- const columnRenames = [];
16366
- const columnCreates = [];
16367
- const columnDeletes = [];
16368
- for (let entry of Object.values(res)) {
16369
- const { renamed, created, deleted } = await columnsResolver2({
16370
- tableName: entry.name,
16371
- schema: entry.schema,
16372
- deleted: entry.columns.deleted,
16373
- created: entry.columns.added
16374
- });
16375
- if (created.length > 0) {
16376
- columnCreates.push({
16377
- table: entry.name,
16378
- columns: created
16379
- });
16380
- }
16381
- if (deleted.length > 0) {
16382
- columnDeletes.push({
16383
- table: entry.name,
16384
- columns: deleted
16385
- });
16386
- }
16387
- if (renamed.length > 0) {
16388
- columnRenames.push({
16389
- table: entry.name,
16390
- renames: renamed
16391
- });
16392
- }
16393
- }
16394
- const columnRenamesDict = columnRenames.reduce(
16395
- (acc, it) => {
16396
- acc[it.table] = it.renames;
16397
- return acc;
16398
- },
16399
- {}
16400
- );
16401
- const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
16402
- columnsPatchedSnap1.tables = mapEntries(
16403
- columnsPatchedSnap1.tables,
16404
- (tableKey2, tableValue) => {
16405
- const patchedColumns = mapKeys(
16406
- tableValue.columns,
16407
- (columnKey, column4) => {
16408
- const rens = columnRenamesDict[tableValue.name] || [];
16409
- const newName = columnChangeFor(columnKey, rens);
16410
- column4.name = newName;
16411
- return newName;
16412
- }
16413
- );
16414
- tableValue.columns = patchedColumns;
16415
- return [tableKey2, tableValue];
16416
- }
16417
- );
16418
- const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
16419
- const typedResult = diffResultSchemeSQLite.parse(diffResult);
16420
- const tablesMap = {};
16421
- typedResult.alteredTablesWithColumns.forEach((obj) => {
16422
- tablesMap[obj.name] = obj;
16423
- });
16424
- const jsonCreateTables = createdTables.map((it) => {
16425
- return prepareSQLiteCreateTable(it, action);
16426
- });
16427
- const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
16428
- return prepareCreateIndexesJson(
16429
- it.name,
16430
- it.schema,
16431
- it.indexes,
16432
- curFull.internal
16433
- );
16434
- }).flat();
16435
- const jsonDropTables = deletedTables.map((it) => {
16436
- return prepareDropTableJson(it);
16437
- });
16438
- const jsonRenameTables = renamedTables.map((it) => {
16439
- return prepareRenameTableJson(it.from, it.to);
16440
- });
16441
- const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
16442
- const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
16443
- const jsonAddColumnsStatemets = columnCreates.map((it) => {
16444
- return _prepareSqliteAddColumns(
16445
- it.table,
16446
- it.columns,
16447
- tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
16448
- );
16449
- }).flat();
16450
- const allAltered = typedResult.alteredTablesWithColumns;
16451
- const jsonAddedCompositePKs = [];
16452
- const jsonDeletedCompositePKs = [];
16453
- const jsonAlteredCompositePKs = [];
16454
- const jsonAddedUniqueConstraints = [];
16455
- const jsonDeletedUniqueConstraints = [];
16456
- const jsonAlteredUniqueConstraints = [];
16457
- allAltered.forEach((it) => {
16458
- let addedColumns = [];
16459
- for (const addedPkName of Object.keys(it.addedCompositePKs)) {
16460
- const addedPkColumns = it.addedCompositePKs[addedPkName];
16461
- addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
16462
- }
16463
- let deletedColumns = [];
16464
- for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
16465
- const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
16466
- deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
16467
- }
16468
- const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
16469
- let addedCompositePKs = [];
16470
- let deletedCompositePKs = [];
16471
- let alteredCompositePKs = [];
16472
- if (doPerformDeleteAndCreate) {
16473
- addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
16474
- it.name,
16475
- it.addedCompositePKs
16476
- );
16477
- deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
16478
- it.name,
16479
- it.deletedCompositePKs
16480
- );
16481
- }
16482
- alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
16483
- it.name,
16484
- it.alteredCompositePKs
16485
- );
16486
- let addedUniqueConstraints = [];
16487
- let deletedUniqueConstraints = [];
16488
- let alteredUniqueConstraints = [];
16489
- addedUniqueConstraints = prepareAddUniqueConstraintPg(
16490
- it.name,
16491
- it.schema,
16492
- it.addedUniqueConstraints
16493
- );
16494
- deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
16495
- it.name,
16496
- it.schema,
16497
- it.deletedUniqueConstraints
16498
- );
16499
- if (it.alteredUniqueConstraints) {
16500
- const added = {};
16501
- const deleted = {};
16502
- for (const k of Object.keys(it.alteredUniqueConstraints)) {
16503
- added[k] = it.alteredUniqueConstraints[k].__new;
16504
- deleted[k] = it.alteredUniqueConstraints[k].__old;
16505
- }
16506
- addedUniqueConstraints.push(
16507
- ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
16508
- );
16509
- deletedUniqueConstraints.push(
16510
- ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
16511
- );
16512
- }
16513
- jsonAddedCompositePKs.push(...addedCompositePKs);
16514
- jsonDeletedCompositePKs.push(...deletedCompositePKs);
16515
- jsonAlteredCompositePKs.push(...alteredCompositePKs);
16516
- jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
16517
- jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
16518
- jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
16519
- });
16520
- const rColumns = jsonRenameColumnsStatements.map((it) => {
16521
- const tableName = it.tableName;
16522
- const schema4 = it.schema;
16523
- return {
16524
- from: { schema: schema4, table: tableName, column: it.oldColumnName },
16525
- to: { schema: schema4, table: tableName, column: it.newColumnName }
16526
- };
16527
- });
16528
- const jsonTableAlternations = allAltered.map((it) => {
16529
- return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
16530
- }).flat();
16531
- const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
16532
- return prepareCreateIndexesJson(
16533
- it.name,
16534
- it.schema,
16535
- it.addedIndexes || {},
16536
- curFull.internal
16537
- );
16538
- }).flat();
16539
- const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
16540
- return prepareDropIndexesJson(
16541
- it.name,
16542
- it.schema,
16543
- it.deletedIndexes || {}
16544
- );
16545
- }).flat();
16546
- allAltered.forEach((it) => {
16547
- const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
16548
- (current, item) => {
16549
- current[item] = it.alteredIndexes[item].__old;
16550
- return current;
16551
- },
16552
- {}
16553
- );
16554
- const createdIndexes = Object.keys(it.alteredIndexes).reduce(
16555
- (current, item) => {
16556
- current[item] = it.alteredIndexes[item].__new;
16557
- return current;
16558
- },
16559
- {}
16560
- );
16561
- jsonCreateIndexesForAllAlteredTables.push(
16562
- ...prepareCreateIndexesJson(
16563
- it.name,
16564
- it.schema,
16565
- createdIndexes || {},
16566
- curFull.internal
16567
- )
16568
- );
16569
- jsonDropIndexesForAllAlteredTables.push(
16570
- ...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
16571
- );
16572
- });
16573
- const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
16574
- const forAdded = prepareCreateReferencesJson(
16575
- it.name,
16576
- it.schema,
16577
- it.addedForeignKeys
16578
- );
16579
- const forAltered = prepareDropReferencesJson(
16580
- it.name,
16581
- it.schema,
16582
- it.deletedForeignKeys
16583
- );
16584
- const alteredFKs = prepareAlterReferencesJson(
16585
- it.name,
16586
- it.schema,
16587
- it.alteredForeignKeys
16588
- );
16589
- return [...forAdded, ...forAltered, ...alteredFKs];
16590
- }).flat();
16591
- const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16592
- (t) => t.type === "create_reference"
16593
- );
16594
- const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16595
- (t) => t.type === "delete_reference"
16596
- );
16597
- const jsonStatements = [];
16598
- jsonStatements.push(...jsonCreateTables);
15515
+ });
15516
+ jsonStatements.push(...jsonMySqlCreateTables);
16599
15517
  jsonStatements.push(...jsonDropTables);
16600
15518
  jsonStatements.push(...jsonRenameTables);
16601
15519
  jsonStatements.push(...jsonRenameColumnsStatements);
15520
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16602
15521
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16603
15522
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16604
15523
  jsonStatements.push(...jsonDeletedCompositePKs);
16605
15524
  jsonStatements.push(...jsonTableAlternations);
16606
15525
  jsonStatements.push(...jsonAddedCompositePKs);
15526
+ jsonStatements.push(...jsonAddedUniqueConstraints);
15527
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
16607
15528
  jsonStatements.push(...jsonAddColumnsStatemets);
15529
+ jsonStatements.push(...jsonCreateReferencesForCreatedTables);
16608
15530
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16609
- jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16610
15531
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
15532
+ jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16611
15533
  jsonStatements.push(...jsonDropColumnsStatemets);
16612
15534
  jsonStatements.push(...jsonAlteredCompositePKs);
15535
+ jsonStatements.push(...jsonAddedUniqueConstraints);
16613
15536
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16614
- const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json2, action);
16615
- const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
15537
+ const sqlStatements = fromJson(jsonStatements, "mysql");
16616
15538
  const uniqueSqlStatements = [];
16617
15539
  sqlStatements.forEach((ss) => {
16618
15540
  if (!uniqueSqlStatements.includes(ss)) {
@@ -16624,12 +15546,12 @@ var init_snapshotsDiffer = __esm({
16624
15546
  });
16625
15547
  const _meta = prepareMigrationMeta([], rTables, rColumns);
16626
15548
  return {
16627
- statements: combinedJsonStatements,
15549
+ statements: jsonStatements,
16628
15550
  sqlStatements: uniqueSqlStatements,
16629
15551
  _meta
16630
15552
  };
16631
15553
  };
16632
- applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
15554
+ applySqliteSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
16633
15555
  const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
16634
15556
  const {
16635
15557
  created: createdTables,
@@ -16731,18 +15653,6 @@ var init_snapshotsDiffer = __esm({
16731
15653
  tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
16732
15654
  );
16733
15655
  }).flat();
16734
- const rColumns = jsonRenameColumnsStatements.map((it) => {
16735
- const tableName = it.tableName;
16736
- const schema4 = it.schema;
16737
- return {
16738
- from: { schema: schema4, table: tableName, column: it.oldColumnName },
16739
- to: { schema: schema4, table: tableName, column: it.newColumnName }
16740
- };
16741
- });
16742
- const rTables = renamedTables.map((it) => {
16743
- return { from: it.from, to: it.to };
16744
- });
16745
- const _meta = prepareMigrationMeta([], rTables, rColumns);
16746
15656
  const allAltered = typedResult.alteredTablesWithColumns;
16747
15657
  const jsonAddedCompositePKs = [];
16748
15658
  const jsonDeletedCompositePKs = [];
@@ -16813,6 +15723,14 @@ var init_snapshotsDiffer = __esm({
16813
15723
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
16814
15724
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
16815
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
+ });
16816
15734
  const jsonTableAlternations = allAltered.map((it) => {
16817
15735
  return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
16818
15736
  }).flat();
@@ -16859,22 +15777,21 @@ var init_snapshotsDiffer = __esm({
16859
15777
  );
16860
15778
  });
16861
15779
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
16862
- const forAdded = prepareLibSQLCreateReferencesJson(
15780
+ const forAdded = prepareCreateReferencesJson(
16863
15781
  it.name,
16864
15782
  it.schema,
16865
- it.addedForeignKeys,
16866
- json2,
16867
- action
15783
+ it.addedForeignKeys
16868
15784
  );
16869
- const forAltered = prepareLibSQLDropReferencesJson(
15785
+ const forAltered = prepareDropReferencesJson(
16870
15786
  it.name,
16871
15787
  it.schema,
16872
- it.deletedForeignKeys,
16873
- json2,
16874
- _meta,
16875
- action
15788
+ it.deletedForeignKeys
15789
+ );
15790
+ const alteredFKs = prepareAlterReferencesJson(
15791
+ it.name,
15792
+ it.schema,
15793
+ it.alteredForeignKeys
16876
15794
  );
16877
- const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
16878
15795
  return [...forAdded, ...forAltered, ...alteredFKs];
16879
15796
  }).flat();
16880
15797
  const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
@@ -16900,22 +15817,19 @@ var init_snapshotsDiffer = __esm({
16900
15817
  jsonStatements.push(...jsonDropColumnsStatemets);
16901
15818
  jsonStatements.push(...jsonAlteredCompositePKs);
16902
15819
  jsonStatements.push(...jsonAlteredUniqueConstraints);
16903
- const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
16904
- const sqlStatements = fromJson(
16905
- combinedJsonStatements,
16906
- "sqlite",
16907
- action,
16908
- "turso",
16909
- json2
16910
- );
15820
+ const sqlStatements = fromJson(jsonStatements, "sqlite");
16911
15821
  const uniqueSqlStatements = [];
16912
15822
  sqlStatements.forEach((ss) => {
16913
15823
  if (!uniqueSqlStatements.includes(ss)) {
16914
15824
  uniqueSqlStatements.push(ss);
16915
15825
  }
16916
15826
  });
15827
+ const rTables = renamedTables.map((it) => {
15828
+ return { from: it.from, to: it.to };
15829
+ });
15830
+ const _meta = prepareMigrationMeta([], rTables, rColumns);
16917
15831
  return {
16918
- statements: combinedJsonStatements,
15832
+ statements: jsonStatements,
16919
15833
  sqlStatements: uniqueSqlStatements,
16920
15834
  _meta
16921
15835
  };
@@ -20479,7 +19393,7 @@ function jaccardDistance(column4, value) {
20479
19393
  }
20480
19394
  return sql`${column4} <%> ${value}`;
20481
19395
  }
20482
- var init_vector = __esm({
19396
+ var init_vector2 = __esm({
20483
19397
  "../drizzle-orm/dist/sql/functions/vector.js"() {
20484
19398
  "use strict";
20485
19399
  init_sql();
@@ -20491,7 +19405,7 @@ var init_functions = __esm({
20491
19405
  "../drizzle-orm/dist/sql/functions/index.js"() {
20492
19406
  "use strict";
20493
19407
  init_aggregate();
20494
- init_vector();
19408
+ init_vector2();
20495
19409
  }
20496
19410
  });
20497
19411
 
@@ -22155,7 +21069,7 @@ var init_sparsevec = __esm({
22155
21069
 
22156
21070
  // ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
22157
21071
  var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
22158
- var init_vector2 = __esm({
21072
+ var init_vector3 = __esm({
22159
21073
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
22160
21074
  "use strict";
22161
21075
  init_entity();
@@ -22227,7 +21141,7 @@ var init_columns = __esm({
22227
21141
  init_bit();
22228
21142
  init_halfvec();
22229
21143
  init_sparsevec();
22230
- init_vector2();
21144
+ init_vector3();
22231
21145
  }
22232
21146
  });
22233
21147
 
@@ -25725,24 +24639,6 @@ var init_pg_core = __esm({
25725
24639
  }
25726
24640
  });
25727
24641
 
25728
- // src/extensions/vector.ts
25729
- var vectorOps;
25730
- var init_vector3 = __esm({
25731
- "src/extensions/vector.ts"() {
25732
- "use strict";
25733
- vectorOps = [
25734
- "vector_l2_ops",
25735
- "vector_ip_ops",
25736
- "vector_cosine_ops",
25737
- "vector_l1_ops",
25738
- "bit_hamming_ops",
25739
- "bit_jaccard_ops",
25740
- "halfvec_l2_ops",
25741
- "sparsevec_l2_ops"
25742
- ];
25743
- }
25744
- });
25745
-
25746
24642
  // src/serializer/pgSerializer.ts
25747
24643
  function stringFromIdentityProperty(field) {
25748
24644
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
@@ -25780,7 +24676,7 @@ function buildArrayString(array, sqlType) {
25780
24676
  }).join(",");
25781
24677
  return `{${values}}`;
25782
24678
  }
25783
- var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24679
+ var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
25784
24680
  var init_pgSerializer = __esm({
25785
24681
  "src/serializer/pgSerializer.ts"() {
25786
24682
  "use strict";
@@ -25788,7 +24684,7 @@ var init_pgSerializer = __esm({
25788
24684
  init_dist();
25789
24685
  init_pg_core();
25790
24686
  init_pg_core();
25791
- init_vector3();
24687
+ init_vector();
25792
24688
  init_outputs();
25793
24689
  init_utils();
25794
24690
  init_serializer();
@@ -25901,7 +24797,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
25901
24797
  columnToSet.default = `'${buildArrayString(
25902
24798
  column4.default,
25903
24799
  sqlTypeLowered
25904
- )}'::${sqlTypeLowered}`;
24800
+ )}'`;
25905
24801
  } else {
25906
24802
  columnToSet.default = column4.default;
25907
24803
  }
@@ -26248,7 +25144,7 @@ ${withStyle.errorWarning(
26248
25144
  WHEN 'int2'::regtype THEN 'smallserial'
26249
25145
  END
26250
25146
  ELSE format_type(a.atttypid, a.atttypmod)
26251
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
25147
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
26252
25148
  pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
26253
25149
  INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
26254
25150
  INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
@@ -26259,6 +25155,7 @@ ${withStyle.errorWarning(
26259
25155
  INFORMATION_SCHEMA.COLUMNS.identity_cycle
26260
25156
  FROM pg_attribute a
26261
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
26262
25159
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
26263
25160
  AND a.attnum > 0
26264
25161
  AND NOT a.attisdropped
@@ -26278,30 +25175,42 @@ ${withStyle.errorWarning(
26278
25175
  }
26279
25176
  const tableForeignKeys = await db.query(
26280
25177
  `SELECT
26281
- tc.table_schema,
26282
- tc.constraint_name,
26283
- tc.table_name,
26284
- kcu.column_name,
26285
- (
26286
- SELECT ccu.table_schema
26287
- FROM information_schema.constraint_column_usage ccu
26288
- WHERE ccu.constraint_name = tc.constraint_name
26289
- LIMIT 1
26290
- ) AS foreign_table_schema,
26291
- ccu.table_name AS foreign_table_name,
26292
- ccu.column_name AS foreign_column_name,
26293
- rc.delete_rule,
26294
- rc.update_rule
26295
- FROM
26296
- information_schema.table_constraints AS tc
26297
- JOIN information_schema.key_column_usage AS kcu
26298
- ON tc.constraint_name = kcu.constraint_name
26299
- AND tc.table_schema = kcu.table_schema
26300
- JOIN information_schema.constraint_column_usage AS ccu
26301
- ON ccu.constraint_name = tc.constraint_name
26302
- JOIN information_schema.referential_constraints AS rc
26303
- ON ccu.constraint_name = rc.constraint_name
26304
- 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');`
26305
25214
  );
26306
25215
  foreignKeysCount += tableForeignKeys.length;
26307
25216
  if (progressCallback) {
@@ -26359,6 +25268,8 @@ ${withStyle.errorWarning(
26359
25268
  const columnDimensions = columnResponse.array_dimensions;
26360
25269
  const enumType2 = columnResponse.enum_name;
26361
25270
  let columnType = columnResponse.data_type;
25271
+ const typeSchema = columnResponse.type_schema;
25272
+ const defaultValueRes = columnResponse.column_default;
26362
25273
  const isGenerated = columnResponse.is_generated === "ALWAYS";
26363
25274
  const generationExpression = columnResponse.generation_expression;
26364
25275
  const isIdentity = columnResponse.is_identity === "YES";
@@ -26389,12 +25300,7 @@ ${withStyle.errorWarning(
26389
25300
  columns: cprimaryKey.map((c) => c.column_name)
26390
25301
  };
26391
25302
  }
26392
- const defaultValue = defaultForColumn(columnResponse);
26393
- const isSerial = columnType === "serial";
26394
25303
  let columnTypeMapped = columnType;
26395
- if (columnTypeMapped.startsWith("numeric(")) {
26396
- columnTypeMapped = columnTypeMapped.replace(",", ", ");
26397
- }
26398
25304
  if (columnAdditionalDT === "ARRAY") {
26399
25305
  if (typeof internals.tables[tableName] === "undefined") {
26400
25306
  internals.tables[tableName] = {
@@ -26422,6 +25328,34 @@ ${withStyle.errorWarning(
26422
25328
  }
26423
25329
  }
26424
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
+ }
26425
25359
  if (columnAdditionalDT === "ARRAY") {
26426
25360
  for (let i = 1; i < Number(columnDimensions); i++) {
26427
25361
  columnTypeMapped += "[]";
@@ -26435,7 +25369,7 @@ ${withStyle.errorWarning(
26435
25369
  // filter vectors, but in future we should filter any extension that was installed by user
26436
25370
  columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
26437
25371
  ),
26438
- 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,
26439
25373
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
26440
25374
  // default: isSerial ? undefined : defaultValue,
26441
25375
  notNull: columnResponse.is_nullable === "NO",
@@ -26606,59 +25540,71 @@ ${withStyle.errorWarning(
26606
25540
  internal: internals
26607
25541
  };
26608
25542
  };
26609
- columnToDefault = {
26610
- "numeric(": "::numeric",
26611
- // text: "::text",
26612
- // "character varying": "::character varying",
26613
- // "double precision": "::double precision",
26614
- // "time with time zone": "::time with time zone",
26615
- "time without time zone": "::time without time zone",
26616
- // "timestamp with time zone": "::timestamp with time zone",
26617
- "timestamp without time zone": "::timestamp without time zone",
26618
- "timestamp(": "::timestamp without time zone",
26619
- // date: "::date",
26620
- // interval: "::interval",
26621
- // character: "::bpchar",
26622
- // macaddr8: "::macaddr8",
26623
- // macaddr: "::macaddr",
26624
- // inet: "::inet",
26625
- // cidr: "::cidr",
26626
- // jsonb: "::jsonb",
26627
- // json: "::json",
26628
- "character(": "::bpchar"
26629
- };
26630
- defaultForColumn = (column4) => {
25543
+ defaultForColumn = (column4, internals, tableName) => {
25544
+ const columnName = column4.attname;
25545
+ const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
26631
25546
  if (column4.column_default === null) {
26632
25547
  return void 0;
26633
25548
  }
26634
25549
  if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
26635
25550
  return void 0;
26636
25551
  }
26637
- 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"])(?=$)/, "");
26638
25556
  const columnDefaultAsString = column4.column_default.toString();
26639
- if (columnDefaultAsString.endsWith(
26640
- hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
26641
- )) {
26642
- const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
26643
- const rt = column4.column_default.toString().substring(1, nonPrefixPart);
26644
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
26645
- return Number(rt);
26646
- } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
26647
- const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
26648
- return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
26649
- } else if (column4.data_type === "boolean") {
26650
- return column4.column_default === "true";
26651
- } else {
26652
- return `'${rt}'`;
26653
- }
26654
- } else {
26655
- 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)) {
26656
25576
  return Number(columnDefaultAsString);
26657
- } else if (column4.data_type === "boolean") {
26658
- return column4.column_default === "true";
26659
25577
  } else {
26660
- 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;
26661
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, "`\\")}`;
26662
25608
  }
26663
25609
  };
26664
25610
  }
@@ -34977,8 +33923,7 @@ var init_cli = __esm({
34977
33923
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
34978
33924
  extensionsFilters: literalType("postgis").array().optional(),
34979
33925
  verbose: booleanType().optional(),
34980
- strict: booleanType().optional(),
34981
- driver: driver.optional()
33926
+ strict: booleanType().optional()
34982
33927
  }).passthrough();
34983
33928
  pullParams = objectType({
34984
33929
  config: stringType().optional(),
@@ -34989,7 +33934,7 @@ var init_cli = __esm({
34989
33934
  extensionsFilters: literalType("postgis").array().optional(),
34990
33935
  introspectCasing: casing,
34991
33936
  breakpoints: booleanType().optional().default(true),
34992
- database: objectType({
33937
+ migrations: objectType({
34993
33938
  prefix: prefix.optional().default("index")
34994
33939
  }).optional()
34995
33940
  }).passthrough();
@@ -36144,8 +35089,284 @@ var sqlitePushIntrospect = async (db, filters) => {
36144
35089
  return { schema: schema4 };
36145
35090
  };
36146
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
+
36147
35369
  // src/api.ts
36148
- init_sqlitePushUtils();
36149
35370
  init_global();
36150
35371
  init_migrationPreparator();
36151
35372
  init_mysqlSchema();