drizzle-kit 0.19.3-d338b71 → 0.19.4-2a2e18d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +491 -78
  2. package/package.json +2 -2
  3. package/utils.js +277 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.3-d338b71",
3
+ "version": "0.19.4-2a2e18d",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
@@ -79,7 +79,7 @@
79
79
  "better-sqlite3": "^8.4.0",
80
80
  "dockerode": "^3.3.4",
81
81
  "dotenv": "^16.0.3",
82
- "drizzle-orm": "0.27.0",
82
+ "drizzle-orm": "0.27.0-7b55cc2",
83
83
  "eslint": "^8.29.0",
84
84
  "eslint-config-prettier": "^8.5.0",
85
85
  "eslint-plugin-prettier": "^4.2.1",
package/utils.js CHANGED
@@ -12759,6 +12759,10 @@ var compositePK = objectType({
12759
12759
  name: stringType(),
12760
12760
  columns: stringType().array()
12761
12761
  }).strict();
12762
+ var uniqueConstraint = objectType({
12763
+ name: stringType(),
12764
+ columns: stringType().array()
12765
+ }).strict();
12762
12766
  var tableV4 = objectType({
12763
12767
  name: stringType(),
12764
12768
  schema: stringType().optional(),
@@ -12772,7 +12776,8 @@ var table = objectType({
12772
12776
  columns: recordType(stringType(), column),
12773
12777
  indexes: recordType(stringType(), index),
12774
12778
  foreignKeys: recordType(stringType(), fk),
12775
- compositePrimaryKeys: recordType(stringType(), compositePK)
12779
+ compositePrimaryKeys: recordType(stringType(), compositePK),
12780
+ uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
12776
12781
  }).strict();
12777
12782
  var dialect = literalType("mysql");
12778
12783
  var schemaHash = objectType({
@@ -12855,6 +12860,13 @@ var MySqlSquasher = {
12855
12860
  const splitted = pk.split(";");
12856
12861
  return { name: splitted[0], columns: splitted[1].split(",") };
12857
12862
  },
12863
+ squashUnique: (unq) => {
12864
+ return `${unq.name};${unq.columns.join(",")}`;
12865
+ },
12866
+ unsquashUnique: (unq) => {
12867
+ const [name, columns] = unq.split(";");
12868
+ return { name, columns: columns.split(",") };
12869
+ },
12858
12870
  squashFK: (fk4) => {
12859
12871
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
12860
12872
  },
@@ -12881,7 +12893,11 @@ var MySqlSquasher = {
12881
12893
  }
12882
12894
  };
12883
12895
  var mysqlSchema = schema;
12884
- var backwardCompatibleMysqlSchema = unionType([schemaV3, schemaV4, schema]);
12896
+ var backwardCompatibleMysqlSchema = unionType([
12897
+ schemaV3,
12898
+ schemaV4,
12899
+ schema
12900
+ ]);
12885
12901
  var dryMySql = mysqlSchema.parse({
12886
12902
  version: snapshotVersion,
12887
12903
  dialect: "mysql",
@@ -12974,7 +12990,10 @@ var column2 = objectType({
12974
12990
  type: stringType(),
12975
12991
  primaryKey: booleanType(),
12976
12992
  notNull: booleanType(),
12977
- default: anyType().optional()
12993
+ default: anyType().optional(),
12994
+ isUnique: anyType().optional(),
12995
+ uniqueName: stringType().optional(),
12996
+ nullsNotDistinct: booleanType().optional()
12978
12997
  }).strict();
12979
12998
  var tableV32 = objectType({
12980
12999
  name: stringType(),
@@ -12986,6 +13005,11 @@ var compositePK2 = objectType({
12986
13005
  name: stringType(),
12987
13006
  columns: stringType().array()
12988
13007
  }).strict();
13008
+ var uniqueConstraint2 = objectType({
13009
+ name: stringType(),
13010
+ columns: stringType().array(),
13011
+ nullsNotDistinct: booleanType()
13012
+ }).strict();
12989
13013
  var tableV42 = objectType({
12990
13014
  name: stringType(),
12991
13015
  schema: stringType(),
@@ -12999,7 +13023,8 @@ var table2 = objectType({
12999
13023
  columns: recordType(stringType(), column2),
13000
13024
  indexes: recordType(stringType(), index2),
13001
13025
  foreignKeys: recordType(stringType(), fk2),
13002
- compositePrimaryKeys: recordType(stringType(), compositePK2)
13026
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
13027
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
13003
13028
  }).strict();
13004
13029
  var schemaHash2 = objectType({
13005
13030
  id: stringType(),
@@ -13036,7 +13061,8 @@ var tableSquashed2 = objectType({
13036
13061
  columns: recordType(stringType(), column2),
13037
13062
  indexes: recordType(stringType(), stringType()),
13038
13063
  foreignKeys: recordType(stringType(), stringType()),
13039
- compositePrimaryKeys: recordType(stringType(), stringType())
13064
+ compositePrimaryKeys: recordType(stringType(), stringType()),
13065
+ uniqueConstraints: recordType(stringType(), stringType())
13040
13066
  }).strict();
13041
13067
  var tableSquashedV42 = objectType({
13042
13068
  name: stringType(),
@@ -13092,6 +13118,17 @@ var PgSquasher = {
13092
13118
  unsquashPK: (pk) => {
13093
13119
  return { name: "", columns: pk.split(",") };
13094
13120
  },
13121
+ squashUnique: (unq) => {
13122
+ return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
13123
+ },
13124
+ unsquashUnique: (unq) => {
13125
+ const [
13126
+ name,
13127
+ columns,
13128
+ nullsNotDistinct
13129
+ ] = unq.split(";");
13130
+ return { name, columns: columns.split(","), nullsNotDistinct: nullsNotDistinct === "true" };
13131
+ },
13095
13132
  unsquashFK: (input) => {
13096
13133
  const [
13097
13134
  name,
@@ -13126,6 +13163,9 @@ var squashPgScheme = (json) => {
13126
13163
  const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
13127
13164
  return PgSquasher.squashPK(pk);
13128
13165
  });
13166
+ const squashedUniqueConstraints = mapValues(it[1].uniqueConstraints, (unq) => {
13167
+ return PgSquasher.squashUnique(unq);
13168
+ });
13129
13169
  return [
13130
13170
  it[0],
13131
13171
  {
@@ -13134,7 +13174,8 @@ var squashPgScheme = (json) => {
13134
13174
  columns: it[1].columns,
13135
13175
  indexes: squashedIndexes,
13136
13176
  foreignKeys: squashedFKs,
13137
- compositePrimaryKeys: squashedPKs
13177
+ compositePrimaryKeys: squashedPKs,
13178
+ uniqueConstraints: squashedUniqueConstraints
13138
13179
  }
13139
13180
  ];
13140
13181
  })
@@ -13196,12 +13237,17 @@ var tableV33 = objectType({
13196
13237
  indexes: recordType(stringType(), index3),
13197
13238
  foreignKeys: recordType(stringType(), fk3)
13198
13239
  }).strict();
13240
+ var uniqueConstraint3 = objectType({
13241
+ name: stringType(),
13242
+ columns: stringType().array()
13243
+ }).strict();
13199
13244
  var table3 = objectType({
13200
13245
  name: stringType(),
13201
13246
  columns: recordType(stringType(), column3),
13202
13247
  indexes: recordType(stringType(), index3),
13203
13248
  foreignKeys: recordType(stringType(), fk3),
13204
- compositePrimaryKeys: recordType(stringType(), compositePK3)
13249
+ compositePrimaryKeys: recordType(stringType(), compositePK3),
13250
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
13205
13251
  }).strict();
13206
13252
  var dialect2 = enumType(["sqlite"]);
13207
13253
  var schemaHash3 = objectType({
@@ -13262,6 +13308,13 @@ var SQLiteSquasher = {
13262
13308
  });
13263
13309
  return result;
13264
13310
  },
13311
+ squashUnique: (unq) => {
13312
+ return `${unq.name};${unq.columns.join(",")}`;
13313
+ },
13314
+ unsquashUnique: (unq) => {
13315
+ const [name, columns] = unq.split(";");
13316
+ return { name, columns: columns.split(",") };
13317
+ },
13265
13318
  squashFK: (fk4) => {
13266
13319
  return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
13267
13320
  },
@@ -13440,6 +13493,15 @@ var findAlternationsInTable = (table4, tableSchema) => {
13440
13493
  const alteredCompositePKs = Object.fromEntries(Object.entries(table4.compositePrimaryKeys || {}).filter((it) => {
13441
13494
  return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
13442
13495
  }));
13496
+ const addedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
13497
+ return it[0].endsWith("__added");
13498
+ }));
13499
+ const deletedUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
13500
+ return it[0].endsWith("__deleted");
13501
+ }));
13502
+ const alteredUniqueConstraints = Object.fromEntries(Object.entries(table4.uniqueConstraints || {}).filter((it) => {
13503
+ return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
13504
+ }));
13443
13505
  const mappedAltered = altered.map((it) => alternationsInColumn(it));
13444
13506
  return {
13445
13507
  name: table4.name,
@@ -13455,7 +13517,10 @@ var findAlternationsInTable = (table4, tableSchema) => {
13455
13517
  alteredForeignKeys,
13456
13518
  addedCompositePKs,
13457
13519
  deletedCompositePKs,
13458
- alteredCompositePKs
13520
+ alteredCompositePKs,
13521
+ addedUniqueConstraints,
13522
+ deletedUniqueConstraints,
13523
+ alteredUniqueConstraints
13459
13524
  };
13460
13525
  };
13461
13526
  var alternationsInColumn = (column4) => {
@@ -13603,30 +13668,37 @@ var PgCreateTableConvertor = class extends Convertor {
13603
13668
  return statement.type === "create_table" && dialect3 === "pg";
13604
13669
  }
13605
13670
  convert(st) {
13606
- const { tableName, schema: schema4, columns, compositePKs } = st;
13671
+ const { tableName, schema: schema4, columns, compositePKs, uniqueConstraints } = st;
13607
13672
  let statement = "";
13608
13673
  const name = schema4 ? `"${schema4}"."${tableName}"` : `"${tableName}"`;
13609
13674
  statement += `CREATE TABLE IF NOT EXISTS ${name} (
13610
13675
  `;
13611
13676
  for (let i = 0; i < columns.length; i++) {
13612
13677
  const column4 = columns[i];
13613
- const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
13614
- const notNullStatement = column4.notNull ? "NOT NULL" : "";
13615
- const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
13678
+ const primaryKeyStatement = column4.primaryKey ? " PRIMARY KEY" : "";
13679
+ const notNullStatement = column4.notNull ? " NOT NULL" : "";
13680
+ const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
13681
+ const uniqueConstraint4 = column4.isUnique ? ` CONSTRAINT ${column4.uniqueName} UNIQUE${column4.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}` : "";
13616
13682
  const type = isPgNativeType(column4.type) ? column4.type : `"${column4.type}"`;
13617
- statement += " " + `"${column4.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
13618
- statement += (i === columns.length - 1 ? "" : ",") + "\n";
13683
+ statement += ` "${column4.name}" ${type}${primaryKeyStatement}${defaultStatement}${notNullStatement}${uniqueConstraint4}`;
13684
+ statement += i === columns.length - 1 ? "" : ",\n";
13619
13685
  }
13620
- statement += `);`;
13621
- statement += `
13622
- `;
13623
13686
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
13687
+ statement += ",\n";
13624
13688
  const compositePK4 = PgSquasher.unsquashPK(compositePKs[0]);
13625
- statement += BREAKPOINT;
13626
- statement += `ALTER TABLE ${name} ADD CONSTRAINT "${st.compositePkName}" PRIMARY KEY("${compositePK4.columns.join('","')}");`;
13627
- statement += `
13628
- `;
13689
+ statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
13629
13690
  }
13691
+ if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
13692
+ for (const uniqueConstraint4 of uniqueConstraints) {
13693
+ statement += ",\n";
13694
+ const unsquashedUnique = PgSquasher.unsquashUnique(uniqueConstraint4);
13695
+ statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE("${unsquashedUnique.columns.join(`","`)}")`;
13696
+ }
13697
+ }
13698
+ statement += `
13699
+ );`;
13700
+ statement += `
13701
+ `;
13630
13702
  return statement;
13631
13703
  }
13632
13704
  };
@@ -13635,7 +13707,7 @@ var MySqlCreateTableConvertor = class extends Convertor {
13635
13707
  return statement.type === "create_table" && dialect3 === "mysql";
13636
13708
  }
13637
13709
  convert(st) {
13638
- const { tableName, columns, schema: schema4, compositePKs } = st;
13710
+ const { tableName, columns, schema: schema4, compositePKs, uniqueConstraints } = st;
13639
13711
  let statement = "";
13640
13712
  const tName = schema4 ? `\`${schema4}\`.\`${tableName}\`` : `\`${tableName}\``;
13641
13713
  statement += `CREATE TABLE ${tName} (
@@ -13647,17 +13719,23 @@ var MySqlCreateTableConvertor = class extends Convertor {
13647
13719
  const defaultStatement = column4.default !== void 0 ? ` DEFAULT ${column4.default}` : "";
13648
13720
  const onUpdateStatement = column4.onUpdate ? ` ON UPDATE CURRENT_TIMESTAMP` : "";
13649
13721
  const autoincrementStatement = column4.autoincrement ? " AUTO_INCREMENT" : "";
13650
- statement += " " + `\`${column4.name}\` ${column4.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`.trim();
13722
+ statement += ` \`${column4.name}\` ${column4.type}${autoincrementStatement}${primaryKeyStatement}${notNullStatement}${defaultStatement}${onUpdateStatement}`;
13651
13723
  statement += i === columns.length - 1 ? "" : ",\n";
13652
13724
  }
13653
13725
  if (typeof compositePKs !== "undefined" && compositePKs.length > 0) {
13654
13726
  statement += ",\n";
13655
13727
  const compositePK4 = MySqlSquasher.unsquashPK(compositePKs[0]);
13656
- statement += ` PRIMARY KEY(\`${compositePK4.columns.join("`,`")}\`)`;
13657
- statement += `
13658
- `;
13728
+ statement += ` CONSTRAINT ${st.compositePkName} PRIMARY KEY("${compositePK4.columns.join(`","`)}")`;
13659
13729
  }
13660
- statement += `);`;
13730
+ if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
13731
+ for (const uniqueConstraint4 of uniqueConstraints) {
13732
+ statement += ",\n";
13733
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
13734
+ statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
13735
+ }
13736
+ }
13737
+ statement += `
13738
+ );`;
13661
13739
  statement += `
13662
13740
  `;
13663
13741
  return statement;
@@ -13668,7 +13746,13 @@ var SQLiteCreateTableConvertor = class extends Convertor {
13668
13746
  return statement.type === "sqlite_create_table" && dialect3 === "sqlite";
13669
13747
  }
13670
13748
  convert(st) {
13671
- const { tableName, columns, referenceData, compositePKs } = st;
13749
+ const {
13750
+ tableName,
13751
+ columns,
13752
+ referenceData,
13753
+ compositePKs,
13754
+ uniqueConstraints
13755
+ } = st;
13672
13756
  let statement = "";
13673
13757
  statement += `CREATE TABLE \`${tableName}\` (`;
13674
13758
  for (let i = 0; i < columns.length; i++) {
@@ -13700,11 +13784,17 @@ var SQLiteCreateTableConvertor = class extends Convertor {
13700
13784
  const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
13701
13785
  const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
13702
13786
  const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
13787
+ statement += ",";
13703
13788
  statement += "\n ";
13704
13789
  statement += `FOREIGN KEY (${fromColumnsString}) REFERENCES \`${tableTo}\`(${toColumnsString})${onUpdateStatement}${onDeleteStatement}`;
13705
- statement += ",";
13706
13790
  }
13707
- statement = statement.trimChar(",");
13791
+ if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
13792
+ for (const uniqueConstraint4 of uniqueConstraints) {
13793
+ statement += ",\n";
13794
+ const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
13795
+ statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
13796
+ }
13797
+ }
13708
13798
  statement += `
13709
13799
  `;
13710
13800
  statement += `);`;
@@ -13713,6 +13803,72 @@ var SQLiteCreateTableConvertor = class extends Convertor {
13713
13803
  return statement;
13714
13804
  }
13715
13805
  };
13806
+ var PgAlterTableAddUniqueConstraintConvertor = class extends Convertor {
13807
+ can(statement, dialect3) {
13808
+ return statement.type === "create_unique_constraint" && dialect3 === "pg";
13809
+ }
13810
+ convert(statement) {
13811
+ const unsquashed = PgSquasher.unsquashUnique(statement.data);
13812
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
13813
+ return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" UNIQUE("${unsquashed.columns.join('","')}");`;
13814
+ }
13815
+ };
13816
+ var PgAlterTableDropUniqueConstraintConvertor = class extends Convertor {
13817
+ can(statement, dialect3) {
13818
+ return statement.type === "delete_unique_constraint" && dialect3 === "pg";
13819
+ }
13820
+ convert(statement) {
13821
+ const unsquashed = PgSquasher.unsquashUnique(statement.data);
13822
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
13823
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
13824
+ }
13825
+ };
13826
+ var MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
13827
+ can(statement, dialect3) {
13828
+ return statement.type === "create_unique_constraint" && dialect3 === "mysql";
13829
+ }
13830
+ convert(statement) {
13831
+ const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
13832
+ const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
13833
+ return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT \`${unsquashed.name}\` UNIQUE(\`${unsquashed.columns.join("`,`")}\`);`;
13834
+ }
13835
+ };
13836
+ var MySQLAlterTableDropUniqueConstraintConvertor = class extends Convertor {
13837
+ can(statement, dialect3) {
13838
+ return statement.type === "delete_unique_constraint" && dialect3 === "mysql";
13839
+ }
13840
+ convert(statement) {
13841
+ const unsquashed = MySqlSquasher.unsquashUnique(statement.data);
13842
+ const tableNameWithSchema = statement.schema ? `\`${statement.schema}\`.\`${statement.tableName}\`` : `\`${statement.tableName}\``;
13843
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT \`${unsquashed.name}\`;`;
13844
+ }
13845
+ };
13846
+ var SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
13847
+ can(statement, dialect3) {
13848
+ return statement.type === "create_unique_constraint" && dialect3 === "sqlite";
13849
+ }
13850
+ convert(statement) {
13851
+ return `/*
13852
+ SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
13853
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
13854
+
13855
+ Due to that we don't generate migration automatically and it has to be done manually
13856
+ */`;
13857
+ }
13858
+ };
13859
+ var SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
13860
+ can(statement, dialect3) {
13861
+ return statement.type === "delete_unique_constraint" && dialect3 === "sqlite";
13862
+ }
13863
+ convert(statement) {
13864
+ return `/*
13865
+ SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
13866
+ Please refer to: https://www.techonthenet.com/sqlite/unique.php
13867
+
13868
+ Due to that we don't generate migration automatically and it has to be done manually
13869
+ */`;
13870
+ }
13871
+ };
13716
13872
  var CreateTypeEnumConvertor = class extends Convertor {
13717
13873
  can(statement) {
13718
13874
  return statement.type === "create_type_enum";
@@ -14668,6 +14824,10 @@ convertors.push(new PgAlterTableAddColumnConvertor());
14668
14824
  convertors.push(new MySqlAlterTableAddColumnConvertor());
14669
14825
  convertors.push(new SQLiteAlterTableAddColumnConvertor());
14670
14826
  convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
14827
+ convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
14828
+ convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
14829
+ convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
14830
+ convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
14671
14831
  convertors.push(new CreatePgIndexConvertor());
14672
14832
  convertors.push(new CreateMySqlIndexConvertor());
14673
14833
  convertors.push(new CreateSqliteIndexConvertor());
@@ -14702,6 +14862,8 @@ convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
14702
14862
  convertors.push(new SqliteAlterForeignKeyConvertor());
14703
14863
  convertors.push(new SqliteDeleteForeignKeyConvertor());
14704
14864
  convertors.push(new SqliteCreateForeignKeyConvertor());
14865
+ convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
14866
+ convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
14705
14867
  convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
14706
14868
  convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
14707
14869
  convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
@@ -14762,7 +14924,7 @@ init_lib();
14762
14924
 
14763
14925
  // src/jsonStatements.ts
14764
14926
  var preparePgCreateTableJson = (table4, json2) => {
14765
- const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
14927
+ const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
14766
14928
  return {
14767
14929
  type: "create_table",
14768
14930
  tableName: name,
@@ -14771,11 +14933,12 @@ var preparePgCreateTableJson = (table4, json2) => {
14771
14933
  compositePKs: Object.values(compositePrimaryKeys),
14772
14934
  compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${PgSquasher.unsquashPK(
14773
14935
  Object.values(compositePrimaryKeys)[0]
14774
- ).columns.join("_")}`].name : ""
14936
+ ).columns.join("_")}`].name : "",
14937
+ uniqueConstraints: Object.values(uniqueConstraints)
14775
14938
  };
14776
14939
  };
14777
14940
  var prepareMySqlCreateTableJson = (table4, json2) => {
14778
- const { name, schema: schema4, columns, compositePrimaryKeys } = table4;
14941
+ const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
14779
14942
  return {
14780
14943
  type: "create_table",
14781
14944
  tableName: name,
@@ -14784,11 +14947,12 @@ var prepareMySqlCreateTableJson = (table4, json2) => {
14784
14947
  compositePKs: Object.values(compositePrimaryKeys),
14785
14948
  compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${name}_${MySqlSquasher.unsquashPK(
14786
14949
  Object.values(compositePrimaryKeys)[0]
14787
- ).columns.join("_")}`].name : ""
14950
+ ).columns.join("_")}`].name : "",
14951
+ uniqueConstraints: Object.values(uniqueConstraints)
14788
14952
  };
14789
14953
  };
14790
14954
  var prepareSQLiteCreateTable = (table4) => {
14791
- const { name, columns } = table4;
14955
+ const { name, columns, uniqueConstraints } = table4;
14792
14956
  const references2 = Object.values(table4.foreignKeys);
14793
14957
  const composites = Object.values(table4.compositePrimaryKeys).map(
14794
14958
  (it) => SQLiteSquasher.unsquashPK(it)
@@ -14798,7 +14962,8 @@ var prepareSQLiteCreateTable = (table4) => {
14798
14962
  tableName: name,
14799
14963
  columns: Object.values(columns),
14800
14964
  referenceData: references2,
14801
- compositePKs: composites
14965
+ compositePKs: composites,
14966
+ uniqueConstraints: Object.values(uniqueConstraints)
14802
14967
  };
14803
14968
  };
14804
14969
  var prepareDropTableJson = (table4) => {
@@ -15269,6 +15434,26 @@ var prepareAlterCompositePrimaryKeyPg = (tableName, schema4, pks, json1, json2)
15269
15434
  };
15270
15435
  });
15271
15436
  };
15437
+ var prepareAddUniqueConstraintPg = (tableName, schema4, unqs) => {
15438
+ return Object.values(unqs).map((it) => {
15439
+ return {
15440
+ type: "create_unique_constraint",
15441
+ tableName,
15442
+ data: it,
15443
+ schema: schema4
15444
+ };
15445
+ });
15446
+ };
15447
+ var prepareDeleteUniqueConstraintPg = (tableName, schema4, unqs) => {
15448
+ return Object.values(unqs).map((it) => {
15449
+ return {
15450
+ type: "delete_unique_constraint",
15451
+ tableName,
15452
+ data: it,
15453
+ schema: schema4
15454
+ };
15455
+ });
15456
+ };
15272
15457
  var prepareAddCompositePrimaryKeyMySql = (tableName, pks, json2) => {
15273
15458
  return Object.values(pks).map((it) => {
15274
15459
  return {
@@ -15374,12 +15559,14 @@ var columnSchema = objectType({
15374
15559
  name: stringType(),
15375
15560
  type: stringType(),
15376
15561
  primaryKey: booleanType().optional(),
15377
- unique: booleanType().optional(),
15378
15562
  default: anyType().optional(),
15379
15563
  notNull: booleanType().optional(),
15380
15564
  // should it be optional? should if be here?
15381
15565
  autoincrement: booleanType().optional(),
15382
- onUpdate: booleanType().optional()
15566
+ onUpdate: booleanType().optional(),
15567
+ isUnique: anyType().optional(),
15568
+ uniqueName: stringType().optional(),
15569
+ nullsNotDistinct: booleanType().optional()
15383
15570
  }).strict();
15384
15571
  var alteredColumnSchema = objectType({
15385
15572
  name: makeSelfOrChanged(stringType()),
@@ -15405,7 +15592,8 @@ var tableScheme = objectType({
15405
15592
  columns: recordType(stringType(), columnSchema),
15406
15593
  indexes: recordType(stringType(), stringType()),
15407
15594
  foreignKeys: recordType(stringType(), stringType()),
15408
- compositePrimaryKeys: recordType(stringType(), stringType()).default({})
15595
+ compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
15596
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
15409
15597
  }).strict();
15410
15598
  var alteredTableScheme = objectType({
15411
15599
  name: stringType(),
@@ -15439,6 +15627,15 @@ var alteredTableScheme = objectType({
15439
15627
  __new: stringType(),
15440
15628
  __old: stringType()
15441
15629
  })
15630
+ ),
15631
+ addedUniqueConstraints: recordType(stringType(), stringType()),
15632
+ deletedUniqueConstraints: recordType(stringType(), stringType()),
15633
+ alteredUniqueConstraints: recordType(
15634
+ stringType(),
15635
+ objectType({
15636
+ __new: stringType(),
15637
+ __old: stringType()
15638
+ })
15442
15639
  )
15443
15640
  }).strict();
15444
15641
  var diffResultScheme = objectType({
@@ -15528,13 +15725,19 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15528
15725
  alteredForeignKeys: table4.alteredForeignKeys,
15529
15726
  addedCompositePKs: table4.addedCompositePKs,
15530
15727
  deletedCompositePKs: table4.deletedCompositePKs,
15531
- alteredCompositePKs: table4.alteredCompositePKs
15728
+ alteredCompositePKs: table4.alteredCompositePKs,
15729
+ addedUniqueConstraints: table4.addedUniqueConstraints,
15730
+ deletedUniqueConstraints: table4.deletedUniqueConstraints,
15731
+ alteredUniqueConstraints: table4.alteredUniqueConstraints
15532
15732
  };
15533
15733
  allAlteredResolved.push(resolved);
15534
15734
  }
15535
15735
  const jsonAddedCompositePKs = [];
15536
15736
  const jsonDeletedCompositePKs = [];
15537
15737
  const jsonAlteredCompositePKs = [];
15738
+ const jsonAddedUniqueConstraints = [];
15739
+ const jsonDeletedUniqueConstraints = [];
15740
+ const jsonAlteredUniqueConstraints = [];
15538
15741
  const jsonSetTableSchemas = [];
15539
15742
  const jsonRemoveTableFromSchemas = [];
15540
15743
  const jsonSetNewTableSchemas = [];
@@ -15626,6 +15829,33 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15626
15829
  curFull
15627
15830
  );
15628
15831
  }
15832
+ let addedUniqueConstraints = [];
15833
+ let deletedUniqueConstraints = [];
15834
+ let alteredUniqueConstraints = [];
15835
+ addedUniqueConstraints = prepareAddUniqueConstraintPg(
15836
+ it.name,
15837
+ schemaUnwrapped,
15838
+ it.addedUniqueConstraints
15839
+ );
15840
+ deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
15841
+ it.name,
15842
+ schemaUnwrapped,
15843
+ it.deletedUniqueConstraints
15844
+ );
15845
+ if (it.alteredUniqueConstraints) {
15846
+ const added = {};
15847
+ const deleted2 = {};
15848
+ for (const k of Object.keys(it.alteredUniqueConstraints)) {
15849
+ added[k] = it.alteredUniqueConstraints[k].__new;
15850
+ deleted2[k] = it.alteredUniqueConstraints[k].__old;
15851
+ }
15852
+ addedUniqueConstraints.push(
15853
+ ...prepareAddUniqueConstraintPg(it.name, schemaUnwrapped, added)
15854
+ );
15855
+ deletedUniqueConstraints.push(
15856
+ ...prepareDeleteUniqueConstraintPg(it.name, schemaUnwrapped, deleted2)
15857
+ );
15858
+ }
15629
15859
  if (it.schema && typeof it.schema !== "string") {
15630
15860
  switch (it.schema.type) {
15631
15861
  case "added": {
@@ -15658,6 +15888,9 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15658
15888
  jsonAddedCompositePKs.push(...addedCompositePKs);
15659
15889
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
15660
15890
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
15891
+ jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
15892
+ jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
15893
+ jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
15661
15894
  });
15662
15895
  const rColumns = jsonRenameColumnsStatements.map((it) => {
15663
15896
  const tableName = it.tableName;
@@ -15782,6 +16015,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15782
16015
  jsonStatements.push(...jsonSQLiteCreateTables);
15783
16016
  } else if (dialect3 === "pg") {
15784
16017
  const jsonPgCreateTables = created.map((it) => {
16018
+ console.log(it);
15785
16019
  return preparePgCreateTableJson(it, curFull);
15786
16020
  });
15787
16021
  jsonStatements.push(...jsonPgCreateTables);
@@ -15795,6 +16029,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15795
16029
  jsonStatements.push(...jsonRenameTables);
15796
16030
  jsonStatements.push(...jsonRenameColumnsStatements);
15797
16031
  jsonStatements.push(...jsonDeletedCompositePKs);
16032
+ jsonStatements.push(...jsonDeletedUniqueConstraints);
15798
16033
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
15799
16034
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
15800
16035
  jsonStatements.push(...jsonTableAlternations.alterColumns);
@@ -15807,6 +16042,8 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
15807
16042
  jsonStatements.push(...jsonCreateReferences);
15808
16043
  jsonStatements.push(...jsonAddedCompositePKs);
15809
16044
  jsonStatements.push(...jsonAlteredCompositePKs);
16045
+ jsonStatements.push(...jsonAddedUniqueConstraints);
16046
+ jsonStatements.push(...jsonAlteredUniqueConstraints);
15810
16047
  jsonStatements.push(...jsonSetTableSchemas);
15811
16048
  jsonStatements.push(...filteredJsonSetNewTableSchemas);
15812
16049
  jsonStatements.push(...jsonRemoveTableFromSchemas);