drizzle-kit 0.25.0-1f15bfd → 0.25.0-20acc2f

Sign up to get free protection for your applications and to get access to all the features.
package/bin.cjs CHANGED
@@ -1315,6 +1315,11 @@ Is ${source_default.bold.blue(
1315
1315
  count: 0,
1316
1316
  name: "foreign keys",
1317
1317
  status: "fetching"
1318
+ },
1319
+ checks: {
1320
+ count: 0,
1321
+ name: "check constraints",
1322
+ status: "fetching"
1318
1323
  }
1319
1324
  };
1320
1325
  this.formatCount = (count) => {
@@ -1352,6 +1357,7 @@ Is ${source_default.bold.blue(
1352
1357
  info2 += this.hasEnums ? this.statusText(spin, this.state.enums) : "";
1353
1358
  info2 += this.statusText(spin, this.state.indexes);
1354
1359
  info2 += this.statusText(spin, this.state.fks);
1360
+ info2 += this.statusText(spin, this.state.checks);
1355
1361
  return info2;
1356
1362
  }
1357
1363
  };
@@ -5421,7 +5427,7 @@ var init_lib = __esm({
5421
5427
  });
5422
5428
 
5423
5429
  // src/serializer/mysqlSchema.ts
5424
- var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV5, mysqlSchemaSquashed, backwardCompatibleMysqlSchema, dryMySql;
5430
+ var index, fk, column, tableV3, compositePK, uniqueConstraint, checkConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV5, mysqlSchemaSquashed, backwardCompatibleMysqlSchema, dryMySql;
5425
5431
  var init_mysqlSchema = __esm({
5426
5432
  "src/serializer/mysqlSchema.ts"() {
5427
5433
  "use strict";
@@ -5471,6 +5477,10 @@ var init_mysqlSchema = __esm({
5471
5477
  name: stringType(),
5472
5478
  columns: stringType().array()
5473
5479
  }).strict();
5480
+ checkConstraint = objectType({
5481
+ name: stringType(),
5482
+ value: stringType()
5483
+ }).strict();
5474
5484
  tableV4 = objectType({
5475
5485
  name: stringType(),
5476
5486
  schema: stringType().optional(),
@@ -5484,7 +5494,8 @@ var init_mysqlSchema = __esm({
5484
5494
  indexes: recordType(stringType(), index),
5485
5495
  foreignKeys: recordType(stringType(), fk),
5486
5496
  compositePrimaryKeys: recordType(stringType(), compositePK),
5487
- uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
5497
+ uniqueConstraints: recordType(stringType(), uniqueConstraint).default({}),
5498
+ checkConstraint: recordType(stringType(), checkConstraint).default({})
5488
5499
  }).strict();
5489
5500
  kitInternals = objectType({
5490
5501
  tables: recordType(
@@ -5561,7 +5572,8 @@ var init_mysqlSchema = __esm({
5561
5572
  indexes: recordType(stringType(), stringType()),
5562
5573
  foreignKeys: recordType(stringType(), stringType()),
5563
5574
  compositePrimaryKeys: recordType(stringType(), stringType()),
5564
- uniqueConstraints: recordType(stringType(), stringType()).default({})
5575
+ uniqueConstraints: recordType(stringType(), stringType()).default({}),
5576
+ checkConstraints: recordType(stringType(), stringType()).default({})
5565
5577
  }).strict();
5566
5578
  schemaSquashed = objectType({
5567
5579
  version: literalType("5"),
@@ -5628,6 +5640,13 @@ var init_mysqlSchema = __esm({
5628
5640
  onDelete
5629
5641
  });
5630
5642
  return result;
5643
+ },
5644
+ squashCheck: (input) => {
5645
+ return `${input.name};${input.value}`;
5646
+ },
5647
+ unsquashCheck: (input) => {
5648
+ const [name, value] = input.split(";");
5649
+ return { name, value };
5631
5650
  }
5632
5651
  };
5633
5652
  squashMysqlScheme = (json) => {
@@ -5648,6 +5667,9 @@ var init_mysqlSchema = __esm({
5648
5667
  return MySqlSquasher.squashUnique(unq);
5649
5668
  }
5650
5669
  );
5670
+ const squashedCheckConstraints = mapValues(it[1].checkConstraint, (check2) => {
5671
+ return MySqlSquasher.squashCheck(check2);
5672
+ });
5651
5673
  return [
5652
5674
  it[0],
5653
5675
  {
@@ -5656,7 +5678,8 @@ var init_mysqlSchema = __esm({
5656
5678
  indexes: squashedIndexes,
5657
5679
  foreignKeys: squashedFKs,
5658
5680
  compositePrimaryKeys: squashedPKs,
5659
- uniqueConstraints: squashedUniqueConstraints
5681
+ uniqueConstraints: squashedUniqueConstraints,
5682
+ checkConstraints: squashedCheckConstraints
5660
5683
  }
5661
5684
  ];
5662
5685
  })
@@ -5706,7 +5729,7 @@ var init_vector = __esm({
5706
5729
  });
5707
5730
 
5708
5731
  // src/serializer/pgSchema.ts
5709
- 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;
5732
+ var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, checkConstraint2, 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;
5710
5733
  var init_pgSchema = __esm({
5711
5734
  "src/serializer/pgSchema.ts"() {
5712
5735
  "use strict";
@@ -5870,6 +5893,10 @@ var init_pgSchema = __esm({
5870
5893
  }).optional(),
5871
5894
  identity: sequenceSchema.merge(objectType({ type: enumType(["always", "byDefault"]) })).optional()
5872
5895
  }).strict();
5896
+ checkConstraint2 = objectType({
5897
+ name: stringType(),
5898
+ value: stringType()
5899
+ }).strict();
5873
5900
  columnSquashed = objectType({
5874
5901
  name: stringType(),
5875
5902
  type: stringType(),
@@ -5942,7 +5969,8 @@ var init_pgSchema = __esm({
5942
5969
  indexes: recordType(stringType(), index2),
5943
5970
  foreignKeys: recordType(stringType(), fk2),
5944
5971
  compositePrimaryKeys: recordType(stringType(), compositePK2),
5945
- uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
5972
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({}),
5973
+ checkConstraints: recordType(stringType(), checkConstraint2).default({})
5946
5974
  }).strict();
5947
5975
  schemaHash2 = objectType({
5948
5976
  id: stringType(),
@@ -6050,7 +6078,8 @@ var init_pgSchema = __esm({
6050
6078
  indexes: recordType(stringType(), stringType()),
6051
6079
  foreignKeys: recordType(stringType(), stringType()),
6052
6080
  compositePrimaryKeys: recordType(stringType(), stringType()),
6053
- uniqueConstraints: recordType(stringType(), stringType())
6081
+ uniqueConstraints: recordType(stringType(), stringType()),
6082
+ checkConstraints: recordType(stringType(), stringType())
6054
6083
  }).strict();
6055
6084
  tableSquashedV42 = objectType({
6056
6085
  name: stringType(),
@@ -6232,6 +6261,16 @@ var init_pgSchema = __esm({
6232
6261
  cache: splitted[6] !== "undefined" ? splitted[6] : void 0,
6233
6262
  cycle: splitted[7] === "true"
6234
6263
  };
6264
+ },
6265
+ squashCheck: (check2) => {
6266
+ return `${check2.name};${check2.value}`;
6267
+ },
6268
+ unsquashCheck: (input) => {
6269
+ const [
6270
+ name,
6271
+ value
6272
+ ] = input.split(";");
6273
+ return { name, value };
6235
6274
  }
6236
6275
  };
6237
6276
  squashPgScheme = (json, action) => {
@@ -6264,6 +6303,12 @@ var init_pgSchema = __esm({
6264
6303
  return PgSquasher.squashUnique(unq);
6265
6304
  }
6266
6305
  );
6306
+ const squashedChecksContraints = mapValues(
6307
+ it[1].checkConstraints,
6308
+ (check2) => {
6309
+ return PgSquasher.squashCheck(check2);
6310
+ }
6311
+ );
6267
6312
  return [
6268
6313
  it[0],
6269
6314
  {
@@ -6273,7 +6318,8 @@ var init_pgSchema = __esm({
6273
6318
  indexes: squashedIndexes,
6274
6319
  foreignKeys: squashedFKs,
6275
6320
  compositePrimaryKeys: squashedPKs,
6276
- uniqueConstraints: squashedUniqueConstraints
6321
+ uniqueConstraints: squashedUniqueConstraints,
6322
+ checkConstraints: squashedChecksContraints
6277
6323
  }
6278
6324
  ];
6279
6325
  })
@@ -6318,7 +6364,7 @@ var init_pgSchema = __esm({
6318
6364
  });
6319
6365
 
6320
6366
  // src/serializer/sqliteSchema.ts
6321
- var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, schemaInternalV52, kitInternals3, latestVersion, schemaInternal2, schemaV32, schemaV42, schemaV52, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV5, sqliteSchema, SQLiteSchemaSquashed, backwardCompatibleSqliteSchema;
6367
+ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, checkConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, schemaInternalV52, kitInternals3, latestVersion, schemaInternal2, schemaV32, schemaV42, schemaV52, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV5, sqliteSchema, SQLiteSchemaSquashed, backwardCompatibleSqliteSchema;
6322
6368
  var init_sqliteSchema = __esm({
6323
6369
  "src/serializer/sqliteSchema.ts"() {
6324
6370
  "use strict";
@@ -6365,13 +6411,18 @@ var init_sqliteSchema = __esm({
6365
6411
  name: stringType(),
6366
6412
  columns: stringType().array()
6367
6413
  }).strict();
6414
+ checkConstraint3 = objectType({
6415
+ name: stringType(),
6416
+ value: stringType()
6417
+ }).strict();
6368
6418
  table3 = objectType({
6369
6419
  name: stringType(),
6370
6420
  columns: recordType(stringType(), column3),
6371
6421
  indexes: recordType(stringType(), index3),
6372
6422
  foreignKeys: recordType(stringType(), fk3),
6373
6423
  compositePrimaryKeys: recordType(stringType(), compositePK3),
6374
- uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
6424
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({}),
6425
+ checkConstraints: recordType(stringType(), checkConstraint3).default({})
6375
6426
  }).strict();
6376
6427
  dialect2 = enumType(["sqlite"]);
6377
6428
  schemaHash3 = objectType({
@@ -6433,7 +6484,8 @@ var init_sqliteSchema = __esm({
6433
6484
  indexes: recordType(stringType(), stringType()),
6434
6485
  foreignKeys: recordType(stringType(), stringType()),
6435
6486
  compositePrimaryKeys: recordType(stringType(), stringType()),
6436
- uniqueConstraints: recordType(stringType(), stringType()).default({})
6487
+ uniqueConstraints: recordType(stringType(), stringType()).default({}),
6488
+ checkConstraints: recordType(stringType(), stringType()).default({})
6437
6489
  }).strict();
6438
6490
  schemaSquashed2 = objectType({
6439
6491
  version: latestVersion,
@@ -6515,6 +6567,16 @@ var init_sqliteSchema = __esm({
6515
6567
  },
6516
6568
  unsquashPK: (pk) => {
6517
6569
  return pk.split(",");
6570
+ },
6571
+ squashCheck: (check2) => {
6572
+ return `${check2.name};${check2.value}`;
6573
+ },
6574
+ unsquashCheck: (input) => {
6575
+ const [
6576
+ name,
6577
+ value
6578
+ ] = input.split(";");
6579
+ return { name, value };
6518
6580
  }
6519
6581
  };
6520
6582
  squashSqliteScheme = (json, action) => {
@@ -6541,6 +6603,12 @@ var init_sqliteSchema = __esm({
6541
6603
  return SQLiteSquasher.squashUnique(unq);
6542
6604
  }
6543
6605
  );
6606
+ const squashedCheckConstraints = mapValues(
6607
+ it[1].checkConstraints,
6608
+ (check2) => {
6609
+ return SQLiteSquasher.squashCheck(check2);
6610
+ }
6611
+ );
6544
6612
  return [
6545
6613
  it[0],
6546
6614
  {
@@ -6549,7 +6617,8 @@ var init_sqliteSchema = __esm({
6549
6617
  indexes: squashedIndexes,
6550
6618
  foreignKeys: squashedFKs,
6551
6619
  compositePrimaryKeys: squashedPKs,
6552
- uniqueConstraints: squashedUniqueConstraints
6620
+ uniqueConstraints: squashedUniqueConstraints,
6621
+ checkConstraints: squashedCheckConstraints
6553
6622
  }
6554
6623
  ];
6555
6624
  })
@@ -17948,6 +18017,7 @@ var init_mysqlSerializer = __esm({
17948
18017
  indexes,
17949
18018
  foreignKeys,
17950
18019
  schema: schema5,
18020
+ checks,
17951
18021
  primaryKeys,
17952
18022
  uniqueConstraints
17953
18023
  } = (0, import_mysql_core3.getTableConfig)(table4);
@@ -17956,6 +18026,8 @@ var init_mysqlSerializer = __esm({
17956
18026
  const foreignKeysObject = {};
17957
18027
  const primaryKeysObject = {};
17958
18028
  const uniqueConstraintObject = {};
18029
+ const checkConstraintObject = {};
18030
+ let checksInTable = {};
17959
18031
  columns.forEach((column7) => {
17960
18032
  const name = getColumnCasing(column7, casing2);
17961
18033
  const notNull = column7.notNull;
@@ -18187,6 +18259,32 @@ We have encountered a collision between the index name on columns ${source_defau
18187
18259
  lock: value.config.lock
18188
18260
  };
18189
18261
  });
18262
+ checks.forEach((check2) => {
18263
+ check2;
18264
+ const checkName = check2.name;
18265
+ if (typeof checksInTable[tableName] !== "undefined") {
18266
+ if (checksInTable[tableName].includes(check2.name)) {
18267
+ console.log(
18268
+ `
18269
+ ${withStyle.errorWarning(
18270
+ `We've found duplicated check constraint name in ${source_default.underline.blue(
18271
+ tableName
18272
+ )}. Please rename your check constraint in the ${source_default.underline.blue(
18273
+ tableName
18274
+ )} table`
18275
+ )}`
18276
+ );
18277
+ process.exit(1);
18278
+ }
18279
+ checksInTable[tableName].push(checkName);
18280
+ } else {
18281
+ checksInTable[tableName] = [check2.name];
18282
+ }
18283
+ checkConstraintObject[checkName] = {
18284
+ name: checkName,
18285
+ value: dialect4.sqlToQuery(check2.value).sql
18286
+ };
18287
+ });
18190
18288
  if (!schema5) {
18191
18289
  result[tableName] = {
18192
18290
  name: tableName,
@@ -18194,7 +18292,8 @@ We have encountered a collision between the index name on columns ${source_defau
18194
18292
  indexes: indexesObject,
18195
18293
  foreignKeys: foreignKeysObject,
18196
18294
  compositePrimaryKeys: primaryKeysObject,
18197
- uniqueConstraints: uniqueConstraintObject
18295
+ uniqueConstraints: uniqueConstraintObject,
18296
+ checkConstraint: checkConstraintObject
18198
18297
  };
18199
18298
  }
18200
18299
  }
@@ -18221,6 +18320,7 @@ We have encountered a collision between the index name on columns ${source_defau
18221
18320
  let tablesCount = /* @__PURE__ */ new Set();
18222
18321
  let indexesCount = 0;
18223
18322
  let foreignKeysCount = 0;
18323
+ let checksCount = 0;
18224
18324
  const idxs = await db.query(
18225
18325
  `select * from INFORMATION_SCHEMA.STATISTICS
18226
18326
  WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
@@ -18316,7 +18416,8 @@ We have encountered a collision between the index name on columns ${source_defau
18316
18416
  compositePrimaryKeys: {},
18317
18417
  indexes: {},
18318
18418
  foreignKeys: {},
18319
- uniqueConstraints: {}
18419
+ uniqueConstraints: {},
18420
+ checkConstraint: {}
18320
18421
  };
18321
18422
  } else {
18322
18423
  result[tableName].columns[columnName] = newColumn;
@@ -18467,6 +18568,38 @@ We have encountered a collision between the index name on columns ${source_defau
18467
18568
  progressCallback("indexes", indexesCount, "done");
18468
18569
  progressCallback("enums", 0, "done");
18469
18570
  }
18571
+ const checkConstraints = await db.query(
18572
+ `SELECT
18573
+ tc.table_name,
18574
+ tc.constraint_name,
18575
+ cc.check_clause
18576
+ FROM
18577
+ information_schema.table_constraints tc
18578
+ JOIN
18579
+ information_schema.check_constraints cc
18580
+ ON tc.constraint_name = cc.constraint_name
18581
+ WHERE
18582
+ tc.constraint_schema = '${inputSchema}'
18583
+ AND
18584
+ tc.constraint_type = 'CHECK';`
18585
+ );
18586
+ checksCount += checkConstraints.length;
18587
+ if (progressCallback) {
18588
+ progressCallback("checks", checksCount, "fetching");
18589
+ }
18590
+ for (const checkConstraintRow of checkConstraints) {
18591
+ const constraintName = checkConstraintRow["CONSTRAINT_NAME"];
18592
+ const constraintValue = checkConstraintRow["CHECK_CLAUSE"];
18593
+ const tableName = checkConstraintRow["TABLE_NAME"];
18594
+ const tableInResult = result[tableName];
18595
+ tableInResult.checkConstraint[constraintName] = {
18596
+ name: constraintName,
18597
+ value: constraintValue
18598
+ };
18599
+ }
18600
+ if (progressCallback) {
18601
+ progressCallback("checks", checksCount, "done");
18602
+ }
18470
18603
  return {
18471
18604
  version: "5",
18472
18605
  dialect: "mysql",
@@ -18603,6 +18736,7 @@ var init_pgSerializer = __esm({
18603
18736
  const sequencesToReturn = {};
18604
18737
  const indexesInSchema = {};
18605
18738
  for (const table4 of tables) {
18739
+ const checksInTable = {};
18606
18740
  const {
18607
18741
  name: tableName,
18608
18742
  columns,
@@ -18618,6 +18752,7 @@ var init_pgSerializer = __esm({
18618
18752
  }
18619
18753
  const columnsObject = {};
18620
18754
  const indexesObject = {};
18755
+ const checksObject = {};
18621
18756
  const foreignKeysObject = {};
18622
18757
  const primaryKeysObject = {};
18623
18758
  const uniqueConstraintObject = {};
@@ -18885,6 +19020,33 @@ ${withStyle.errorWarning(
18885
19020
  with: value.config.with ?? {}
18886
19021
  };
18887
19022
  });
19023
+ checks.forEach((check2) => {
19024
+ const checkName = check2.name;
19025
+ if (typeof checksInTable[`"${schema5 ?? "public"}"."${tableName}"`] !== "undefined") {
19026
+ if (checksInTable[`"${schema5 ?? "public"}"."${tableName}"`].includes(check2.name)) {
19027
+ console.log(
19028
+ `
19029
+ ${withStyle.errorWarning(
19030
+ `We've found duplicated check constraint name across ${source_default.underline.blue(
19031
+ schema5 ?? "public"
19032
+ )} schema in ${source_default.underline.blue(
19033
+ tableName
19034
+ )}. Please rename your check constraint in either the ${source_default.underline.blue(
19035
+ tableName
19036
+ )} table or the table with the duplicated check contraint name`
19037
+ )}`
19038
+ );
19039
+ process.exit(1);
19040
+ }
19041
+ checksInTable[`"${schema5 ?? "public"}"."${tableName}"`].push(checkName);
19042
+ } else {
19043
+ checksInTable[`"${schema5 ?? "public"}"."${tableName}"`] = [check2.name];
19044
+ }
19045
+ checksObject[checkName] = {
19046
+ name: checkName,
19047
+ value: dialect4.sqlToQuery(check2.value).sql
19048
+ };
19049
+ });
18888
19050
  const tableKey2 = `${schema5 ?? "public"}.${tableName}`;
18889
19051
  result[tableKey2] = {
18890
19052
  name: tableName,
@@ -18893,7 +19055,8 @@ ${withStyle.errorWarning(
18893
19055
  indexes: indexesObject,
18894
19056
  foreignKeys: foreignKeysObject,
18895
19057
  compositePrimaryKeys: primaryKeysObject,
18896
- uniqueConstraints: uniqueConstraintObject
19058
+ uniqueConstraints: uniqueConstraintObject,
19059
+ checkConstraints: checksObject
18897
19060
  };
18898
19061
  }
18899
19062
  for (const sequence of sequences) {
@@ -18984,6 +19147,7 @@ ${withStyle.errorWarning(
18984
19147
  let indexesCount = 0;
18985
19148
  let foreignKeysCount = 0;
18986
19149
  let tableCount = 0;
19150
+ let checksCount = 0;
18987
19151
  const sequencesToReturn = {};
18988
19152
  const seqWhere = schemaFilters.map((t2) => `schemaname = '${t2}'`).join(" or ");
18989
19153
  const allSequences = await db.query(
@@ -19055,7 +19219,8 @@ ${withStyle.errorWarning(
19055
19219
  const indexToReturn = {};
19056
19220
  const foreignKeysToReturn = {};
19057
19221
  const primaryKeys = {};
19058
- const uniqueConstrains = {};
19222
+ const uniqueConstraints = {};
19223
+ const checkConstraints = {};
19059
19224
  const tableResponse = await db.query(
19060
19225
  `SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
19061
19226
  , CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
@@ -19093,55 +19258,97 @@ ${withStyle.errorWarning(
19093
19258
  ORDER BY a.attnum;`
19094
19259
  );
19095
19260
  const tableConstraints = await db.query(
19096
- `SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
19097
- FROM information_schema.table_constraints tc
19098
- JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
19099
- JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
19100
- AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
19101
- WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
19261
+ `SELECT c.column_name,
19262
+ c.data_type,
19263
+ tc.constraint_type,
19264
+ tc.constraint_name,
19265
+ tc.constraint_schema,
19266
+ pg_get_constraintdef(con.oid) AS check_constraint_definition
19267
+ FROM information_schema.table_constraints tc
19268
+ JOIN information_schema.constraint_column_usage AS ccu
19269
+ USING (constraint_schema, constraint_name)
19270
+ JOIN information_schema.columns AS c
19271
+ ON c.table_schema = tc.constraint_schema
19272
+ AND tc.table_name = c.table_name
19273
+ AND ccu.column_name = c.column_name
19274
+ JOIN pg_constraint con
19275
+ ON con.conname = tc.constraint_name
19276
+ AND con.conrelid = (
19277
+ SELECT oid
19278
+ FROM pg_class
19279
+ WHERE relname = tc.table_name
19280
+ AND relnamespace = (
19281
+ SELECT oid
19282
+ FROM pg_namespace
19283
+ WHERE nspname = tc.constraint_schema
19284
+ )
19285
+ )
19286
+ WHERE tc.table_name = '${tableName}' AND tc.constraint_schema = '${tableSchema}';`
19102
19287
  );
19288
+ const tableChecks = await db.query(`SELECT
19289
+ tc.constraint_name,
19290
+ tc.constraint_type,
19291
+ pg_get_constraintdef(con.oid) AS constraint_definition
19292
+ FROM
19293
+ information_schema.table_constraints AS tc
19294
+ JOIN pg_constraint AS con
19295
+ ON tc.constraint_name = con.conname
19296
+ AND con.conrelid = (
19297
+ SELECT oid
19298
+ FROM pg_class
19299
+ WHERE relname = tc.table_name
19300
+ AND relnamespace = (
19301
+ SELECT oid
19302
+ FROM pg_namespace
19303
+ WHERE nspname = tc.constraint_schema
19304
+ )
19305
+ )
19306
+ WHERE
19307
+ tc.table_name = '${tableName}'
19308
+ AND tc.constraint_schema = '${tableSchema}'
19309
+ AND tc.constraint_type = 'CHECK';`);
19103
19310
  columnsCount += tableResponse.length;
19104
19311
  if (progressCallback) {
19105
19312
  progressCallback("columns", columnsCount, "fetching");
19106
19313
  }
19107
19314
  const tableForeignKeys = await db.query(
19108
19315
  `SELECT
19109
- con.contype AS constraint_type,
19110
- nsp.nspname AS constraint_schema,
19111
- con.conname AS constraint_name,
19112
- rel.relname AS table_name,
19113
- att.attname AS column_name,
19114
- fnsp.nspname AS foreign_table_schema,
19115
- frel.relname AS foreign_table_name,
19116
- fatt.attname AS foreign_column_name,
19117
- CASE con.confupdtype
19118
- WHEN 'a' THEN 'NO ACTION'
19119
- WHEN 'r' THEN 'RESTRICT'
19120
- WHEN 'n' THEN 'SET NULL'
19121
- WHEN 'c' THEN 'CASCADE'
19122
- WHEN 'd' THEN 'SET DEFAULT'
19123
- END AS update_rule,
19124
- CASE con.confdeltype
19125
- WHEN 'a' THEN 'NO ACTION'
19126
- WHEN 'r' THEN 'RESTRICT'
19127
- WHEN 'n' THEN 'SET NULL'
19128
- WHEN 'c' THEN 'CASCADE'
19129
- WHEN 'd' THEN 'SET DEFAULT'
19130
- END AS delete_rule
19131
- FROM
19132
- pg_catalog.pg_constraint con
19133
- JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
19134
- JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
19135
- LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
19136
- AND att.attrelid = con.conrelid
19137
- LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
19138
- LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
19139
- LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
19140
- AND fatt.attrelid = con.confrelid
19141
- WHERE
19142
- nsp.nspname = '${tableSchema}'
19143
- AND rel.relname = '${tableName}'
19144
- AND con.contype IN ('f');`
19316
+ con.contype AS constraint_type,
19317
+ nsp.nspname AS constraint_schema,
19318
+ con.conname AS constraint_name,
19319
+ rel.relname AS table_name,
19320
+ att.attname AS column_name,
19321
+ fnsp.nspname AS foreign_table_schema,
19322
+ frel.relname AS foreign_table_name,
19323
+ fatt.attname AS foreign_column_name,
19324
+ CASE con.confupdtype
19325
+ WHEN 'a' THEN 'NO ACTION'
19326
+ WHEN 'r' THEN 'RESTRICT'
19327
+ WHEN 'n' THEN 'SET NULL'
19328
+ WHEN 'c' THEN 'CASCADE'
19329
+ WHEN 'd' THEN 'SET DEFAULT'
19330
+ END AS update_rule,
19331
+ CASE con.confdeltype
19332
+ WHEN 'a' THEN 'NO ACTION'
19333
+ WHEN 'r' THEN 'RESTRICT'
19334
+ WHEN 'n' THEN 'SET NULL'
19335
+ WHEN 'c' THEN 'CASCADE'
19336
+ WHEN 'd' THEN 'SET DEFAULT'
19337
+ END AS delete_rule
19338
+ FROM
19339
+ pg_catalog.pg_constraint con
19340
+ JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
19341
+ JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
19342
+ LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
19343
+ AND att.attrelid = con.conrelid
19344
+ LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
19345
+ LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
19346
+ LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
19347
+ AND fatt.attrelid = con.confrelid
19348
+ WHERE
19349
+ nsp.nspname = '${tableSchema}'
19350
+ AND rel.relname = '${tableName}'
19351
+ AND con.contype IN ('f');`
19145
19352
  );
19146
19353
  foreignKeysCount += tableForeignKeys.length;
19147
19354
  if (progressCallback) {
@@ -19183,16 +19390,29 @@ ${withStyle.errorWarning(
19183
19390
  for (const unqs of uniqueConstrainsRows) {
19184
19391
  const columnName = unqs.column_name;
19185
19392
  const constraintName = unqs.constraint_name;
19186
- if (typeof uniqueConstrains[constraintName] !== "undefined") {
19187
- uniqueConstrains[constraintName].columns.push(columnName);
19393
+ if (typeof uniqueConstraints[constraintName] !== "undefined") {
19394
+ uniqueConstraints[constraintName].columns.push(columnName);
19188
19395
  } else {
19189
- uniqueConstrains[constraintName] = {
19396
+ uniqueConstraints[constraintName] = {
19190
19397
  columns: [columnName],
19191
19398
  nullsNotDistinct: false,
19192
19399
  name: constraintName
19193
19400
  };
19194
19401
  }
19195
19402
  }
19403
+ checksCount += tableChecks.length;
19404
+ if (progressCallback) {
19405
+ progressCallback("checks", checksCount, "fetching");
19406
+ }
19407
+ for (const checks of tableChecks) {
19408
+ let checkValue = checks.constraint_definition;
19409
+ const constraintName = checks.constraint_name;
19410
+ checkValue = checkValue.replace(/^CHECK\s*\(\(/, "").replace(/\)\)\s*$/, "");
19411
+ checkConstraints[constraintName] = {
19412
+ name: constraintName,
19413
+ value: checkValue
19414
+ };
19415
+ }
19196
19416
  for (const columnResponse of tableResponse) {
19197
19417
  const columnName = columnResponse.attname;
19198
19418
  const columnAdditionalDT = columnResponse.additional_dt;
@@ -19437,7 +19657,8 @@ ${withStyle.errorWarning(
19437
19657
  indexes: indexToReturn,
19438
19658
  foreignKeys: foreignKeysToReturn,
19439
19659
  compositePrimaryKeys: primaryKeys,
19440
- uniqueConstraints: uniqueConstrains
19660
+ uniqueConstraints,
19661
+ checkConstraints
19441
19662
  };
19442
19663
  } catch (e2) {
19443
19664
  rej(e2);
@@ -19455,6 +19676,7 @@ ${withStyle.errorWarning(
19455
19676
  progressCallback("columns", columnsCount, "done");
19456
19677
  progressCallback("indexes", indexesCount, "done");
19457
19678
  progressCallback("fks", foreignKeysCount, "done");
19679
+ progressCallback("checks", checksCount, "done");
19458
19680
  }
19459
19681
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
19460
19682
  return {
@@ -19527,6 +19749,8 @@ ${withStyle.errorWarning(
19527
19749
  }
19528
19750
  return columnDefaultAsString;
19529
19751
  }
19752
+ } else if (column7.data_type.includes("numeric")) {
19753
+ return columnDefaultAsString.includes("'") ? columnDefaultAsString : `'${columnDefaultAsString}'`;
19530
19754
  } else if (column7.data_type === "json" || column7.data_type === "jsonb") {
19531
19755
  const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
19532
19756
  return `'${jsonWithoutSpaces}'::${column7.data_type}`;
@@ -19668,10 +19892,13 @@ var init_sqliteSerializer = __esm({
19668
19892
  const foreignKeysObject = {};
19669
19893
  const primaryKeysObject = {};
19670
19894
  const uniqueConstraintObject = {};
19895
+ const checkConstraintObject = {};
19896
+ const checksInTable = {};
19671
19897
  const {
19672
19898
  name: tableName,
19673
19899
  columns,
19674
19900
  indexes,
19901
+ checks,
19675
19902
  foreignKeys: tableForeignKeys,
19676
19903
  primaryKeys,
19677
19904
  uniqueConstraints
@@ -19848,13 +20075,39 @@ The unique constraint ${source_default.underline.blue(
19848
20075
  columnsObject[getColumnCasing(it.columns[0], casing2)].primaryKey = true;
19849
20076
  }
19850
20077
  });
20078
+ checks.forEach((check2) => {
20079
+ const checkName = check2.name;
20080
+ if (typeof checksInTable[tableName] !== "undefined") {
20081
+ if (checksInTable[tableName].includes(check2.name)) {
20082
+ console.log(
20083
+ `
20084
+ ${withStyle.errorWarning(
20085
+ `We've found duplicated check constraint name in ${source_default.underline.blue(
20086
+ tableName
20087
+ )}. Please rename your check constraint in the ${source_default.underline.blue(
20088
+ tableName
20089
+ )} table`
20090
+ )}`
20091
+ );
20092
+ process.exit(1);
20093
+ }
20094
+ checksInTable[tableName].push(checkName);
20095
+ } else {
20096
+ checksInTable[tableName] = [check2.name];
20097
+ }
20098
+ checkConstraintObject[checkName] = {
20099
+ name: checkName,
20100
+ value: dialect4.sqlToQuery(check2.value).sql
20101
+ };
20102
+ });
19851
20103
  result[tableName] = {
19852
20104
  name: tableName,
19853
20105
  columns: columnsObject,
19854
20106
  indexes: indexesObject,
19855
20107
  foreignKeys: foreignKeysObject,
19856
20108
  compositePrimaryKeys: primaryKeysObject,
19857
- uniqueConstraints: uniqueConstraintObject
20109
+ uniqueConstraints: uniqueConstraintObject,
20110
+ checkConstraints: checkConstraintObject
19858
20111
  };
19859
20112
  }
19860
20113
  return {
@@ -19901,6 +20154,7 @@ The unique constraint ${source_default.underline.blue(
19901
20154
  let tablesCount = /* @__PURE__ */ new Set();
19902
20155
  let indexesCount = 0;
19903
20156
  let foreignKeysCount = 0;
20157
+ let checksCount = 0;
19904
20158
  const tableToPk = {};
19905
20159
  let tableToGeneratedColumnsInfo = {};
19906
20160
  for (const column7 of columns) {
@@ -19959,7 +20213,8 @@ The unique constraint ${source_default.underline.blue(
19959
20213
  compositePrimaryKeys: {},
19960
20214
  indexes: {},
19961
20215
  foreignKeys: {},
19962
- uniqueConstraints: {}
20216
+ uniqueConstraints: {},
20217
+ checkConstraints: {}
19963
20218
  };
19964
20219
  } else {
19965
20220
  result[tableName].columns[columnName] = newColumn;
@@ -20075,6 +20330,57 @@ WHERE
20075
20330
  progressCallback("indexes", indexesCount, "done");
20076
20331
  progressCallback("enums", 0, "done");
20077
20332
  }
20333
+ const namedCheckPattern = /CONSTRAINT\s*["']?(\w+)["']?\s*CHECK\s*\((.*?)\)/gi;
20334
+ const unnamedCheckPattern = /CHECK\s*\((.*?)\)/gi;
20335
+ let checkCounter = 0;
20336
+ const checkConstraints = {};
20337
+ const checks = await db.query(`SELECT name as "tableName", sql as "sql"
20338
+ FROM sqlite_master
20339
+ WHERE type = 'table' AND name != 'sqlite_sequence';`);
20340
+ for (const check2 of checks) {
20341
+ if (!tablesFilter(check2.tableName))
20342
+ continue;
20343
+ const { tableName, sql } = check2;
20344
+ let namedChecks = [...sql.matchAll(namedCheckPattern)];
20345
+ if (namedChecks.length > 0) {
20346
+ namedChecks.forEach(([_2, checkName, checkValue]) => {
20347
+ checkConstraints[checkName] = {
20348
+ name: checkName,
20349
+ value: checkValue.trim()
20350
+ };
20351
+ });
20352
+ } else {
20353
+ let unnamedChecks = [...sql.matchAll(unnamedCheckPattern)];
20354
+ unnamedChecks.forEach(([_2, checkValue]) => {
20355
+ let checkName = `${tableName}_check_${++checkCounter}`;
20356
+ checkConstraints[checkName] = {
20357
+ name: checkName,
20358
+ value: checkValue.trim()
20359
+ };
20360
+ });
20361
+ }
20362
+ checksCount += Object.values(checkConstraints).length;
20363
+ if (progressCallback) {
20364
+ progressCallback("checks", checksCount, "fetching");
20365
+ }
20366
+ const table4 = result[tableName];
20367
+ if (!table4) {
20368
+ result[tableName] = {
20369
+ name: tableName,
20370
+ columns: {},
20371
+ compositePrimaryKeys: {},
20372
+ indexes: {},
20373
+ foreignKeys: {},
20374
+ uniqueConstraints: {},
20375
+ checkConstraints
20376
+ };
20377
+ } else {
20378
+ result[tableName].checkConstraints = checkConstraints;
20379
+ }
20380
+ }
20381
+ if (progressCallback) {
20382
+ progressCallback("checks", checksCount, "done");
20383
+ }
20078
20384
  return {
20079
20385
  version: "6",
20080
20386
  dialect: "sqlite",
@@ -22815,6 +23121,21 @@ var init_jsonDiffer = __esm({
22815
23121
  return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
22816
23122
  })
22817
23123
  );
23124
+ const addedCheckConstraints = Object.fromEntries(
23125
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23126
+ return it[0].endsWith("__added");
23127
+ })
23128
+ );
23129
+ const deletedCheckConstraints = Object.fromEntries(
23130
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23131
+ return it[0].endsWith("__deleted");
23132
+ })
23133
+ );
23134
+ const alteredCheckConstraints = Object.fromEntries(
23135
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23136
+ return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
23137
+ })
23138
+ );
22818
23139
  const mappedAltered = altered.map((it) => alternationsInColumn(it)).filter(Boolean);
22819
23140
  return {
22820
23141
  name: table4.name,
@@ -22831,7 +23152,10 @@ var init_jsonDiffer = __esm({
22831
23152
  alteredCompositePKs,
22832
23153
  addedUniqueConstraints,
22833
23154
  deletedUniqueConstraints,
22834
- alteredUniqueConstraints
23155
+ alteredUniqueConstraints,
23156
+ addedCheckConstraints,
23157
+ deletedCheckConstraints,
23158
+ alteredCheckConstraints
22835
23159
  };
22836
23160
  };
22837
23161
  alternationsInColumn = (column7) => {
@@ -23085,6 +23409,32 @@ var init_jsonDiffer = __esm({
23085
23409
  };
23086
23410
  }
23087
23411
  return it;
23412
+ }).map((it) => {
23413
+ if ("" in it) {
23414
+ return {
23415
+ ...it,
23416
+ autoincrement: {
23417
+ type: "changed",
23418
+ old: it.autoincrement.__old,
23419
+ new: it.autoincrement.__new
23420
+ }
23421
+ };
23422
+ }
23423
+ if ("autoincrement__added" in it) {
23424
+ const { autoincrement__added, ...others } = it;
23425
+ return {
23426
+ ...others,
23427
+ autoincrement: { type: "added", value: it.autoincrement__added }
23428
+ };
23429
+ }
23430
+ if ("autoincrement__deleted" in it) {
23431
+ const { autoincrement__deleted, ...others } = it;
23432
+ return {
23433
+ ...others,
23434
+ autoincrement: { type: "deleted", value: it.autoincrement__deleted }
23435
+ };
23436
+ }
23437
+ return it;
23088
23438
  }).filter(Boolean);
23089
23439
  return result[0];
23090
23440
  };
@@ -23105,7 +23455,7 @@ function fromJson(statements, dialect4, action, json2) {
23105
23455
  }).filter((it) => it !== "");
23106
23456
  return result;
23107
23457
  }
23108
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
23458
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, DropTypeEnumConvertor, AlterTypeAddValueConvertor, AlterTypeSetSchemaConvertor, AlterRenameTypeConvertor, AlterTypeDropValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
23109
23459
  var init_sqlgenerator = __esm({
23110
23460
  "src/sqlgenerator.ts"() {
23111
23461
  "use strict";
@@ -23167,7 +23517,7 @@ var init_sqlgenerator = __esm({
23167
23517
  return statement.type === "create_table" && dialect4 === "postgresql";
23168
23518
  }
23169
23519
  convert(st) {
23170
- const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints } = st;
23520
+ const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints, checkConstraints } = st;
23171
23521
  let statement = "";
23172
23522
  const name = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
23173
23523
  statement += `CREATE TABLE IF NOT EXISTS ${name} (
@@ -23200,6 +23550,13 @@ var init_sqlgenerator = __esm({
23200
23550
  statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
23201
23551
  }
23202
23552
  }
23553
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23554
+ for (const checkConstraint4 of checkConstraints) {
23555
+ statement += ",\n";
23556
+ const unsquashedCheck = PgSquasher.unsquashCheck(checkConstraint4);
23557
+ statement += ` CONSTRAINT "${unsquashedCheck.name}" CHECK (${unsquashedCheck.value})`;
23558
+ }
23559
+ }
23203
23560
  statement += `
23204
23561
  );`;
23205
23562
  statement += `
@@ -23217,6 +23574,7 @@ var init_sqlgenerator = __esm({
23217
23574
  tableName,
23218
23575
  columns,
23219
23576
  schema: schema5,
23577
+ checkConstraints,
23220
23578
  compositePKs,
23221
23579
  uniqueConstraints,
23222
23580
  internals
@@ -23251,6 +23609,13 @@ var init_sqlgenerator = __esm({
23251
23609
  statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(${uniqueString})`;
23252
23610
  }
23253
23611
  }
23612
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23613
+ for (const checkConstraint4 of checkConstraints) {
23614
+ statement += ",\n";
23615
+ const unsquashedCheck = MySqlSquasher.unsquashCheck(checkConstraint4);
23616
+ statement += ` CONSTRAINT \`${unsquashedCheck.name}\` CHECK(${unsquashedCheck.value})`;
23617
+ }
23618
+ }
23254
23619
  statement += `
23255
23620
  );`;
23256
23621
  statement += `
@@ -23268,7 +23633,8 @@ var init_sqlgenerator = __esm({
23268
23633
  columns,
23269
23634
  referenceData,
23270
23635
  compositePKs,
23271
- uniqueConstraints
23636
+ uniqueConstraints,
23637
+ checkConstraints
23272
23638
  } = st;
23273
23639
  let statement = "";
23274
23640
  statement += `CREATE TABLE \`${tableName}\` (
@@ -23309,10 +23675,17 @@ var init_sqlgenerator = __esm({
23309
23675
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
23310
23676
  for (const uniqueConstraint4 of uniqueConstraints) {
23311
23677
  statement += ",\n";
23312
- const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
23678
+ const unsquashedUnique = SQLiteSquasher.unsquashUnique(uniqueConstraint4);
23313
23679
  statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
23314
23680
  }
23315
23681
  }
23682
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23683
+ for (const check2 of checkConstraints) {
23684
+ statement += ",\n";
23685
+ const { value, name } = SQLiteSquasher.unsquashCheck(check2);
23686
+ statement += ` CONSTRAINT "${name}" CHECK(${value})`;
23687
+ }
23688
+ }
23316
23689
  statement += `
23317
23690
  `;
23318
23691
  statement += `);`;
@@ -23412,6 +23785,25 @@ var init_sqlgenerator = __esm({
23412
23785
  return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
23413
23786
  }
23414
23787
  };
23788
+ PgAlterTableAddCheckConstraintConvertor = class extends Convertor {
23789
+ can(statement, dialect4) {
23790
+ return statement.type === "create_check_constraint" && dialect4 === "postgresql";
23791
+ }
23792
+ convert(statement) {
23793
+ const unsquashed = PgSquasher.unsquashCheck(statement.data);
23794
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
23795
+ return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" CHECK (${unsquashed.value});`;
23796
+ }
23797
+ };
23798
+ PgAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
23799
+ can(statement, dialect4) {
23800
+ return statement.type === "delete_check_constraint" && dialect4 === "postgresql";
23801
+ }
23802
+ convert(statement) {
23803
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
23804
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.constraintName}";`;
23805
+ }
23806
+ };
23415
23807
  MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
23416
23808
  can(statement, dialect4) {
23417
23809
  return statement.type === "create_unique_constraint" && dialect4 === "mysql";
@@ -23430,6 +23822,25 @@ var init_sqlgenerator = __esm({
23430
23822
  return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
23431
23823
  }
23432
23824
  };
23825
+ MySqlAlterTableAddCheckConstraintConvertor = class extends Convertor {
23826
+ can(statement, dialect4) {
23827
+ return statement.type === "create_check_constraint" && dialect4 === "mysql";
23828
+ }
23829
+ convert(statement) {
23830
+ const unsquashed = MySqlSquasher.unsquashCheck(statement.data);
23831
+ const { tableName } = statement;
23832
+ return `ALTER TABLE \`${tableName}\` ADD CONSTRAINT \`${unsquashed.name}\` CHECK (${unsquashed.value});`;
23833
+ }
23834
+ };
23835
+ MySqlAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
23836
+ can(statement, dialect4) {
23837
+ return statement.type === "delete_check_constraint" && dialect4 === "mysql";
23838
+ }
23839
+ convert(statement) {
23840
+ const { tableName } = statement;
23841
+ return `ALTER TABLE \`${tableName}\` DROP CONSTRAINT \`${statement.constraintName}\`;`;
23842
+ }
23843
+ };
23433
23844
  CreatePgSequenceConvertor = class extends Convertor {
23434
23845
  can(statement, dialect4) {
23435
23846
  return statement.type === "create_sequence" && dialect4 === "postgresql";
@@ -23504,7 +23915,7 @@ var init_sqlgenerator = __esm({
23504
23915
  convert(st) {
23505
23916
  const { name, schema: schema5 } = st;
23506
23917
  const enumNameWithSchema = schema5 ? `"${schema5}"."${name}"` : `"${name}"`;
23507
- let statement = `DROP TYPE ${enumNameWithSchema} CASCADE;`;
23918
+ let statement = `DROP TYPE ${enumNameWithSchema};`;
23508
23919
  return statement;
23509
23920
  }
23510
23921
  };
@@ -24033,7 +24444,7 @@ var init_sqlgenerator = __esm({
24033
24444
  };
24034
24445
  LibSQLModifyColumn = class extends Convertor {
24035
24446
  can(statement, dialect4) {
24036
- 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") && dialect4 === "turso";
24447
+ 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" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") && dialect4 === "turso";
24037
24448
  }
24038
24449
  convert(statement, json2) {
24039
24450
  const { tableName, columnName } = statement;
@@ -24623,18 +25034,22 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24623
25034
  return statement.type === "recreate_table" && dialect4 === "sqlite";
24624
25035
  }
24625
25036
  convert(statement) {
24626
- const { tableName, columns, compositePKs, referenceData } = statement;
25037
+ const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
24627
25038
  const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
24628
25039
  const newTableName = `__new_${tableName}`;
24629
25040
  const sqlStatements = [];
24630
25041
  sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
25042
+ const mappedCheckConstraints = checkConstraints.map(
25043
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `'${newTableName}'.`)
25044
+ );
24631
25045
  sqlStatements.push(
24632
25046
  new SQLiteCreateTableConvertor().convert({
24633
25047
  type: "sqlite_create_table",
24634
25048
  tableName: newTableName,
24635
25049
  columns,
24636
25050
  referenceData,
24637
- compositePKs
25051
+ compositePKs,
25052
+ checkConstraints: mappedCheckConstraints
24638
25053
  })
24639
25054
  );
24640
25055
  sqlStatements.push(
@@ -24665,10 +25080,13 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24665
25080
  return statement.type === "recreate_table" && dialect4 === "turso";
24666
25081
  }
24667
25082
  convert(statement) {
24668
- const { tableName, columns, compositePKs, referenceData } = statement;
25083
+ const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
24669
25084
  const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
24670
25085
  const newTableName = `__new_${tableName}`;
24671
25086
  const sqlStatements = [];
25087
+ const mappedCheckConstraints = checkConstraints.map(
25088
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
25089
+ );
24672
25090
  sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
24673
25091
  sqlStatements.push(
24674
25092
  new SQLiteCreateTableConvertor().convert({
@@ -24676,7 +25094,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24676
25094
  tableName: newTableName,
24677
25095
  columns,
24678
25096
  referenceData,
24679
- compositePKs
25097
+ compositePKs,
25098
+ checkConstraints: mappedCheckConstraints
24680
25099
  })
24681
25100
  );
24682
25101
  sqlStatements.push(
@@ -24737,6 +25156,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
24737
25156
  convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
24738
25157
  convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
24739
25158
  convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
25159
+ convertors.push(new PgAlterTableAddCheckConstraintConvertor());
25160
+ convertors.push(new PgAlterTableDeleteCheckConstraintConvertor());
25161
+ convertors.push(new MySqlAlterTableAddCheckConstraintConvertor());
25162
+ convertors.push(new MySqlAlterTableDeleteCheckConstraintConvertor());
24740
25163
  convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
24741
25164
  convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
24742
25165
  convertors.push(new CreatePgIndexConvertor());
@@ -24827,6 +25250,10 @@ var init_sqlitePushUtils = __esm({
24827
25250
  const compositePKs = Object.values(
24828
25251
  json.tables[tableName].compositePrimaryKeys
24829
25252
  ).map((it) => SQLiteSquasher.unsquashPK(it));
25253
+ const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
25254
+ const mappedCheckConstraints = checkConstraints.map(
25255
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
25256
+ );
24830
25257
  const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
24831
25258
  statements.push(
24832
25259
  new SQLiteCreateTableConvertor().convert({
@@ -24834,7 +25261,8 @@ var init_sqlitePushUtils = __esm({
24834
25261
  tableName: newTableName,
24835
25262
  columns: tableColumns,
24836
25263
  referenceData: fks,
24837
- compositePKs
25264
+ compositePKs,
25265
+ checkConstraints: mappedCheckConstraints
24838
25266
  })
24839
25267
  );
24840
25268
  if (!dataLoss) {
@@ -25046,7 +25474,7 @@ var init_sqlitePushUtils = __esm({
25046
25474
  });
25047
25475
 
25048
25476
  // src/jsonStatements.ts
25049
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, 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;
25477
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumValues, 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, prepareAddCheckConstraint, prepareDeleteCheckConstraint, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
25050
25478
  var init_jsonStatements = __esm({
25051
25479
  "src/jsonStatements.ts"() {
25052
25480
  "use strict";
@@ -25057,7 +25485,7 @@ var init_jsonStatements = __esm({
25057
25485
  init_pgSchema();
25058
25486
  init_sqliteSchema();
25059
25487
  preparePgCreateTableJson = (table4, json2) => {
25060
- const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
25488
+ const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
25061
25489
  const tableKey2 = `${schema5 || "public"}.${name}`;
25062
25490
  const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
25063
25491
  return {
@@ -25067,11 +25495,12 @@ var init_jsonStatements = __esm({
25067
25495
  columns: Object.values(columns),
25068
25496
  compositePKs: Object.values(compositePrimaryKeys),
25069
25497
  compositePkName,
25070
- uniqueConstraints: Object.values(uniqueConstraints)
25498
+ uniqueConstraints: Object.values(uniqueConstraints),
25499
+ checkConstraints: Object.values(checkConstraints)
25071
25500
  };
25072
25501
  };
25073
25502
  prepareMySqlCreateTableJson = (table4, json2, internals) => {
25074
- const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
25503
+ const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
25075
25504
  return {
25076
25505
  type: "create_table",
25077
25506
  tableName: name,
@@ -25080,11 +25509,12 @@ var init_jsonStatements = __esm({
25080
25509
  compositePKs: Object.values(compositePrimaryKeys),
25081
25510
  compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
25082
25511
  uniqueConstraints: Object.values(uniqueConstraints),
25083
- internals
25512
+ internals,
25513
+ checkConstraints: Object.values(checkConstraints)
25084
25514
  };
25085
25515
  };
25086
25516
  prepareSQLiteCreateTable = (table4, action) => {
25087
- const { name, columns, uniqueConstraints } = table4;
25517
+ const { name, columns, uniqueConstraints, checkConstraints } = table4;
25088
25518
  const references2 = Object.values(table4.foreignKeys);
25089
25519
  const composites = Object.values(table4.compositePrimaryKeys).map(
25090
25520
  (it) => SQLiteSquasher.unsquashPK(it)
@@ -25098,7 +25528,8 @@ var init_jsonStatements = __esm({
25098
25528
  columns: Object.values(columns),
25099
25529
  referenceData: fks,
25100
25530
  compositePKs: composites,
25101
- uniqueConstraints: Object.values(uniqueConstraints)
25531
+ uniqueConstraints: Object.values(uniqueConstraints),
25532
+ checkConstraints: Object.values(checkConstraints)
25102
25533
  };
25103
25534
  };
25104
25535
  prepareDropTableJson = (table4) => {
@@ -26368,6 +26799,26 @@ var init_jsonStatements = __esm({
26368
26799
  };
26369
26800
  });
26370
26801
  };
26802
+ prepareAddCheckConstraint = (tableName, schema5, check2) => {
26803
+ return Object.values(check2).map((it) => {
26804
+ return {
26805
+ type: "create_check_constraint",
26806
+ tableName,
26807
+ data: it,
26808
+ schema: schema5
26809
+ };
26810
+ });
26811
+ };
26812
+ prepareDeleteCheckConstraint = (tableName, schema5, check2) => {
26813
+ return Object.values(check2).map((it) => {
26814
+ return {
26815
+ type: "delete_check_constraint",
26816
+ tableName,
26817
+ constraintName: PgSquasher.unsquashCheck(it).name,
26818
+ schema: schema5
26819
+ };
26820
+ });
26821
+ };
26371
26822
  prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
26372
26823
  var _a, _b;
26373
26824
  const res = [];
@@ -26418,7 +26869,7 @@ var init_statementCombiner = __esm({
26418
26869
  init_jsonStatements();
26419
26870
  init_sqliteSchema();
26420
26871
  prepareLibSQLRecreateTable = (table4, action) => {
26421
- const { name, columns, uniqueConstraints, indexes } = table4;
26872
+ const { name, columns, uniqueConstraints, indexes, checkConstraints } = table4;
26422
26873
  const composites = Object.values(table4.compositePrimaryKeys).map(
26423
26874
  (it) => SQLiteSquasher.unsquashPK(it)
26424
26875
  );
@@ -26433,7 +26884,8 @@ var init_statementCombiner = __esm({
26433
26884
  columns: Object.values(columns),
26434
26885
  compositePKs: composites,
26435
26886
  referenceData: fks,
26436
- uniqueConstraints: Object.values(uniqueConstraints)
26887
+ uniqueConstraints: Object.values(uniqueConstraints),
26888
+ checkConstraints: Object.values(checkConstraints)
26437
26889
  }
26438
26890
  ];
26439
26891
  if (Object.keys(indexes).length) {
@@ -26442,7 +26894,7 @@ var init_statementCombiner = __esm({
26442
26894
  return statements;
26443
26895
  };
26444
26896
  prepareSQLiteRecreateTable = (table4, action) => {
26445
- const { name, columns, uniqueConstraints, indexes } = table4;
26897
+ const { name, columns, uniqueConstraints, indexes, checkConstraints } = table4;
26446
26898
  const composites = Object.values(table4.compositePrimaryKeys).map(
26447
26899
  (it) => SQLiteSquasher.unsquashPK(it)
26448
26900
  );
@@ -26457,7 +26909,8 @@ var init_statementCombiner = __esm({
26457
26909
  columns: Object.values(columns),
26458
26910
  compositePKs: composites,
26459
26911
  referenceData: fks,
26460
- uniqueConstraints: Object.values(uniqueConstraints)
26912
+ uniqueConstraints: Object.values(uniqueConstraints),
26913
+ checkConstraints: Object.values(checkConstraints)
26461
26914
  }
26462
26915
  ];
26463
26916
  if (Object.keys(indexes).length) {
@@ -26468,7 +26921,7 @@ var init_statementCombiner = __esm({
26468
26921
  libSQLCombineStatements = (statements, json2, action) => {
26469
26922
  const newStatements = {};
26470
26923
  for (const statement of statements) {
26471
- 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") {
26924
+ 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" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") {
26472
26925
  const tableName2 = statement.tableName;
26473
26926
  const statementsForTable2 = newStatements[tableName2];
26474
26927
  if (!statementsForTable2) {
@@ -26609,16 +27062,16 @@ var init_statementCombiner = __esm({
26609
27062
  sqliteCombineStatements = (statements, json2, action) => {
26610
27063
  const newStatements = {};
26611
27064
  for (const statement of statements) {
26612
- 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") {
27065
+ 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" || statement.type === "create_check_constraint" || statement.type === "delete_check_constraint") {
26613
27066
  const tableName2 = statement.tableName;
26614
27067
  const statementsForTable2 = newStatements[tableName2];
26615
27068
  if (!statementsForTable2) {
26616
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
27069
+ newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
26617
27070
  continue;
26618
27071
  }
26619
27072
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
26620
27073
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
26621
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
27074
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
26622
27075
  if (wasRename) {
26623
27076
  newStatements[tableName2].push(...preparedStatements);
26624
27077
  } else {
@@ -26632,12 +27085,12 @@ var init_statementCombiner = __esm({
26632
27085
  const tableName2 = statement.tableName;
26633
27086
  const statementsForTable2 = newStatements[tableName2];
26634
27087
  if (!statementsForTable2) {
26635
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
27088
+ newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
26636
27089
  continue;
26637
27090
  }
26638
27091
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
26639
27092
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
26640
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
27093
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
26641
27094
  if (wasRename) {
26642
27095
  newStatements[tableName2].push(...preparedStatements);
26643
27096
  } else {
@@ -26662,7 +27115,7 @@ var init_statementCombiner = __esm({
26662
27115
  }
26663
27116
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
26664
27117
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
26665
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
27118
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
26666
27119
  if (wasRename) {
26667
27120
  newStatements[tableName2].push(...preparedStatements);
26668
27121
  } else {
@@ -26797,7 +27250,8 @@ var init_snapshotsDiffer = __esm({
26797
27250
  indexes: recordType(stringType(), stringType()),
26798
27251
  foreignKeys: recordType(stringType(), stringType()),
26799
27252
  compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
26800
- uniqueConstraints: recordType(stringType(), stringType()).default({})
27253
+ uniqueConstraints: recordType(stringType(), stringType()).default({}),
27254
+ checkConstraints: recordType(stringType(), stringType()).default({})
26801
27255
  }).strict();
26802
27256
  alteredTableScheme = objectType({
26803
27257
  name: stringType(),
@@ -26838,6 +27292,21 @@ var init_snapshotsDiffer = __esm({
26838
27292
  __new: stringType(),
26839
27293
  __old: stringType()
26840
27294
  })
27295
+ ),
27296
+ addedCheckConstraints: recordType(
27297
+ stringType(),
27298
+ stringType()
27299
+ ),
27300
+ deletedCheckConstraints: recordType(
27301
+ stringType(),
27302
+ stringType()
27303
+ ),
27304
+ alteredCheckConstraints: recordType(
27305
+ stringType(),
27306
+ objectType({
27307
+ __new: stringType(),
27308
+ __old: stringType()
27309
+ })
26841
27310
  )
26842
27311
  }).strict();
26843
27312
  diffResultScheme = objectType({
@@ -27178,6 +27647,8 @@ var init_snapshotsDiffer = __esm({
27178
27647
  schemaTo: it.schemaTo || "public"
27179
27648
  });
27180
27649
  }
27650
+ const jsonDeletedCheckConstraints = [];
27651
+ const jsonCreatedCheckConstraints = [];
27181
27652
  for (let it of alteredTables) {
27182
27653
  let addedColumns = [];
27183
27654
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -27217,6 +27688,8 @@ var init_snapshotsDiffer = __esm({
27217
27688
  let addedUniqueConstraints = [];
27218
27689
  let deletedUniqueConstraints = [];
27219
27690
  let alteredUniqueConstraints = [];
27691
+ let createCheckConstraints = [];
27692
+ let deleteCheckConstraints = [];
27220
27693
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
27221
27694
  it.name,
27222
27695
  it.schema,
@@ -27241,6 +27714,24 @@ var init_snapshotsDiffer = __esm({
27241
27714
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
27242
27715
  );
27243
27716
  }
27717
+ createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
27718
+ deleteCheckConstraints = prepareDeleteCheckConstraint(
27719
+ it.name,
27720
+ it.schema,
27721
+ it.deletedCheckConstraints
27722
+ );
27723
+ if (it.alteredCheckConstraints && action !== "push") {
27724
+ const added = {};
27725
+ const deleted = {};
27726
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
27727
+ added[k] = it.alteredCheckConstraints[k].__new;
27728
+ deleted[k] = it.alteredCheckConstraints[k].__old;
27729
+ }
27730
+ createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
27731
+ deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
27732
+ }
27733
+ jsonCreatedCheckConstraints.push(...createCheckConstraints);
27734
+ jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
27244
27735
  jsonAddedCompositePKs.push(...addedCompositePKs);
27245
27736
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
27246
27737
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
@@ -27397,6 +27888,7 @@ var init_snapshotsDiffer = __esm({
27397
27888
  jsonStatements.push(...jsonRenameTables);
27398
27889
  jsonStatements.push(...jsonRenameColumnsStatements);
27399
27890
  jsonStatements.push(...jsonDeletedUniqueConstraints);
27891
+ jsonStatements.push(...jsonDeletedCheckConstraints);
27400
27892
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
27401
27893
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
27402
27894
  jsonStatements.push(...jsonDeletedCompositePKs);
@@ -27410,6 +27902,7 @@ var init_snapshotsDiffer = __esm({
27410
27902
  jsonStatements.push(...jsonDropColumnsStatemets);
27411
27903
  jsonStatements.push(...jsonAlteredCompositePKs);
27412
27904
  jsonStatements.push(...jsonAddedUniqueConstraints);
27905
+ jsonStatements.push(...jsonCreatedCheckConstraints);
27413
27906
  jsonStatements.push(...jsonAlteredUniqueConstraints);
27414
27907
  jsonStatements.push(...jsonAlterEnumsWithDroppedValues);
27415
27908
  jsonStatements.push(...dropEnums);
@@ -27432,7 +27925,17 @@ var init_snapshotsDiffer = __esm({
27432
27925
  }
27433
27926
  return true;
27434
27927
  });
27435
- const sqlStatements = fromJson(filteredJsonStatements, "postgresql");
27928
+ const filteredEnumsJsonStatements = filteredJsonStatements.filter((st) => {
27929
+ if (st.type === "alter_type_add_value") {
27930
+ if (jsonStatements.find(
27931
+ (it) => it.type === "alter_type_drop_value" && it.name === st.name && it.schema === st.schema
27932
+ )) {
27933
+ return false;
27934
+ }
27935
+ }
27936
+ return true;
27937
+ });
27938
+ const sqlStatements = fromJson(filteredEnumsJsonStatements, "postgresql");
27436
27939
  const uniqueSqlStatements = [];
27437
27940
  sqlStatements.forEach((ss) => {
27438
27941
  if (!uniqueSqlStatements.includes(ss)) {
@@ -27448,7 +27951,7 @@ var init_snapshotsDiffer = __esm({
27448
27951
  });
27449
27952
  const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
27450
27953
  return {
27451
- statements: filteredJsonStatements,
27954
+ statements: filteredEnumsJsonStatements,
27452
27955
  sqlStatements: uniqueSqlStatements,
27453
27956
  _meta
27454
27957
  };
@@ -27574,6 +28077,8 @@ var init_snapshotsDiffer = __esm({
27574
28077
  const jsonAddedUniqueConstraints = [];
27575
28078
  const jsonDeletedUniqueConstraints = [];
27576
28079
  const jsonAlteredUniqueConstraints = [];
28080
+ const jsonCreatedCheckConstraints = [];
28081
+ const jsonDeletedCheckConstraints = [];
27577
28082
  const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
27578
28083
  const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
27579
28084
  const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
@@ -27612,6 +28117,8 @@ var init_snapshotsDiffer = __esm({
27612
28117
  let addedUniqueConstraints = [];
27613
28118
  let deletedUniqueConstraints = [];
27614
28119
  let alteredUniqueConstraints = [];
28120
+ let createdCheckConstraints = [];
28121
+ let deletedCheckConstraints = [];
27615
28122
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
27616
28123
  it.name,
27617
28124
  it.schema,
@@ -27636,12 +28143,30 @@ var init_snapshotsDiffer = __esm({
27636
28143
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
27637
28144
  );
27638
28145
  }
28146
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
28147
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
28148
+ it.name,
28149
+ it.schema,
28150
+ it.deletedCheckConstraints
28151
+ );
28152
+ if (it.alteredCheckConstraints && action !== "push") {
28153
+ const added = {};
28154
+ const deleted = {};
28155
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
28156
+ added[k] = it.alteredCheckConstraints[k].__new;
28157
+ deleted[k] = it.alteredCheckConstraints[k].__old;
28158
+ }
28159
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
28160
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
28161
+ }
27639
28162
  jsonAddedCompositePKs.push(...addedCompositePKs);
27640
28163
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
27641
28164
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
27642
28165
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
27643
28166
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
27644
28167
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28168
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28169
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
27645
28170
  });
27646
28171
  const rColumns = jsonRenameColumnsStatements.map((it) => {
27647
28172
  const tableName = it.tableName;
@@ -27737,6 +28262,7 @@ var init_snapshotsDiffer = __esm({
27737
28262
  jsonStatements.push(...jsonRenameTables);
27738
28263
  jsonStatements.push(...jsonRenameColumnsStatements);
27739
28264
  jsonStatements.push(...jsonDeletedUniqueConstraints);
28265
+ jsonStatements.push(...jsonDeletedCheckConstraints);
27740
28266
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
27741
28267
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
27742
28268
  jsonStatements.push(...jsonDeletedCompositePKs);
@@ -27747,11 +28273,11 @@ var init_snapshotsDiffer = __esm({
27747
28273
  jsonStatements.push(...jsonAddColumnsStatemets);
27748
28274
  jsonStatements.push(...jsonCreateReferencesForCreatedTables);
27749
28275
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
28276
+ jsonStatements.push(...jsonCreatedCheckConstraints);
27750
28277
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
27751
28278
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
27752
28279
  jsonStatements.push(...jsonDropColumnsStatemets);
27753
28280
  jsonStatements.push(...jsonAlteredCompositePKs);
27754
- jsonStatements.push(...jsonAddedUniqueConstraints);
27755
28281
  jsonStatements.push(...jsonAlteredUniqueConstraints);
27756
28282
  const sqlStatements = fromJson(jsonStatements, "mysql");
27757
28283
  const uniqueSqlStatements = [];
@@ -27879,6 +28405,8 @@ var init_snapshotsDiffer = __esm({
27879
28405
  const jsonAddedUniqueConstraints = [];
27880
28406
  const jsonDeletedUniqueConstraints = [];
27881
28407
  const jsonAlteredUniqueConstraints = [];
28408
+ const jsonDeletedCheckConstraints = [];
28409
+ const jsonCreatedCheckConstraints = [];
27882
28410
  allAltered.forEach((it) => {
27883
28411
  let addedColumns = [];
27884
28412
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -27935,12 +28463,56 @@ var init_snapshotsDiffer = __esm({
27935
28463
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
27936
28464
  );
27937
28465
  }
28466
+ let createdCheckConstraints = [];
28467
+ let deletedCheckConstraints = [];
28468
+ addedUniqueConstraints = prepareAddUniqueConstraintPg(
28469
+ it.name,
28470
+ it.schema,
28471
+ it.addedUniqueConstraints
28472
+ );
28473
+ deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
28474
+ it.name,
28475
+ it.schema,
28476
+ it.deletedUniqueConstraints
28477
+ );
28478
+ if (it.alteredUniqueConstraints) {
28479
+ const added = {};
28480
+ const deleted = {};
28481
+ for (const k of Object.keys(it.alteredUniqueConstraints)) {
28482
+ added[k] = it.alteredUniqueConstraints[k].__new;
28483
+ deleted[k] = it.alteredUniqueConstraints[k].__old;
28484
+ }
28485
+ addedUniqueConstraints.push(
28486
+ ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
28487
+ );
28488
+ deletedUniqueConstraints.push(
28489
+ ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
28490
+ );
28491
+ }
28492
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
28493
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
28494
+ it.name,
28495
+ it.schema,
28496
+ it.deletedCheckConstraints
28497
+ );
28498
+ if (it.alteredCheckConstraints && action !== "push") {
28499
+ const added = {};
28500
+ const deleted = {};
28501
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
28502
+ added[k] = it.alteredCheckConstraints[k].__new;
28503
+ deleted[k] = it.alteredCheckConstraints[k].__old;
28504
+ }
28505
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
28506
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
28507
+ }
27938
28508
  jsonAddedCompositePKs.push(...addedCompositePKs);
27939
28509
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
27940
28510
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
27941
28511
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
27942
28512
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
27943
28513
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28514
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28515
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
27944
28516
  });
27945
28517
  const rColumns = jsonRenameColumnsStatements.map((it) => {
27946
28518
  const tableName = it.tableName;
@@ -28025,6 +28597,7 @@ var init_snapshotsDiffer = __esm({
28025
28597
  jsonStatements.push(...jsonRenameTables);
28026
28598
  jsonStatements.push(...jsonRenameColumnsStatements);
28027
28599
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28600
+ jsonStatements.push(...jsonDeletedCheckConstraints);
28028
28601
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
28029
28602
  jsonStatements.push(...jsonDeletedCompositePKs);
28030
28603
  jsonStatements.push(...jsonTableAlternations);
@@ -28032,6 +28605,7 @@ var init_snapshotsDiffer = __esm({
28032
28605
  jsonStatements.push(...jsonAddColumnsStatemets);
28033
28606
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
28034
28607
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
28608
+ jsonStatements.push(...jsonCreatedCheckConstraints);
28035
28609
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
28036
28610
  jsonStatements.push(...jsonDropColumnsStatemets);
28037
28611
  jsonStatements.push(...jsonAlteredCompositePKs);
@@ -28175,6 +28749,8 @@ var init_snapshotsDiffer = __esm({
28175
28749
  const jsonAddedUniqueConstraints = [];
28176
28750
  const jsonDeletedUniqueConstraints = [];
28177
28751
  const jsonAlteredUniqueConstraints = [];
28752
+ const jsonDeletedCheckConstraints = [];
28753
+ const jsonCreatedCheckConstraints = [];
28178
28754
  allAltered.forEach((it) => {
28179
28755
  let addedColumns = [];
28180
28756
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -28207,6 +28783,8 @@ var init_snapshotsDiffer = __esm({
28207
28783
  let addedUniqueConstraints = [];
28208
28784
  let deletedUniqueConstraints = [];
28209
28785
  let alteredUniqueConstraints = [];
28786
+ let createdCheckConstraints = [];
28787
+ let deletedCheckConstraints = [];
28210
28788
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
28211
28789
  it.name,
28212
28790
  it.schema,
@@ -28231,12 +28809,30 @@ var init_snapshotsDiffer = __esm({
28231
28809
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
28232
28810
  );
28233
28811
  }
28812
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
28813
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
28814
+ it.name,
28815
+ it.schema,
28816
+ it.deletedCheckConstraints
28817
+ );
28818
+ if (it.alteredCheckConstraints && action !== "push") {
28819
+ const added = {};
28820
+ const deleted = {};
28821
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
28822
+ added[k] = it.alteredCheckConstraints[k].__new;
28823
+ deleted[k] = it.alteredCheckConstraints[k].__old;
28824
+ }
28825
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
28826
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
28827
+ }
28234
28828
  jsonAddedCompositePKs.push(...addedCompositePKs);
28235
28829
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
28236
28830
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
28237
28831
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
28238
28832
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
28239
28833
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28834
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28835
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
28240
28836
  });
28241
28837
  const jsonTableAlternations = allAltered.map((it) => {
28242
28838
  return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
@@ -28314,6 +28910,7 @@ var init_snapshotsDiffer = __esm({
28314
28910
  jsonStatements.push(...jsonRenameTables);
28315
28911
  jsonStatements.push(...jsonRenameColumnsStatements);
28316
28912
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28913
+ jsonStatements.push(...jsonDeletedCheckConstraints);
28317
28914
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
28318
28915
  jsonStatements.push(...jsonDeletedCompositePKs);
28319
28916
  jsonStatements.push(...jsonTableAlternations);
@@ -28321,6 +28918,7 @@ var init_snapshotsDiffer = __esm({
28321
28918
  jsonStatements.push(...jsonAddColumnsStatemets);
28322
28919
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
28323
28920
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
28921
+ jsonStatements.push(...jsonCreatedCheckConstraints);
28324
28922
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
28325
28923
  jsonStatements.push(...jsonDropColumnsStatemets);
28326
28924
  jsonStatements.push(...jsonAlteredCompositePKs);
@@ -77223,14 +77821,19 @@ var init_libSqlPushUtils = __esm({
77223
77821
  const compositePKs = Object.values(
77224
77822
  json.tables[tableName].compositePrimaryKeys
77225
77823
  ).map((it) => SQLiteSquasher.unsquashPK(it));
77824
+ const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
77226
77825
  const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
77826
+ const mappedCheckConstraints = checkConstraints.map(
77827
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
77828
+ );
77227
77829
  statements.push(
77228
77830
  new SQLiteCreateTableConvertor().convert({
77229
77831
  type: "sqlite_create_table",
77230
77832
  tableName: newTableName,
77231
77833
  columns: tableColumns,
77232
77834
  referenceData: fks,
77233
- compositePKs
77835
+ compositePKs,
77836
+ checkConstraints: mappedCheckConstraints
77234
77837
  })
77235
77838
  );
77236
77839
  if (!dataLoss) {
@@ -79121,7 +79724,7 @@ var init_pgIntrospect = __esm({
79121
79724
  });
79122
79725
 
79123
79726
  // src/introspect-sqlite.ts
79124
- var import_casing3, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
79727
+ var import_casing3, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTableChecks, createTablePKs, createTableFKs;
79125
79728
  var init_introspect_sqlite = __esm({
79126
79729
  "src/introspect-sqlite.ts"() {
79127
79730
  "use strict";
@@ -79191,10 +79794,14 @@ var init_introspect_sqlite = __esm({
79191
79794
  const uniqueImports = Object.values(it.uniqueConstraints).map(
79192
79795
  (it2) => "unique"
79193
79796
  );
79797
+ const checkImports = Object.values(it.checkConstraints).map(
79798
+ (it2) => "check"
79799
+ );
79194
79800
  res.sqlite.push(...idxImports);
79195
79801
  res.sqlite.push(...fkImpots);
79196
79802
  res.sqlite.push(...pkImports);
79197
79803
  res.sqlite.push(...uniqueImports);
79804
+ res.sqlite.push(...checkImports);
79198
79805
  const columnImports = Object.values(it.columns).map((col) => {
79199
79806
  return col.type;
79200
79807
  }).filter((type) => {
@@ -79227,7 +79834,7 @@ var init_introspect_sqlite = __esm({
79227
79834
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
79228
79835
  return it.columnsFrom.length > 1 || isSelf(it);
79229
79836
  });
79230
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
79837
+ if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0 || Object.keys(table4.checkConstraints).length > 0) {
79231
79838
  statement += ",\n";
79232
79839
  statement += "(table) => {\n";
79233
79840
  statement += " return {\n";
@@ -79245,6 +79852,10 @@ var init_introspect_sqlite = __esm({
79245
79852
  Object.values(table4.uniqueConstraints),
79246
79853
  casing2
79247
79854
  );
79855
+ statement += createTableChecks(
79856
+ Object.values(table4.checkConstraints),
79857
+ casing2
79858
+ );
79248
79859
  statement += " }\n";
79249
79860
  statement += "}";
79250
79861
  }
@@ -79396,6 +80007,19 @@ var init_introspect_sqlite = __esm({
79396
80007
  statement += `"${it.name}")`;
79397
80008
  statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing2)}`).join(", ")}),`;
79398
80009
  statement += `
80010
+ `;
80011
+ });
80012
+ return statement;
80013
+ };
80014
+ createTableChecks = (checks, casing2) => {
80015
+ let statement = "";
80016
+ checks.forEach((it) => {
80017
+ const checkKey = withCasing(it.name, casing2);
80018
+ statement += ` ${checkKey}: `;
80019
+ statement += "check(";
80020
+ statement += `"${it.name}", `;
80021
+ statement += `sql\`${it.value}\`)`;
80022
+ statement += `,
79399
80023
  `;
79400
80024
  });
79401
80025
  return statement;
@@ -80244,7 +80868,7 @@ var require_pluralize = __commonJS({
80244
80868
  });
80245
80869
 
80246
80870
  // src/introspect-mysql.ts
80247
- var import_casing4, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
80871
+ var import_casing4, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTableChecks2, createTablePKs2, createTableFKs2;
80248
80872
  var init_introspect_mysql = __esm({
80249
80873
  "src/introspect-mysql.ts"() {
80250
80874
  "use strict";
@@ -80359,10 +80983,14 @@ var init_introspect_mysql = __esm({
80359
80983
  const uniqueImports = Object.values(it.uniqueConstraints).map(
80360
80984
  (it2) => "unique"
80361
80985
  );
80986
+ const checkImports = Object.values(it.checkConstraint).map(
80987
+ (it2) => "check"
80988
+ );
80362
80989
  res.mysql.push(...idxImports);
80363
80990
  res.mysql.push(...fkImpots);
80364
80991
  res.mysql.push(...pkImports);
80365
80992
  res.mysql.push(...uniqueImports);
80993
+ res.mysql.push(...checkImports);
80366
80994
  const columnImports = Object.values(it.columns).map((col) => {
80367
80995
  let patched = importsPatch[col.type] ?? col.type;
80368
80996
  patched = patched.startsWith("varchar(") ? "varchar" : patched;
@@ -80408,7 +81036,7 @@ var init_introspect_mysql = __esm({
80408
81036
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
80409
81037
  return it.columnsFrom.length > 1 || isSelf2(it);
80410
81038
  });
80411
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
81039
+ if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0 || Object.keys(table4.checkConstraint).length > 0) {
80412
81040
  statement += ",\n";
80413
81041
  statement += "(table) => {\n";
80414
81042
  statement += " return {\n";
@@ -80426,6 +81054,10 @@ var init_introspect_mysql = __esm({
80426
81054
  Object.values(table4.uniqueConstraints),
80427
81055
  withCasing4
80428
81056
  );
81057
+ statement += createTableChecks2(
81058
+ Object.values(table4.checkConstraint),
81059
+ withCasing4
81060
+ );
80429
81061
  statement += " }\n";
80430
81062
  statement += "}";
80431
81063
  }
@@ -80765,6 +81397,19 @@ import { sql } from "drizzle-orm"
80765
81397
  statement += `"${it.name}")`;
80766
81398
  statement += `.on(${it.columns.map((it2) => `table.${casing2(it2)}`).join(", ")}),`;
80767
81399
  statement += `
81400
+ `;
81401
+ });
81402
+ return statement;
81403
+ };
81404
+ createTableChecks2 = (checks, casing2) => {
81405
+ let statement = "";
81406
+ checks.forEach((it) => {
81407
+ const checkKey = casing2(it.name);
81408
+ statement += ` ${checkKey}: `;
81409
+ statement += "check(";
81410
+ statement += `"${it.name}", `;
81411
+ statement += `sql\`${it.value.replace(/`/g, "\\`")}\`)`;
81412
+ statement += `,
80768
81413
  `;
80769
81414
  });
80770
81415
  return statement;
@@ -80835,7 +81480,7 @@ function generateIdentityParams(identity) {
80835
81480
  }
80836
81481
  return `.generatedByDefaultAsIdentity(${paramsObj})`;
80837
81482
  }
80838
- var import_drizzle_orm9, import_relations, import_casing5, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
81483
+ var import_drizzle_orm9, import_relations, import_casing5, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableChecks3, createTableFKs3;
80839
81484
  var init_introspect_pg = __esm({
80840
81485
  "src/introspect-pg.ts"() {
80841
81486
  "use strict";
@@ -81013,6 +81658,9 @@ var init_introspect_pg = __esm({
81013
81658
  const uniqueImports = Object.values(it.uniqueConstraints).map(
81014
81659
  (it2) => "unique"
81015
81660
  );
81661
+ const checkImports = Object.values(it.checkConstraints).map(
81662
+ (it2) => "check"
81663
+ );
81016
81664
  if (it.schema && it.schema !== "public" && it.schema !== "") {
81017
81665
  res.pg.push("pgSchema");
81018
81666
  }
@@ -81020,6 +81668,7 @@ var init_introspect_pg = __esm({
81020
81668
  res.pg.push(...fkImpots);
81021
81669
  res.pg.push(...pkImports);
81022
81670
  res.pg.push(...uniqueImports);
81671
+ res.pg.push(...checkImports);
81023
81672
  const columnImports = Object.values(it.columns).map((col) => {
81024
81673
  let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
81025
81674
  patched = patched === "double precision" ? "doublePrecision" : patched;
@@ -81109,7 +81758,7 @@ var init_introspect_pg = __esm({
81109
81758
  schema5.internal
81110
81759
  );
81111
81760
  statement += "}";
81112
- if (Object.keys(table4.indexes).length > 0 || Object.values(table4.foreignKeys).length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
81761
+ if (Object.keys(table4.indexes).length > 0 || Object.values(table4.foreignKeys).length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0 || Object.keys(table4.checkConstraints).length > 0) {
81113
81762
  statement += ",\n";
81114
81763
  statement += "(table) => {\n";
81115
81764
  statement += " return {\n";
@@ -81127,6 +81776,10 @@ var init_introspect_pg = __esm({
81127
81776
  Object.values(table4.uniqueConstraints),
81128
81777
  casing2
81129
81778
  );
81779
+ statement += createTableChecks3(
81780
+ Object.values(table4.checkConstraints),
81781
+ casing2
81782
+ );
81130
81783
  statement += " }\n";
81131
81784
  statement += "}";
81132
81785
  }
@@ -81589,6 +82242,19 @@ var init_introspect_pg = __esm({
81589
82242
  statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing2)}`).join(", ")})`;
81590
82243
  statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
81591
82244
  statement += `,
82245
+ `;
82246
+ });
82247
+ return statement;
82248
+ };
82249
+ createTableChecks3 = (checkConstraints, casing2) => {
82250
+ let statement = "";
82251
+ checkConstraints.forEach((it) => {
82252
+ const checkKey = withCasing2(it.name, casing2);
82253
+ statement += ` ${checkKey}: `;
82254
+ statement += "check(";
82255
+ statement += `"${it.name}", `;
82256
+ statement += `sql\`${it.value}\`)`;
82257
+ statement += `,
81592
82258
  `;
81593
82259
  });
81594
82260
  return statement;
@@ -85433,7 +86099,7 @@ init_utils2();
85433
86099
  var version2 = async () => {
85434
86100
  const { npmVersion } = await ormCoreVersions();
85435
86101
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
85436
- const envVersion = "0.25.0-1f15bfd";
86102
+ const envVersion = "0.25.0-20acc2f";
85437
86103
  const kitVersion = envVersion ? `v${envVersion}` : "--";
85438
86104
  const versions = `drizzle-kit: ${kitVersion}
85439
86105
  ${ormVersion}`;