drizzle-kit 0.25.0-05b9e35 → 0.25.0-06c725b

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. package/api.d.mts +82 -474
  2. package/api.d.ts +82 -474
  3. package/api.js +16085 -95988
  4. package/api.mjs +16084 -95983
  5. package/bin.cjs +843 -1198
  6. package/package.json +1 -1
  7. package/utils.js +35 -57
  8. package/utils.mjs +35 -57
package/bin.cjs CHANGED
@@ -922,8 +922,8 @@ var require_hanji = __commonJS({
922
922
  };
923
923
  exports2.deferred = deferred;
924
924
  var Terminal = class {
925
- constructor(view2, stdin, stdout, closable) {
926
- this.view = view2;
925
+ constructor(view, stdin, stdout, closable) {
926
+ this.view = view;
927
927
  this.stdin = stdin;
928
928
  this.stdout = stdout;
929
929
  this.closable = closable;
@@ -961,7 +961,7 @@ var require_hanji = __commonJS({
961
961
  this.resolve({ status: "submitted", data: this.view.result() });
962
962
  return;
963
963
  }
964
- view2.input(str, key);
964
+ view.input(str, key);
965
965
  };
966
966
  this.stdin.on("keypress", keypress);
967
967
  this.view.attach(this);
@@ -1023,8 +1023,8 @@ var require_hanji = __commonJS({
1023
1023
  };
1024
1024
  exports2.TaskView = TaskView2;
1025
1025
  var TaskTerminal = class {
1026
- constructor(view2, stdout) {
1027
- this.view = view2;
1026
+ constructor(view, stdout) {
1027
+ this.view = view;
1028
1028
  this.stdout = stdout;
1029
1029
  this.text = "";
1030
1030
  this.view.attach(this);
@@ -1043,22 +1043,22 @@ var require_hanji = __commonJS({
1043
1043
  }
1044
1044
  };
1045
1045
  exports2.TaskTerminal = TaskTerminal;
1046
- function render9(view2) {
1046
+ function render9(view) {
1047
1047
  const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
1048
- if (view2 instanceof Prompt3) {
1049
- const terminal = new Terminal(view2, stdin, stdout, closable);
1048
+ if (view instanceof Prompt3) {
1049
+ const terminal = new Terminal(view, stdin, stdout, closable);
1050
1050
  terminal.requestLayout();
1051
1051
  return terminal.result();
1052
1052
  }
1053
- stdout.write(`${view2}
1053
+ stdout.write(`${view}
1054
1054
  `);
1055
1055
  closable.close();
1056
1056
  return;
1057
1057
  }
1058
1058
  exports2.render = render9;
1059
- function renderWithTask6(view2, task) {
1059
+ function renderWithTask6(view, task) {
1060
1060
  return __awaiter2(this, void 0, void 0, function* () {
1061
- const terminal = new TaskTerminal(view2, process.stdout);
1061
+ const terminal = new TaskTerminal(view, process.stdout);
1062
1062
  terminal.requestLayout();
1063
1063
  const result = yield task;
1064
1064
  terminal.clear();
@@ -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, viewWithOption, matViewWithOption, mergedViewWithOption, view, 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(),
@@ -5901,44 +5928,6 @@ var init_pgSchema = __esm({
5901
5928
  columns: stringType().array(),
5902
5929
  nullsNotDistinct: booleanType()
5903
5930
  }).strict();
5904
- viewWithOption = objectType({
5905
- checkOption: enumType(["local", "cascaded"]).optional(),
5906
- securityBarrier: booleanType().optional(),
5907
- securityInvoker: booleanType().optional()
5908
- }).strict();
5909
- matViewWithOption = objectType({
5910
- fillfactor: numberType().optional(),
5911
- toastTupleTarget: numberType().optional(),
5912
- parallelWorkers: numberType().optional(),
5913
- autovacuumEnabled: booleanType().optional(),
5914
- vacuumIndexCleanup: enumType(["auto", "off", "on"]).optional(),
5915
- vacuumTruncate: booleanType().optional(),
5916
- autovacuumVacuumThreshold: numberType().optional(),
5917
- autovacuumVacuumScaleFactor: numberType().optional(),
5918
- autovacuumVacuumCostDelay: numberType().optional(),
5919
- autovacuumVacuumCostLimit: numberType().optional(),
5920
- autovacuumFreezeMinAge: numberType().optional(),
5921
- autovacuumFreezeMaxAge: numberType().optional(),
5922
- autovacuumFreezeTableAge: numberType().optional(),
5923
- autovacuumMultixactFreezeMinAge: numberType().optional(),
5924
- autovacuumMultixactFreezeMaxAge: numberType().optional(),
5925
- autovacuumMultixactFreezeTableAge: numberType().optional(),
5926
- logAutovacuumMinDuration: numberType().optional(),
5927
- userCatalogTable: booleanType().optional()
5928
- }).strict();
5929
- mergedViewWithOption = viewWithOption.merge(matViewWithOption);
5930
- view = objectType({
5931
- name: stringType(),
5932
- schema: stringType(),
5933
- columns: recordType(stringType(), column2),
5934
- definition: stringType().optional(),
5935
- materialized: booleanType(),
5936
- with: mergedViewWithOption.optional(),
5937
- isExisting: booleanType(),
5938
- withNoData: booleanType().optional(),
5939
- using: stringType().optional(),
5940
- tablespace: stringType().optional()
5941
- }).strict();
5942
5931
  tableV42 = objectType({
5943
5932
  name: stringType(),
5944
5933
  schema: stringType(),
@@ -5980,7 +5969,8 @@ var init_pgSchema = __esm({
5980
5969
  indexes: recordType(stringType(), index2),
5981
5970
  foreignKeys: recordType(stringType(), fk2),
5982
5971
  compositePrimaryKeys: recordType(stringType(), compositePK2),
5983
- uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
5972
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({}),
5973
+ checkConstraints: recordType(stringType(), checkConstraint2).default({})
5984
5974
  }).strict();
5985
5975
  schemaHash2 = objectType({
5986
5976
  id: stringType(),
@@ -6073,7 +6063,6 @@ var init_pgSchema = __esm({
6073
6063
  tables: recordType(stringType(), table2),
6074
6064
  enums: recordType(stringType(), enumSchema),
6075
6065
  schemas: recordType(stringType(), stringType()),
6076
- views: recordType(stringType(), view).default({}),
6077
6066
  sequences: recordType(stringType(), sequenceSchema).default({}),
6078
6067
  _meta: objectType({
6079
6068
  schemas: recordType(stringType(), stringType()),
@@ -6089,7 +6078,8 @@ var init_pgSchema = __esm({
6089
6078
  indexes: recordType(stringType(), stringType()),
6090
6079
  foreignKeys: recordType(stringType(), stringType()),
6091
6080
  compositePrimaryKeys: recordType(stringType(), stringType()),
6092
- uniqueConstraints: recordType(stringType(), stringType())
6081
+ uniqueConstraints: recordType(stringType(), stringType()),
6082
+ checkConstraints: recordType(stringType(), stringType())
6093
6083
  }).strict();
6094
6084
  tableSquashedV42 = objectType({
6095
6085
  name: stringType(),
@@ -6118,7 +6108,6 @@ var init_pgSchema = __esm({
6118
6108
  tables: recordType(stringType(), tableSquashed2),
6119
6109
  enums: recordType(stringType(), enumSchema),
6120
6110
  schemas: recordType(stringType(), stringType()),
6121
- views: recordType(stringType(), view),
6122
6111
  sequences: recordType(stringType(), sequenceSquashed)
6123
6112
  }).strict();
6124
6113
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
@@ -6272,6 +6261,16 @@ var init_pgSchema = __esm({
6272
6261
  cache: splitted[6] !== "undefined" ? splitted[6] : void 0,
6273
6262
  cycle: splitted[7] === "true"
6274
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 };
6275
6274
  }
6276
6275
  };
6277
6276
  squashPgScheme = (json, action) => {
@@ -6304,6 +6303,12 @@ var init_pgSchema = __esm({
6304
6303
  return PgSquasher.squashUnique(unq);
6305
6304
  }
6306
6305
  );
6306
+ const squashedChecksContraints = mapValues(
6307
+ it[1].checkConstraints,
6308
+ (check2) => {
6309
+ return PgSquasher.squashCheck(check2);
6310
+ }
6311
+ );
6307
6312
  return [
6308
6313
  it[0],
6309
6314
  {
@@ -6313,7 +6318,8 @@ var init_pgSchema = __esm({
6313
6318
  indexes: squashedIndexes,
6314
6319
  foreignKeys: squashedFKs,
6315
6320
  compositePrimaryKeys: squashedPKs,
6316
- uniqueConstraints: squashedUniqueConstraints
6321
+ uniqueConstraints: squashedUniqueConstraints,
6322
+ checkConstraints: squashedChecksContraints
6317
6323
  }
6318
6324
  ];
6319
6325
  })
@@ -6336,7 +6342,6 @@ var init_pgSchema = __esm({
6336
6342
  tables: mappedTables,
6337
6343
  enums: json.enums,
6338
6344
  schemas: json.schemas,
6339
- views: json.views,
6340
6345
  sequences: mappedSequences
6341
6346
  };
6342
6347
  };
@@ -6359,7 +6364,7 @@ var init_pgSchema = __esm({
6359
6364
  });
6360
6365
 
6361
6366
  // src/serializer/sqliteSchema.ts
6362
- 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;
6363
6368
  var init_sqliteSchema = __esm({
6364
6369
  "src/serializer/sqliteSchema.ts"() {
6365
6370
  "use strict";
@@ -6406,13 +6411,18 @@ var init_sqliteSchema = __esm({
6406
6411
  name: stringType(),
6407
6412
  columns: stringType().array()
6408
6413
  }).strict();
6414
+ checkConstraint3 = objectType({
6415
+ name: stringType(),
6416
+ value: stringType()
6417
+ }).strict();
6409
6418
  table3 = objectType({
6410
6419
  name: stringType(),
6411
6420
  columns: recordType(stringType(), column3),
6412
6421
  indexes: recordType(stringType(), index3),
6413
6422
  foreignKeys: recordType(stringType(), fk3),
6414
6423
  compositePrimaryKeys: recordType(stringType(), compositePK3),
6415
- uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
6424
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({}),
6425
+ checkConstraints: recordType(stringType(), checkConstraint3).default({})
6416
6426
  }).strict();
6417
6427
  dialect2 = enumType(["sqlite"]);
6418
6428
  schemaHash3 = objectType({
@@ -6474,7 +6484,8 @@ var init_sqliteSchema = __esm({
6474
6484
  indexes: recordType(stringType(), stringType()),
6475
6485
  foreignKeys: recordType(stringType(), stringType()),
6476
6486
  compositePrimaryKeys: recordType(stringType(), stringType()),
6477
- uniqueConstraints: recordType(stringType(), stringType()).default({})
6487
+ uniqueConstraints: recordType(stringType(), stringType()).default({}),
6488
+ checkConstraints: recordType(stringType(), stringType()).default({})
6478
6489
  }).strict();
6479
6490
  schemaSquashed2 = objectType({
6480
6491
  version: latestVersion,
@@ -6556,6 +6567,16 @@ var init_sqliteSchema = __esm({
6556
6567
  },
6557
6568
  unsquashPK: (pk) => {
6558
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 };
6559
6580
  }
6560
6581
  };
6561
6582
  squashSqliteScheme = (json, action) => {
@@ -6582,6 +6603,12 @@ var init_sqliteSchema = __esm({
6582
6603
  return SQLiteSquasher.squashUnique(unq);
6583
6604
  }
6584
6605
  );
6606
+ const squashedCheckConstraints = mapValues(
6607
+ it[1].checkConstraints,
6608
+ (check2) => {
6609
+ return SQLiteSquasher.squashCheck(check2);
6610
+ }
6611
+ );
6585
6612
  return [
6586
6613
  it[0],
6587
6614
  {
@@ -6590,7 +6617,8 @@ var init_sqliteSchema = __esm({
6590
6617
  indexes: squashedIndexes,
6591
6618
  foreignKeys: squashedFKs,
6592
6619
  compositePrimaryKeys: squashedPKs,
6593
- uniqueConstraints: squashedUniqueConstraints
6620
+ uniqueConstraints: squashedUniqueConstraints,
6621
+ checkConstraints: squashedCheckConstraints
6594
6622
  }
6595
6623
  ];
6596
6624
  })
@@ -8852,9 +8880,6 @@ var init_utils3 = __esm({
8852
8880
  String.prototype.concatIf = function(it, condition) {
8853
8881
  return condition ? `${this}${it}` : String(this);
8854
8882
  };
8855
- String.prototype.snake_case = function() {
8856
- return this && this.length > 0 ? `${this.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)}` : String(this);
8857
- };
8858
8883
  Array.prototype.random = function() {
8859
8884
  return this[~~(Math.random() * this.length)];
8860
8885
  };
@@ -12551,11 +12576,11 @@ var require_node2 = __commonJS({
12551
12576
  };
12552
12577
  var require_base64 = __commonJS3((exports3) => {
12553
12578
  var intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
12554
- exports3.encode = function(number2) {
12555
- if (0 <= number2 && number2 < intToCharMap.length) {
12556
- return intToCharMap[number2];
12579
+ exports3.encode = function(number3) {
12580
+ if (0 <= number3 && number3 < intToCharMap.length) {
12581
+ return intToCharMap[number3];
12557
12582
  }
12558
- throw new TypeError("Must be between 0 and 63: " + number2);
12583
+ throw new TypeError("Must be between 0 and 63: " + number3);
12559
12584
  };
12560
12585
  exports3.decode = function(charCode) {
12561
12586
  var bigA = 65;
@@ -17975,6 +18000,7 @@ var init_mysqlSerializer = __esm({
17975
18000
  indexes,
17976
18001
  foreignKeys,
17977
18002
  schema: schema5,
18003
+ checks,
17978
18004
  primaryKeys,
17979
18005
  uniqueConstraints
17980
18006
  } = (0, import_mysql_core3.getTableConfig)(table4);
@@ -17983,6 +18009,8 @@ var init_mysqlSerializer = __esm({
17983
18009
  const foreignKeysObject = {};
17984
18010
  const primaryKeysObject = {};
17985
18011
  const uniqueConstraintObject = {};
18012
+ const checkConstraintObject = {};
18013
+ let checksInTable = {};
17986
18014
  columns.forEach((column7) => {
17987
18015
  const notNull = column7.notNull;
17988
18016
  const sqlTypeLowered = column7.getSQLType().toLowerCase();
@@ -18196,6 +18224,32 @@ We have encountered a collision between the index name on columns ${source_defau
18196
18224
  lock: value.config.lock
18197
18225
  };
18198
18226
  });
18227
+ checks.forEach((check2) => {
18228
+ check2;
18229
+ const checkName = check2.name;
18230
+ if (typeof checksInTable[tableName] !== "undefined") {
18231
+ if (checksInTable[tableName].includes(check2.name)) {
18232
+ console.log(
18233
+ `
18234
+ ${withStyle.errorWarning(
18235
+ `We've found duplicated check constraint name in ${source_default.underline.blue(
18236
+ tableName
18237
+ )}. Please rename your check constraint in the ${source_default.underline.blue(
18238
+ tableName
18239
+ )} table`
18240
+ )}`
18241
+ );
18242
+ process.exit(1);
18243
+ }
18244
+ checksInTable[tableName].push(checkName);
18245
+ } else {
18246
+ checksInTable[tableName] = [check2.name];
18247
+ }
18248
+ checkConstraintObject[checkName] = {
18249
+ name: checkName,
18250
+ value: dialect4.sqlToQuery(check2.value).sql
18251
+ };
18252
+ });
18199
18253
  if (!schema5) {
18200
18254
  result[tableName] = {
18201
18255
  name: tableName,
@@ -18203,7 +18257,8 @@ We have encountered a collision between the index name on columns ${source_defau
18203
18257
  indexes: indexesObject,
18204
18258
  foreignKeys: foreignKeysObject,
18205
18259
  compositePrimaryKeys: primaryKeysObject,
18206
- uniqueConstraints: uniqueConstraintObject
18260
+ uniqueConstraints: uniqueConstraintObject,
18261
+ checkConstraint: checkConstraintObject
18207
18262
  };
18208
18263
  }
18209
18264
  }
@@ -18230,6 +18285,7 @@ We have encountered a collision between the index name on columns ${source_defau
18230
18285
  let tablesCount = /* @__PURE__ */ new Set();
18231
18286
  let indexesCount = 0;
18232
18287
  let foreignKeysCount = 0;
18288
+ let checksCount = 0;
18233
18289
  const idxs = await db.query(
18234
18290
  `select * from INFORMATION_SCHEMA.STATISTICS
18235
18291
  WHERE INFORMATION_SCHEMA.STATISTICS.TABLE_SCHEMA = '${inputSchema}' and INFORMATION_SCHEMA.STATISTICS.INDEX_NAME != 'PRIMARY';`
@@ -18325,7 +18381,8 @@ We have encountered a collision between the index name on columns ${source_defau
18325
18381
  compositePrimaryKeys: {},
18326
18382
  indexes: {},
18327
18383
  foreignKeys: {},
18328
- uniqueConstraints: {}
18384
+ uniqueConstraints: {},
18385
+ checkConstraint: {}
18329
18386
  };
18330
18387
  } else {
18331
18388
  result[tableName].columns[columnName] = newColumn;
@@ -18476,6 +18533,38 @@ We have encountered a collision between the index name on columns ${source_defau
18476
18533
  progressCallback("indexes", indexesCount, "done");
18477
18534
  progressCallback("enums", 0, "done");
18478
18535
  }
18536
+ const checkConstraints = await db.query(
18537
+ `SELECT
18538
+ tc.table_name,
18539
+ tc.constraint_name,
18540
+ cc.check_clause
18541
+ FROM
18542
+ information_schema.table_constraints tc
18543
+ JOIN
18544
+ information_schema.check_constraints cc
18545
+ ON tc.constraint_name = cc.constraint_name
18546
+ WHERE
18547
+ tc.constraint_schema = '${inputSchema}'
18548
+ AND
18549
+ tc.constraint_type = 'CHECK';`
18550
+ );
18551
+ checksCount += checkConstraints.length;
18552
+ if (progressCallback) {
18553
+ progressCallback("checks", checksCount, "fetching");
18554
+ }
18555
+ for (const checkConstraintRow of checkConstraints) {
18556
+ const constraintName = checkConstraintRow["CONSTRAINT_NAME"];
18557
+ const constraintValue = checkConstraintRow["CHECK_CLAUSE"];
18558
+ const tableName = checkConstraintRow["TABLE_NAME"];
18559
+ const tableInResult = result[tableName];
18560
+ tableInResult.checkConstraint[constraintName] = {
18561
+ name: constraintName,
18562
+ value: constraintValue
18563
+ };
18564
+ }
18565
+ if (progressCallback) {
18566
+ progressCallback("checks", checksCount, "done");
18567
+ }
18479
18568
  return {
18480
18569
  version: "5",
18481
18570
  dialect: "mysql",
@@ -18508,8 +18597,6 @@ var init_pgImports = __esm({
18508
18597
  const enums = [];
18509
18598
  const schemas = [];
18510
18599
  const sequences = [];
18511
- const views = [];
18512
- const matViews = [];
18513
18600
  const i0values = Object.values(exports2);
18514
18601
  i0values.forEach((t2) => {
18515
18602
  if ((0, import_pg_core.isPgEnum)(t2)) {
@@ -18522,25 +18609,17 @@ var init_pgImports = __esm({
18522
18609
  if ((0, import_drizzle_orm4.is)(t2, import_pg_core.PgSchema)) {
18523
18610
  schemas.push(t2);
18524
18611
  }
18525
- if ((0, import_pg_core.isPgView)(t2)) {
18526
- views.push(t2);
18527
- }
18528
- if ((0, import_pg_core.isPgMaterializedView)(t2)) {
18529
- matViews.push(t2);
18530
- }
18531
18612
  if ((0, import_pg_core.isPgSequence)(t2)) {
18532
18613
  sequences.push(t2);
18533
18614
  }
18534
18615
  });
18535
- return { tables, enums, schemas, sequences, views, matViews };
18616
+ return { tables, enums, schemas, sequences };
18536
18617
  };
18537
18618
  prepareFromPgImports = async (imports) => {
18538
- const tables = [];
18539
- const enums = [];
18540
- const schemas = [];
18541
- const sequences = [];
18542
- const views = [];
18543
- const matViews = [];
18619
+ let tables = [];
18620
+ let enums = [];
18621
+ let schemas = [];
18622
+ let sequences = [];
18544
18623
  const { unregister } = await safeRegister();
18545
18624
  for (let i2 = 0; i2 < imports.length; i2++) {
18546
18625
  const it = imports[i2];
@@ -18550,11 +18629,9 @@ var init_pgImports = __esm({
18550
18629
  enums.push(...prepared.enums);
18551
18630
  schemas.push(...prepared.schemas);
18552
18631
  sequences.push(...prepared.sequences);
18553
- views.push(...prepared.views);
18554
- matViews.push(...prepared.matViews);
18555
18632
  }
18556
18633
  unregister();
18557
- return { tables: Array.from(new Set(tables)), enums, schemas, sequences, views, matViews };
18634
+ return { tables: Array.from(new Set(tables)), enums, schemas, sequences };
18558
18635
  };
18559
18636
  }
18560
18637
  });
@@ -18618,13 +18695,13 @@ var init_pgSerializer = __esm({
18618
18695
  indexName2 = (tableName, columns) => {
18619
18696
  return `${tableName}_${columns.join("_")}_index`;
18620
18697
  };
18621
- generatePgSnapshot = (tables, enums, schemas, sequences, views, matViews, schemaFilter) => {
18622
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
18698
+ generatePgSnapshot = (tables, enums, schemas, sequences, schemaFilter) => {
18699
+ var _a, _b, _c, _d, _e, _f;
18623
18700
  const result = {};
18624
- const resultViews = {};
18625
18701
  const sequencesToReturn = {};
18626
18702
  const indexesInSchema = {};
18627
18703
  for (const table4 of tables) {
18704
+ const checksInTable = {};
18628
18705
  const {
18629
18706
  name: tableName,
18630
18707
  columns,
@@ -18640,6 +18717,7 @@ var init_pgSerializer = __esm({
18640
18717
  }
18641
18718
  const columnsObject = {};
18642
18719
  const indexesObject = {};
18720
+ const checksObject = {};
18643
18721
  const foreignKeysObject = {};
18644
18722
  const primaryKeysObject = {};
18645
18723
  const uniqueConstraintObject = {};
@@ -18888,6 +18966,33 @@ ${withStyle.errorWarning(
18888
18966
  with: value.config.with ?? {}
18889
18967
  };
18890
18968
  });
18969
+ checks.forEach((check2) => {
18970
+ const checkName = check2.name;
18971
+ if (typeof checksInTable[`"${schema5 ?? "public"}"."${tableName}"`] !== "undefined") {
18972
+ if (checksInTable[`"${schema5 ?? "public"}"."${tableName}"`].includes(check2.name)) {
18973
+ console.log(
18974
+ `
18975
+ ${withStyle.errorWarning(
18976
+ `We've found duplicated check constraint name across ${source_default.underline.blue(
18977
+ schema5 ?? "public"
18978
+ )} schema in ${source_default.underline.blue(
18979
+ tableName
18980
+ )}. Please rename your check constraint in either the ${source_default.underline.blue(
18981
+ tableName
18982
+ )} table or the table with the duplicated check contraint name`
18983
+ )}`
18984
+ );
18985
+ process.exit(1);
18986
+ }
18987
+ checksInTable[`"${schema5 ?? "public"}"."${tableName}"`].push(checkName);
18988
+ } else {
18989
+ checksInTable[`"${schema5 ?? "public"}"."${tableName}"`] = [check2.name];
18990
+ }
18991
+ checksObject[checkName] = {
18992
+ name: checkName,
18993
+ value: dialect5.sqlToQuery(check2.value).sql
18994
+ };
18995
+ });
18891
18996
  const tableKey2 = `${schema5 ?? "public"}.${tableName}`;
18892
18997
  result[tableKey2] = {
18893
18998
  name: tableName,
@@ -18896,7 +19001,8 @@ ${withStyle.errorWarning(
18896
19001
  indexes: indexesObject,
18897
19002
  foreignKeys: foreignKeysObject,
18898
19003
  compositePrimaryKeys: primaryKeysObject,
18899
- uniqueConstraints: uniqueConstraintObject
19004
+ uniqueConstraints: uniqueConstraintObject,
19005
+ checkConstraints: checksObject
18900
19006
  };
18901
19007
  }
18902
19008
  for (const sequence of sequences) {
@@ -18920,149 +19026,6 @@ ${withStyle.errorWarning(
18920
19026
  } else {
18921
19027
  }
18922
19028
  }
18923
- const combinedViews = [...views, ...matViews];
18924
- for (const view2 of combinedViews) {
18925
- let viewName;
18926
- let schema5;
18927
- let query;
18928
- let selectedFields;
18929
- let isExisting;
18930
- let withOption;
18931
- let tablespace;
18932
- let using;
18933
- let withNoData;
18934
- let materialized = false;
18935
- if ((0, import_drizzle_orm5.is)(view2, import_pg_core2.PgView)) {
18936
- ({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption } = (0, import_pg_core2.getViewConfig)(view2));
18937
- } else {
18938
- ({ name: viewName, schema: schema5, query, selectedFields, isExisting, with: withOption, tablespace, using, withNoData } = (0, import_pg_core2.getMaterializedViewConfig)(
18939
- view2
18940
- ));
18941
- materialized = true;
18942
- }
18943
- const viewSchema = schema5 ?? "public";
18944
- const viewKey = `${viewSchema}.${viewName}`;
18945
- const columnsObject = {};
18946
- const uniqueConstraintObject = {};
18947
- const existingView = resultViews[viewKey];
18948
- if (typeof existingView !== "undefined") {
18949
- console.log(
18950
- `
18951
- ${withStyle.errorWarning(
18952
- `We've found duplicated view name across ${source_default.underline.blue(
18953
- schema5 ?? "public"
18954
- )} schema. Please rename your view`
18955
- )}`
18956
- );
18957
- process.exit(1);
18958
- }
18959
- for (const key in selectedFields) {
18960
- if ((0, import_drizzle_orm5.is)(selectedFields[key], import_pg_core2.PgColumn)) {
18961
- const column7 = selectedFields[key];
18962
- const notNull = column7.notNull;
18963
- const primaryKey = column7.primary;
18964
- const sqlTypeLowered = column7.getSQLType().toLowerCase();
18965
- const typeSchema = (0, import_drizzle_orm5.is)(column7, import_pg_core2.PgEnumColumn) ? column7.enum.schema || "public" : void 0;
18966
- const generated = column7.generated;
18967
- const identity = column7.generatedIdentity;
18968
- const increment = stringFromIdentityProperty((_g = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _g.increment) ?? "1";
18969
- const minValue = stringFromIdentityProperty((_h = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _h.minValue) ?? (parseFloat(increment) < 0 ? minRangeForIdentityBasedOn(column7.columnType) : "1");
18970
- const maxValue = stringFromIdentityProperty((_i = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _i.maxValue) ?? (parseFloat(increment) < 0 ? "-1" : maxRangeForIdentityBasedOn(column7.getSQLType()));
18971
- const startWith = stringFromIdentityProperty((_j = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _j.startWith) ?? (parseFloat(increment) < 0 ? maxValue : minValue);
18972
- const cache = stringFromIdentityProperty((_k = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _k.cache) ?? "1";
18973
- const columnToSet = {
18974
- name: column7.name,
18975
- type: column7.getSQLType(),
18976
- typeSchema,
18977
- primaryKey,
18978
- notNull,
18979
- generated: generated ? {
18980
- as: (0, import_drizzle_orm5.is)(generated.as, import_drizzle_orm5.SQL) ? dialect5.sqlToQuery(generated.as).sql : typeof generated.as === "function" ? dialect5.sqlToQuery(generated.as()).sql : generated.as,
18981
- type: "stored"
18982
- } : void 0,
18983
- identity: identity ? {
18984
- type: identity.type,
18985
- name: identity.sequenceName ?? `${viewName}_${column7.name}_seq`,
18986
- schema: schema5 ?? "public",
18987
- increment,
18988
- startWith,
18989
- minValue,
18990
- maxValue,
18991
- cache,
18992
- cycle: ((_l = identity == null ? void 0 : identity.sequenceOptions) == null ? void 0 : _l.cycle) ?? false
18993
- } : void 0
18994
- };
18995
- if (column7.isUnique) {
18996
- const existingUnique = uniqueConstraintObject[column7.uniqueName];
18997
- if (typeof existingUnique !== "undefined") {
18998
- console.log(
18999
- `
19000
- ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${source_default.underline.blue(
19001
- viewName
19002
- )} table.
19003
- The unique constraint ${source_default.underline.blue(
19004
- column7.uniqueName
19005
- )} on the ${source_default.underline.blue(
19006
- column7.name
19007
- )} column is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
19008
- existingUnique.columns.join(",")
19009
- )} columns
19010
- `)}`
19011
- );
19012
- process.exit(1);
19013
- }
19014
- uniqueConstraintObject[column7.uniqueName] = {
19015
- name: column7.uniqueName,
19016
- nullsNotDistinct: column7.uniqueType === "not distinct",
19017
- columns: [columnToSet.name]
19018
- };
19019
- }
19020
- if (column7.default !== void 0) {
19021
- if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
19022
- columnToSet.default = sqlToStr(column7.default);
19023
- } else {
19024
- if (typeof column7.default === "string") {
19025
- columnToSet.default = `'${column7.default}'`;
19026
- } else {
19027
- if (sqlTypeLowered === "jsonb" || sqlTypeLowered === "json") {
19028
- columnToSet.default = `'${JSON.stringify(
19029
- column7.default
19030
- )}'::${sqlTypeLowered}`;
19031
- } else if (column7.default instanceof Date) {
19032
- if (sqlTypeLowered === "date") {
19033
- columnToSet.default = `'${column7.default.toISOString().split("T")[0]}'`;
19034
- } else if (sqlTypeLowered === "timestamp") {
19035
- columnToSet.default = `'${column7.default.toISOString().replace("T", " ").slice(0, 23)}'`;
19036
- } else {
19037
- columnToSet.default = `'${column7.default.toISOString()}'`;
19038
- }
19039
- } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column7.default)) {
19040
- columnToSet.default = `'${buildArrayString(
19041
- column7.default,
19042
- sqlTypeLowered
19043
- )}'`;
19044
- } else {
19045
- columnToSet.default = column7.default;
19046
- }
19047
- }
19048
- }
19049
- }
19050
- columnsObject[column7.name] = columnToSet;
19051
- }
19052
- }
19053
- resultViews[viewKey] = {
19054
- columns: columnsObject,
19055
- definition: isExisting ? void 0 : dialect5.sqlToQuery(query).sql,
19056
- name: viewName,
19057
- schema: viewSchema,
19058
- isExisting,
19059
- with: withOption,
19060
- withNoData,
19061
- materialized,
19062
- tablespace,
19063
- using
19064
- };
19065
- }
19066
19029
  const enumsToReturn = enums.reduce((map, obj) => {
19067
19030
  const enumSchema3 = obj.schema || "public";
19068
19031
  const key = `${enumSchema3}.${obj.enumName}`;
@@ -19089,7 +19052,6 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
19089
19052
  enums: enumsToReturn,
19090
19053
  schemas: schemasObject,
19091
19054
  sequences: sequencesToReturn,
19092
- views: resultViews,
19093
19055
  _meta: {
19094
19056
  schemas: {},
19095
19057
  tables: {},
@@ -19108,25 +19070,10 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
19108
19070
  };
19109
19071
  fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
19110
19072
  const result = {};
19111
- const views = {};
19112
19073
  const internals = { tables: {} };
19113
- const where = schemaFilters.map((t2) => `n.nspname = '${t2}'`).join(" or ");
19074
+ const where = schemaFilters.map((t2) => `table_schema = '${t2}'`).join(" or ");
19114
19075
  const allTables = await db.query(
19115
- `SELECT
19116
- n.nspname AS table_schema,
19117
- c.relname AS table_name,
19118
- CASE
19119
- WHEN c.relkind = 'r' THEN 'table'
19120
- WHEN c.relkind = 'v' THEN 'view'
19121
- WHEN c.relkind = 'm' THEN 'materialized_view'
19122
- END AS type
19123
- FROM
19124
- pg_catalog.pg_class c
19125
- JOIN
19126
- pg_catalog.pg_namespace n ON n.oid = c.relnamespace
19127
- WHERE
19128
- c.relkind IN ('r', 'v', 'm')
19129
- ${where === "" ? "" : ` AND ${where}`};`
19076
+ `SELECT table_schema, table_name FROM information_schema.tables${where === "" ? "" : ` WHERE ${where}`};`
19130
19077
  );
19131
19078
  const schemas = new Set(allTables.map((it) => it.table_schema));
19132
19079
  schemas.delete("public");
@@ -19146,6 +19093,7 @@ WHERE
19146
19093
  let indexesCount = 0;
19147
19094
  let foreignKeysCount = 0;
19148
19095
  let tableCount = 0;
19096
+ let checksCount = 0;
19149
19097
  const sequencesToReturn = {};
19150
19098
  const seqWhere = schemaFilters.map((t2) => `schemaname = '${t2}'`).join(" or ");
19151
19099
  const allSequences = await db.query(
@@ -19204,7 +19152,7 @@ WHERE
19204
19152
  progressCallback("enums", Object.keys(enumsToReturn).length, "done");
19205
19153
  }
19206
19154
  const sequencesInColumns = [];
19207
- const all = allTables.filter((it) => it.type === "table").map((row) => {
19155
+ const all = allTables.map((row) => {
19208
19156
  return new Promise(async (res, rej) => {
19209
19157
  var _a, _b, _c, _d, _e, _f;
19210
19158
  const tableName = row.table_name;
@@ -19217,7 +19165,8 @@ WHERE
19217
19165
  const indexToReturn = {};
19218
19166
  const foreignKeysToReturn = {};
19219
19167
  const primaryKeys = {};
19220
- const uniqueConstrains = {};
19168
+ const uniqueConstraints = {};
19169
+ const checkConstraints = {};
19221
19170
  const tableResponse = await db.query(
19222
19171
  `SELECT a.attrelid::regclass::text, a.attname, is_nullable, a.attndims as array_dimensions
19223
19172
  , CASE WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[])
@@ -19255,55 +19204,97 @@ WHERE
19255
19204
  ORDER BY a.attnum;`
19256
19205
  );
19257
19206
  const tableConstraints = await db.query(
19258
- `SELECT c.column_name, c.data_type, constraint_type, constraint_name, constraint_schema
19259
- FROM information_schema.table_constraints tc
19260
- JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
19261
- JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema
19262
- AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
19263
- WHERE tc.table_name = '${tableName}' and constraint_schema = '${tableSchema}';`
19207
+ `SELECT c.column_name,
19208
+ c.data_type,
19209
+ tc.constraint_type,
19210
+ tc.constraint_name,
19211
+ tc.constraint_schema,
19212
+ pg_get_constraintdef(con.oid) AS check_constraint_definition
19213
+ FROM information_schema.table_constraints tc
19214
+ JOIN information_schema.constraint_column_usage AS ccu
19215
+ USING (constraint_schema, constraint_name)
19216
+ JOIN information_schema.columns AS c
19217
+ ON c.table_schema = tc.constraint_schema
19218
+ AND tc.table_name = c.table_name
19219
+ AND ccu.column_name = c.column_name
19220
+ JOIN pg_constraint con
19221
+ ON con.conname = tc.constraint_name
19222
+ AND con.conrelid = (
19223
+ SELECT oid
19224
+ FROM pg_class
19225
+ WHERE relname = tc.table_name
19226
+ AND relnamespace = (
19227
+ SELECT oid
19228
+ FROM pg_namespace
19229
+ WHERE nspname = tc.constraint_schema
19230
+ )
19231
+ )
19232
+ WHERE tc.table_name = '${tableName}' AND tc.constraint_schema = '${tableSchema}';`
19264
19233
  );
19234
+ const tableChecks = await db.query(`SELECT
19235
+ tc.constraint_name,
19236
+ tc.constraint_type,
19237
+ pg_get_constraintdef(con.oid) AS constraint_definition
19238
+ FROM
19239
+ information_schema.table_constraints AS tc
19240
+ JOIN pg_constraint AS con
19241
+ ON tc.constraint_name = con.conname
19242
+ AND con.conrelid = (
19243
+ SELECT oid
19244
+ FROM pg_class
19245
+ WHERE relname = tc.table_name
19246
+ AND relnamespace = (
19247
+ SELECT oid
19248
+ FROM pg_namespace
19249
+ WHERE nspname = tc.constraint_schema
19250
+ )
19251
+ )
19252
+ WHERE
19253
+ tc.table_name = '${tableName}'
19254
+ AND tc.constraint_schema = '${tableSchema}'
19255
+ AND tc.constraint_type = 'CHECK';`);
19265
19256
  columnsCount += tableResponse.length;
19266
19257
  if (progressCallback) {
19267
19258
  progressCallback("columns", columnsCount, "fetching");
19268
19259
  }
19269
19260
  const tableForeignKeys = await db.query(
19270
19261
  `SELECT
19271
- con.contype AS constraint_type,
19272
- nsp.nspname AS constraint_schema,
19273
- con.conname AS constraint_name,
19274
- rel.relname AS table_name,
19275
- att.attname AS column_name,
19276
- fnsp.nspname AS foreign_table_schema,
19277
- frel.relname AS foreign_table_name,
19278
- fatt.attname AS foreign_column_name,
19279
- CASE con.confupdtype
19280
- WHEN 'a' THEN 'NO ACTION'
19281
- WHEN 'r' THEN 'RESTRICT'
19282
- WHEN 'n' THEN 'SET NULL'
19283
- WHEN 'c' THEN 'CASCADE'
19284
- WHEN 'd' THEN 'SET DEFAULT'
19285
- END AS update_rule,
19286
- CASE con.confdeltype
19287
- WHEN 'a' THEN 'NO ACTION'
19288
- WHEN 'r' THEN 'RESTRICT'
19289
- WHEN 'n' THEN 'SET NULL'
19290
- WHEN 'c' THEN 'CASCADE'
19291
- WHEN 'd' THEN 'SET DEFAULT'
19292
- END AS delete_rule
19293
- FROM
19294
- pg_catalog.pg_constraint con
19295
- JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
19296
- JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
19297
- LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
19298
- AND att.attrelid = con.conrelid
19299
- LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
19300
- LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
19301
- LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
19302
- AND fatt.attrelid = con.confrelid
19303
- WHERE
19304
- nsp.nspname = '${tableSchema}'
19305
- AND rel.relname = '${tableName}'
19306
- AND con.contype IN ('f');`
19262
+ con.contype AS constraint_type,
19263
+ nsp.nspname AS constraint_schema,
19264
+ con.conname AS constraint_name,
19265
+ rel.relname AS table_name,
19266
+ att.attname AS column_name,
19267
+ fnsp.nspname AS foreign_table_schema,
19268
+ frel.relname AS foreign_table_name,
19269
+ fatt.attname AS foreign_column_name,
19270
+ CASE con.confupdtype
19271
+ WHEN 'a' THEN 'NO ACTION'
19272
+ WHEN 'r' THEN 'RESTRICT'
19273
+ WHEN 'n' THEN 'SET NULL'
19274
+ WHEN 'c' THEN 'CASCADE'
19275
+ WHEN 'd' THEN 'SET DEFAULT'
19276
+ END AS update_rule,
19277
+ CASE con.confdeltype
19278
+ WHEN 'a' THEN 'NO ACTION'
19279
+ WHEN 'r' THEN 'RESTRICT'
19280
+ WHEN 'n' THEN 'SET NULL'
19281
+ WHEN 'c' THEN 'CASCADE'
19282
+ WHEN 'd' THEN 'SET DEFAULT'
19283
+ END AS delete_rule
19284
+ FROM
19285
+ pg_catalog.pg_constraint con
19286
+ JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
19287
+ JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
19288
+ LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
19289
+ AND att.attrelid = con.conrelid
19290
+ LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
19291
+ LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
19292
+ LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
19293
+ AND fatt.attrelid = con.confrelid
19294
+ WHERE
19295
+ nsp.nspname = '${tableSchema}'
19296
+ AND rel.relname = '${tableName}'
19297
+ AND con.contype IN ('f');`
19307
19298
  );
19308
19299
  foreignKeysCount += tableForeignKeys.length;
19309
19300
  if (progressCallback) {
@@ -19345,16 +19336,29 @@ WHERE
19345
19336
  for (const unqs of uniqueConstrainsRows) {
19346
19337
  const columnName = unqs.column_name;
19347
19338
  const constraintName = unqs.constraint_name;
19348
- if (typeof uniqueConstrains[constraintName] !== "undefined") {
19349
- uniqueConstrains[constraintName].columns.push(columnName);
19339
+ if (typeof uniqueConstraints[constraintName] !== "undefined") {
19340
+ uniqueConstraints[constraintName].columns.push(columnName);
19350
19341
  } else {
19351
- uniqueConstrains[constraintName] = {
19342
+ uniqueConstraints[constraintName] = {
19352
19343
  columns: [columnName],
19353
19344
  nullsNotDistinct: false,
19354
19345
  name: constraintName
19355
19346
  };
19356
19347
  }
19357
19348
  }
19349
+ checksCount += tableChecks.length;
19350
+ if (progressCallback) {
19351
+ progressCallback("checks", checksCount, "fetching");
19352
+ }
19353
+ for (const checks of tableChecks) {
19354
+ let checkValue = checks.constraint_definition;
19355
+ const constraintName = checks.constraint_name;
19356
+ checkValue = checkValue.replace(/^CHECK\s*\(\(/, "").replace(/\)\)\s*$/, "");
19357
+ checkConstraints[constraintName] = {
19358
+ name: constraintName,
19359
+ value: checkValue
19360
+ };
19361
+ }
19358
19362
  for (const columnResponse of tableResponse) {
19359
19363
  const columnName = columnResponse.attname;
19360
19364
  const columnAdditionalDT = columnResponse.additional_dt;
@@ -19599,7 +19603,8 @@ WHERE
19599
19603
  indexes: indexToReturn,
19600
19604
  foreignKeys: foreignKeysToReturn,
19601
19605
  compositePrimaryKeys: primaryKeys,
19602
- uniqueConstraints: uniqueConstrains
19606
+ uniqueConstraints,
19607
+ checkConstraints
19603
19608
  };
19604
19609
  } catch (e2) {
19605
19610
  rej(e2);
@@ -19613,340 +19618,11 @@ WHERE
19613
19618
  }
19614
19619
  for await (const _2 of all) {
19615
19620
  }
19616
- const allViews = allTables.filter((it) => it.type === "view" || it.type === "materialized_view").map((row) => {
19617
- return new Promise(async (res, rej) => {
19618
- var _a, _b, _c, _d;
19619
- const viewName = row.table_name;
19620
- if (!tablesFilter(viewName))
19621
- return res("");
19622
- tableCount += 1;
19623
- const viewSchema = row.table_schema;
19624
- try {
19625
- const columnToReturn = {};
19626
- const viewResponses = await db.query(`WITH view_columns AS (
19627
- SELECT DISTINCT
19628
- nv.nspname::information_schema.sql_identifier AS view_schema,
19629
- v.relname::information_schema.sql_identifier AS view_name,
19630
- nt.nspname::information_schema.sql_identifier AS table_schema,
19631
- t.relname::information_schema.sql_identifier AS table_name,
19632
- a.attname::information_schema.sql_identifier AS column_name
19633
- FROM pg_namespace nv
19634
- JOIN pg_class v ON nv.oid = v.relnamespace
19635
- JOIN pg_depend dv ON v.oid = dv.refobjid
19636
- JOIN pg_depend dt ON dv.objid = dt.objid
19637
- JOIN pg_class t ON dt.refobjid = t.oid
19638
- JOIN pg_namespace nt ON t.relnamespace = nt.oid
19639
- JOIN pg_attribute a ON t.oid = a.attrelid
19640
- WHERE (v.relkind = 'v'::"char" OR v.relkind = 'm'::"char")
19641
- AND dv.refclassid = 'pg_class'::regclass::oid
19642
- AND dv.classid = 'pg_rewrite'::regclass::oid
19643
- AND dv.deptype = 'i'::"char"
19644
- AND dv.objid = dt.objid
19645
- AND dv.refobjid <> dt.refobjid
19646
- AND dt.classid = 'pg_rewrite'::regclass::oid
19647
- AND dt.refclassid = 'pg_class'::regclass::oid
19648
- AND t.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
19649
- AND dt.refobjsubid = a.attnum
19650
- AND pg_has_role(t.relowner, 'USAGE'::text)
19651
- AND nv.nspname::information_schema.sql_identifier = '${viewSchema}'
19652
- AND v.relname::information_schema.sql_identifier = '${viewName}'
19653
- ),
19654
- column_descriptions AS (
19655
- SELECT DISTINCT
19656
- a.attrelid::regclass::text AS table_name,
19657
- a.attname AS column_name,
19658
- c.is_nullable,
19659
- a.attndims AS array_dimensions,
19660
- CASE
19661
- WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
19662
- SELECT FROM pg_attrdef ad
19663
- WHERE ad.adrelid = a.attrelid
19664
- AND ad.adnum = a.attnum
19665
- AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
19666
- )
19667
- THEN CASE a.atttypid
19668
- WHEN 'int'::regtype THEN 'serial'
19669
- WHEN 'int8'::regtype THEN 'bigserial'
19670
- WHEN 'int2'::regtype THEN 'smallserial'
19671
- END
19672
- ELSE format_type(a.atttypid, a.atttypmod)
19673
- END AS data_type,
19674
- pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
19675
- c.column_default,
19676
- c.data_type AS additional_dt,
19677
- c.udt_name AS enum_name,
19678
- c.is_generated,
19679
- c.generation_expression,
19680
- c.is_identity,
19681
- c.identity_generation,
19682
- c.identity_start,
19683
- c.identity_increment,
19684
- c.identity_maximum,
19685
- c.identity_minimum,
19686
- c.identity_cycle
19687
- FROM pg_attribute a
19688
- JOIN information_schema.columns c ON c.column_name = a.attname
19689
- JOIN pg_type t ON t.oid = a.atttypid
19690
- LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
19691
- WHERE a.attnum > 0
19692
- AND NOT a.attisdropped
19693
- ),
19694
- table_constraints AS (
19695
- SELECT DISTINCT ON (ccu.column_name)
19696
- ccu.column_name,
19697
- c.data_type,
19698
- tc.constraint_type,
19699
- tc.constraint_name,
19700
- tc.constraint_schema,
19701
- tc.table_name
19702
- FROM information_schema.table_constraints tc
19703
- JOIN information_schema.constraint_column_usage ccu USING (constraint_schema, constraint_name)
19704
- JOIN information_schema.columns c ON c.table_schema = tc.constraint_schema
19705
- AND tc.table_name = c.table_name
19706
- AND ccu.column_name = c.column_name
19707
- ),
19708
- additional_column_info AS (
19709
- SELECT DISTINCT
19710
- a.attrelid::regclass::text AS table_name,
19711
- a.attname AS column_name,
19712
- is_nullable,
19713
- a.attndims AS array_dimensions,
19714
- CASE
19715
- WHEN a.atttypid = ANY ('{int,int8,int2}'::regtype[]) AND EXISTS (
19716
- SELECT FROM pg_attrdef ad
19717
- WHERE ad.adrelid = a.attrelid
19718
- AND ad.adnum = a.attnum
19719
- AND pg_get_expr(ad.adbin, ad.adrelid) = 'nextval(''' || pg_get_serial_sequence(a.attrelid::regclass::text, a.attname)::regclass || '''::regclass)'
19720
- )
19721
- THEN CASE a.atttypid
19722
- WHEN 'int'::regtype THEN 'serial'
19723
- WHEN 'int8'::regtype THEN 'bigserial'
19724
- WHEN 'int2'::regtype THEN 'smallserial'
19725
- END
19726
- ELSE format_type(a.atttypid, a.atttypmod)
19727
- END AS data_type,
19728
- pg_get_serial_sequence('"' || c.table_schema || '"."' || c.table_name || '"', a.attname)::regclass AS seq_name,
19729
- c.column_default,
19730
- c.data_type AS additional_dt,
19731
- c.udt_name AS enum_name,
19732
- c.is_generated,
19733
- generation_expression,
19734
- is_identity,
19735
- identity_generation,
19736
- identity_start,
19737
- identity_increment,
19738
- identity_maximum,
19739
- identity_minimum,
19740
- identity_cycle
19741
- FROM pg_attribute a
19742
- JOIN information_schema.columns c ON c.column_name = a.attname
19743
- LEFT JOIN pg_type t ON t.oid = a.atttypid
19744
- LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
19745
- WHERE a.attnum > 0
19746
- AND NOT a.attisdropped
19747
- )
19748
- SELECT DISTINCT ON (vc.table_name, vc.column_name)
19749
- vc.view_schema,
19750
- vc.view_name,
19751
- vc.table_schema,
19752
- vc.table_name,
19753
- vc.column_name,
19754
- COALESCE(cd.data_type, aci.data_type) AS data_type,
19755
- tc.constraint_type,
19756
- tc.constraint_name,
19757
- aci.is_nullable,
19758
- aci.array_dimensions,
19759
- aci.seq_name,
19760
- aci.column_default,
19761
- aci.additional_dt,
19762
- aci.enum_name,
19763
- aci.is_generated,
19764
- aci.generation_expression,
19765
- aci.is_identity,
19766
- aci.identity_generation,
19767
- aci.identity_start,
19768
- aci.identity_increment,
19769
- aci.identity_maximum,
19770
- aci.identity_minimum,
19771
- aci.identity_cycle
19772
- FROM view_columns vc
19773
- LEFT JOIN column_descriptions cd ON vc.table_name = cd.table_name AND vc.column_name = cd.column_name
19774
- LEFT JOIN table_constraints tc ON vc.table_name = tc.table_name AND vc.column_name = tc.column_name
19775
- LEFT JOIN additional_column_info aci ON vc.table_name = aci.table_name AND vc.column_name = aci.column_name
19776
- ORDER BY vc.table_name, vc.column_name;`);
19777
- for (const viewResponse of viewResponses) {
19778
- const columnName = viewResponse.column_name;
19779
- const columnAdditionalDT = viewResponse.additional_dt;
19780
- const columnDimensions = viewResponse.array_dimensions;
19781
- const enumType2 = viewResponse.enum_name;
19782
- let columnType = viewResponse.data_type;
19783
- const typeSchema = viewResponse.type_schema;
19784
- const isGenerated = viewResponse.is_generated === "ALWAYS";
19785
- const generationExpression = viewResponse.generation_expression;
19786
- const isIdentity = viewResponse.is_identity === "YES";
19787
- const identityGeneration = viewResponse.identity_generation === "ALWAYS" ? "always" : "byDefault";
19788
- const identityStart = viewResponse.identity_start;
19789
- const identityIncrement = viewResponse.identity_increment;
19790
- const identityMaximum = viewResponse.identity_maximum;
19791
- const identityMinimum = viewResponse.identity_minimum;
19792
- const identityCycle = viewResponse.identity_cycle === "YES";
19793
- const identityName = viewResponse.seq_name;
19794
- const defaultValueRes = viewResponse.column_default;
19795
- const primaryKey = viewResponse.constraint_type === "PRIMARY KEY";
19796
- let columnTypeMapped = columnType;
19797
- if (columnAdditionalDT === "ARRAY") {
19798
- if (typeof internals.tables[viewName] === "undefined") {
19799
- internals.tables[viewName] = {
19800
- columns: {
19801
- [columnName]: {
19802
- isArray: true,
19803
- dimensions: columnDimensions,
19804
- rawType: columnTypeMapped.substring(
19805
- 0,
19806
- columnTypeMapped.length - 2
19807
- )
19808
- }
19809
- }
19810
- };
19811
- } else {
19812
- if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
19813
- internals.tables[viewName].columns[columnName] = {
19814
- isArray: true,
19815
- dimensions: columnDimensions,
19816
- rawType: columnTypeMapped.substring(
19817
- 0,
19818
- columnTypeMapped.length - 2
19819
- )
19820
- };
19821
- }
19822
- }
19823
- }
19824
- const defaultValue = defaultForColumn(
19825
- viewResponse,
19826
- internals,
19827
- viewName
19828
- );
19829
- if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
19830
- if (typeof internals.tables[viewName] === "undefined") {
19831
- internals.tables[viewName] = {
19832
- columns: {
19833
- [columnName]: {
19834
- isDefaultAnExpression: true
19835
- }
19836
- }
19837
- };
19838
- } else {
19839
- if (typeof internals.tables[viewName].columns[columnName] === "undefined") {
19840
- internals.tables[viewName].columns[columnName] = {
19841
- isDefaultAnExpression: true
19842
- };
19843
- } else {
19844
- internals.tables[viewName].columns[columnName].isDefaultAnExpression = true;
19845
- }
19846
- }
19847
- }
19848
- const isSerial = columnType === "serial";
19849
- if (columnTypeMapped.startsWith("numeric(")) {
19850
- columnTypeMapped = columnTypeMapped.replace(",", ", ");
19851
- }
19852
- if (columnAdditionalDT === "ARRAY") {
19853
- for (let i2 = 1; i2 < Number(columnDimensions); i2++) {
19854
- columnTypeMapped += "[]";
19855
- }
19856
- }
19857
- columnTypeMapped = columnTypeMapped.replace("character varying", "varchar").replace(" without time zone", "").replace("character", "char");
19858
- columnTypeMapped = trimChar(columnTypeMapped, '"');
19859
- columnToReturn[columnName] = {
19860
- name: columnName,
19861
- type: (
19862
- // filter vectors, but in future we should filter any extension that was installed by user
19863
- columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
19864
- ),
19865
- typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
19866
- primaryKey,
19867
- notNull: viewResponse.is_nullable === "NO",
19868
- generated: isGenerated ? { as: generationExpression, type: "stored" } : void 0,
19869
- identity: isIdentity ? {
19870
- type: identityGeneration,
19871
- name: identityName,
19872
- increment: stringFromDatabaseIdentityProperty(identityIncrement),
19873
- minValue: stringFromDatabaseIdentityProperty(identityMinimum),
19874
- maxValue: stringFromDatabaseIdentityProperty(identityMaximum),
19875
- startWith: stringFromDatabaseIdentityProperty(identityStart),
19876
- cache: ((_a = sequencesToReturn[identityName]) == null ? void 0 : _a.cache) ? (_b = sequencesToReturn[identityName]) == null ? void 0 : _b.cache : ((_c = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _c.cache) ? (_d = sequencesToReturn[`${viewSchema}.${identityName}`]) == null ? void 0 : _d.cache : void 0,
19877
- cycle: identityCycle,
19878
- schema: viewSchema
19879
- } : void 0
19880
- };
19881
- if (identityName) {
19882
- delete sequencesToReturn[`${viewSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
19883
- delete sequencesToReturn[identityName];
19884
- }
19885
- if (!isSerial && typeof defaultValue !== "undefined") {
19886
- columnToReturn[columnName].default = defaultValue;
19887
- }
19888
- }
19889
- const [viewInfo] = await db.query(`
19890
- SELECT
19891
- c.relname AS view_name,
19892
- n.nspname AS schema_name,
19893
- pg_get_viewdef(c.oid, true) AS definition,
19894
- ts.spcname AS tablespace_name,
19895
- c.reloptions AS options,
19896
- pg_tablespace_location(ts.oid) AS location
19897
- FROM
19898
- pg_class c
19899
- JOIN
19900
- pg_namespace n ON c.relnamespace = n.oid
19901
- LEFT JOIN
19902
- pg_tablespace ts ON c.reltablespace = ts.oid
19903
- WHERE
19904
- (c.relkind = 'm' OR c.relkind = 'v')
19905
- AND n.nspname = '${viewSchema}'
19906
- AND c.relname = '${viewName}';`);
19907
- const resultWith = {};
19908
- if (viewInfo.options) {
19909
- viewInfo.options.forEach((pair) => {
19910
- const splitted = pair.split("=");
19911
- const key = splitted[0];
19912
- const value = splitted[1];
19913
- if (value === "true") {
19914
- resultWith[key] = true;
19915
- } else if (value === "false") {
19916
- resultWith[key] = false;
19917
- } else if (!isNaN(Number(value))) {
19918
- resultWith[key] = Number(value);
19919
- } else {
19920
- resultWith[key] = value;
19921
- }
19922
- });
19923
- }
19924
- const definition = viewInfo.definition.replace(/\s+/g, " ").replace(";", "").trim();
19925
- const withOption = Object.values(resultWith).length ? Object.fromEntries(Object.entries(resultWith).map(([key, value]) => [key.camelCase(), value])) : void 0;
19926
- const materialized = row.type === "materialized_view";
19927
- views[`${viewSchema}.${viewName}`] = {
19928
- name: viewName,
19929
- schema: viewSchema,
19930
- columns: columnToReturn,
19931
- isExisting: false,
19932
- definition,
19933
- materialized,
19934
- with: withOption,
19935
- tablespace: viewInfo.tablespace_name ?? void 0
19936
- };
19937
- } catch (e2) {
19938
- rej(e2);
19939
- return;
19940
- }
19941
- res("");
19942
- });
19943
- });
19944
- for await (const _2 of allViews) {
19945
- }
19946
19621
  if (progressCallback) {
19947
19622
  progressCallback("columns", columnsCount, "done");
19948
19623
  progressCallback("indexes", indexesCount, "done");
19949
19624
  progressCallback("fks", foreignKeysCount, "done");
19625
+ progressCallback("checks", checksCount, "done");
19950
19626
  }
19951
19627
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
19952
19628
  return {
@@ -19956,7 +19632,6 @@ WHERE
19956
19632
  enums: enumsToReturn,
19957
19633
  schemas: schemasObject,
19958
19634
  sequences: sequencesToReturn,
19959
- views,
19960
19635
  _meta: {
19961
19636
  schemas: {},
19962
19637
  tables: {},
@@ -20020,6 +19695,8 @@ WHERE
20020
19695
  }
20021
19696
  return columnDefaultAsString;
20022
19697
  }
19698
+ } else if (column7.data_type.includes("numeric")) {
19699
+ return columnDefaultAsString.includes("'") ? columnDefaultAsString : `'${columnDefaultAsString}'`;
20023
19700
  } else if (column7.data_type === "json" || column7.data_type === "jsonb") {
20024
19701
  const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
20025
19702
  return `'${jsonWithoutSpaces}'::${column7.data_type}`;
@@ -20160,10 +19837,13 @@ var init_sqliteSerializer = __esm({
20160
19837
  const foreignKeysObject = {};
20161
19838
  const primaryKeysObject = {};
20162
19839
  const uniqueConstraintObject = {};
19840
+ const checkConstraintObject = {};
19841
+ const checksInTable = {};
20163
19842
  const {
20164
19843
  name: tableName,
20165
19844
  columns,
20166
19845
  indexes,
19846
+ checks,
20167
19847
  foreignKeys: tableForeignKeys,
20168
19848
  primaryKeys,
20169
19849
  uniqueConstraints
@@ -20321,13 +20001,39 @@ The unique constraint ${source_default.underline.blue(
20321
20001
  columnsObject[it.columns[0].name].primaryKey = true;
20322
20002
  }
20323
20003
  });
20004
+ checks.forEach((check2) => {
20005
+ const checkName = check2.name;
20006
+ if (typeof checksInTable[tableName] !== "undefined") {
20007
+ if (checksInTable[tableName].includes(check2.name)) {
20008
+ console.log(
20009
+ `
20010
+ ${withStyle.errorWarning(
20011
+ `We've found duplicated check constraint name in ${source_default.underline.blue(
20012
+ tableName
20013
+ )}. Please rename your check constraint in the ${source_default.underline.blue(
20014
+ tableName
20015
+ )} table`
20016
+ )}`
20017
+ );
20018
+ process.exit(1);
20019
+ }
20020
+ checksInTable[tableName].push(checkName);
20021
+ } else {
20022
+ checksInTable[tableName] = [check2.name];
20023
+ }
20024
+ checkConstraintObject[checkName] = {
20025
+ name: checkName,
20026
+ value: dialect6.sqlToQuery(check2.value).sql
20027
+ };
20028
+ });
20324
20029
  result[tableName] = {
20325
20030
  name: tableName,
20326
20031
  columns: columnsObject,
20327
20032
  indexes: indexesObject,
20328
20033
  foreignKeys: foreignKeysObject,
20329
20034
  compositePrimaryKeys: primaryKeysObject,
20330
- uniqueConstraints: uniqueConstraintObject
20035
+ uniqueConstraints: uniqueConstraintObject,
20036
+ checkConstraints: checkConstraintObject
20331
20037
  };
20332
20038
  }
20333
20039
  return {
@@ -20374,6 +20080,7 @@ The unique constraint ${source_default.underline.blue(
20374
20080
  let tablesCount = /* @__PURE__ */ new Set();
20375
20081
  let indexesCount = 0;
20376
20082
  let foreignKeysCount = 0;
20083
+ let checksCount = 0;
20377
20084
  const tableToPk = {};
20378
20085
  let tableToGeneratedColumnsInfo = {};
20379
20086
  for (const column7 of columns) {
@@ -20432,7 +20139,8 @@ The unique constraint ${source_default.underline.blue(
20432
20139
  compositePrimaryKeys: {},
20433
20140
  indexes: {},
20434
20141
  foreignKeys: {},
20435
- uniqueConstraints: {}
20142
+ uniqueConstraints: {},
20143
+ checkConstraints: {}
20436
20144
  };
20437
20145
  } else {
20438
20146
  result[tableName].columns[columnName] = newColumn;
@@ -20548,6 +20256,57 @@ WHERE
20548
20256
  progressCallback("indexes", indexesCount, "done");
20549
20257
  progressCallback("enums", 0, "done");
20550
20258
  }
20259
+ const namedCheckPattern = /CONSTRAINT\s*["']?(\w+)["']?\s*CHECK\s*\((.*?)\)/gi;
20260
+ const unnamedCheckPattern = /CHECK\s*\((.*?)\)/gi;
20261
+ let checkCounter = 0;
20262
+ const checkConstraints = {};
20263
+ const checks = await db.query(`SELECT name as "tableName", sql as "sql"
20264
+ FROM sqlite_master
20265
+ WHERE type = 'table' AND name != 'sqlite_sequence';`);
20266
+ for (const check2 of checks) {
20267
+ if (!tablesFilter(check2.tableName))
20268
+ continue;
20269
+ const { tableName, sql } = check2;
20270
+ let namedChecks = [...sql.matchAll(namedCheckPattern)];
20271
+ if (namedChecks.length > 0) {
20272
+ namedChecks.forEach(([_2, checkName, checkValue]) => {
20273
+ checkConstraints[checkName] = {
20274
+ name: checkName,
20275
+ value: checkValue.trim()
20276
+ };
20277
+ });
20278
+ } else {
20279
+ let unnamedChecks = [...sql.matchAll(unnamedCheckPattern)];
20280
+ unnamedChecks.forEach(([_2, checkValue]) => {
20281
+ let checkName = `${tableName}_check_${++checkCounter}`;
20282
+ checkConstraints[checkName] = {
20283
+ name: checkName,
20284
+ value: checkValue.trim()
20285
+ };
20286
+ });
20287
+ }
20288
+ checksCount += Object.values(checkConstraints).length;
20289
+ if (progressCallback) {
20290
+ progressCallback("checks", checksCount, "fetching");
20291
+ }
20292
+ const table4 = result[tableName];
20293
+ if (!table4) {
20294
+ result[tableName] = {
20295
+ name: tableName,
20296
+ columns: {},
20297
+ compositePrimaryKeys: {},
20298
+ indexes: {},
20299
+ foreignKeys: {},
20300
+ uniqueConstraints: {},
20301
+ checkConstraints
20302
+ };
20303
+ } else {
20304
+ result[tableName].checkConstraints = checkConstraints;
20305
+ }
20306
+ }
20307
+ if (progressCallback) {
20308
+ progressCallback("checks", checksCount, "done");
20309
+ }
20551
20310
  return {
20552
20311
  version: "6",
20553
20312
  dialect: "sqlite",
@@ -20599,10 +20358,10 @@ ${filenames.join("\n")}
20599
20358
  const filenames = prepareFilenames(path5);
20600
20359
  const { prepareFromPgImports: prepareFromPgImports2 } = await Promise.resolve().then(() => (init_pgImports(), pgImports_exports));
20601
20360
  const { generatePgSnapshot: generatePgSnapshot2 } = await Promise.resolve().then(() => (init_pgSerializer(), pgSerializer_exports));
20602
- const { tables, enums, schemas, sequences, views, matViews } = await prepareFromPgImports2(
20361
+ const { tables, enums, schemas, sequences } = await prepareFromPgImports2(
20603
20362
  filenames
20604
20363
  );
20605
- return generatePgSnapshot2(tables, enums, schemas, sequences, views, matViews, schemaFilter);
20364
+ return generatePgSnapshot2(tables, enums, schemas, sequences, schemaFilter);
20606
20365
  };
20607
20366
  serializeSQLite = async (path5) => {
20608
20367
  const filenames = prepareFilenames(path5);
@@ -23118,7 +22877,6 @@ function applyJsonDiff(json1, json2) {
23118
22877
  difference.tables = difference.tables || {};
23119
22878
  difference.enums = difference.enums || {};
23120
22879
  difference.sequences = difference.sequences || {};
23121
- difference.views = difference.views || {};
23122
22880
  const schemaKeys = Object.keys(difference.schemas);
23123
22881
  for (let key of schemaKeys) {
23124
22882
  if (key.endsWith("__added") || key.endsWith("__deleted")) {
@@ -23174,60 +22932,6 @@ function applyJsonDiff(json1, json2) {
23174
22932
  const alteredSequences = sequencesEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted")) && "values" in it[1]).map((it) => {
23175
22933
  return json2.sequences[it[0]];
23176
22934
  });
23177
- const viewsEntries = Object.entries(difference.views);
23178
- const alteredViews = viewsEntries.filter((it) => !(it[0].includes("__added") || it[0].includes("__deleted"))).map(
23179
- ([nameWithSchema, view2]) => {
23180
- const deletedWithOption = view2.with__deleted;
23181
- const addedWithOption = view2.with__added;
23182
- const deletedWith = Object.fromEntries(
23183
- Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__deleted")).map(([key, value]) => {
23184
- return [key.replace("__deleted", ""), value];
23185
- })
23186
- );
23187
- const addedWith = Object.fromEntries(
23188
- Object.entries(view2.with || {}).filter((it) => it[0].endsWith("__added")).map(([key, value]) => {
23189
- return [key.replace("__added", ""), value];
23190
- })
23191
- );
23192
- const alterWith = Object.fromEntries(
23193
- Object.entries(view2.with || {}).filter(
23194
- (it) => typeof it[1].__old !== "undefined" && typeof it[1].__new !== "undefined"
23195
- ).map(
23196
- (it) => {
23197
- return [it[0], it[1].__new];
23198
- }
23199
- )
23200
- );
23201
- const alteredSchema = view2.schema;
23202
- const alteredDefinition = view2.definition;
23203
- const alteredExisting = view2.isExisting;
23204
- const addedTablespace = view2.tablespace__added;
23205
- const droppedTablespace = view2.tablespace__deleted;
23206
- const alterTablespaceTo = view2.tablespace;
23207
- let alteredTablespace;
23208
- if (addedTablespace)
23209
- alteredTablespace = { __new: addedTablespace, __old: "pg_default" };
23210
- if (droppedTablespace)
23211
- alteredTablespace = { __new: "pg_default", __old: droppedTablespace };
23212
- if (alterTablespaceTo)
23213
- alteredTablespace = alterTablespaceTo;
23214
- return {
23215
- name: json2.views[nameWithSchema].name,
23216
- schema: json2.views[nameWithSchema].schema,
23217
- deletedWithOption,
23218
- addedWithOption,
23219
- alteredWith: {
23220
- deletedWith: Object.keys(deletedWith).length ? deletedWith : void 0,
23221
- addedWith: Object.keys(addedWith).length ? addedWith : void 0,
23222
- alterWith: Object.keys(alterWith).length ? alterWith : void 0
23223
- },
23224
- alteredSchema,
23225
- alteredDefinition,
23226
- alteredExisting,
23227
- alteredTablespace
23228
- };
23229
- }
23230
- );
23231
22935
  const alteredTablesWithColumns = Object.values(difference.tables).map(
23232
22936
  (table4) => {
23233
22937
  return findAlternationsInTable(table4);
@@ -23236,8 +22940,7 @@ function applyJsonDiff(json1, json2) {
23236
22940
  return {
23237
22941
  alteredTablesWithColumns,
23238
22942
  alteredEnums,
23239
- alteredSequences,
23240
- alteredViews
22943
+ alteredSequences
23241
22944
  };
23242
22945
  }
23243
22946
  var import_json_diff, mapArraysDiff, findAlternationsInTable, alternationsInColumn;
@@ -23342,6 +23045,21 @@ var init_jsonDiffer = __esm({
23342
23045
  return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
23343
23046
  })
23344
23047
  );
23048
+ const addedCheckConstraints = Object.fromEntries(
23049
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23050
+ return it[0].endsWith("__added");
23051
+ })
23052
+ );
23053
+ const deletedCheckConstraints = Object.fromEntries(
23054
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23055
+ return it[0].endsWith("__deleted");
23056
+ })
23057
+ );
23058
+ const alteredCheckConstraints = Object.fromEntries(
23059
+ Object.entries(table4.checkConstraints || {}).filter((it) => {
23060
+ return !it[0].endsWith("__deleted") && !it[0].endsWith("__added");
23061
+ })
23062
+ );
23345
23063
  const mappedAltered = altered.map((it) => alternationsInColumn(it)).filter(Boolean);
23346
23064
  return {
23347
23065
  name: table4.name,
@@ -23358,7 +23076,10 @@ var init_jsonDiffer = __esm({
23358
23076
  alteredCompositePKs,
23359
23077
  addedUniqueConstraints,
23360
23078
  deletedUniqueConstraints,
23361
- alteredUniqueConstraints
23079
+ alteredUniqueConstraints,
23080
+ addedCheckConstraints,
23081
+ deletedCheckConstraints,
23082
+ alteredCheckConstraints
23362
23083
  };
23363
23084
  };
23364
23085
  alternationsInColumn = (column7) => {
@@ -23612,6 +23333,32 @@ var init_jsonDiffer = __esm({
23612
23333
  };
23613
23334
  }
23614
23335
  return it;
23336
+ }).map((it) => {
23337
+ if ("" in it) {
23338
+ return {
23339
+ ...it,
23340
+ autoincrement: {
23341
+ type: "changed",
23342
+ old: it.autoincrement.__old,
23343
+ new: it.autoincrement.__new
23344
+ }
23345
+ };
23346
+ }
23347
+ if ("autoincrement__added" in it) {
23348
+ const { autoincrement__added, ...others } = it;
23349
+ return {
23350
+ ...others,
23351
+ autoincrement: { type: "added", value: it.autoincrement__added }
23352
+ };
23353
+ }
23354
+ if ("autoincrement__deleted" in it) {
23355
+ const { autoincrement__deleted, ...others } = it;
23356
+ return {
23357
+ ...others,
23358
+ autoincrement: { type: "deleted", value: it.autoincrement__deleted }
23359
+ };
23360
+ }
23361
+ return it;
23615
23362
  }).filter(Boolean);
23616
23363
  return result[0];
23617
23364
  };
@@ -23632,7 +23379,7 @@ function fromJson(statements, dialect7, action, json2) {
23632
23379
  }).filter((it) => it !== "");
23633
23380
  return result;
23634
23381
  }
23635
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgCreateViewConvertor, PgDropViewConvertor, PgRenameViewConvertor, PgAlterViewSchemaConvertor, PgAlterViewAddWithOptionConvertor, PgAlterViewDropWithOptionConvertor, PgAlterViewAlterTablespaceConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
23382
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, PgAlterTableAddCheckConstraintConvertor, PgAlterTableDeleteCheckConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, MySqlAlterTableAddCheckConstraintConvertor, MySqlAlterTableDeleteCheckConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
23636
23383
  var init_sqlgenerator = __esm({
23637
23384
  "src/sqlgenerator.ts"() {
23638
23385
  "use strict";
@@ -23694,7 +23441,7 @@ var init_sqlgenerator = __esm({
23694
23441
  return statement.type === "create_table" && dialect7 === "postgresql";
23695
23442
  }
23696
23443
  convert(st) {
23697
- const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints } = st;
23444
+ const { tableName, schema: schema5, columns, compositePKs, uniqueConstraints, checkConstraints } = st;
23698
23445
  let statement = "";
23699
23446
  const name = schema5 ? `"${schema5}"."${tableName}"` : `"${tableName}"`;
23700
23447
  statement += `CREATE TABLE IF NOT EXISTS ${name} (
@@ -23727,6 +23474,13 @@ var init_sqlgenerator = __esm({
23727
23474
  statement += ` CONSTRAINT "${unsquashedUnique.name}" UNIQUE${unsquashedUnique.nullsNotDistinct ? " NULLS NOT DISTINCT" : ""}("${unsquashedUnique.columns.join(`","`)}")`;
23728
23475
  }
23729
23476
  }
23477
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23478
+ for (const checkConstraint4 of checkConstraints) {
23479
+ statement += ",\n";
23480
+ const unsquashedCheck = PgSquasher.unsquashCheck(checkConstraint4);
23481
+ statement += ` CONSTRAINT "${unsquashedCheck.name}" CHECK (${unsquashedCheck.value})`;
23482
+ }
23483
+ }
23730
23484
  statement += `
23731
23485
  );`;
23732
23486
  statement += `
@@ -23744,6 +23498,7 @@ var init_sqlgenerator = __esm({
23744
23498
  tableName,
23745
23499
  columns,
23746
23500
  schema: schema5,
23501
+ checkConstraints,
23747
23502
  compositePKs,
23748
23503
  uniqueConstraints,
23749
23504
  internals
@@ -23778,6 +23533,13 @@ var init_sqlgenerator = __esm({
23778
23533
  statement += ` CONSTRAINT \`${unsquashedUnique.name}\` UNIQUE(${uniqueString})`;
23779
23534
  }
23780
23535
  }
23536
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23537
+ for (const checkConstraint4 of checkConstraints) {
23538
+ statement += ",\n";
23539
+ const unsquashedCheck = MySqlSquasher.unsquashCheck(checkConstraint4);
23540
+ statement += ` CONSTRAINT \`${unsquashedCheck.name}\` CHECK(${unsquashedCheck.value})`;
23541
+ }
23542
+ }
23781
23543
  statement += `
23782
23544
  );`;
23783
23545
  statement += `
@@ -23795,7 +23557,8 @@ var init_sqlgenerator = __esm({
23795
23557
  columns,
23796
23558
  referenceData,
23797
23559
  compositePKs,
23798
- uniqueConstraints
23560
+ uniqueConstraints,
23561
+ checkConstraints
23799
23562
  } = st;
23800
23563
  let statement = "";
23801
23564
  statement += `CREATE TABLE \`${tableName}\` (
@@ -23836,10 +23599,17 @@ var init_sqlgenerator = __esm({
23836
23599
  if (typeof uniqueConstraints !== "undefined" && uniqueConstraints.length > 0) {
23837
23600
  for (const uniqueConstraint4 of uniqueConstraints) {
23838
23601
  statement += ",\n";
23839
- const unsquashedUnique = MySqlSquasher.unsquashUnique(uniqueConstraint4);
23602
+ const unsquashedUnique = SQLiteSquasher.unsquashUnique(uniqueConstraint4);
23840
23603
  statement += ` CONSTRAINT ${unsquashedUnique.name} UNIQUE(\`${unsquashedUnique.columns.join(`\`,\``)}\`)`;
23841
23604
  }
23842
23605
  }
23606
+ if (typeof checkConstraints !== "undefined" && checkConstraints.length > 0) {
23607
+ for (const check2 of checkConstraints) {
23608
+ statement += ",\n";
23609
+ const { value, name } = SQLiteSquasher.unsquashCheck(check2);
23610
+ statement += ` CONSTRAINT "${name}" CHECK(${value})`;
23611
+ }
23612
+ }
23843
23613
  statement += `
23844
23614
  `;
23845
23615
  statement += `);`;
@@ -23848,108 +23618,6 @@ var init_sqlgenerator = __esm({
23848
23618
  return statement;
23849
23619
  }
23850
23620
  };
23851
- PgCreateViewConvertor = class extends Convertor {
23852
- can(statement, dialect7) {
23853
- return statement.type === "create_view" && dialect7 === "postgresql";
23854
- }
23855
- convert(st) {
23856
- const { definition, name: viewName, schema: schema5, with: withOption, materialized, withNoData, tablespace, using } = st;
23857
- const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
23858
- let statement = materialized ? `CREATE MATERIALIZED VIEW ${name}` : `CREATE VIEW ${name}`;
23859
- if (using)
23860
- statement += ` USING "${using}"`;
23861
- const options = [];
23862
- if (withOption) {
23863
- statement += ` WITH (`;
23864
- Object.entries(withOption).forEach(([key, value]) => {
23865
- if (typeof value === "undefined")
23866
- return;
23867
- options.push(`${key.snake_case()} = ${value}`);
23868
- });
23869
- statement += options.join(", ");
23870
- statement += `)`;
23871
- }
23872
- if (tablespace)
23873
- statement += ` TABLESPACE ${tablespace}`;
23874
- statement += ` AS (${definition})`;
23875
- if (withNoData)
23876
- statement += ` WITH NO DATA`;
23877
- statement += `;`;
23878
- return statement;
23879
- }
23880
- };
23881
- PgDropViewConvertor = class extends Convertor {
23882
- can(statement, dialect7) {
23883
- return statement.type === "drop_view" && dialect7 === "postgresql";
23884
- }
23885
- convert(st) {
23886
- const { name: viewName, schema: schema5, materialized } = st;
23887
- const name = schema5 ? `"${schema5}"."${viewName}"` : `"${viewName}"`;
23888
- return `DROP${materialized ? " MATERIALIZED" : ""} VIEW ${name};`;
23889
- }
23890
- };
23891
- PgRenameViewConvertor = class extends Convertor {
23892
- can(statement, dialect7) {
23893
- return statement.type === "rename_view" && dialect7 === "postgresql";
23894
- }
23895
- convert(st) {
23896
- const { nameFrom: from, nameTo: to, schema: schema5, materialized } = st;
23897
- const nameFrom = `"${schema5}"."${from}"`;
23898
- return `ALTER${materialized ? " MATERIALIZED" : ""} VIEW ${nameFrom} RENAME TO "${to}";`;
23899
- }
23900
- };
23901
- PgAlterViewSchemaConvertor = class extends Convertor {
23902
- can(statement, dialect7) {
23903
- return statement.type === "alter_view_alter_schema" && dialect7 === "postgresql";
23904
- }
23905
- convert(st) {
23906
- const { fromSchema, toSchema, name, materialized } = st;
23907
- const statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${fromSchema}"."${name}" SET SCHEMA "${toSchema}";`;
23908
- return statement;
23909
- }
23910
- };
23911
- PgAlterViewAddWithOptionConvertor = class extends Convertor {
23912
- can(statement, dialect7) {
23913
- return statement.type === "alter_view_add_with_option" && dialect7 === "postgresql";
23914
- }
23915
- convert(st) {
23916
- const { schema: schema5, with: withOption, name, materialized } = st;
23917
- let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" SET (`;
23918
- const options = [];
23919
- Object.entries(withOption).forEach(([key, value]) => {
23920
- options.push(`${key.snake_case()} = ${value}`);
23921
- });
23922
- statement += options.join(", ");
23923
- statement += `);`;
23924
- return statement;
23925
- }
23926
- };
23927
- PgAlterViewDropWithOptionConvertor = class extends Convertor {
23928
- can(statement, dialect7) {
23929
- return statement.type === "alter_view_drop_with_option" && dialect7 === "postgresql";
23930
- }
23931
- convert(st) {
23932
- const { schema: schema5, name, materialized, with: withOptions } = st;
23933
- let statement = `ALTER${materialized ? " MATERIALIZED" : ""} VIEW "${schema5}"."${name}" RESET (`;
23934
- const options = [];
23935
- Object.entries(withOptions).forEach(([key, value]) => {
23936
- options.push(`${key.snake_case()}`);
23937
- });
23938
- statement += options.join(", ");
23939
- statement += ");";
23940
- return statement;
23941
- }
23942
- };
23943
- PgAlterViewAlterTablespaceConvertor = class extends Convertor {
23944
- can(statement, dialect7) {
23945
- return statement.type === "alter_view_alter_tablespace" && dialect7 === "postgresql";
23946
- }
23947
- convert(st) {
23948
- const { schema: schema5, name, toTablespace } = st;
23949
- const statement = `ALTER MATERIALIZED VIEW "${schema5}"."${name}" SET TABLESPACE ${toTablespace};`;
23950
- return statement;
23951
- }
23952
- };
23953
23621
  PgAlterTableAlterColumnSetGenerated = class extends Convertor {
23954
23622
  can(statement, dialect7) {
23955
23623
  return statement.type === "alter_table_alter_column_set_identity" && dialect7 === "postgresql";
@@ -24041,6 +23709,25 @@ var init_sqlgenerator = __esm({
24041
23709
  return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${unsquashed.name}";`;
24042
23710
  }
24043
23711
  };
23712
+ PgAlterTableAddCheckConstraintConvertor = class extends Convertor {
23713
+ can(statement, dialect7) {
23714
+ return statement.type === "create_check_constraint" && dialect7 === "postgresql";
23715
+ }
23716
+ convert(statement) {
23717
+ const unsquashed = PgSquasher.unsquashCheck(statement.data);
23718
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
23719
+ return `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${unsquashed.name}" CHECK (${unsquashed.value});`;
23720
+ }
23721
+ };
23722
+ PgAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
23723
+ can(statement, dialect7) {
23724
+ return statement.type === "delete_check_constraint" && dialect7 === "postgresql";
23725
+ }
23726
+ convert(statement) {
23727
+ const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
23728
+ return `ALTER TABLE ${tableNameWithSchema} DROP CONSTRAINT "${statement.constraintName}";`;
23729
+ }
23730
+ };
24044
23731
  MySQLAlterTableAddUniqueConstraintConvertor = class extends Convertor {
24045
23732
  can(statement, dialect7) {
24046
23733
  return statement.type === "create_unique_constraint" && dialect7 === "mysql";
@@ -24059,6 +23746,25 @@ var init_sqlgenerator = __esm({
24059
23746
  return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
24060
23747
  }
24061
23748
  };
23749
+ MySqlAlterTableAddCheckConstraintConvertor = class extends Convertor {
23750
+ can(statement, dialect7) {
23751
+ return statement.type === "create_check_constraint" && dialect7 === "mysql";
23752
+ }
23753
+ convert(statement) {
23754
+ const unsquashed = MySqlSquasher.unsquashCheck(statement.data);
23755
+ const { tableName } = statement;
23756
+ return `ALTER TABLE \`${tableName}\` ADD CONSTRAINT \`${unsquashed.name}\` CHECK (${unsquashed.value});`;
23757
+ }
23758
+ };
23759
+ MySqlAlterTableDeleteCheckConstraintConvertor = class extends Convertor {
23760
+ can(statement, dialect7) {
23761
+ return statement.type === "delete_check_constraint" && dialect7 === "mysql";
23762
+ }
23763
+ convert(statement) {
23764
+ const { tableName } = statement;
23765
+ return `ALTER TABLE \`${tableName}\` DROP CONSTRAINT \`${statement.constraintName}\`;`;
23766
+ }
23767
+ };
24062
23768
  CreatePgSequenceConvertor = class extends Convertor {
24063
23769
  can(statement, dialect7) {
24064
23770
  return statement.type === "create_sequence" && dialect7 === "postgresql";
@@ -24613,7 +24319,7 @@ var init_sqlgenerator = __esm({
24613
24319
  };
24614
24320
  LibSQLModifyColumn = class extends Convertor {
24615
24321
  can(statement, dialect7) {
24616
- return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect7 === "turso";
24322
+ 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") && dialect7 === "turso";
24617
24323
  }
24618
24324
  convert(statement, json2) {
24619
24325
  const { tableName, columnName } = statement;
@@ -25203,18 +24909,22 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
25203
24909
  return statement.type === "recreate_table" && dialect7 === "sqlite";
25204
24910
  }
25205
24911
  convert(statement) {
25206
- const { tableName, columns, compositePKs, referenceData } = statement;
24912
+ const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
25207
24913
  const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
25208
24914
  const newTableName = `__new_${tableName}`;
25209
24915
  const sqlStatements = [];
25210
24916
  sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
24917
+ const mappedCheckConstraints = checkConstraints.map(
24918
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `'${newTableName}'.`)
24919
+ );
25211
24920
  sqlStatements.push(
25212
24921
  new SQLiteCreateTableConvertor().convert({
25213
24922
  type: "sqlite_create_table",
25214
24923
  tableName: newTableName,
25215
24924
  columns,
25216
24925
  referenceData,
25217
- compositePKs
24926
+ compositePKs,
24927
+ checkConstraints: mappedCheckConstraints
25218
24928
  })
25219
24929
  );
25220
24930
  sqlStatements.push(
@@ -25245,10 +24955,13 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
25245
24955
  return statement.type === "recreate_table" && dialect7 === "turso";
25246
24956
  }
25247
24957
  convert(statement) {
25248
- const { tableName, columns, compositePKs, referenceData } = statement;
24958
+ const { tableName, columns, compositePKs, referenceData, checkConstraints } = statement;
25249
24959
  const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
25250
24960
  const newTableName = `__new_${tableName}`;
25251
24961
  const sqlStatements = [];
24962
+ const mappedCheckConstraints = checkConstraints.map(
24963
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
24964
+ );
25252
24965
  sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
25253
24966
  sqlStatements.push(
25254
24967
  new SQLiteCreateTableConvertor().convert({
@@ -25256,7 +24969,8 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
25256
24969
  tableName: newTableName,
25257
24970
  columns,
25258
24971
  referenceData,
25259
- compositePKs
24972
+ compositePKs,
24973
+ checkConstraints: mappedCheckConstraints
25260
24974
  })
25261
24975
  );
25262
24976
  sqlStatements.push(
@@ -25288,13 +25002,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
25288
25002
  convertors.push(new SQLiteCreateTableConvertor());
25289
25003
  convertors.push(new SQLiteRecreateTableConvertor());
25290
25004
  convertors.push(new LibSQLRecreateTableConvertor());
25291
- convertors.push(new PgCreateViewConvertor());
25292
- convertors.push(new PgDropViewConvertor());
25293
- convertors.push(new PgRenameViewConvertor());
25294
- convertors.push(new PgAlterViewSchemaConvertor());
25295
- convertors.push(new PgAlterViewAddWithOptionConvertor());
25296
- convertors.push(new PgAlterViewDropWithOptionConvertor());
25297
- convertors.push(new PgAlterViewAlterTablespaceConvertor());
25298
25005
  convertors.push(new CreateTypeEnumConvertor());
25299
25006
  convertors.push(new CreatePgSequenceConvertor());
25300
25007
  convertors.push(new DropPgSequenceConvertor());
@@ -25319,6 +25026,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
25319
25026
  convertors.push(new PgAlterTableAlterColumnSetTypeConvertor());
25320
25027
  convertors.push(new PgAlterTableAddUniqueConstraintConvertor());
25321
25028
  convertors.push(new PgAlterTableDropUniqueConstraintConvertor());
25029
+ convertors.push(new PgAlterTableAddCheckConstraintConvertor());
25030
+ convertors.push(new PgAlterTableDeleteCheckConstraintConvertor());
25031
+ convertors.push(new MySqlAlterTableAddCheckConstraintConvertor());
25032
+ convertors.push(new MySqlAlterTableDeleteCheckConstraintConvertor());
25322
25033
  convertors.push(new MySQLAlterTableAddUniqueConstraintConvertor());
25323
25034
  convertors.push(new MySQLAlterTableDropUniqueConstraintConvertor());
25324
25035
  convertors.push(new CreatePgIndexConvertor());
@@ -25410,6 +25121,10 @@ var init_sqlitePushUtils = __esm({
25410
25121
  const compositePKs = Object.values(
25411
25122
  json.tables[tableName].compositePrimaryKeys
25412
25123
  ).map((it) => SQLiteSquasher.unsquashPK(it));
25124
+ const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
25125
+ const mappedCheckConstraints = checkConstraints.map(
25126
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
25127
+ );
25413
25128
  const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
25414
25129
  statements.push(
25415
25130
  new SQLiteCreateTableConvertor().convert({
@@ -25417,7 +25132,8 @@ var init_sqlitePushUtils = __esm({
25417
25132
  tableName: newTableName,
25418
25133
  columns: tableColumns,
25419
25134
  referenceData: fks,
25420
- compositePKs
25135
+ compositePKs,
25136
+ checkConstraints: mappedCheckConstraints
25421
25137
  })
25422
25138
  );
25423
25139
  if (!dataLoss) {
@@ -25629,7 +25345,7 @@ var init_sqlitePushUtils = __esm({
25629
25345
  });
25630
25346
 
25631
25347
  // src/jsonStatements.ts
25632
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql, preparePgCreateViewJson, preparePgDropViewJson, preparePgRenameViewJson, preparePgAlterViewAlterSchemaJson, preparePgAlterViewAddWithOptionJson, preparePgAlterViewDropWithOptionJson, preparePgAlterViewAlterTablespaceOptionJson;
25348
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCheckConstraint, prepareDeleteCheckConstraint, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
25633
25349
  var init_jsonStatements = __esm({
25634
25350
  "src/jsonStatements.ts"() {
25635
25351
  "use strict";
@@ -25640,7 +25356,7 @@ var init_jsonStatements = __esm({
25640
25356
  init_pgSchema();
25641
25357
  init_sqliteSchema();
25642
25358
  preparePgCreateTableJson = (table4, json2) => {
25643
- const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
25359
+ const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
25644
25360
  const tableKey2 = `${schema5 || "public"}.${name}`;
25645
25361
  const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey2].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
25646
25362
  return {
@@ -25650,11 +25366,12 @@ var init_jsonStatements = __esm({
25650
25366
  columns: Object.values(columns),
25651
25367
  compositePKs: Object.values(compositePrimaryKeys),
25652
25368
  compositePkName,
25653
- uniqueConstraints: Object.values(uniqueConstraints)
25369
+ uniqueConstraints: Object.values(uniqueConstraints),
25370
+ checkConstraints: Object.values(checkConstraints)
25654
25371
  };
25655
25372
  };
25656
25373
  prepareMySqlCreateTableJson = (table4, json2, internals) => {
25657
- const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints } = table4;
25374
+ const { name, schema: schema5, columns, compositePrimaryKeys, uniqueConstraints, checkConstraints } = table4;
25658
25375
  return {
25659
25376
  type: "create_table",
25660
25377
  tableName: name,
@@ -25663,11 +25380,12 @@ var init_jsonStatements = __esm({
25663
25380
  compositePKs: Object.values(compositePrimaryKeys),
25664
25381
  compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[MySqlSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name].name : "",
25665
25382
  uniqueConstraints: Object.values(uniqueConstraints),
25666
- internals
25383
+ internals,
25384
+ checkConstraints: Object.values(checkConstraints)
25667
25385
  };
25668
25386
  };
25669
25387
  prepareSQLiteCreateTable = (table4, action) => {
25670
- const { name, columns, uniqueConstraints } = table4;
25388
+ const { name, columns, uniqueConstraints, checkConstraints } = table4;
25671
25389
  const references2 = Object.values(table4.foreignKeys);
25672
25390
  const composites = Object.values(table4.compositePrimaryKeys).map(
25673
25391
  (it) => SQLiteSquasher.unsquashPK(it)
@@ -25681,7 +25399,8 @@ var init_jsonStatements = __esm({
25681
25399
  columns: Object.values(columns),
25682
25400
  referenceData: fks,
25683
25401
  compositePKs: composites,
25684
- uniqueConstraints: Object.values(uniqueConstraints)
25402
+ uniqueConstraints: Object.values(uniqueConstraints),
25403
+ checkConstraints: Object.values(checkConstraints)
25685
25404
  };
25686
25405
  };
25687
25406
  prepareDropTableJson = (table4) => {
@@ -26929,6 +26648,26 @@ var init_jsonStatements = __esm({
26929
26648
  };
26930
26649
  });
26931
26650
  };
26651
+ prepareAddCheckConstraint = (tableName, schema5, check2) => {
26652
+ return Object.values(check2).map((it) => {
26653
+ return {
26654
+ type: "create_check_constraint",
26655
+ tableName,
26656
+ data: it,
26657
+ schema: schema5
26658
+ };
26659
+ });
26660
+ };
26661
+ prepareDeleteCheckConstraint = (tableName, schema5, check2) => {
26662
+ return Object.values(check2).map((it) => {
26663
+ return {
26664
+ type: "delete_check_constraint",
26665
+ tableName,
26666
+ constraintName: PgSquasher.unsquashCheck(it).name,
26667
+ schema: schema5
26668
+ };
26669
+ });
26670
+ };
26932
26671
  prepareAddCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
26933
26672
  var _a, _b;
26934
26673
  const res = [];
@@ -26968,72 +26707,6 @@ var init_jsonStatements = __esm({
26968
26707
  };
26969
26708
  });
26970
26709
  };
26971
- preparePgCreateViewJson = (name, schema5, definition, materialized, withNoData = false, withOption, using, tablespace) => {
26972
- return {
26973
- type: "create_view",
26974
- name,
26975
- schema: schema5,
26976
- definition,
26977
- with: withOption,
26978
- materialized,
26979
- withNoData,
26980
- using,
26981
- tablespace
26982
- };
26983
- };
26984
- preparePgDropViewJson = (name, schema5, materialized) => {
26985
- return {
26986
- type: "drop_view",
26987
- name,
26988
- schema: schema5,
26989
- materialized
26990
- };
26991
- };
26992
- preparePgRenameViewJson = (to, from, schema5, materialized) => {
26993
- return {
26994
- type: "rename_view",
26995
- nameTo: to,
26996
- nameFrom: from,
26997
- schema: schema5,
26998
- materialized
26999
- };
27000
- };
27001
- preparePgAlterViewAlterSchemaJson = (to, from, name, materialized) => {
27002
- return {
27003
- type: "alter_view_alter_schema",
27004
- fromSchema: from,
27005
- toSchema: to,
27006
- name,
27007
- materialized
27008
- };
27009
- };
27010
- preparePgAlterViewAddWithOptionJson = (name, schema5, materialized, withOption) => {
27011
- return {
27012
- type: "alter_view_add_with_option",
27013
- name,
27014
- schema: schema5,
27015
- materialized,
27016
- with: withOption
27017
- };
27018
- };
27019
- preparePgAlterViewDropWithOptionJson = (name, schema5, materialized, withOption) => {
27020
- return {
27021
- type: "alter_view_drop_with_option",
27022
- name,
27023
- schema: schema5,
27024
- materialized,
27025
- with: withOption
27026
- };
27027
- };
27028
- preparePgAlterViewAlterTablespaceOptionJson = (name, schema5, materialized, to) => {
27029
- return {
27030
- type: "alter_view_alter_tablespace",
27031
- name,
27032
- schema: schema5,
27033
- materialized,
27034
- toTablespace: to
27035
- };
27036
- };
27037
26710
  }
27038
26711
  });
27039
26712
 
@@ -27045,7 +26718,7 @@ var init_statementCombiner = __esm({
27045
26718
  init_jsonStatements();
27046
26719
  init_sqliteSchema();
27047
26720
  prepareLibSQLRecreateTable = (table4, action) => {
27048
- const { name, columns, uniqueConstraints, indexes } = table4;
26721
+ const { name, columns, uniqueConstraints, indexes, checkConstraints } = table4;
27049
26722
  const composites = Object.values(table4.compositePrimaryKeys).map(
27050
26723
  (it) => SQLiteSquasher.unsquashPK(it)
27051
26724
  );
@@ -27060,7 +26733,8 @@ var init_statementCombiner = __esm({
27060
26733
  columns: Object.values(columns),
27061
26734
  compositePKs: composites,
27062
26735
  referenceData: fks,
27063
- uniqueConstraints: Object.values(uniqueConstraints)
26736
+ uniqueConstraints: Object.values(uniqueConstraints),
26737
+ checkConstraints: Object.values(checkConstraints)
27064
26738
  }
27065
26739
  ];
27066
26740
  if (Object.keys(indexes).length) {
@@ -27069,7 +26743,7 @@ var init_statementCombiner = __esm({
27069
26743
  return statements;
27070
26744
  };
27071
26745
  prepareSQLiteRecreateTable = (table4, action) => {
27072
- const { name, columns, uniqueConstraints, indexes } = table4;
26746
+ const { name, columns, uniqueConstraints, indexes, checkConstraints } = table4;
27073
26747
  const composites = Object.values(table4.compositePrimaryKeys).map(
27074
26748
  (it) => SQLiteSquasher.unsquashPK(it)
27075
26749
  );
@@ -27084,7 +26758,8 @@ var init_statementCombiner = __esm({
27084
26758
  columns: Object.values(columns),
27085
26759
  compositePKs: composites,
27086
26760
  referenceData: fks,
27087
- uniqueConstraints: Object.values(uniqueConstraints)
26761
+ uniqueConstraints: Object.values(uniqueConstraints),
26762
+ checkConstraints: Object.values(checkConstraints)
27088
26763
  }
27089
26764
  ];
27090
26765
  if (Object.keys(indexes).length) {
@@ -27095,7 +26770,7 @@ var init_statementCombiner = __esm({
27095
26770
  libSQLCombineStatements = (statements, json2, action) => {
27096
26771
  const newStatements = {};
27097
26772
  for (const statement of statements) {
27098
- 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") {
26773
+ 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") {
27099
26774
  const tableName2 = statement.tableName;
27100
26775
  const statementsForTable2 = newStatements[tableName2];
27101
26776
  if (!statementsForTable2) {
@@ -27236,16 +26911,16 @@ var init_statementCombiner = __esm({
27236
26911
  sqliteCombineStatements = (statements, json2, action) => {
27237
26912
  const newStatements = {};
27238
26913
  for (const statement of statements) {
27239
- 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") {
26914
+ 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") {
27240
26915
  const tableName2 = statement.tableName;
27241
26916
  const statementsForTable2 = newStatements[tableName2];
27242
26917
  if (!statementsForTable2) {
27243
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
26918
+ newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
27244
26919
  continue;
27245
26920
  }
27246
26921
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
27247
26922
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
27248
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
26923
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
27249
26924
  if (wasRename) {
27250
26925
  newStatements[tableName2].push(...preparedStatements);
27251
26926
  } else {
@@ -27259,12 +26934,12 @@ var init_statementCombiner = __esm({
27259
26934
  const tableName2 = statement.tableName;
27260
26935
  const statementsForTable2 = newStatements[tableName2];
27261
26936
  if (!statementsForTable2) {
27262
- newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
26937
+ newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
27263
26938
  continue;
27264
26939
  }
27265
26940
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
27266
26941
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
27267
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
26942
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
27268
26943
  if (wasRename) {
27269
26944
  newStatements[tableName2].push(...preparedStatements);
27270
26945
  } else {
@@ -27289,7 +26964,7 @@ var init_statementCombiner = __esm({
27289
26964
  }
27290
26965
  if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
27291
26966
  const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
27292
- const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
26967
+ const preparedStatements = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
27293
26968
  if (wasRename) {
27294
26969
  newStatements[tableName2].push(...preparedStatements);
27295
26970
  } else {
@@ -27319,7 +26994,7 @@ var init_statementCombiner = __esm({
27319
26994
  });
27320
26995
 
27321
26996
  // src/snapshotsDiffer.ts
27322
- var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, alteredViewSchema, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
26997
+ var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
27323
26998
  var init_snapshotsDiffer = __esm({
27324
26999
  "src/snapshotsDiffer.ts"() {
27325
27000
  "use strict";
@@ -27424,7 +27099,8 @@ var init_snapshotsDiffer = __esm({
27424
27099
  indexes: recordType(stringType(), stringType()),
27425
27100
  foreignKeys: recordType(stringType(), stringType()),
27426
27101
  compositePrimaryKeys: recordType(stringType(), stringType()).default({}),
27427
- uniqueConstraints: recordType(stringType(), stringType()).default({})
27102
+ uniqueConstraints: recordType(stringType(), stringType()).default({}),
27103
+ checkConstraints: recordType(stringType(), stringType()).default({})
27428
27104
  }).strict();
27429
27105
  alteredTableScheme = objectType({
27430
27106
  name: stringType(),
@@ -27465,40 +27141,27 @@ var init_snapshotsDiffer = __esm({
27465
27141
  __new: stringType(),
27466
27142
  __old: stringType()
27467
27143
  })
27144
+ ),
27145
+ addedCheckConstraints: recordType(
27146
+ stringType(),
27147
+ stringType()
27148
+ ),
27149
+ deletedCheckConstraints: recordType(
27150
+ stringType(),
27151
+ stringType()
27152
+ ),
27153
+ alteredCheckConstraints: recordType(
27154
+ stringType(),
27155
+ objectType({
27156
+ __new: stringType(),
27157
+ __old: stringType()
27158
+ })
27468
27159
  )
27469
27160
  }).strict();
27470
- alteredViewSchema = objectType({
27471
- name: stringType(),
27472
- schema: stringType(),
27473
- deletedWithOption: mergedViewWithOption.optional(),
27474
- addedWithOption: mergedViewWithOption.optional(),
27475
- alteredWith: objectType({
27476
- addedWith: mergedViewWithOption.optional(),
27477
- deletedWith: mergedViewWithOption.optional(),
27478
- alterWith: mergedViewWithOption.optional()
27479
- }).strict(),
27480
- alteredSchema: objectType({
27481
- __old: stringType(),
27482
- __new: stringType()
27483
- }).strict().optional(),
27484
- alteredDefinition: objectType({
27485
- __old: stringType(),
27486
- __new: stringType()
27487
- }).strict().optional(),
27488
- alteredExisting: objectType({
27489
- __old: booleanType(),
27490
- __new: booleanType()
27491
- }).strict().optional(),
27492
- alteredTablespace: objectType({
27493
- __old: stringType(),
27494
- __new: stringType()
27495
- }).strict().optional()
27496
- }).strict();
27497
27161
  diffResultScheme = objectType({
27498
27162
  alteredTablesWithColumns: alteredTableScheme.array(),
27499
27163
  alteredEnums: changedEnumSchema.array(),
27500
- alteredSequences: sequenceSquashed.array(),
27501
- alteredViews: alteredViewSchema.array()
27164
+ alteredSequences: sequenceSquashed.array()
27502
27165
  }).strict();
27503
27166
  diffResultSchemeMysql = objectType({
27504
27167
  alteredTablesWithColumns: alteredTableScheme.array(),
@@ -27553,7 +27216,7 @@ var init_snapshotsDiffer = __esm({
27553
27216
  }
27554
27217
  return column7;
27555
27218
  };
27556
- applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, viewsResolver2, prevFull, curFull, action) => {
27219
+ applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, sequencesResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
27557
27220
  const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
27558
27221
  const {
27559
27222
  created: createdSchemas,
@@ -27781,16 +27444,6 @@ var init_snapshotsDiffer = __esm({
27781
27444
  return [tableKey2, tableValue];
27782
27445
  }
27783
27446
  );
27784
- const viewsDiff = diffSchemasOrTables(json1.views, json2.views);
27785
- const {
27786
- created: createdViews,
27787
- deleted: deletedViews,
27788
- renamed: renamedViews,
27789
- moved: movedViews
27790
- } = await viewsResolver2({
27791
- created: viewsDiff.added,
27792
- deleted: viewsDiff.deleted
27793
- });
27794
27447
  const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
27795
27448
  const typedResult = diffResultScheme.parse(diffResult);
27796
27449
  const jsonStatements = [];
@@ -27843,6 +27496,8 @@ var init_snapshotsDiffer = __esm({
27843
27496
  schemaTo: it.schemaTo || "public"
27844
27497
  });
27845
27498
  }
27499
+ const jsonDeletedCheckConstraints = [];
27500
+ const jsonCreatedCheckConstraints = [];
27846
27501
  for (let it of alteredTables) {
27847
27502
  let addedColumns = [];
27848
27503
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -27882,6 +27537,8 @@ var init_snapshotsDiffer = __esm({
27882
27537
  let addedUniqueConstraints = [];
27883
27538
  let deletedUniqueConstraints = [];
27884
27539
  let alteredUniqueConstraints = [];
27540
+ let createCheckConstraints = [];
27541
+ let deleteCheckConstraints = [];
27885
27542
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
27886
27543
  it.name,
27887
27544
  it.schema,
@@ -27906,6 +27563,24 @@ var init_snapshotsDiffer = __esm({
27906
27563
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
27907
27564
  );
27908
27565
  }
27566
+ createCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
27567
+ deleteCheckConstraints = prepareDeleteCheckConstraint(
27568
+ it.name,
27569
+ it.schema,
27570
+ it.deletedCheckConstraints
27571
+ );
27572
+ if (it.alteredCheckConstraints && action !== "push") {
27573
+ const added = {};
27574
+ const deleted = {};
27575
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
27576
+ added[k] = it.alteredCheckConstraints[k].__new;
27577
+ deleted[k] = it.alteredCheckConstraints[k].__old;
27578
+ }
27579
+ createCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
27580
+ deleteCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
27581
+ }
27582
+ jsonCreatedCheckConstraints.push(...createCheckConstraints);
27583
+ jsonDeletedCheckConstraints.push(...deleteCheckConstraints);
27909
27584
  jsonAddedCompositePKs.push(...addedCompositePKs);
27910
27585
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
27911
27586
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
@@ -28043,127 +27718,6 @@ var init_snapshotsDiffer = __esm({
28043
27718
  const createTables = createdTables.map((it) => {
28044
27719
  return preparePgCreateTableJson(it, curFull);
28045
27720
  });
28046
- const createViews = [];
28047
- const dropViews = [];
28048
- const renameViews = [];
28049
- const alterViews = [];
28050
- createViews.push(
28051
- ...createdViews.filter((it) => !it.isExisting).map((it) => {
28052
- return preparePgCreateViewJson(
28053
- it.name,
28054
- it.schema,
28055
- it.definition,
28056
- it.materialized,
28057
- it.withNoData,
28058
- it.with,
28059
- it.using,
28060
- it.tablespace
28061
- );
28062
- })
28063
- );
28064
- dropViews.push(
28065
- ...deletedViews.filter((it) => !it.isExisting).map((it) => {
28066
- return preparePgDropViewJson(it.name, it.schema, it.materialized);
28067
- })
28068
- );
28069
- renameViews.push(
28070
- ...renamedViews.filter((it) => !it.to.isExisting).map((it) => {
28071
- return preparePgRenameViewJson(it.to.name, it.from.name, it.to.schema, it.to.materialized);
28072
- })
28073
- );
28074
- alterViews.push(
28075
- ...movedViews.filter((it) => !json2.views[`${it.schemaTo}.${it.name}`].isExisting).map((it) => {
28076
- return preparePgAlterViewAlterSchemaJson(
28077
- it.schemaTo,
28078
- it.schemaFrom,
28079
- it.name,
28080
- json2.views[`${it.schemaTo}.${it.name}`].materialized
28081
- );
28082
- })
28083
- );
28084
- const alteredViews = typedResult.alteredViews.filter((it) => !json2.views[`${it.schema}.${it.name}`].isExisting);
28085
- for (const alteredView of alteredViews) {
28086
- const viewKey = `${alteredView.schema}.${alteredView.name}`;
28087
- const { materialized, with: withOption, definition, withNoData, using, tablespace } = json2.views[viewKey];
28088
- if (alteredView.alteredExisting || alteredView.alteredDefinition && action !== "push") {
28089
- dropViews.push(preparePgDropViewJson(alteredView.name, alteredView.schema, materialized));
28090
- createViews.push(
28091
- preparePgCreateViewJson(
28092
- alteredView.name,
28093
- alteredView.schema,
28094
- definition,
28095
- materialized,
28096
- withNoData,
28097
- withOption,
28098
- using,
28099
- tablespace
28100
- )
28101
- );
28102
- continue;
28103
- }
28104
- if (alteredView.addedWithOption) {
28105
- alterViews.push(
28106
- preparePgAlterViewAddWithOptionJson(
28107
- alteredView.name,
28108
- alteredView.schema,
28109
- materialized,
28110
- alteredView.addedWithOption
28111
- )
28112
- );
28113
- }
28114
- if (alteredView.deletedWithOption) {
28115
- alterViews.push(
28116
- preparePgAlterViewDropWithOptionJson(
28117
- alteredView.name,
28118
- alteredView.schema,
28119
- materialized,
28120
- alteredView.deletedWithOption
28121
- )
28122
- );
28123
- }
28124
- if (alteredView.alteredWith) {
28125
- if (alteredView.alteredWith.addedWith) {
28126
- alterViews.push(
28127
- preparePgAlterViewAddWithOptionJson(
28128
- alteredView.name,
28129
- alteredView.schema,
28130
- materialized,
28131
- alteredView.alteredWith.addedWith
28132
- )
28133
- );
28134
- }
28135
- if (alteredView.alteredWith.deletedWith) {
28136
- alterViews.push(
28137
- preparePgAlterViewDropWithOptionJson(
28138
- alteredView.name,
28139
- alteredView.schema,
28140
- materialized,
28141
- alteredView.alteredWith.deletedWith
28142
- )
28143
- );
28144
- }
28145
- if (alteredView.alteredWith.alterWith) {
28146
- alterViews.push(
28147
- preparePgAlterViewAddWithOptionJson(
28148
- alteredView.name,
28149
- alteredView.schema,
28150
- materialized,
28151
- alteredView.alteredWith.alterWith
28152
- )
28153
- );
28154
- }
28155
- }
28156
- if (alteredView.alteredTablespace) {
28157
- alterViews.push(
28158
- preparePgAlterViewAlterTablespaceOptionJson(
28159
- alteredView.name,
28160
- alteredView.schema,
28161
- materialized,
28162
- alteredView.alteredTablespace.__new
28163
- )
28164
- );
28165
- }
28166
- }
28167
27721
  jsonStatements.push(...createSchemas);
28168
27722
  jsonStatements.push(...renameSchemas);
28169
27723
  jsonStatements.push(...createEnums);
@@ -28175,14 +27729,12 @@ var init_snapshotsDiffer = __esm({
28175
27729
  jsonStatements.push(...renameSequences);
28176
27730
  jsonStatements.push(...jsonAlterSequences);
28177
27731
  jsonStatements.push(...createTables);
28178
- jsonStatements.push(...dropViews);
28179
- jsonStatements.push(...renameViews);
28180
- jsonStatements.push(...alterViews);
28181
27732
  jsonStatements.push(...jsonDropTables);
28182
27733
  jsonStatements.push(...jsonSetTableSchemas);
28183
27734
  jsonStatements.push(...jsonRenameTables);
28184
27735
  jsonStatements.push(...jsonRenameColumnsStatements);
28185
27736
  jsonStatements.push(...jsonDeletedUniqueConstraints);
27737
+ jsonStatements.push(...jsonDeletedCheckConstraints);
28186
27738
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28187
27739
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
28188
27740
  jsonStatements.push(...jsonDeletedCompositePKs);
@@ -28196,8 +27748,8 @@ var init_snapshotsDiffer = __esm({
28196
27748
  jsonStatements.push(...jsonDropColumnsStatemets);
28197
27749
  jsonStatements.push(...jsonAlteredCompositePKs);
28198
27750
  jsonStatements.push(...jsonAddedUniqueConstraints);
27751
+ jsonStatements.push(...jsonCreatedCheckConstraints);
28199
27752
  jsonStatements.push(...jsonAlteredUniqueConstraints);
28200
- jsonStatements.push(...createViews);
28201
27753
  jsonStatements.push(...dropEnums);
28202
27754
  jsonStatements.push(...dropSequences);
28203
27755
  jsonStatements.push(...dropSchemas);
@@ -28360,6 +27912,8 @@ var init_snapshotsDiffer = __esm({
28360
27912
  const jsonAddedUniqueConstraints = [];
28361
27913
  const jsonDeletedUniqueConstraints = [];
28362
27914
  const jsonAlteredUniqueConstraints = [];
27915
+ const jsonCreatedCheckConstraints = [];
27916
+ const jsonDeletedCheckConstraints = [];
28363
27917
  const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
28364
27918
  const jsonAddColumnsStatemets = columnCreates.map((it) => _prepareAddColumns(it.table, "", it.columns)).flat();
28365
27919
  const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
@@ -28398,6 +27952,8 @@ var init_snapshotsDiffer = __esm({
28398
27952
  let addedUniqueConstraints = [];
28399
27953
  let deletedUniqueConstraints = [];
28400
27954
  let alteredUniqueConstraints = [];
27955
+ let createdCheckConstraints = [];
27956
+ let deletedCheckConstraints = [];
28401
27957
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
28402
27958
  it.name,
28403
27959
  it.schema,
@@ -28422,12 +27978,30 @@ var init_snapshotsDiffer = __esm({
28422
27978
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
28423
27979
  );
28424
27980
  }
27981
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
27982
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
27983
+ it.name,
27984
+ it.schema,
27985
+ it.deletedCheckConstraints
27986
+ );
27987
+ if (it.alteredCheckConstraints && action !== "push") {
27988
+ const added = {};
27989
+ const deleted = {};
27990
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
27991
+ added[k] = it.alteredCheckConstraints[k].__new;
27992
+ deleted[k] = it.alteredCheckConstraints[k].__old;
27993
+ }
27994
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
27995
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
27996
+ }
28425
27997
  jsonAddedCompositePKs.push(...addedCompositePKs);
28426
27998
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
28427
27999
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
28428
28000
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
28429
28001
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
28430
28002
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28003
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28004
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
28431
28005
  });
28432
28006
  const rColumns = jsonRenameColumnsStatements.map((it) => {
28433
28007
  const tableName = it.tableName;
@@ -28523,6 +28097,7 @@ var init_snapshotsDiffer = __esm({
28523
28097
  jsonStatements.push(...jsonRenameTables);
28524
28098
  jsonStatements.push(...jsonRenameColumnsStatements);
28525
28099
  jsonStatements.push(...jsonDeletedUniqueConstraints);
28100
+ jsonStatements.push(...jsonDeletedCheckConstraints);
28526
28101
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28527
28102
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
28528
28103
  jsonStatements.push(...jsonDeletedCompositePKs);
@@ -28533,11 +28108,11 @@ var init_snapshotsDiffer = __esm({
28533
28108
  jsonStatements.push(...jsonAddColumnsStatemets);
28534
28109
  jsonStatements.push(...jsonCreateReferencesForCreatedTables);
28535
28110
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
28111
+ jsonStatements.push(...jsonCreatedCheckConstraints);
28536
28112
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
28537
28113
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
28538
28114
  jsonStatements.push(...jsonDropColumnsStatemets);
28539
28115
  jsonStatements.push(...jsonAlteredCompositePKs);
28540
- jsonStatements.push(...jsonAddedUniqueConstraints);
28541
28116
  jsonStatements.push(...jsonAlteredUniqueConstraints);
28542
28117
  const sqlStatements = fromJson(jsonStatements, "mysql");
28543
28118
  const uniqueSqlStatements = [];
@@ -28665,6 +28240,8 @@ var init_snapshotsDiffer = __esm({
28665
28240
  const jsonAddedUniqueConstraints = [];
28666
28241
  const jsonDeletedUniqueConstraints = [];
28667
28242
  const jsonAlteredUniqueConstraints = [];
28243
+ const jsonDeletedCheckConstraints = [];
28244
+ const jsonCreatedCheckConstraints = [];
28668
28245
  allAltered.forEach((it) => {
28669
28246
  let addedColumns = [];
28670
28247
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -28721,12 +28298,56 @@ var init_snapshotsDiffer = __esm({
28721
28298
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
28722
28299
  );
28723
28300
  }
28301
+ let createdCheckConstraints = [];
28302
+ let deletedCheckConstraints = [];
28303
+ addedUniqueConstraints = prepareAddUniqueConstraintPg(
28304
+ it.name,
28305
+ it.schema,
28306
+ it.addedUniqueConstraints
28307
+ );
28308
+ deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
28309
+ it.name,
28310
+ it.schema,
28311
+ it.deletedUniqueConstraints
28312
+ );
28313
+ if (it.alteredUniqueConstraints) {
28314
+ const added = {};
28315
+ const deleted = {};
28316
+ for (const k of Object.keys(it.alteredUniqueConstraints)) {
28317
+ added[k] = it.alteredUniqueConstraints[k].__new;
28318
+ deleted[k] = it.alteredUniqueConstraints[k].__old;
28319
+ }
28320
+ addedUniqueConstraints.push(
28321
+ ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
28322
+ );
28323
+ deletedUniqueConstraints.push(
28324
+ ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
28325
+ );
28326
+ }
28327
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
28328
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
28329
+ it.name,
28330
+ it.schema,
28331
+ it.deletedCheckConstraints
28332
+ );
28333
+ if (it.alteredCheckConstraints && action !== "push") {
28334
+ const added = {};
28335
+ const deleted = {};
28336
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
28337
+ added[k] = it.alteredCheckConstraints[k].__new;
28338
+ deleted[k] = it.alteredCheckConstraints[k].__old;
28339
+ }
28340
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
28341
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
28342
+ }
28724
28343
  jsonAddedCompositePKs.push(...addedCompositePKs);
28725
28344
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
28726
28345
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
28727
28346
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
28728
28347
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
28729
28348
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28349
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28350
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
28730
28351
  });
28731
28352
  const rColumns = jsonRenameColumnsStatements.map((it) => {
28732
28353
  const tableName = it.tableName;
@@ -28811,6 +28432,7 @@ var init_snapshotsDiffer = __esm({
28811
28432
  jsonStatements.push(...jsonRenameTables);
28812
28433
  jsonStatements.push(...jsonRenameColumnsStatements);
28813
28434
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28435
+ jsonStatements.push(...jsonDeletedCheckConstraints);
28814
28436
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
28815
28437
  jsonStatements.push(...jsonDeletedCompositePKs);
28816
28438
  jsonStatements.push(...jsonTableAlternations);
@@ -28818,6 +28440,7 @@ var init_snapshotsDiffer = __esm({
28818
28440
  jsonStatements.push(...jsonAddColumnsStatemets);
28819
28441
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
28820
28442
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
28443
+ jsonStatements.push(...jsonCreatedCheckConstraints);
28821
28444
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
28822
28445
  jsonStatements.push(...jsonDropColumnsStatemets);
28823
28446
  jsonStatements.push(...jsonAlteredCompositePKs);
@@ -28961,6 +28584,8 @@ var init_snapshotsDiffer = __esm({
28961
28584
  const jsonAddedUniqueConstraints = [];
28962
28585
  const jsonDeletedUniqueConstraints = [];
28963
28586
  const jsonAlteredUniqueConstraints = [];
28587
+ const jsonDeletedCheckConstraints = [];
28588
+ const jsonCreatedCheckConstraints = [];
28964
28589
  allAltered.forEach((it) => {
28965
28590
  let addedColumns = [];
28966
28591
  for (const addedPkName of Object.keys(it.addedCompositePKs)) {
@@ -28993,6 +28618,8 @@ var init_snapshotsDiffer = __esm({
28993
28618
  let addedUniqueConstraints = [];
28994
28619
  let deletedUniqueConstraints = [];
28995
28620
  let alteredUniqueConstraints = [];
28621
+ let createdCheckConstraints = [];
28622
+ let deletedCheckConstraints = [];
28996
28623
  addedUniqueConstraints = prepareAddUniqueConstraintPg(
28997
28624
  it.name,
28998
28625
  it.schema,
@@ -29017,12 +28644,30 @@ var init_snapshotsDiffer = __esm({
29017
28644
  ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
29018
28645
  );
29019
28646
  }
28647
+ createdCheckConstraints = prepareAddCheckConstraint(it.name, it.schema, it.addedCheckConstraints);
28648
+ deletedCheckConstraints = prepareDeleteCheckConstraint(
28649
+ it.name,
28650
+ it.schema,
28651
+ it.deletedCheckConstraints
28652
+ );
28653
+ if (it.alteredCheckConstraints && action !== "push") {
28654
+ const added = {};
28655
+ const deleted = {};
28656
+ for (const k of Object.keys(it.alteredCheckConstraints)) {
28657
+ added[k] = it.alteredCheckConstraints[k].__new;
28658
+ deleted[k] = it.alteredCheckConstraints[k].__old;
28659
+ }
28660
+ createdCheckConstraints.push(...prepareAddCheckConstraint(it.name, it.schema, added));
28661
+ deletedCheckConstraints.push(...prepareDeleteCheckConstraint(it.name, it.schema, deleted));
28662
+ }
29020
28663
  jsonAddedCompositePKs.push(...addedCompositePKs);
29021
28664
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
29022
28665
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
29023
28666
  jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
29024
28667
  jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
29025
28668
  jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
28669
+ jsonCreatedCheckConstraints.push(...createdCheckConstraints);
28670
+ jsonDeletedCheckConstraints.push(...deletedCheckConstraints);
29026
28671
  });
29027
28672
  const jsonTableAlternations = allAltered.map((it) => {
29028
28673
  return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
@@ -29100,6 +28745,7 @@ var init_snapshotsDiffer = __esm({
29100
28745
  jsonStatements.push(...jsonRenameTables);
29101
28746
  jsonStatements.push(...jsonRenameColumnsStatements);
29102
28747
  jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
28748
+ jsonStatements.push(...jsonDeletedCheckConstraints);
29103
28749
  jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
29104
28750
  jsonStatements.push(...jsonDeletedCompositePKs);
29105
28751
  jsonStatements.push(...jsonTableAlternations);
@@ -29107,6 +28753,7 @@ var init_snapshotsDiffer = __esm({
29107
28753
  jsonStatements.push(...jsonAddColumnsStatemets);
29108
28754
  jsonStatements.push(...jsonCreateIndexesForCreatedTables);
29109
28755
  jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
28756
+ jsonStatements.push(...jsonCreatedCheckConstraints);
29110
28757
  jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
29111
28758
  jsonStatements.push(...jsonDropColumnsStatemets);
29112
28759
  jsonStatements.push(...jsonAlteredCompositePKs);
@@ -30476,10 +30123,9 @@ __export(migrate_exports, {
30476
30123
  schemasResolver: () => schemasResolver,
30477
30124
  sequencesResolver: () => sequencesResolver,
30478
30125
  tablesResolver: () => tablesResolver,
30479
- viewsResolver: () => viewsResolver,
30480
30126
  writeResult: () => writeResult
30481
30127
  });
30482
- var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, viewsResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
30128
+ var import_fs5, import_hanji3, import_path4, schemasResolver, tablesResolver, sequencesResolver, enumsResolver, columnsResolver, prepareAndMigratePg, preparePgPush, prepareMySQLPush, prepareAndMigrateMysql, prepareAndMigrateSqlite, prepareAndMigrateLibSQL, prepareSQLitePush, prepareLibSQLPush, promptColumnsConflicts, promptNamedWithSchemasConflict, promptSchemasConflict, BREAKPOINT, writeResult, embeddedMigrations, prepareSnapshotFolderName, two;
30483
30129
  var init_migrate = __esm({
30484
30130
  "src/cli/commands/migrate.ts"() {
30485
30131
  "use strict";
@@ -30526,24 +30172,6 @@ var init_migrate = __esm({
30526
30172
  throw e2;
30527
30173
  }
30528
30174
  };
30529
- viewsResolver = async (input) => {
30530
- try {
30531
- const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
30532
- input.created,
30533
- input.deleted,
30534
- "view"
30535
- );
30536
- return {
30537
- created,
30538
- deleted,
30539
- moved,
30540
- renamed
30541
- };
30542
- } catch (e2) {
30543
- console.error(e2);
30544
- throw e2;
30545
- }
30546
- };
30547
30175
  sequencesResolver = async (input) => {
30548
30176
  try {
30549
30177
  const { created, deleted, moved, renamed } = await promptNamedWithSchemasConflict(
@@ -30632,7 +30260,6 @@ var init_migrate = __esm({
30632
30260
  sequencesResolver,
30633
30261
  tablesResolver,
30634
30262
  columnsResolver,
30635
- viewsResolver,
30636
30263
  validatedPrev,
30637
30264
  validatedCur
30638
30265
  );
@@ -30667,7 +30294,6 @@ var init_migrate = __esm({
30667
30294
  sequencesResolver,
30668
30295
  tablesResolver,
30669
30296
  columnsResolver,
30670
- viewsResolver,
30671
30297
  validatedPrev,
30672
30298
  validatedCur,
30673
30299
  "push"
@@ -35489,20 +35115,20 @@ var require_ponyfill_es2018 = __commonJS({
35489
35115
  ;
35490
35116
  ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
35491
35117
  }
35492
- respondWithNewView(view2) {
35118
+ respondWithNewView(view) {
35493
35119
  if (!IsReadableStreamBYOBRequest(this)) {
35494
35120
  throw byobRequestBrandCheckException("respondWithNewView");
35495
35121
  }
35496
- assertRequiredArgument(view2, 1, "respondWithNewView");
35497
- if (!ArrayBuffer.isView(view2)) {
35122
+ assertRequiredArgument(view, 1, "respondWithNewView");
35123
+ if (!ArrayBuffer.isView(view)) {
35498
35124
  throw new TypeError("You can only respond with array buffer views");
35499
35125
  }
35500
35126
  if (this._associatedReadableByteStreamController === void 0) {
35501
35127
  throw new TypeError("This BYOB request has been invalidated");
35502
35128
  }
35503
- if (IsDetachedBuffer(view2.buffer))
35129
+ if (IsDetachedBuffer(view.buffer))
35504
35130
  ;
35505
- ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view2);
35131
+ ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
35506
35132
  }
35507
35133
  }
35508
35134
  Object.defineProperties(ReadableStreamBYOBRequest.prototype, {
@@ -35603,8 +35229,8 @@ var require_ponyfill_es2018 = __commonJS({
35603
35229
  const entry = this._queue.shift();
35604
35230
  this._queueTotalSize -= entry.byteLength;
35605
35231
  ReadableByteStreamControllerHandleQueueDrain(this);
35606
- const view2 = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
35607
- readRequest._chunkSteps(view2);
35232
+ const view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength);
35233
+ readRequest._chunkSteps(view);
35608
35234
  return;
35609
35235
  }
35610
35236
  const autoAllocateChunkSize = this._autoAllocateChunkSize;
@@ -35770,19 +35396,19 @@ var require_ponyfill_es2018 = __commonJS({
35770
35396
  }
35771
35397
  }
35772
35398
  }
35773
- function ReadableByteStreamControllerPullInto(controller, view2, readIntoRequest) {
35399
+ function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest) {
35774
35400
  const stream = controller._controlledReadableByteStream;
35775
35401
  let elementSize = 1;
35776
- if (view2.constructor !== DataView) {
35777
- elementSize = view2.constructor.BYTES_PER_ELEMENT;
35402
+ if (view.constructor !== DataView) {
35403
+ elementSize = view.constructor.BYTES_PER_ELEMENT;
35778
35404
  }
35779
- const ctor = view2.constructor;
35780
- const buffer = TransferArrayBuffer(view2.buffer);
35405
+ const ctor = view.constructor;
35406
+ const buffer = TransferArrayBuffer(view.buffer);
35781
35407
  const pullIntoDescriptor = {
35782
35408
  buffer,
35783
35409
  bufferByteLength: buffer.byteLength,
35784
- byteOffset: view2.byteOffset,
35785
- byteLength: view2.byteLength,
35410
+ byteOffset: view.byteOffset,
35411
+ byteLength: view.byteLength,
35786
35412
  bytesFilled: 0,
35787
35413
  elementSize,
35788
35414
  viewConstructor: ctor,
@@ -35950,9 +35576,9 @@ var require_ponyfill_es2018 = __commonJS({
35950
35576
  function ReadableByteStreamControllerGetBYOBRequest(controller) {
35951
35577
  if (controller._byobRequest === null && controller._pendingPullIntos.length > 0) {
35952
35578
  const firstDescriptor = controller._pendingPullIntos.peek();
35953
- const view2 = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
35579
+ const view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled);
35954
35580
  const byobRequest = Object.create(ReadableStreamBYOBRequest.prototype);
35955
- SetUpReadableStreamBYOBRequest(byobRequest, controller, view2);
35581
+ SetUpReadableStreamBYOBRequest(byobRequest, controller, view);
35956
35582
  controller._byobRequest = byobRequest;
35957
35583
  }
35958
35584
  return controller._byobRequest;
@@ -35985,29 +35611,29 @@ var require_ponyfill_es2018 = __commonJS({
35985
35611
  firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer);
35986
35612
  ReadableByteStreamControllerRespondInternal(controller, bytesWritten);
35987
35613
  }
35988
- function ReadableByteStreamControllerRespondWithNewView(controller, view2) {
35614
+ function ReadableByteStreamControllerRespondWithNewView(controller, view) {
35989
35615
  const firstDescriptor = controller._pendingPullIntos.peek();
35990
35616
  const state = controller._controlledReadableByteStream._state;
35991
35617
  if (state === "closed") {
35992
- if (view2.byteLength !== 0) {
35618
+ if (view.byteLength !== 0) {
35993
35619
  throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
35994
35620
  }
35995
35621
  } else {
35996
- if (view2.byteLength === 0) {
35622
+ if (view.byteLength === 0) {
35997
35623
  throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");
35998
35624
  }
35999
35625
  }
36000
- if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view2.byteOffset) {
35626
+ if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {
36001
35627
  throw new RangeError("The region specified by view does not match byobRequest");
36002
35628
  }
36003
- if (firstDescriptor.bufferByteLength !== view2.buffer.byteLength) {
35629
+ if (firstDescriptor.bufferByteLength !== view.buffer.byteLength) {
36004
35630
  throw new RangeError("The buffer of view has different capacity than byobRequest");
36005
35631
  }
36006
- if (firstDescriptor.bytesFilled + view2.byteLength > firstDescriptor.byteLength) {
35632
+ if (firstDescriptor.bytesFilled + view.byteLength > firstDescriptor.byteLength) {
36007
35633
  throw new RangeError("The region specified by view is larger than byobRequest");
36008
35634
  }
36009
- const viewByteLength = view2.byteLength;
36010
- firstDescriptor.buffer = TransferArrayBuffer(view2.buffer);
35635
+ const viewByteLength = view.byteLength;
35636
+ firstDescriptor.buffer = TransferArrayBuffer(view.buffer);
36011
35637
  ReadableByteStreamControllerRespondInternal(controller, viewByteLength);
36012
35638
  }
36013
35639
  function SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {
@@ -36053,9 +35679,9 @@ var require_ponyfill_es2018 = __commonJS({
36053
35679
  }
36054
35680
  SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize);
36055
35681
  }
36056
- function SetUpReadableStreamBYOBRequest(request, controller, view2) {
35682
+ function SetUpReadableStreamBYOBRequest(request, controller, view) {
36057
35683
  request._associatedReadableByteStreamController = controller;
36058
- request._view = view2;
35684
+ request._view = view;
36059
35685
  }
36060
35686
  function byobRequestBrandCheckException(name) {
36061
35687
  return new TypeError(`ReadableStreamBYOBRequest.prototype.${name} can only be used on a ReadableStreamBYOBRequest`);
@@ -36131,20 +35757,20 @@ var require_ponyfill_es2018 = __commonJS({
36131
35757
  *
36132
35758
  * If reading a chunk causes the queue to become empty, more data will be pulled from the underlying source.
36133
35759
  */
36134
- read(view2) {
35760
+ read(view) {
36135
35761
  if (!IsReadableStreamBYOBReader(this)) {
36136
35762
  return promiseRejectedWith(byobReaderBrandCheckException("read"));
36137
35763
  }
36138
- if (!ArrayBuffer.isView(view2)) {
35764
+ if (!ArrayBuffer.isView(view)) {
36139
35765
  return promiseRejectedWith(new TypeError("view must be an array buffer view"));
36140
35766
  }
36141
- if (view2.byteLength === 0) {
35767
+ if (view.byteLength === 0) {
36142
35768
  return promiseRejectedWith(new TypeError("view must have non-zero byteLength"));
36143
35769
  }
36144
- if (view2.buffer.byteLength === 0) {
35770
+ if (view.buffer.byteLength === 0) {
36145
35771
  return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
36146
35772
  }
36147
- if (IsDetachedBuffer(view2.buffer))
35773
+ if (IsDetachedBuffer(view.buffer))
36148
35774
  ;
36149
35775
  if (this._ownerReadableStream === void 0) {
36150
35776
  return promiseRejectedWith(readerLockException("read from"));
@@ -36160,7 +35786,7 @@ var require_ponyfill_es2018 = __commonJS({
36160
35786
  _closeSteps: (chunk) => resolvePromise({ value: chunk, done: true }),
36161
35787
  _errorSteps: (e2) => rejectPromise(e2)
36162
35788
  };
36163
- ReadableStreamBYOBReaderRead(this, view2, readIntoRequest);
35789
+ ReadableStreamBYOBReaderRead(this, view, readIntoRequest);
36164
35790
  return promise;
36165
35791
  }
36166
35792
  /**
@@ -36206,13 +35832,13 @@ var require_ponyfill_es2018 = __commonJS({
36206
35832
  }
36207
35833
  return x2 instanceof ReadableStreamBYOBReader;
36208
35834
  }
36209
- function ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest) {
35835
+ function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
36210
35836
  const stream = reader._ownerReadableStream;
36211
35837
  stream._disturbed = true;
36212
35838
  if (stream._state === "errored") {
36213
35839
  readIntoRequest._errorSteps(stream._storedError);
36214
35840
  } else {
36215
- ReadableByteStreamControllerPullInto(stream._readableStreamController, view2, readIntoRequest);
35841
+ ReadableByteStreamControllerPullInto(stream._readableStreamController, view, readIntoRequest);
36216
35842
  }
36217
35843
  }
36218
35844
  function byobReaderBrandCheckException(name) {
@@ -37761,7 +37387,7 @@ var require_ponyfill_es2018 = __commonJS({
37761
37387
  };
37762
37388
  ReadableStreamDefaultReaderRead(reader, readRequest);
37763
37389
  }
37764
- function pullWithBYOBReader(view2, forBranch2) {
37390
+ function pullWithBYOBReader(view, forBranch2) {
37765
37391
  if (IsReadableStreamDefaultReader(reader)) {
37766
37392
  ReadableStreamReaderGenericRelease(reader);
37767
37393
  reader = AcquireReadableStreamBYOBReader(stream);
@@ -37827,7 +37453,7 @@ var require_ponyfill_es2018 = __commonJS({
37827
37453
  reading = false;
37828
37454
  }
37829
37455
  };
37830
- ReadableStreamBYOBReaderRead(reader, view2, readIntoRequest);
37456
+ ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
37831
37457
  }
37832
37458
  function pull1Algorithm() {
37833
37459
  if (reading) {
@@ -52686,15 +52312,15 @@ var require_dist_cjs36 = __commonJS({
52686
52312
  throw new Error("Int64 buffers must be exactly 8 bytes");
52687
52313
  }
52688
52314
  }
52689
- static fromNumber(number2) {
52690
- if (number2 > 9223372036854776e3 || number2 < -9223372036854776e3) {
52691
- throw new Error(`${number2} is too large (or, if negative, too small) to represent as an Int64`);
52315
+ static fromNumber(number3) {
52316
+ if (number3 > 9223372036854776e3 || number3 < -9223372036854776e3) {
52317
+ throw new Error(`${number3} is too large (or, if negative, too small) to represent as an Int64`);
52692
52318
  }
52693
52319
  const bytes = new Uint8Array(8);
52694
- for (let i2 = 7, remaining = Math.abs(Math.round(number2)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
52320
+ for (let i2 = 7, remaining = Math.abs(Math.round(number3)); i2 > -1 && remaining > 0; i2--, remaining /= 256) {
52695
52321
  bytes[i2] = remaining;
52696
52322
  }
52697
- if (number2 < 0) {
52323
+ if (number3 < 0) {
52698
52324
  negate(bytes);
52699
52325
  }
52700
52326
  return new _Int642(bytes);
@@ -64125,16 +63751,16 @@ var require_map_stream = __commonJS({
64125
63751
  var writeQueue = {};
64126
63752
  stream.writable = true;
64127
63753
  stream.readable = true;
64128
- function queueData(data, number2) {
63754
+ function queueData(data, number3) {
64129
63755
  var nextToWrite = lastWritten + 1;
64130
- if (number2 === nextToWrite) {
63756
+ if (number3 === nextToWrite) {
64131
63757
  if (data !== void 0) {
64132
63758
  stream.emit.apply(stream, ["data", data]);
64133
63759
  }
64134
63760
  lastWritten++;
64135
63761
  nextToWrite++;
64136
63762
  } else {
64137
- writeQueue[number2] = data;
63763
+ writeQueue[number3] = data;
64138
63764
  }
64139
63765
  if (writeQueue.hasOwnProperty(nextToWrite)) {
64140
63766
  var dataToWrite = writeQueue[nextToWrite];
@@ -64149,21 +63775,21 @@ var require_map_stream = __commonJS({
64149
63775
  end();
64150
63776
  }
64151
63777
  }
64152
- function next(err2, data, number2) {
63778
+ function next(err2, data, number3) {
64153
63779
  if (destroyed)
64154
63780
  return;
64155
63781
  inNext = true;
64156
63782
  if (!err2 || self2.opts.failures) {
64157
- queueData(data, number2);
63783
+ queueData(data, number3);
64158
63784
  }
64159
63785
  if (err2) {
64160
63786
  stream.emit.apply(stream, [errorEventName, err2]);
64161
63787
  }
64162
63788
  inNext = false;
64163
63789
  }
64164
- function wrappedMapper(input, number2, callback) {
63790
+ function wrappedMapper(input, number3, callback) {
64165
63791
  return mapper.call(null, input, function(err2, data) {
64166
- callback(err2, data, number2);
63792
+ callback(err2, data, number3);
64167
63793
  });
64168
63794
  }
64169
63795
  stream.write = function(data) {
@@ -77995,7 +77621,7 @@ var init_selector_ui = __esm({
77995
77621
  });
77996
77622
 
77997
77623
  // src/cli/commands/libSqlPushUtils.ts
77998
- var getOldTableName2, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
77624
+ var getOldTableName3, _moveDataStatements2, libSqlLogSuggestionsAndReturn;
77999
77625
  var init_libSqlPushUtils = __esm({
78000
77626
  "src/cli/commands/libSqlPushUtils.ts"() {
78001
77627
  "use strict";
@@ -78003,7 +77629,7 @@ var init_libSqlPushUtils = __esm({
78003
77629
  init_utils();
78004
77630
  init_sqliteSchema();
78005
77631
  init_sqlgenerator();
78006
- getOldTableName2 = (tableName, meta) => {
77632
+ getOldTableName3 = (tableName, meta) => {
78007
77633
  for (const key of Object.keys(meta.tables)) {
78008
77634
  const value = meta.tables[key];
78009
77635
  if (`"${tableName}"` === value) {
@@ -78020,14 +77646,19 @@ var init_libSqlPushUtils = __esm({
78020
77646
  const compositePKs = Object.values(
78021
77647
  json.tables[tableName].compositePrimaryKeys
78022
77648
  ).map((it) => SQLiteSquasher.unsquashPK(it));
77649
+ const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
78023
77650
  const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
77651
+ const mappedCheckConstraints = checkConstraints.map(
77652
+ (it) => it.replaceAll(`"${tableName}".`, `"${newTableName}".`).replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`).replaceAll(`${tableName}.`, `${newTableName}.`).replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
77653
+ );
78024
77654
  statements.push(
78025
77655
  new SQLiteCreateTableConvertor().convert({
78026
77656
  type: "sqlite_create_table",
78027
77657
  tableName: newTableName,
78028
77658
  columns: tableColumns,
78029
77659
  referenceData: fks,
78030
- compositePKs
77660
+ compositePKs,
77661
+ checkConstraints: mappedCheckConstraints
78031
77662
  })
78032
77663
  );
78033
77664
  if (!dataLoss) {
@@ -78158,7 +77789,7 @@ var init_libSqlPushUtils = __esm({
78158
77789
  } else if (statement.type === "recreate_table") {
78159
77790
  const tableName = statement.tableName;
78160
77791
  let dataLoss = false;
78161
- const oldTableName = getOldTableName2(tableName, meta);
77792
+ const oldTableName = getOldTableName3(tableName, meta);
78162
77793
  const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
78163
77794
  const currentColumnNames = Object.keys(json2.tables[tableName].columns);
78164
77795
  const { removedColumns, addedColumns } = findAddedAndRemoved(
@@ -79918,7 +79549,7 @@ var init_pgIntrospect = __esm({
79918
79549
  });
79919
79550
 
79920
79551
  // src/introspect-sqlite.ts
79921
- var import_casing, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTablePKs, createTableFKs;
79552
+ var import_casing, sqliteImportsList, indexName3, objToStatement2, relations, escapeColumnKey, withCasing, dbColumnName, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, column4, createTableColumns, createTableIndexes, createTableUniques, createTableChecks, createTablePKs, createTableFKs;
79922
79553
  var init_introspect_sqlite = __esm({
79923
79554
  "src/introspect-sqlite.ts"() {
79924
79555
  "use strict";
@@ -79988,10 +79619,14 @@ var init_introspect_sqlite = __esm({
79988
79619
  const uniqueImports = Object.values(it.uniqueConstraints).map(
79989
79620
  (it2) => "unique"
79990
79621
  );
79622
+ const checkImports = Object.values(it.checkConstraints).map(
79623
+ (it2) => "check"
79624
+ );
79991
79625
  res.sqlite.push(...idxImports);
79992
79626
  res.sqlite.push(...fkImpots);
79993
79627
  res.sqlite.push(...pkImports);
79994
79628
  res.sqlite.push(...uniqueImports);
79629
+ res.sqlite.push(...checkImports);
79995
79630
  const columnImports = Object.values(it.columns).map((col) => {
79996
79631
  return col.type;
79997
79632
  }).filter((type) => {
@@ -80024,7 +79659,7 @@ var init_introspect_sqlite = __esm({
80024
79659
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
80025
79660
  return it.columnsFrom.length > 1 || isSelf(it);
80026
79661
  });
80027
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
79662
+ 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) {
80028
79663
  statement += ",\n";
80029
79664
  statement += "(table) => {\n";
80030
79665
  statement += " return {\n";
@@ -80042,6 +79677,10 @@ var init_introspect_sqlite = __esm({
80042
79677
  Object.values(table4.uniqueConstraints),
80043
79678
  casing2
80044
79679
  );
79680
+ statement += createTableChecks(
79681
+ Object.values(table4.checkConstraints),
79682
+ casing2
79683
+ );
80045
79684
  statement += " }\n";
80046
79685
  statement += "}";
80047
79686
  }
@@ -80193,6 +79832,19 @@ var init_introspect_sqlite = __esm({
80193
79832
  statement += `"${it.name}")`;
80194
79833
  statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing2)}`).join(", ")}),`;
80195
79834
  statement += `
79835
+ `;
79836
+ });
79837
+ return statement;
79838
+ };
79839
+ createTableChecks = (checks, casing2) => {
79840
+ let statement = "";
79841
+ checks.forEach((it) => {
79842
+ const checkKey = withCasing(it.name, casing2);
79843
+ statement += ` ${checkKey}: `;
79844
+ statement += "check(";
79845
+ statement += `"${it.name}", `;
79846
+ statement += `sql\`${it.value}\`)`;
79847
+ statement += `,
80196
79848
  `;
80197
79849
  });
80198
79850
  return statement;
@@ -81041,7 +80693,7 @@ var require_pluralize = __commonJS({
81041
80693
  });
81042
80694
 
81043
80695
  // src/introspect-mysql.ts
81044
- var import_casing2, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTablePKs2, createTableFKs2;
80696
+ var import_casing2, mysqlImportsList, objToStatement22, timeConfig, binaryConfig, importsPatch, relations2, escapeColumnKey2, prepareCasing, dbColumnName2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, mapColumnDefaultForJson, column5, createTableColumns2, createTableIndexes2, createTableUniques2, createTableChecks2, createTablePKs2, createTableFKs2;
81045
80697
  var init_introspect_mysql = __esm({
81046
80698
  "src/introspect-mysql.ts"() {
81047
80699
  "use strict";
@@ -81156,10 +80808,14 @@ var init_introspect_mysql = __esm({
81156
80808
  const uniqueImports = Object.values(it.uniqueConstraints).map(
81157
80809
  (it2) => "unique"
81158
80810
  );
80811
+ const checkImports = Object.values(it.checkConstraint).map(
80812
+ (it2) => "check"
80813
+ );
81159
80814
  res.mysql.push(...idxImports);
81160
80815
  res.mysql.push(...fkImpots);
81161
80816
  res.mysql.push(...pkImports);
81162
80817
  res.mysql.push(...uniqueImports);
80818
+ res.mysql.push(...checkImports);
81163
80819
  const columnImports = Object.values(it.columns).map((col) => {
81164
80820
  let patched = importsPatch[col.type] ?? col.type;
81165
80821
  patched = patched.startsWith("varchar(") ? "varchar" : patched;
@@ -81205,7 +80861,7 @@ var init_introspect_mysql = __esm({
81205
80861
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
81206
80862
  return it.columnsFrom.length > 1 || isSelf2(it);
81207
80863
  });
81208
- if (Object.keys(table4.indexes).length > 0 || filteredFKs.length > 0 || Object.keys(table4.compositePrimaryKeys).length > 0 || Object.keys(table4.uniqueConstraints).length > 0) {
80864
+ 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) {
81209
80865
  statement += ",\n";
81210
80866
  statement += "(table) => {\n";
81211
80867
  statement += " return {\n";
@@ -81223,6 +80879,10 @@ var init_introspect_mysql = __esm({
81223
80879
  Object.values(table4.uniqueConstraints),
81224
80880
  withCasing4
81225
80881
  );
80882
+ statement += createTableChecks2(
80883
+ Object.values(table4.checkConstraint),
80884
+ withCasing4
80885
+ );
81226
80886
  statement += " }\n";
81227
80887
  statement += "}";
81228
80888
  }
@@ -81562,6 +81222,19 @@ import { sql } from "drizzle-orm"
81562
81222
  statement += `"${it.name}")`;
81563
81223
  statement += `.on(${it.columns.map((it2) => `table.${casing2(it2)}`).join(", ")}),`;
81564
81224
  statement += `
81225
+ `;
81226
+ });
81227
+ return statement;
81228
+ };
81229
+ createTableChecks2 = (checks, casing2) => {
81230
+ let statement = "";
81231
+ checks.forEach((it) => {
81232
+ const checkKey = casing2(it.name);
81233
+ statement += ` ${checkKey}: `;
81234
+ statement += "check(";
81235
+ statement += `"${it.name}", `;
81236
+ statement += `sql\`${it.value.replace(/`/g, "\\`")}\`)`;
81237
+ statement += `,
81565
81238
  `;
81566
81239
  });
81567
81240
  return statement;
@@ -81632,7 +81305,7 @@ function generateIdentityParams(identity) {
81632
81305
  }
81633
81306
  return `.generatedByDefaultAsIdentity(${paramsObj})`;
81634
81307
  }
81635
- var import_drizzle_orm9, import_relations, import_casing3, pgImportsList, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, mapColumnDefault3, importsPatch2, relations3, escapeColumnKey3, withCasing2, dbColumnName3, paramNameFor, schemaToTypeScript3, isCyclic3, isSelf3, buildArrayDefault, mapDefault, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableUniques3, createTableFKs3;
81308
+ var import_drizzle_orm9, import_relations, import_casing3, 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;
81636
81309
  var init_introspect_pg = __esm({
81637
81310
  "src/introspect-pg.ts"() {
81638
81311
  "use strict";
@@ -81810,6 +81483,9 @@ var init_introspect_pg = __esm({
81810
81483
  const uniqueImports = Object.values(it.uniqueConstraints).map(
81811
81484
  (it2) => "unique"
81812
81485
  );
81486
+ const checkImports = Object.values(it.checkConstraints).map(
81487
+ (it2) => "check"
81488
+ );
81813
81489
  if (it.schema && it.schema !== "public" && it.schema !== "") {
81814
81490
  res.pg.push("pgSchema");
81815
81491
  }
@@ -81817,6 +81493,7 @@ var init_introspect_pg = __esm({
81817
81493
  res.pg.push(...fkImpots);
81818
81494
  res.pg.push(...pkImports);
81819
81495
  res.pg.push(...uniqueImports);
81496
+ res.pg.push(...checkImports);
81820
81497
  const columnImports = Object.values(it.columns).map((col) => {
81821
81498
  let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
81822
81499
  patched = patched === "double precision" ? "doublePrecision" : patched;
@@ -81836,30 +81513,6 @@ var init_introspect_pg = __esm({
81836
81513
  },
81837
81514
  { pg: [] }
81838
81515
  );
81839
- Object.values(schema5.views).forEach((it) => {
81840
- if (it.schema && it.schema !== "public" && it.schema !== "") {
81841
- imports.pg.push("pgSchema");
81842
- } else if (it.schema === "public") {
81843
- it.materialized ? imports.pg.push("pgMaterializedView") : imports.pg.push("pgView");
81844
- }
81845
- Object.values(it.columns).forEach(() => {
81846
- const columnImports = Object.values(it.columns).map((col) => {
81847
- let patched = (importsPatch2[col.type] || col.type).replace("[]", "");
81848
- patched = patched === "double precision" ? "doublePrecision" : patched;
81849
- patched = patched.startsWith("varchar(") ? "varchar" : patched;
81850
- patched = patched.startsWith("char(") ? "char" : patched;
81851
- patched = patched.startsWith("numeric(") ? "numeric" : patched;
81852
- patched = patched.startsWith("time(") ? "time" : patched;
81853
- patched = patched.startsWith("timestamp(") ? "timestamp" : patched;
81854
- patched = patched.startsWith("vector(") ? "vector" : patched;
81855
- patched = patched.startsWith("geometry(") ? "geometry" : patched;
81856
- return patched;
81857
- }).filter((type) => {
81858
- return pgImportsList.has(type);
81859
- });
81860
- imports.pg.push(...columnImports);
81861
- });
81862
- });
81863
81516
  Object.values(schema5.sequences).forEach((it) => {
81864
81517
  if (it.schema && it.schema !== "public" && it.schema !== "") {
81865
81518
  imports.pg.push("pgSchema");
@@ -81930,7 +81583,7 @@ var init_introspect_pg = __esm({
81930
81583
  schema5.internal
81931
81584
  );
81932
81585
  statement += "}";
81933
- 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) {
81586
+ 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) {
81934
81587
  statement += ",\n";
81935
81588
  statement += "(table) => {\n";
81936
81589
  statement += " return {\n";
@@ -81948,34 +81601,16 @@ var init_introspect_pg = __esm({
81948
81601
  Object.values(table4.uniqueConstraints),
81949
81602
  casing2
81950
81603
  );
81604
+ statement += createTableChecks3(
81605
+ Object.values(table4.checkConstraints),
81606
+ casing2
81607
+ );
81951
81608
  statement += " }\n";
81952
81609
  statement += "}";
81953
81610
  }
81954
81611
  statement += ");";
81955
81612
  return statement;
81956
81613
  });
81957
- const viewsStatements = Object.values(schema5.views).map((it) => {
81958
- const viewSchema = schemas[it.schema];
81959
- const paramName = paramNameFor(it.name, viewSchema);
81960
- const func = viewSchema ? it.materialized ? `${viewSchema}.materializedView` : `${viewSchema}.view` : it.materialized ? "pgMaterializedView" : "pgView";
81961
- const withOption = it.with ?? "";
81962
- const as = `sql\`${it.definition}\``;
81963
- const tablespace = it.tablespace ?? "";
81964
- const columns = createTableColumns3(
81965
- "",
81966
- Object.values(it.columns),
81967
- [],
81968
- enumTypes,
81969
- schemas,
81970
- casing2,
81971
- schema5.internal
81972
- );
81973
- let statement = `export const ${withCasing2(paramName, casing2)} = ${func}("${it.name}", {${columns}})`;
81974
- statement += tablespace ? `.tablespace("${tablespace}")` : "";
81975
- statement += withOption ? `.with(${JSON.stringify(withOption)})` : "";
81976
- statement += `.as(${as});`;
81977
- return statement;
81978
- }).join("\n\n");
81979
81614
  const uniquePgImports = ["pgTable", ...new Set(imports.pg)];
81980
81615
  const importsTs = `import { ${uniquePgImports.join(
81981
81616
  ", "
@@ -81988,8 +81623,6 @@ var init_introspect_pg = __esm({
81988
81623
  decalrations += sequencesStatements;
81989
81624
  decalrations += "\n";
81990
81625
  decalrations += tableStatements.join("\n\n");
81991
- decalrations += "\n";
81992
- decalrations += viewsStatements;
81993
81626
  const file = importsTs + decalrations;
81994
81627
  const schemaEntry = `
81995
81628
  {
@@ -82434,6 +82067,19 @@ var init_introspect_pg = __esm({
82434
82067
  statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing2)}`).join(", ")})`;
82435
82068
  statement += it.nullsNotDistinct ? `.nullsNotDistinct()` : "";
82436
82069
  statement += `,
82070
+ `;
82071
+ });
82072
+ return statement;
82073
+ };
82074
+ createTableChecks3 = (checkConstraints, casing2) => {
82075
+ let statement = "";
82076
+ checkConstraints.forEach((it) => {
82077
+ const checkKey = withCasing2(it.name, casing2);
82078
+ statement += ` ${checkKey}: `;
82079
+ statement += "check(";
82080
+ statement += `"${it.name}", `;
82081
+ statement += `sql\`${it.value}\`)`;
82082
+ statement += `,
82437
82083
  `;
82438
82084
  });
82439
82085
  return statement;
@@ -82548,7 +82194,6 @@ var init_introspect = __esm({
82548
82194
  sequencesResolver,
82549
82195
  tablesResolver,
82550
82196
  columnsResolver,
82551
- viewsResolver,
82552
82197
  dryPg,
82553
82198
  schema5
82554
82199
  );
@@ -86270,7 +85915,7 @@ init_utils2();
86270
85915
  var version2 = async () => {
86271
85916
  const { npmVersion } = await ormCoreVersions();
86272
85917
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
86273
- const envVersion = "0.25.0-05b9e35";
85918
+ const envVersion = "0.25.0-06c725b";
86274
85919
  const kitVersion = envVersion ? `v${envVersion}` : "--";
86275
85920
  const versions = `drizzle-kit: ${kitVersion}
86276
85921
  ${ormVersion}`;