drizzle-kit 0.16.8 → 0.16.9-139ff3e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +2233 -478
  2. package/package.json +22 -21
package/index.js CHANGED
@@ -613,7 +613,7 @@ var require_command = __commonJS({
613
613
  "node_modules/.pnpm/commander@9.5.0/node_modules/commander/lib/command.js"(exports) {
614
614
  var EventEmitter = require("events").EventEmitter;
615
615
  var childProcess = require("child_process");
616
- var path5 = require("path");
616
+ var path4 = require("path");
617
617
  var fs7 = require("fs");
618
618
  var process3 = require("process");
619
619
  var { Argument: Argument2, humanReadableArgName } = require_argument();
@@ -1053,10 +1053,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1053
1053
  let launchWithNode = false;
1054
1054
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1055
1055
  function findFile(baseDir, baseName) {
1056
- const localBin = path5.resolve(baseDir, baseName);
1056
+ const localBin = path4.resolve(baseDir, baseName);
1057
1057
  if (fs7.existsSync(localBin))
1058
1058
  return localBin;
1059
- if (sourceExt.includes(path5.extname(baseName)))
1059
+ if (sourceExt.includes(path4.extname(baseName)))
1060
1060
  return void 0;
1061
1061
  const foundExt = sourceExt.find((ext) => fs7.existsSync(`${localBin}${ext}`));
1062
1062
  if (foundExt)
@@ -1074,19 +1074,19 @@ Expecting one of '${allowedValues.join("', '")}'`);
1074
1074
  } catch (err2) {
1075
1075
  resolvedScriptPath = this._scriptPath;
1076
1076
  }
1077
- executableDir = path5.resolve(path5.dirname(resolvedScriptPath), executableDir);
1077
+ executableDir = path4.resolve(path4.dirname(resolvedScriptPath), executableDir);
1078
1078
  }
1079
1079
  if (executableDir) {
1080
1080
  let localFile = findFile(executableDir, executableFile);
1081
1081
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
1082
- const legacyName = path5.basename(this._scriptPath, path5.extname(this._scriptPath));
1082
+ const legacyName = path4.basename(this._scriptPath, path4.extname(this._scriptPath));
1083
1083
  if (legacyName !== this._name) {
1084
1084
  localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1085
1085
  }
1086
1086
  }
1087
1087
  executableFile = localFile || executableFile;
1088
1088
  }
1089
- launchWithNode = sourceExt.includes(path5.extname(executableFile));
1089
+ launchWithNode = sourceExt.includes(path4.extname(executableFile));
1090
1090
  let proc;
1091
1091
  if (process3.platform !== "win32") {
1092
1092
  if (launchWithNode) {
@@ -1658,13 +1658,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
1658
1658
  return this;
1659
1659
  }
1660
1660
  nameFromFilename(filename) {
1661
- this._name = path5.basename(filename, path5.extname(filename));
1661
+ this._name = path4.basename(filename, path4.extname(filename));
1662
1662
  return this;
1663
1663
  }
1664
- executableDir(path6) {
1665
- if (path6 === void 0)
1664
+ executableDir(path5) {
1665
+ if (path5 === void 0)
1666
1666
  return this._executableDir;
1667
- this._executableDir = path6;
1667
+ this._executableDir = path5;
1668
1668
  return this;
1669
1669
  }
1670
1670
  helpInformation(contextOptions) {
@@ -2252,8 +2252,8 @@ var init_lib = __esm({
2252
2252
  };
2253
2253
  overrideErrorMap = errorMap;
2254
2254
  makeIssue = (params) => {
2255
- const { data, path: path5, errorMaps, issueData } = params;
2256
- const fullPath = [...path5, ...issueData.path || []];
2255
+ const { data, path: path4, errorMaps, issueData } = params;
2256
+ const fullPath = [...path4, ...issueData.path || []];
2257
2257
  const fullIssue = {
2258
2258
  ...issueData,
2259
2259
  path: fullPath
@@ -2335,10 +2335,10 @@ var init_lib = __esm({
2335
2335
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
2336
2336
  })(errorUtil || (errorUtil = {}));
2337
2337
  ParseInputLazyPath = class {
2338
- constructor(parent, value, path5, key) {
2338
+ constructor(parent, value, path4, key) {
2339
2339
  this.parent = parent;
2340
2340
  this.data = value;
2341
- this._path = path5;
2341
+ this._path = path4;
2342
2342
  this._key = key;
2343
2343
  }
2344
2344
  get path() {
@@ -6232,29 +6232,30 @@ Is ${source_default.bold.blue(
6232
6232
  this.requestLayout();
6233
6233
  }
6234
6234
  render() {
6235
- let info3 = "";
6235
+ let info2 = "";
6236
6236
  const spin = this.spinner.value();
6237
- info3 += this.statusText(spin, this.state.tables);
6238
- info3 += this.statusText(spin, this.state.columns);
6239
- info3 += this.statusText(spin, this.state.enums);
6240
- info3 += this.statusText(spin, this.state.indexes);
6241
- info3 += this.statusText(spin, this.state.fks);
6242
- return info3;
6237
+ info2 += this.statusText(spin, this.state.tables);
6238
+ info2 += this.statusText(spin, this.state.columns);
6239
+ info2 += this.statusText(spin, this.state.enums);
6240
+ info2 += this.statusText(spin, this.state.indexes);
6241
+ info2 += this.statusText(spin, this.state.fks);
6242
+ return info2;
6243
6243
  }
6244
6244
  };
6245
6245
  }
6246
6246
  });
6247
6247
 
6248
6248
  // src/global.ts
6249
- var originUUID;
6249
+ var originUUID, snapshotVersion;
6250
6250
  var init_global = __esm({
6251
6251
  "src/global.ts"() {
6252
6252
  originUUID = "00000000-0000-0000-0000-000000000000";
6253
+ snapshotVersion = "5";
6253
6254
  }
6254
6255
  });
6255
6256
 
6256
6257
  // src/serializer/mysqlSchema.ts
6257
- var index, fk, column, tableV3, table, dialect, schemaHash, schemaInternalV3, schemaInternal, schemaV3, schema2, tableSquashed, schemaSquashed, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
6258
+ var index, fk, column, tableV3, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashed, schemaSquashed, MySqlSquasher, squashMysqlScheme, mysqlSchema, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
6258
6259
  var init_mysqlSchema = __esm({
6259
6260
  "src/serializer/mysqlSchema.ts"() {
6260
6261
  init_global();
@@ -6298,7 +6299,7 @@ var init_mysqlSchema = __esm({
6298
6299
  indexes: recordType(stringType(), index),
6299
6300
  foreignKeys: recordType(stringType(), fk)
6300
6301
  }).strict();
6301
- dialect = enumType(["mysql"]);
6302
+ dialect = literalType("mysql");
6302
6303
  schemaHash = objectType({
6303
6304
  id: stringType(),
6304
6305
  prevId: stringType()
@@ -6308,13 +6309,25 @@ var init_mysqlSchema = __esm({
6308
6309
  dialect,
6309
6310
  tables: recordType(stringType(), tableV3)
6310
6311
  }).strict();
6311
- schemaInternal = objectType({
6312
+ schemaInternalV4 = objectType({
6312
6313
  version: literalType("4"),
6313
6314
  dialect,
6314
6315
  tables: recordType(stringType(), table),
6315
6316
  schemas: recordType(stringType(), stringType())
6316
6317
  }).strict();
6318
+ schemaInternal = objectType({
6319
+ version: literalType("5"),
6320
+ dialect,
6321
+ tables: recordType(stringType(), table),
6322
+ schemas: recordType(stringType(), stringType()),
6323
+ _meta: objectType({
6324
+ schemas: recordType(stringType(), stringType()),
6325
+ tables: recordType(stringType(), stringType()),
6326
+ columns: recordType(stringType(), stringType())
6327
+ })
6328
+ }).strict();
6317
6329
  schemaV3 = schemaInternalV3.merge(schemaHash);
6330
+ schemaV4 = schemaInternalV4.merge(schemaHash);
6318
6331
  schema2 = schemaInternal.merge(schemaHash);
6319
6332
  tableSquashed = objectType({
6320
6333
  name: stringType(),
@@ -6324,7 +6337,7 @@ var init_mysqlSchema = __esm({
6324
6337
  foreignKeys: recordType(stringType(), stringType())
6325
6338
  }).strict();
6326
6339
  schemaSquashed = objectType({
6327
- version: literalType("4"),
6340
+ version: literalType("5"),
6328
6341
  dialect,
6329
6342
  tables: recordType(stringType(), tableSquashed),
6330
6343
  schemas: recordType(stringType(), stringType())
@@ -6403,20 +6416,25 @@ var init_mysqlSchema = __esm({
6403
6416
  };
6404
6417
  mysqlSchema = schema2;
6405
6418
  mysqlSchemaV3 = schemaV3;
6406
- backwardCompatibleMysqlSchema = unionType([schemaV3, schema2]);
6419
+ backwardCompatibleMysqlSchema = unionType([schemaV3, schemaV4, schema2]);
6407
6420
  dryMySql = mysqlSchema.parse({
6408
- version: "4",
6421
+ version: snapshotVersion,
6409
6422
  dialect: "mysql",
6410
6423
  id: originUUID,
6411
6424
  prevId: "",
6412
6425
  tables: {},
6413
- schemas: {}
6426
+ schemas: {},
6427
+ _meta: {
6428
+ schemas: {},
6429
+ tables: {},
6430
+ columns: {}
6431
+ }
6414
6432
  });
6415
6433
  }
6416
6434
  });
6417
6435
 
6418
6436
  // src/serializer/pgSchema.ts
6419
- var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternal, tableSquashed2, pgSchemaSquashed, pgSchemaV3, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
6437
+ var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternal, tableSquashed2, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
6420
6438
  var init_pgSchema = __esm({
6421
6439
  "src/serializer/pgSchema.ts"() {
6422
6440
  init_global();
@@ -6519,17 +6537,29 @@ var init_pgSchema = __esm({
6519
6537
  });
6520
6538
  pgSchemaInternalV3 = objectType({
6521
6539
  version: literalType("3"),
6522
- dialect: enumType(["pg"]),
6540
+ dialect: literalType("pg"),
6523
6541
  tables: recordType(stringType(), tableV32),
6524
6542
  enums: recordType(stringType(), enumSchema)
6525
6543
  }).strict();
6526
- pgSchemaInternal = objectType({
6544
+ pgSchemaInternalV4 = objectType({
6527
6545
  version: literalType("4"),
6528
- dialect: enumType(["pg"]),
6546
+ dialect: literalType("pg"),
6529
6547
  tables: recordType(stringType(), table2),
6530
6548
  enums: recordType(stringType(), enumSchema),
6531
6549
  schemas: recordType(stringType(), stringType())
6532
6550
  }).strict();
6551
+ pgSchemaInternal = objectType({
6552
+ version: literalType("5"),
6553
+ dialect: literalType("pg"),
6554
+ tables: recordType(stringType(), table2),
6555
+ enums: recordType(stringType(), enumSchema),
6556
+ schemas: recordType(stringType(), stringType()),
6557
+ _meta: objectType({
6558
+ schemas: recordType(stringType(), stringType()),
6559
+ tables: recordType(stringType(), stringType()),
6560
+ columns: recordType(stringType(), stringType())
6561
+ })
6562
+ }).strict();
6533
6563
  tableSquashed2 = objectType({
6534
6564
  name: stringType(),
6535
6565
  schema: stringType(),
@@ -6538,18 +6568,20 @@ var init_pgSchema = __esm({
6538
6568
  foreignKeys: recordType(stringType(), stringType())
6539
6569
  }).strict();
6540
6570
  pgSchemaSquashed = objectType({
6541
- version: literalType("4"),
6571
+ version: literalType("5"),
6542
6572
  dialect: enumType(["pg"]),
6543
6573
  tables: recordType(stringType(), tableSquashed2),
6544
6574
  enums: recordType(stringType(), enumSchema),
6545
6575
  schemas: recordType(stringType(), stringType())
6546
6576
  }).strict();
6547
6577
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
6578
+ pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
6548
6579
  pgSchema = pgSchemaInternal.merge(schemaHash2);
6549
6580
  backwardCompatiblePgSchema = unionType([
6550
6581
  pgSchemaV1,
6551
6582
  pgSchemaV2,
6552
6583
  pgSchemaV3,
6584
+ pgSchemaV4,
6553
6585
  pgSchema
6554
6586
  ]);
6555
6587
  PgSquasher = {
@@ -6614,7 +6646,7 @@ var init_pgSchema = __esm({
6614
6646
  })
6615
6647
  );
6616
6648
  return {
6617
- version: json.version,
6649
+ version: "5",
6618
6650
  dialect: json.dialect,
6619
6651
  tables: mappedTables,
6620
6652
  enums: json.enums,
@@ -6622,19 +6654,24 @@ var init_pgSchema = __esm({
6622
6654
  };
6623
6655
  };
6624
6656
  dryPg = pgSchema.parse({
6625
- version: "4",
6657
+ version: snapshotVersion,
6626
6658
  dialect: "pg",
6627
6659
  id: originUUID,
6628
6660
  prevId: "",
6629
6661
  tables: {},
6630
6662
  enums: {},
6631
- schemas: {}
6663
+ schemas: {},
6664
+ _meta: {
6665
+ schemas: {},
6666
+ tables: {},
6667
+ columns: {}
6668
+ }
6632
6669
  });
6633
6670
  }
6634
6671
  });
6635
6672
 
6636
6673
  // src/serializer/sqliteSchema.ts
6637
- var index3, fk3, compositePK, column3, tableV33, table3, dialect2, schemaHash3, schemaInternalV32, latestVersion, schemaInternal2, schemaV32, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchema, backwardCompatibleSqliteSchema;
6674
+ var index3, fk3, compositePK, column3, tableV33, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema3, tableSquashed3, schemaSquashed2, SQLiteSquasher, squashSqliteScheme, drySQLite, sqliteSchemaV3, sqliteSchema, backwardCompatibleSqliteSchema;
6638
6675
  var init_sqliteSchema = __esm({
6639
6676
  "src/serializer/sqliteSchema.ts"() {
6640
6677
  init_global();
@@ -6690,14 +6727,25 @@ var init_sqliteSchema = __esm({
6690
6727
  tables: recordType(stringType(), tableV33),
6691
6728
  enums: objectType({})
6692
6729
  }).strict();
6693
- latestVersion = literalType("4");
6730
+ schemaInternalV42 = objectType({
6731
+ version: literalType("4"),
6732
+ dialect: dialect2,
6733
+ tables: recordType(stringType(), table3),
6734
+ enums: objectType({})
6735
+ }).strict();
6736
+ latestVersion = literalType("5");
6694
6737
  schemaInternal2 = objectType({
6695
6738
  version: latestVersion,
6696
6739
  dialect: dialect2,
6697
6740
  tables: recordType(stringType(), table3),
6698
- enums: objectType({})
6741
+ enums: objectType({}),
6742
+ _meta: objectType({
6743
+ tables: recordType(stringType(), stringType()),
6744
+ columns: recordType(stringType(), stringType())
6745
+ })
6699
6746
  }).strict();
6700
6747
  schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
6748
+ schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
6701
6749
  schema3 = schemaInternal2.merge(schemaHash3).strict();
6702
6750
  tableSquashed3 = objectType({
6703
6751
  name: stringType(),
@@ -6792,21 +6840,25 @@ var init_sqliteSchema = __esm({
6792
6840
  };
6793
6841
  };
6794
6842
  drySQLite = schema3.parse({
6795
- version: "4",
6843
+ version: snapshotVersion,
6796
6844
  dialect: "sqlite",
6797
6845
  id: originUUID,
6798
6846
  prevId: "",
6799
6847
  tables: {},
6800
- enums: {}
6848
+ enums: {},
6849
+ _meta: {
6850
+ tables: {},
6851
+ columns: {}
6852
+ }
6801
6853
  });
6802
6854
  sqliteSchemaV3 = schemaV32;
6803
6855
  sqliteSchema = schema3;
6804
- backwardCompatibleSqliteSchema = unionType([schemaV32, schema3]);
6856
+ backwardCompatibleSqliteSchema = unionType([schemaV32, schemaV42, schema3]);
6805
6857
  }
6806
6858
  });
6807
6859
 
6808
6860
  // src/utils.ts
6809
- var import_fs, prepareOutFolders, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder;
6861
+ var import_fs, import_path, assertV1OutFolder, dryJournal, snapshotsPriorV4, prepareOutFolder, mapValues, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
6810
6862
  var init_utils = __esm({
6811
6863
  "src/utils.ts"() {
6812
6864
  import_fs = require("fs");
@@ -6815,16 +6867,54 @@ var init_utils = __esm({
6815
6867
  init_pgSchema();
6816
6868
  init_sqliteSchema();
6817
6869
  init_source();
6818
- prepareOutFolders = (out) => {
6819
- const outFolderExists = (0, import_fs.existsSync)(out);
6820
- if (!outFolderExists) {
6821
- (0, import_fs.mkdirSync)(out);
6870
+ import_path = require("path");
6871
+ init_global();
6872
+ assertV1OutFolder = (out, dialect6) => {
6873
+ if (!(0, import_fs.existsSync)(out))
6874
+ return;
6875
+ const oldMigrationFolders = (0, import_fs.readdirSync)(out).filter(
6876
+ (it) => it.length === 14 && /^\d+$/.test(it)
6877
+ );
6878
+ if (oldMigrationFolders.length > 0) {
6879
+ console.log(
6880
+ `Your migrations folder format is outdated, please run ${source_default.green.bold(
6881
+ `drizzle-kit up:${dialect6}`
6882
+ )}`
6883
+ );
6884
+ process.exit(1);
6822
6885
  }
6823
- const migrationFolders = (0, import_fs.readdirSync)(out).filter(
6886
+ };
6887
+ dryJournal = (dialect6) => {
6888
+ return {
6889
+ version: snapshotVersion,
6890
+ dialect: dialect6,
6891
+ entries: []
6892
+ };
6893
+ };
6894
+ snapshotsPriorV4 = (out) => {
6895
+ const oldMigrationFolders = (0, import_fs.readdirSync)(out).filter(
6824
6896
  (it) => it.length === 14 && /^\d+$/.test(it)
6825
6897
  );
6826
- migrationFolders.sort();
6827
- return migrationFolders;
6898
+ oldMigrationFolders.sort();
6899
+ return oldMigrationFolders.map(
6900
+ (it) => {
6901
+ const pathJson = (0, import_path.join)(out, it, "snapshot.json");
6902
+ console.log(pathJson);
6903
+ return pathJson;
6904
+ }
6905
+ );
6906
+ };
6907
+ prepareOutFolder = (out, dialect6) => {
6908
+ const meta = (0, import_path.join)(out, "meta");
6909
+ const journalPath = (0, import_path.join)(meta, "_journal.json");
6910
+ if (!(0, import_fs.existsSync)((0, import_path.join)(out, "meta"))) {
6911
+ (0, import_fs.mkdirSync)(meta, { recursive: true });
6912
+ (0, import_fs.writeFileSync)(journalPath, JSON.stringify(dryJournal(dialect6)));
6913
+ }
6914
+ const journal = JSON.parse((0, import_fs.readFileSync)(journalPath).toString());
6915
+ const snapshots = (0, import_fs.readdirSync)(meta).filter((it) => !it.startsWith("_")).map((it) => (0, import_path.join)(meta, it));
6916
+ snapshots.sort();
6917
+ return { meta, snapshots, journal };
6828
6918
  };
6829
6919
  mapValues = (obj, map) => {
6830
6920
  const result = Object.keys(obj).reduce(function(result2, key) {
@@ -6836,46 +6926,43 @@ var init_utils = __esm({
6836
6926
  validatorForDialect = (dialect6) => {
6837
6927
  switch (dialect6) {
6838
6928
  case "pg":
6839
- return { validator: backwardCompatiblePgSchema, version: 4 };
6929
+ return { validator: backwardCompatiblePgSchema, version: 5 };
6840
6930
  case "sqlite":
6841
6931
  return { validator: backwardCompatibleSqliteSchema, version: 4 };
6842
6932
  case "mysql":
6843
6933
  return { validator: backwardCompatibleMysqlSchema, version: 4 };
6844
6934
  }
6845
6935
  };
6846
- validateWithReport = (root, migrationFolders, dialect6) => {
6936
+ validateWithReport = (snapshots, dialect6) => {
6847
6937
  const { validator, version } = validatorForDialect(dialect6);
6848
- const result = migrationFolders.reduce(
6849
- (accum, folder) => {
6938
+ const result = snapshots.reduce(
6939
+ (accum, it) => {
6850
6940
  var _a;
6851
- const snapshotName = `${folder}/snapshot.json`;
6852
- const raw = JSON.parse(
6853
- (0, import_fs.readFileSync)(`./${root}/${folder}/snapshot.json`).toString()
6854
- );
6855
- accum.rawMap[folder] = raw;
6941
+ const raw = JSON.parse((0, import_fs.readFileSync)(`./${it}`).toString());
6942
+ accum.rawMap[it] = raw;
6856
6943
  if (raw["version"] && Number(raw["version"]) > version) {
6857
6944
  console.log(
6858
6945
  info(
6859
- `${folder}/snapshot.json is of unsupported version, please update drizzle-kit`
6946
+ `${it} snapshot is of unsupported version, please update drizzle-kit`
6860
6947
  )
6861
6948
  );
6862
6949
  process.exit(0);
6863
6950
  }
6864
6951
  const result2 = validator.safeParse(raw);
6865
6952
  if (!result2.success) {
6866
- accum.malformed.push(snapshotName);
6953
+ accum.malformed.push(it);
6867
6954
  return accum;
6868
6955
  }
6869
6956
  const snapshot = result2.data;
6870
6957
  if (snapshot.version !== String(version)) {
6871
- accum.nonLatest.push(folder);
6958
+ accum.nonLatest.push(it);
6872
6959
  return accum;
6873
6960
  }
6874
6961
  const idEntry = (_a = accum.idsMap[snapshot["prevId"]]) != null ? _a : {
6875
- parent: folder,
6962
+ parent: it,
6876
6963
  snapshots: []
6877
6964
  };
6878
- idEntry.snapshots.push(snapshotName);
6965
+ idEntry.snapshots.push(it);
6879
6966
  accum.idsMap[snapshot["prevId"]] = idEntry;
6880
6967
  return accum;
6881
6968
  },
@@ -6890,9 +6977,8 @@ var init_utils = __esm({
6890
6977
  return result;
6891
6978
  };
6892
6979
  prepareMigrationFolder = (outFolder = "drizzle", dialect6) => {
6893
- const root = outFolder;
6894
- const migrationFolders = prepareOutFolders(root);
6895
- const report = validateWithReport(root, migrationFolders, dialect6);
6980
+ const { snapshots, journal } = prepareOutFolder(outFolder, dialect6);
6981
+ const report = validateWithReport(snapshots, dialect6);
6896
6982
  if (report.nonLatest.length > 0) {
6897
6983
  console.log(
6898
6984
  report.nonLatest.map((it) => {
@@ -6923,7 +7009,41 @@ var init_utils = __esm({
6923
7009
  if (abort) {
6924
7010
  process.exit(0);
6925
7011
  }
6926
- return { migrationFolders };
7012
+ return { snapshots, journal };
7013
+ };
7014
+ prepareMigrationMeta = (schemas, tables, columns) => {
7015
+ const _meta = {
7016
+ schemas: {},
7017
+ tables: {},
7018
+ columns: {}
7019
+ };
7020
+ schemas.forEach((it) => {
7021
+ const from = schemaRenameKey(it.from);
7022
+ const to = schemaRenameKey(it.to);
7023
+ _meta.schemas[from] = to;
7024
+ });
7025
+ tables.forEach((it) => {
7026
+ const from = tableRenameKey(it.from);
7027
+ const to = tableRenameKey(it.to);
7028
+ _meta.tables[from] = to;
7029
+ });
7030
+ columns.forEach((it) => {
7031
+ const from = columnRenameKey(it.from.table, it.from.schema, it.from.column);
7032
+ const to = columnRenameKey(it.to.table, it.to.schema, it.to.column);
7033
+ _meta.columns[from] = to;
7034
+ });
7035
+ return _meta;
7036
+ };
7037
+ schemaRenameKey = (it) => {
7038
+ return it;
7039
+ };
7040
+ tableRenameKey = (it) => {
7041
+ const out = it.schema ? `"${it.schema}"."${it.name}"` : `"${it.name}"`;
7042
+ return out;
7043
+ };
7044
+ columnRenameKey = (table4, schema4, column5) => {
7045
+ const out = schema4 ? `"${schema4}"."${table4}"."${column5}"` : `"${table4}"."${column5}"`;
7046
+ return out;
6927
7047
  };
6928
7048
  }
6929
7049
  });
@@ -7841,16 +7961,16 @@ var require_node2 = __commonJS({
7841
7961
  }
7842
7962
  exports2.urlGenerate = urlGenerate;
7843
7963
  function normalize(aPath) {
7844
- var path5 = aPath;
7964
+ var path4 = aPath;
7845
7965
  var url = urlParse(aPath);
7846
7966
  if (url) {
7847
7967
  if (!url.path) {
7848
7968
  return aPath;
7849
7969
  }
7850
- path5 = url.path;
7970
+ path4 = url.path;
7851
7971
  }
7852
- var isAbsolute = exports2.isAbsolute(path5);
7853
- var parts = path5.split(/\/+/);
7972
+ var isAbsolute = exports2.isAbsolute(path4);
7973
+ var parts = path4.split(/\/+/);
7854
7974
  for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
7855
7975
  part = parts[i];
7856
7976
  if (part === ".") {
@@ -7867,18 +7987,18 @@ var require_node2 = __commonJS({
7867
7987
  }
7868
7988
  }
7869
7989
  }
7870
- path5 = parts.join("/");
7871
- if (path5 === "") {
7872
- path5 = isAbsolute ? "/" : ".";
7990
+ path4 = parts.join("/");
7991
+ if (path4 === "") {
7992
+ path4 = isAbsolute ? "/" : ".";
7873
7993
  }
7874
7994
  if (url) {
7875
- url.path = path5;
7995
+ url.path = path4;
7876
7996
  return urlGenerate(url);
7877
7997
  }
7878
- return path5;
7998
+ return path4;
7879
7999
  }
7880
8000
  exports2.normalize = normalize;
7881
- function join2(aRoot, aPath) {
8001
+ function join22(aRoot, aPath) {
7882
8002
  if (aRoot === "") {
7883
8003
  aRoot = ".";
7884
8004
  }
@@ -7910,7 +8030,7 @@ var require_node2 = __commonJS({
7910
8030
  }
7911
8031
  return joined;
7912
8032
  }
7913
- exports2.join = join2;
8033
+ exports2.join = join22;
7914
8034
  exports2.isAbsolute = function(aPath) {
7915
8035
  return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
7916
8036
  };
@@ -8083,7 +8203,7 @@ var require_node2 = __commonJS({
8083
8203
  parsed.path = parsed.path.substring(0, index4 + 1);
8084
8204
  }
8085
8205
  }
8086
- sourceURL = join2(urlGenerate(parsed), sourceURL);
8206
+ sourceURL = join22(urlGenerate(parsed), sourceURL);
8087
8207
  }
8088
8208
  return normalize(sourceURL);
8089
8209
  }
@@ -9405,7 +9525,7 @@ var require_node2 = __commonJS({
9405
9525
  });
9406
9526
  var require_source_map_support = __commonJS2((exports2, module22) => {
9407
9527
  var SourceMapConsumer = require_source_map().SourceMapConsumer;
9408
- var path5 = require("path");
9528
+ var path4 = require("path");
9409
9529
  var fs32;
9410
9530
  try {
9411
9531
  fs32 = require("fs");
@@ -9478,15 +9598,15 @@ var require_node2 = __commonJS({
9478
9598
  function supportRelativeURL(file, url) {
9479
9599
  if (!file)
9480
9600
  return url;
9481
- var dir = path5.dirname(file);
9601
+ var dir = path4.dirname(file);
9482
9602
  var match = /^\w+:\/\/[^\/]*/.exec(dir);
9483
9603
  var protocol = match ? match[0] : "";
9484
9604
  var startPath = dir.slice(protocol.length);
9485
9605
  if (protocol && /^\/\w\:/.test(startPath)) {
9486
9606
  protocol += "/";
9487
- return protocol + path5.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
9607
+ return protocol + path4.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
9488
9608
  }
9489
- return protocol + path5.resolve(dir.slice(protocol.length), url);
9609
+ return protocol + path4.resolve(dir.slice(protocol.length), url);
9490
9610
  }
9491
9611
  function retrieveSourceMapURL(source) {
9492
9612
  var fileData;
@@ -9939,13 +10059,13 @@ var require_node2 = __commonJS({
9939
10059
  }
9940
10060
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
9941
10061
  try {
9942
- var info3 = gen[key](arg);
9943
- var value = info3.value;
10062
+ var info2 = gen[key](arg);
10063
+ var value = info2.value;
9944
10064
  } catch (error2) {
9945
10065
  reject(error2);
9946
10066
  return;
9947
10067
  }
9948
- if (info3.done) {
10068
+ if (info2.done) {
9949
10069
  resolve(value);
9950
10070
  } else {
9951
10071
  Promise.resolve(value).then(_next, _throw);
@@ -9973,7 +10093,7 @@ var require_node2 = __commonJS({
9973
10093
  resolve(data);
9974
10094
  });
9975
10095
  });
9976
- var readFileSync2 = (fp) => {
10096
+ var readFileSync3 = (fp) => {
9977
10097
  return _fs.default.readFileSync(fp, "utf8");
9978
10098
  };
9979
10099
  var pathExists = (fp) => new Promise((resolve) => {
@@ -10204,7 +10324,7 @@ var require_node2 = __commonJS({
10204
10324
  data: this.packageJsonCache.get(filepath)[options.packageKey]
10205
10325
  };
10206
10326
  }
10207
- const data = this.options.parseJSON(readFileSync2(filepath));
10327
+ const data = this.options.parseJSON(readFileSync3(filepath));
10208
10328
  return {
10209
10329
  path: filepath,
10210
10330
  data
@@ -10212,7 +10332,7 @@ var require_node2 = __commonJS({
10212
10332
  }
10213
10333
  return {
10214
10334
  path: filepath,
10215
- data: readFileSync2(filepath)
10335
+ data: readFileSync3(filepath)
10216
10336
  };
10217
10337
  }
10218
10338
  return {};
@@ -10281,9 +10401,9 @@ var require_node2 = __commonJS({
10281
10401
  "use strict";
10282
10402
  Object.defineProperty(exports2, "__esModule", { value: true });
10283
10403
  var fs32 = require("fs");
10284
- function fileExistsSync(path5) {
10404
+ function fileExistsSync(path4) {
10285
10405
  try {
10286
- var stats = fs32.statSync(path5);
10406
+ var stats = fs32.statSync(path4);
10287
10407
  return stats.isFile();
10288
10408
  } catch (err2) {
10289
10409
  return false;
@@ -10297,8 +10417,8 @@ var require_node2 = __commonJS({
10297
10417
  return require(packageJsonPath);
10298
10418
  }
10299
10419
  exports2.readJsonFromDiskSync = readJsonFromDiskSync;
10300
- function readJsonFromDiskAsync(path5, callback) {
10301
- fs32.readFile(path5, "utf8", function(err2, result) {
10420
+ function readJsonFromDiskAsync(path4, callback) {
10421
+ fs32.readFile(path4, "utf8", function(err2, result) {
10302
10422
  if (err2 || !result) {
10303
10423
  return callback();
10304
10424
  }
@@ -10316,15 +10436,15 @@ var require_node2 = __commonJS({
10316
10436
  });
10317
10437
  }
10318
10438
  exports2.fileExistsAsync = fileExistsAsync;
10319
- function removeExtension(path5) {
10320
- return path5.substring(0, path5.lastIndexOf(".")) || path5;
10439
+ function removeExtension(path4) {
10440
+ return path4.substring(0, path4.lastIndexOf(".")) || path4;
10321
10441
  }
10322
10442
  exports2.removeExtension = removeExtension;
10323
10443
  });
10324
10444
  var require_mapping_entry = __commonJS2((exports2) => {
10325
10445
  "use strict";
10326
10446
  Object.defineProperty(exports2, "__esModule", { value: true });
10327
- var path5 = require("path");
10447
+ var path4 = require("path");
10328
10448
  function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
10329
10449
  var sortedKeys = sortByLongestPrefix(Object.keys(paths));
10330
10450
  var absolutePaths = [];
@@ -10333,7 +10453,7 @@ var require_node2 = __commonJS({
10333
10453
  absolutePaths.push({
10334
10454
  pattern: key,
10335
10455
  paths: paths[key].map(function(pathToResolve) {
10336
- return path5.join(absoluteBaseUrl, pathToResolve);
10456
+ return path4.join(absoluteBaseUrl, pathToResolve);
10337
10457
  })
10338
10458
  });
10339
10459
  }
@@ -10359,11 +10479,11 @@ var require_node2 = __commonJS({
10359
10479
  var require_try_path = __commonJS2((exports2) => {
10360
10480
  "use strict";
10361
10481
  Object.defineProperty(exports2, "__esModule", { value: true });
10362
- var path5 = require("path");
10482
+ var path4 = require("path");
10363
10483
  var path_1 = require("path");
10364
10484
  var filesystem_1 = require_filesystem();
10365
10485
  function getPathsToTry(extensions, absolutePathMappings, requestedModule) {
10366
- if (!absolutePathMappings || !requestedModule || requestedModule[0] === "." || requestedModule[0] === path5.sep) {
10486
+ if (!absolutePathMappings || !requestedModule || requestedModule[0] === "." || requestedModule[0] === path4.sep) {
10367
10487
  return void 0;
10368
10488
  }
10369
10489
  var pathsToTry = [];
@@ -10379,9 +10499,9 @@ var require_node2 = __commonJS({
10379
10499
  }));
10380
10500
  pathsToTry.push({
10381
10501
  type: "package",
10382
- path: path5.join(physicalPath, "/package.json")
10502
+ path: path4.join(physicalPath, "/package.json")
10383
10503
  });
10384
- var indexPath = path5.join(physicalPath, "/index");
10504
+ var indexPath = path4.join(physicalPath, "/index");
10385
10505
  pathsToTry.push.apply(pathsToTry, extensions.map(function(e) {
10386
10506
  return { type: "index", path: indexPath + e };
10387
10507
  }));
@@ -10428,7 +10548,7 @@ var require_node2 = __commonJS({
10428
10548
  var require_match_path_sync = __commonJS2((exports2) => {
10429
10549
  "use strict";
10430
10550
  Object.defineProperty(exports2, "__esModule", { value: true });
10431
- var path5 = require("path");
10551
+ var path4 = require("path");
10432
10552
  var Filesystem = require_filesystem();
10433
10553
  var MappingEntry = require_mapping_entry();
10434
10554
  var TryPath = require_try_path();
@@ -10470,7 +10590,7 @@ var require_node2 = __commonJS({
10470
10590
  var mainFieldName = mainFields[index4];
10471
10591
  var candidateMapping = packageJson[mainFieldName];
10472
10592
  if (candidateMapping && typeof candidateMapping === "string") {
10473
- var candidateFilePath = path5.join(path5.dirname(packageJsonPath), candidateMapping);
10593
+ var candidateFilePath = path4.join(path4.dirname(packageJsonPath), candidateMapping);
10474
10594
  if (fileExists(candidateFilePath)) {
10475
10595
  return candidateFilePath;
10476
10596
  }
@@ -10509,7 +10629,7 @@ var require_node2 = __commonJS({
10509
10629
  var require_match_path_async = __commonJS2((exports2) => {
10510
10630
  "use strict";
10511
10631
  Object.defineProperty(exports2, "__esModule", { value: true });
10512
- var path5 = require("path");
10632
+ var path4 = require("path");
10513
10633
  var TryPath = require_try_path();
10514
10634
  var MappingEntry = require_mapping_entry();
10515
10635
  var Filesystem = require_filesystem();
@@ -10560,7 +10680,7 @@ var require_node2 = __commonJS({
10560
10680
  if (typeof mainFieldMapping !== "string") {
10561
10681
  return tryNext();
10562
10682
  }
10563
- var mappedFilePath = path5.join(path5.dirname(packageJsonPath), mainFieldMapping);
10683
+ var mappedFilePath = path4.join(path4.dirname(packageJsonPath), mainFieldMapping);
10564
10684
  fileExistsAsync(mappedFilePath, function(err2, exists) {
10565
10685
  if (err2) {
10566
10686
  return doneCallback(err2);
@@ -11780,7 +11900,7 @@ var require_node2 = __commonJS({
11780
11900
  return t;
11781
11901
  };
11782
11902
  Object.defineProperty(exports2, "__esModule", { value: true });
11783
- var path5 = require("path");
11903
+ var path4 = require("path");
11784
11904
  var fs32 = require("fs");
11785
11905
  var JSON5 = require_lib32();
11786
11906
  var StripBom = require_strip_bom();
@@ -11810,43 +11930,43 @@ var require_node2 = __commonJS({
11810
11930
  }
11811
11931
  function resolveConfigPath(cwd, filename) {
11812
11932
  if (filename) {
11813
- var absolutePath = fs32.lstatSync(filename).isDirectory() ? path5.resolve(filename, "./tsconfig.json") : path5.resolve(cwd, filename);
11933
+ var absolutePath = fs32.lstatSync(filename).isDirectory() ? path4.resolve(filename, "./tsconfig.json") : path4.resolve(cwd, filename);
11814
11934
  return absolutePath;
11815
11935
  }
11816
11936
  if (fs32.statSync(cwd).isFile()) {
11817
- return path5.resolve(cwd);
11937
+ return path4.resolve(cwd);
11818
11938
  }
11819
11939
  var configAbsolutePath = walkForTsConfig(cwd);
11820
- return configAbsolutePath ? path5.resolve(configAbsolutePath) : void 0;
11940
+ return configAbsolutePath ? path4.resolve(configAbsolutePath) : void 0;
11821
11941
  }
11822
- function walkForTsConfig(directory, existsSync3) {
11823
- if (existsSync3 === void 0) {
11824
- existsSync3 = fs32.existsSync;
11942
+ function walkForTsConfig(directory, existsSync4) {
11943
+ if (existsSync4 === void 0) {
11944
+ existsSync4 = fs32.existsSync;
11825
11945
  }
11826
- var configPath = path5.join(directory, "./tsconfig.json");
11827
- if (existsSync3(configPath)) {
11946
+ var configPath = path4.join(directory, "./tsconfig.json");
11947
+ if (existsSync4(configPath)) {
11828
11948
  return configPath;
11829
11949
  }
11830
- var parentDirectory = path5.join(directory, "../");
11950
+ var parentDirectory = path4.join(directory, "../");
11831
11951
  if (directory === parentDirectory) {
11832
11952
  return void 0;
11833
11953
  }
11834
- return walkForTsConfig(parentDirectory, existsSync3);
11954
+ return walkForTsConfig(parentDirectory, existsSync4);
11835
11955
  }
11836
11956
  exports2.walkForTsConfig = walkForTsConfig;
11837
- function loadTsconfig(configFilePath, existsSync3, readFileSync2) {
11838
- if (existsSync3 === void 0) {
11839
- existsSync3 = fs32.existsSync;
11957
+ function loadTsconfig(configFilePath, existsSync4, readFileSync3) {
11958
+ if (existsSync4 === void 0) {
11959
+ existsSync4 = fs32.existsSync;
11840
11960
  }
11841
- if (readFileSync2 === void 0) {
11842
- readFileSync2 = function(filename) {
11961
+ if (readFileSync3 === void 0) {
11962
+ readFileSync3 = function(filename) {
11843
11963
  return fs32.readFileSync(filename, "utf8");
11844
11964
  };
11845
11965
  }
11846
- if (!existsSync3(configFilePath)) {
11966
+ if (!existsSync4(configFilePath)) {
11847
11967
  return void 0;
11848
11968
  }
11849
- var configString = readFileSync2(configFilePath);
11969
+ var configString = readFileSync3(configFilePath);
11850
11970
  var cleanedJson = StripBom(configString);
11851
11971
  var config = JSON5.parse(cleanedJson);
11852
11972
  var extendedConfig = config.extends;
@@ -11854,15 +11974,15 @@ var require_node2 = __commonJS({
11854
11974
  if (typeof extendedConfig === "string" && extendedConfig.indexOf(".json") === -1) {
11855
11975
  extendedConfig += ".json";
11856
11976
  }
11857
- var currentDir = path5.dirname(configFilePath);
11858
- var extendedConfigPath = path5.join(currentDir, extendedConfig);
11859
- if (extendedConfig.indexOf("/") !== -1 && extendedConfig.indexOf(".") !== -1 && !existsSync3(extendedConfigPath)) {
11860
- extendedConfigPath = path5.join(currentDir, "node_modules", extendedConfig);
11977
+ var currentDir = path4.dirname(configFilePath);
11978
+ var extendedConfigPath = path4.join(currentDir, extendedConfig);
11979
+ if (extendedConfig.indexOf("/") !== -1 && extendedConfig.indexOf(".") !== -1 && !existsSync4(extendedConfigPath)) {
11980
+ extendedConfigPath = path4.join(currentDir, "node_modules", extendedConfig);
11861
11981
  }
11862
- var base = loadTsconfig(extendedConfigPath, existsSync3, readFileSync2) || {};
11982
+ var base = loadTsconfig(extendedConfigPath, existsSync4, readFileSync3) || {};
11863
11983
  if (base.compilerOptions && base.compilerOptions.baseUrl) {
11864
- var extendsDir = path5.dirname(extendedConfig);
11865
- base.compilerOptions.baseUrl = path5.join(extendsDir, base.compilerOptions.baseUrl);
11984
+ var extendsDir = path4.dirname(extendedConfig);
11985
+ base.compilerOptions.baseUrl = path4.join(extendsDir, base.compilerOptions.baseUrl);
11866
11986
  }
11867
11987
  return __assign({}, base, config, { compilerOptions: __assign({}, base.compilerOptions, config.compilerOptions) });
11868
11988
  }
@@ -12087,7 +12207,7 @@ var require_node2 = __commonJS({
12087
12207
  "use strict";
12088
12208
  Object.defineProperty(exports2, "__esModule", { value: true });
12089
12209
  var TsConfigLoader = require_tsconfig_loader();
12090
- var path5 = require("path");
12210
+ var path4 = require("path");
12091
12211
  var options_1 = require_options();
12092
12212
  function loadConfig2(cwd) {
12093
12213
  if (cwd === void 0) {
@@ -12099,7 +12219,7 @@ var require_node2 = __commonJS({
12099
12219
  function configLoader(_a) {
12100
12220
  var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader.tsConfigLoader : _b;
12101
12221
  if (explicitParams) {
12102
- var absoluteBaseUrl_1 = path5.isAbsolute(explicitParams.baseUrl) ? explicitParams.baseUrl : path5.join(cwd, explicitParams.baseUrl);
12222
+ var absoluteBaseUrl_1 = path4.isAbsolute(explicitParams.baseUrl) ? explicitParams.baseUrl : path4.join(cwd, explicitParams.baseUrl);
12103
12223
  return {
12104
12224
  resultType: "success",
12105
12225
  configFileAbsolutePath: "",
@@ -12128,8 +12248,8 @@ var require_node2 = __commonJS({
12128
12248
  message: "Missing baseUrl in compilerOptions"
12129
12249
  };
12130
12250
  }
12131
- var tsConfigDir = path5.dirname(loadResult.tsConfigPath);
12132
- var absoluteBaseUrl = path5.join(tsConfigDir, loadResult.baseUrl);
12251
+ var tsConfigDir = path4.dirname(loadResult.tsConfigPath);
12252
+ var absoluteBaseUrl = path4.join(tsConfigDir, loadResult.baseUrl);
12133
12253
  return {
12134
12254
  resultType: "success",
12135
12255
  configFileAbsolutePath: loadResult.tsConfigPath,
@@ -12330,8 +12450,8 @@ var require_node2 = __commonJS({
12330
12450
  });
12331
12451
  var getOptions = (cwd) => {
12332
12452
  var _a, _b, _c, _d;
12333
- const { data, path: path5 } = joycon.loadSync(["tsconfig.json", "jsconfig.json"], cwd);
12334
- if (path5 && data) {
12453
+ const { data, path: path4 } = joycon.loadSync(["tsconfig.json", "jsconfig.json"], cwd);
12454
+ if (path4 && data) {
12335
12455
  return {
12336
12456
  jsxFactory: (_a = data.compilerOptions) == null ? void 0 : _a.jsxFactory,
12337
12457
  jsxFragment: (_b = data.compilerOptions) == null ? void 0 : _b.jsxFragmentFactory,
@@ -12682,7 +12802,7 @@ __export(pgSerializer_exports, {
12682
12802
  generatePgSnapshot: () => generatePgSnapshot,
12683
12803
  indexName: () => indexName
12684
12804
  });
12685
- var import_pg_core2, import_utils6, import_sql2, import_table2, dialect4, indexName, generatePgSnapshot, fromDatabase;
12805
+ var import_pg_core2, import_utils6, import_sql2, import_table2, dialect4, indexName, generatePgSnapshot, fromDatabase, defaultForColumn;
12686
12806
  var init_pgSerializer = __esm({
12687
12807
  "src/serializer/pgSerializer.ts"() {
12688
12808
  import_pg_core2 = require("drizzle-orm/pg-core");
@@ -12804,14 +12924,19 @@ var init_pgSerializer = __esm({
12804
12924
  return map;
12805
12925
  }, {});
12806
12926
  const schemasObject = Object.fromEntries(
12807
- schemas.map((it) => [it.schemaName, it.schemaName])
12927
+ schemas.filter((it) => it.schemaName !== "public").map((it) => [it.schemaName, it.schemaName])
12808
12928
  );
12809
12929
  return {
12810
- version: "4",
12930
+ version: "5",
12811
12931
  dialect: "pg",
12812
12932
  tables: result,
12813
12933
  enums: enumsToReturn,
12814
- schemas: schemasObject
12934
+ schemas: schemasObject,
12935
+ _meta: {
12936
+ schemas: {},
12937
+ tables: {},
12938
+ columns: {}
12939
+ }
12815
12940
  };
12816
12941
  };
12817
12942
  fromDatabase = async (db, progressCallback) => {
@@ -12819,7 +12944,10 @@ var init_pgSerializer = __esm({
12819
12944
  const allTables = await db.query(
12820
12945
  `SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'public';`
12821
12946
  );
12822
- const schemas = new Set(allTables.rows.map((it) => it.table_schema));
12947
+ const schemas = new Set(
12948
+ allTables.rows.map((it) => it.table_schema)
12949
+ );
12950
+ schemas.delete("public");
12823
12951
  progressCallback("tables", allTables.rows.length, "done");
12824
12952
  let columnsCount = 0;
12825
12953
  let indexesCount = 0;
@@ -12930,7 +13058,7 @@ var init_pgSerializer = __esm({
12930
13058
  const uniqueKey = tableConstraints.rows.filter(
12931
13059
  (mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "UNIQUE"
12932
13060
  );
12933
- const defaultValue = columnResponse.column_default === null ? void 0 : columnResponse.column_default;
13061
+ const defaultValue = defaultForColumn(columnResponse);
12934
13062
  const isSerial = columnType === "serial";
12935
13063
  columnToReturn[columnName] = {
12936
13064
  name: columnName,
@@ -12983,7 +13111,7 @@ var init_pgSerializer = __esm({
12983
13111
  progressCallback("indexes", indexesCount, "fetching");
12984
13112
  result[tableName] = {
12985
13113
  name: tableName,
12986
- schema: tableSchema,
13114
+ schema: tableSchema !== "public" ? tableSchema : "",
12987
13115
  columns: columnToReturn,
12988
13116
  indexes: indexToReturn,
12989
13117
  foreignKeys: foreignKeysToReturn
@@ -13024,13 +13152,25 @@ var init_pgSerializer = __esm({
13024
13152
  progressCallback("enums", Object.keys(enumsToReturn).length, "done");
13025
13153
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
13026
13154
  return {
13027
- version: "4",
13155
+ version: "5",
13028
13156
  dialect: "pg",
13029
13157
  tables: result,
13030
13158
  enums: enumsToReturn,
13031
- schemas: schemasObject
13159
+ schemas: schemasObject,
13160
+ _meta: {
13161
+ schemas: {},
13162
+ tables: {},
13163
+ columns: {}
13164
+ }
13032
13165
  };
13033
13166
  };
13167
+ defaultForColumn = (column5) => {
13168
+ if (column5.data_type === "serial" || column5.data_type === "smallserial" || column5.data_type === "bigserial") {
13169
+ return void 0;
13170
+ }
13171
+ const defaultValue = column5.column_default === null ? void 0 : column5.column_default;
13172
+ return defaultValue;
13173
+ };
13034
13174
  }
13035
13175
  });
13036
13176
 
@@ -13172,12 +13312,12 @@ var init_sqliteSerializer = __esm({
13172
13312
  });
13173
13313
 
13174
13314
  // src/serializer/index.ts
13175
- var import_fs2, import_node, import_path, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13315
+ var import_fs2, import_node, import_path2, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13176
13316
  var init_serializer = __esm({
13177
13317
  "src/serializer/index.ts"() {
13178
13318
  import_fs2 = __toESM(require("fs"));
13179
13319
  import_node = __toESM(require_node2());
13180
- import_path = __toESM(require("path"));
13320
+ import_path2 = __toESM(require("path"));
13181
13321
  safeRegister = () => {
13182
13322
  try {
13183
13323
  const { unregister } = (0, import_node.register)({
@@ -13190,8 +13330,8 @@ var init_serializer = __esm({
13190
13330
  } };
13191
13331
  }
13192
13332
  };
13193
- serializeMySql = (path5) => {
13194
- const filenames = prepareFilenames(path5);
13333
+ serializeMySql = (path4) => {
13334
+ const filenames = prepareFilenames(path4);
13195
13335
  const { unregister } = safeRegister();
13196
13336
  const { prepareFromMySqlImports: prepareFromMySqlImports2 } = (init_mysqlImports(), __toCommonJS(mysqlImports_exports));
13197
13337
  const { generateMySqlSnapshot: generateMySqlSnapshot2 } = (init_mysqlSerializer(), __toCommonJS(mysqlSerializer_exports));
@@ -13199,8 +13339,8 @@ var init_serializer = __esm({
13199
13339
  unregister();
13200
13340
  return generateMySqlSnapshot2(tables, enums, schemas);
13201
13341
  };
13202
- serializePg = (path5) => {
13203
- const filenames = prepareFilenames(path5);
13342
+ serializePg = (path4) => {
13343
+ const filenames = prepareFilenames(path4);
13204
13344
  const { unregister } = safeRegister();
13205
13345
  const { prepareFromPgImports: prepareFromPgImports2 } = (init_pgImports(), __toCommonJS(pgImports_exports));
13206
13346
  const { generatePgSnapshot: generatePgSnapshot2 } = (init_pgSerializer(), __toCommonJS(pgSerializer_exports));
@@ -13208,8 +13348,8 @@ var init_serializer = __esm({
13208
13348
  unregister();
13209
13349
  return generatePgSnapshot2(tables, enums, schemas);
13210
13350
  };
13211
- serializeSQLite = (path5) => {
13212
- const filenames = prepareFilenames(path5);
13351
+ serializeSQLite = (path4) => {
13352
+ const filenames = prepareFilenames(path4);
13213
13353
  const { unregister } = safeRegister();
13214
13354
  const { prepareFromSqliteImports: prepareFromSqliteImports2 } = (init_sqliteImports(), __toCommonJS(sqliteImports_exports));
13215
13355
  const { generateSqliteSnapshot: generateSqliteSnapshot2 } = (init_sqliteSerializer(), __toCommonJS(sqliteSerializer_exports));
@@ -13217,9 +13357,9 @@ var init_serializer = __esm({
13217
13357
  unregister();
13218
13358
  return generateSqliteSnapshot2(tables, enums);
13219
13359
  };
13220
- prepareFilenames = (path5) => {
13221
- const fileName = import_fs2.default.lstatSync(path5).isDirectory() ? null : import_path.default.resolve(path5);
13222
- const filenames = fileName ? [fileName] : import_fs2.default.readdirSync(path5).map((it) => import_path.default.join(import_path.default.resolve(path5), it));
13360
+ prepareFilenames = (path4) => {
13361
+ const fileName = import_fs2.default.lstatSync(path4).isDirectory() ? null : import_path2.default.resolve(path4);
13362
+ const filenames = fileName ? [fileName] : import_fs2.default.readdirSync(path4).map((it) => import_path2.default.join(import_path2.default.resolve(path4), it));
13223
13363
  return filenames;
13224
13364
  };
13225
13365
  }
@@ -13235,9 +13375,9 @@ var init_migrationPreparator = __esm({
13235
13375
  init_pgSchema();
13236
13376
  init_sqliteSchema();
13237
13377
  init_mysqlSchema();
13238
- prepareMySqlMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13378
+ prepareMySqlMigrationSnapshot = (migrationFolders, schemaPath) => {
13239
13379
  const prevSnapshot = mysqlSchema.parse(
13240
- preparePrevSnapshot(outFolder, migrationFolders, dryMySql)
13380
+ preparePrevSnapshot(migrationFolders, dryMySql)
13241
13381
  );
13242
13382
  const serialized = serializeMySql(schemaPath);
13243
13383
  const id = (0, import_crypto.randomUUID)();
@@ -13246,9 +13386,9 @@ var init_migrationPreparator = __esm({
13246
13386
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13247
13387
  return { prev: prevSnapshot, cur: result };
13248
13388
  };
13249
- prepareSqliteMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13389
+ prepareSqliteMigrationSnapshot = (snapshots, schemaPath) => {
13250
13390
  const prevSnapshot = sqliteSchema.parse(
13251
- preparePrevSnapshot(outFolder, migrationFolders, drySQLite)
13391
+ preparePrevSnapshot(snapshots, drySQLite)
13252
13392
  );
13253
13393
  const serialized = serializeSQLite(schemaPath);
13254
13394
  const id = (0, import_crypto.randomUUID)();
@@ -13263,10 +13403,8 @@ var init_migrationPreparator = __esm({
13263
13403
  };
13264
13404
  return { prev: prevSnapshot, cur: result };
13265
13405
  };
13266
- preparePgMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13267
- const prevSnapshot = pgSchema.parse(
13268
- preparePrevSnapshot(outFolder, migrationFolders, dryPg)
13269
- );
13406
+ preparePgMigrationSnapshot = (snapshots, schemaPath) => {
13407
+ const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
13270
13408
  const serialized = serializePg(schemaPath);
13271
13409
  const id = (0, import_crypto.randomUUID)();
13272
13410
  const idPrev = prevSnapshot.id;
@@ -13274,16 +13412,13 @@ var init_migrationPreparator = __esm({
13274
13412
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13275
13413
  return { prev: prevSnapshot, cur: result };
13276
13414
  };
13277
- preparePrevSnapshot = (outFolder, migrationFolders, defaultPrev) => {
13278
- const root = outFolder;
13415
+ preparePrevSnapshot = (snapshots, defaultPrev) => {
13279
13416
  let prevSnapshot;
13280
- if (migrationFolders.length === 0) {
13417
+ if (snapshots.length === 0) {
13281
13418
  prevSnapshot = defaultPrev;
13282
13419
  } else {
13283
- const lastSnapshotFolder = migrationFolders[migrationFolders.length - 1];
13284
- prevSnapshot = JSON.parse(
13285
- import_fs3.default.readFileSync(`${root}/${lastSnapshotFolder}/snapshot.json`).toString()
13286
- );
13420
+ const lastSnapshot = snapshots[snapshots.length - 1];
13421
+ prevSnapshot = JSON.parse(import_fs3.default.readFileSync(lastSnapshot).toString());
13287
13422
  }
13288
13423
  return prevSnapshot;
13289
13424
  };
@@ -13328,7 +13463,8 @@ var init_sqlgenerator = __esm({
13328
13463
  isPgNativeType = (it) => {
13329
13464
  if (pgNativeTypes.has(it))
13330
13465
  return true;
13331
- return it.startsWith("varchar(") || it.startsWith("numeric(");
13466
+ const toCheck = it.replace(/ /g, "");
13467
+ return toCheck.startsWith("varchar(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(");
13332
13468
  };
13333
13469
  Convertor = class {
13334
13470
  };
@@ -13477,7 +13613,7 @@ var init_sqlgenerator = __esm({
13477
13613
  return statement.type === "rename_table" && dialect6 === "pg";
13478
13614
  }
13479
13615
  convert(statement) {
13480
- const { tableNameFrom, tableNameTo, fromSchema: schema4 } = statement;
13616
+ const { tableNameFrom, tableNameTo, toSchema: schema4 } = statement;
13481
13617
  const from = schema4 ? `"${schema4}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
13482
13618
  const to = schema4 ? `"${schema4}"."${tableNameTo}"` : `"${tableNameTo}"`;
13483
13619
  return `ALTER TABLE ${from} RENAME TO ${to};`;
@@ -17143,7 +17279,7 @@ var require_get = __commonJS({
17143
17279
  return lastId;
17144
17280
  },
17145
17281
  delete: function(id) {
17146
- var index4 = 0, set = map, i, args = cache[id], length = args.length, path5 = [];
17282
+ var index4 = 0, set = map, i, args = cache[id], length = args.length, path4 = [];
17147
17283
  if (length === 0) {
17148
17284
  delete set[length];
17149
17285
  } else if (set = set[length]) {
@@ -17152,7 +17288,7 @@ var require_get = __commonJS({
17152
17288
  if (i === -1) {
17153
17289
  return;
17154
17290
  }
17155
- path5.push(set, i);
17291
+ path4.push(set, i);
17156
17292
  set = set[1][i];
17157
17293
  ++index4;
17158
17294
  }
@@ -17163,9 +17299,9 @@ var require_get = __commonJS({
17163
17299
  id = set[1][i];
17164
17300
  set[0].splice(i, 1);
17165
17301
  set[1].splice(i, 1);
17166
- while (!set[0].length && path5.length) {
17167
- i = path5.pop();
17168
- set = path5.pop();
17302
+ while (!set[0].length && path4.length) {
17303
+ i = path4.pop();
17304
+ set = path4.pop();
17169
17305
  set[0].splice(i, 1);
17170
17306
  set[1].splice(i, 1);
17171
17307
  }
@@ -17257,13 +17393,13 @@ var require_get_fixed = __commonJS({
17257
17393
  return lastId;
17258
17394
  },
17259
17395
  delete: function(id) {
17260
- var index4 = 0, set = map, i, path5 = [], args = cache[id];
17396
+ var index4 = 0, set = map, i, path4 = [], args = cache[id];
17261
17397
  while (index4 < length - 1) {
17262
17398
  i = indexOf.call(set[0], args[index4]);
17263
17399
  if (i === -1) {
17264
17400
  return;
17265
17401
  }
17266
- path5.push(set, i);
17402
+ path4.push(set, i);
17267
17403
  set = set[1][i];
17268
17404
  ++index4;
17269
17405
  }
@@ -17274,9 +17410,9 @@ var require_get_fixed = __commonJS({
17274
17410
  id = set[1][i];
17275
17411
  set[0].splice(i, 1);
17276
17412
  set[1].splice(i, 1);
17277
- while (!set[0].length && path5.length) {
17278
- i = path5.pop();
17279
- set = path5.pop();
17413
+ while (!set[0].length && path4.length) {
17414
+ i = path4.pop();
17415
+ set = path4.pop();
17280
17416
  set[0].splice(i, 1);
17281
17417
  set[1].splice(i, 1);
17282
17418
  }
@@ -18841,7 +18977,7 @@ var require_bare = __commonJS({
18841
18977
  var sgr = require_sgr();
18842
18978
  var supportsColor2 = require_supports_color2();
18843
18979
  var mods = sgr.mods;
18844
- var join = Array.prototype.join;
18980
+ var join4 = Array.prototype.join;
18845
18981
  var defineProperty = Object.defineProperty;
18846
18982
  var max = Math.max;
18847
18983
  var min = Math.min;
@@ -18895,7 +19031,7 @@ var require_bare = __commonJS({
18895
19031
  getFn = function() {
18896
19032
  return setPrototypeOf(
18897
19033
  function self2() {
18898
- var start = "", end = "", msg = join.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
19034
+ var start = "", end = "", msg = join4.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
18899
19035
  forEach(
18900
19036
  conf,
18901
19037
  function(mod, key) {
@@ -20326,7 +20462,7 @@ function diffForRenamedTable(t1, t2) {
20326
20462
  t1.name = t2.name;
20327
20463
  const diffed = (0, import_json_diff.diff)(t1, t2) || {};
20328
20464
  diffed.name = t2.name;
20329
- return findAlternationsInTable(diffed);
20465
+ return findAlternationsInTable(diffed, t2.schema);
20330
20466
  }
20331
20467
  function diffForRenamedColumn(t1, t2) {
20332
20468
  const renamed = { ...t1, name: t2.name };
@@ -20340,6 +20476,10 @@ function applyJsonDiff(json1, json2) {
20340
20476
  json2 = JSON.parse(JSON.stringify(json2));
20341
20477
  const rawDiff = (0, import_json_diff.diff)(json1, json2);
20342
20478
  const difference = rawDiff;
20479
+ const tableToSchema = Object.entries(json2.tables).reduce((res, it) => {
20480
+ res[it[0]] = it[1].schema;
20481
+ return res;
20482
+ }, {});
20343
20483
  if (!difference)
20344
20484
  return {};
20345
20485
  difference.tables = (_a = difference.tables) != null ? _a : {};
@@ -20369,7 +20509,7 @@ function applyJsonDiff(json1, json2) {
20369
20509
  const schemasEntries = Object.entries(difference.schemas);
20370
20510
  const addedSchemas = schemasEntries.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
20371
20511
  const deletedSchemas = schemasEntries.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
20372
- const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4));
20512
+ const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4, tableToSchema[table4.name]));
20373
20513
  return {
20374
20514
  addedTables,
20375
20515
  deletedTables,
@@ -20386,10 +20526,13 @@ var init_jsonDiffer = __esm({
20386
20526
  "src/jsonDiffer.js"() {
20387
20527
  import_json_diff = __toESM(require_lib());
20388
20528
  "use-strict";
20389
- findAlternationsInTable = (table4) => {
20529
+ findAlternationsInTable = (table4, tableSchema) => {
20390
20530
  var _a;
20391
20531
  const columns = (_a = table4.columns) != null ? _a : {};
20392
- let schema4;
20532
+ let schema4 = {
20533
+ type: "none",
20534
+ value: tableSchema
20535
+ };
20393
20536
  if ("schema" in table4) {
20394
20537
  if (table4.schema.__new) {
20395
20538
  schema4 = { type: "changed", old: table4.schema.__old, new: table4.schema.__new };
@@ -20526,7 +20669,8 @@ var init_jsonStatements = __esm({
20526
20669
  prepareDropTableJson = (table4) => {
20527
20670
  return {
20528
20671
  type: "drop_table",
20529
- tableName: table4.name
20672
+ tableName: table4.name,
20673
+ schema: table4.schema
20530
20674
  };
20531
20675
  };
20532
20676
  prepareRenameTableJson = (tableFrom, tableTo) => {
@@ -20579,20 +20723,21 @@ var init_jsonStatements = __esm({
20579
20723
  };
20580
20724
  });
20581
20725
  };
20582
- prepareRenameColumns = (tableName, pairs) => {
20726
+ prepareRenameColumns = (tableName, schema4, pairs) => {
20583
20727
  return pairs.map((it) => {
20584
20728
  return {
20585
20729
  type: "alter_table_rename_column",
20586
20730
  tableName,
20587
20731
  oldColumnName: it.from.name,
20588
- newColumnName: it.to.name
20732
+ newColumnName: it.to.name,
20733
+ schema: schema4
20589
20734
  };
20590
20735
  });
20591
20736
  };
20592
- prepareAlterTableColumnsJson = (tableName, deleted, added, altered, addedFk, dialect6) => {
20737
+ prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, dialect6) => {
20593
20738
  const addColumns = [];
20594
- const dropColumns = _prepareDropColumns(tableName, deleted);
20595
- const alterColumns = _prepareAlterColumns(tableName, altered);
20739
+ const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
20740
+ const alterColumns = _prepareAlterColumns(tableName, schema4, altered);
20596
20741
  if (dialect6 === "sqlite") {
20597
20742
  let jsonCreateFKStatements = Object.values(addedFk);
20598
20743
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -20602,25 +20747,27 @@ var init_jsonStatements = __esm({
20602
20747
  );
20603
20748
  addColumns.push(...sqliteAddColumns);
20604
20749
  } else {
20605
- addColumns.push(..._prepareAddColumns(tableName, added));
20750
+ addColumns.push(..._prepareAddColumns(tableName, schema4, added));
20606
20751
  }
20607
20752
  return { addColumns, dropColumns, alterColumns };
20608
20753
  };
20609
- _prepareDropColumns = (taleName, columns) => {
20754
+ _prepareDropColumns = (taleName, schema4, columns) => {
20610
20755
  return columns.map((it) => {
20611
20756
  return {
20612
20757
  type: "alter_table_drop_column",
20613
20758
  tableName: taleName,
20614
- columnName: it.name
20759
+ columnName: it.name,
20760
+ schema: schema4
20615
20761
  };
20616
20762
  });
20617
20763
  };
20618
- _prepareAddColumns = (tableName, columns) => {
20764
+ _prepareAddColumns = (tableName, schema4, columns) => {
20619
20765
  return columns.map((it) => {
20620
20766
  return {
20621
20767
  type: "alter_table_add_column",
20622
20768
  tableName,
20623
- column: it
20769
+ column: it,
20770
+ schema: schema4
20624
20771
  };
20625
20772
  });
20626
20773
  };
@@ -20640,7 +20787,7 @@ var init_jsonStatements = __esm({
20640
20787
  };
20641
20788
  });
20642
20789
  };
20643
- _prepareAlterColumns = (tableName, columns) => {
20790
+ _prepareAlterColumns = (tableName, schema4, columns) => {
20644
20791
  var _a, _b, _c, _d, _e, _f, _g;
20645
20792
  let statements = [];
20646
20793
  for (const column5 of columns) {
@@ -20650,7 +20797,8 @@ var init_jsonStatements = __esm({
20650
20797
  type: "alter_table_rename_column",
20651
20798
  tableName,
20652
20799
  oldColumnName: column5.name.old,
20653
- newColumnName: column5.name.new
20800
+ newColumnName: column5.name.new,
20801
+ schema: schema4
20654
20802
  });
20655
20803
  }
20656
20804
  if (((_a = column5.type) == null ? void 0 : _a.type) === "changed") {
@@ -20658,7 +20806,8 @@ var init_jsonStatements = __esm({
20658
20806
  type: "alter_table_alter_column_set_type",
20659
20807
  tableName,
20660
20808
  columnName,
20661
- newDataType: column5.type.new
20809
+ newDataType: column5.type.new,
20810
+ schema: schema4
20662
20811
  });
20663
20812
  }
20664
20813
  if (((_b = column5.default) == null ? void 0 : _b.type) === "added") {
@@ -20666,7 +20815,8 @@ var init_jsonStatements = __esm({
20666
20815
  type: "alter_table_alter_column_set_default",
20667
20816
  tableName,
20668
20817
  columnName,
20669
- newDefaultValue: column5.default.value
20818
+ newDefaultValue: column5.default.value,
20819
+ schema: schema4
20670
20820
  });
20671
20821
  }
20672
20822
  if (((_c = column5.default) == null ? void 0 : _c.type) === "changed") {
@@ -20674,21 +20824,24 @@ var init_jsonStatements = __esm({
20674
20824
  type: "alter_table_alter_column_set_default",
20675
20825
  tableName,
20676
20826
  columnName,
20677
- newDefaultValue: column5.default.new
20827
+ newDefaultValue: column5.default.new,
20828
+ schema: schema4
20678
20829
  });
20679
20830
  }
20680
20831
  if (((_d = column5.default) == null ? void 0 : _d.type) === "deleted") {
20681
20832
  statements.push({
20682
20833
  type: "alter_table_alter_column_drop_default",
20683
20834
  tableName,
20684
- columnName
20835
+ columnName,
20836
+ schema: schema4
20685
20837
  });
20686
20838
  }
20687
20839
  if (((_e = column5.notNull) == null ? void 0 : _e.type) === "added") {
20688
20840
  statements.push({
20689
20841
  type: "alter_table_alter_column_set_notnull",
20690
20842
  tableName,
20691
- columnName
20843
+ columnName,
20844
+ schema: schema4
20692
20845
  });
20693
20846
  }
20694
20847
  if (((_f = column5.notNull) == null ? void 0 : _f.type) === "changed") {
@@ -20696,62 +20849,69 @@ var init_jsonStatements = __esm({
20696
20849
  statements.push({
20697
20850
  type,
20698
20851
  tableName,
20699
- columnName
20852
+ columnName,
20853
+ schema: schema4
20700
20854
  });
20701
20855
  }
20702
20856
  if (((_g = column5.notNull) == null ? void 0 : _g.type) === "deleted") {
20703
20857
  statements.push({
20704
20858
  type: "alter_table_alter_column_drop_notnull",
20705
20859
  tableName,
20706
- columnName
20860
+ columnName,
20861
+ schema: schema4
20707
20862
  });
20708
20863
  }
20709
20864
  }
20710
20865
  return statements;
20711
20866
  };
20712
- prepareCreateIndexesJson = (tableName, indexes) => {
20867
+ prepareCreateIndexesJson = (tableName, schema4, indexes) => {
20713
20868
  return Object.values(indexes).map((indexData) => {
20714
20869
  return {
20715
20870
  type: "create_index",
20716
20871
  tableName,
20717
- data: indexData
20872
+ data: indexData,
20873
+ schema: schema4
20718
20874
  };
20719
20875
  });
20720
20876
  };
20721
- prepareCreateReferencesJson = (tableName, foreignKeys) => {
20877
+ prepareCreateReferencesJson = (tableName, schema4, foreignKeys) => {
20722
20878
  return Object.values(foreignKeys).map((fkData) => {
20723
20879
  return {
20724
20880
  type: "create_reference",
20725
20881
  tableName,
20726
- data: fkData
20882
+ data: fkData,
20883
+ schema: schema4
20727
20884
  };
20728
20885
  });
20729
20886
  };
20730
- prepareDropReferencesJson = (tableName, foreignKeys) => {
20887
+ prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
20731
20888
  return Object.values(foreignKeys).map((fkData) => {
20732
20889
  return {
20733
20890
  type: "delete_reference",
20734
20891
  tableName,
20735
- data: fkData
20892
+ data: fkData,
20893
+ schema: schema4
20736
20894
  };
20737
20895
  });
20738
20896
  };
20739
- prepareAlterReferencesJson = (tableName, foreignKeys) => {
20897
+ prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
20740
20898
  return Object.values(foreignKeys).map((fkData) => {
20741
20899
  return {
20742
20900
  type: "alter_reference",
20743
20901
  tableName,
20744
20902
  data: fkData.__new,
20745
- oldFkey: fkData.__old
20903
+ oldFkey: fkData.__old,
20904
+ schema: schema4
20746
20905
  };
20747
20906
  });
20748
20907
  };
20749
- prepareDropIndexesJson = (tableName, indexes) => {
20908
+ prepareDropIndexesJson = (tableName, schema4, indexes) => {
20750
20909
  return Object.values(indexes).map((indexData) => {
20751
20910
  return {
20752
20911
  type: "drop_index",
20753
20912
  tableName,
20754
- data: indexData
20913
+ data: indexData,
20914
+ schema: schema4
20755
20915
  };
20756
20916
  });
20757
20917
  };
@@ -20787,13 +20947,14 @@ var init_jsonStatements = __esm({
20787
20947
  });
20788
20948
 
20789
20949
  // src/snapshotsDiffer.ts
20790
- var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20950
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, valueFromSelfOrPatchedNew, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20791
20951
  var init_snapshotsDiffer = __esm({
20792
20952
  "src/snapshotsDiffer.ts"() {
20793
20953
  init_sqlgenerator();
20794
20954
  init_lib();
20795
20955
  init_jsonDiffer();
20796
20956
  init_jsonStatements();
20957
+ init_utils();
20797
20958
  makeChanged = (schema4) => {
20798
20959
  return objectType({
20799
20960
  type: enumType(["changed"]),
@@ -20814,20 +20975,53 @@ var init_snapshotsDiffer = __esm({
20814
20975
  makePatched = (schema4) => {
20815
20976
  return unionType([
20816
20977
  objectType({
20817
- type: enumType(["added"]),
20978
+ type: literalType("added"),
20818
20979
  value: schema4
20819
20980
  }),
20820
20981
  objectType({
20821
- type: enumType(["deleted"]),
20982
+ type: literalType("deleted"),
20822
20983
  value: schema4
20823
20984
  }),
20824
20985
  objectType({
20825
- type: enumType(["changed"]),
20986
+ type: literalType("changed"),
20826
20987
  old: schema4,
20827
20988
  new: schema4
20828
20989
  })
20829
20990
  ]);
20830
20991
  };
20992
+ makeSelfOrPatched = (schema4) => {
20993
+ return unionType([
20994
+ objectType({
20995
+ type: literalType("none"),
20996
+ value: schema4
20997
+ }),
20998
+ objectType({
20999
+ type: literalType("added"),
21000
+ value: schema4
21001
+ }),
21002
+ objectType({
21003
+ type: literalType("deleted"),
21004
+ value: schema4
21005
+ }),
21006
+ objectType({
21007
+ type: literalType("changed"),
21008
+ old: schema4,
21009
+ new: schema4
21010
+ })
21011
+ ]);
21012
+ };
21013
+ valueFromSelfOrPatchedNew = (it) => {
21014
+ switch (it.type) {
21015
+ case "none":
21016
+ return it.value;
21017
+ case "added":
21018
+ return it.value;
21019
+ case "deleted":
21020
+ return it.value;
21021
+ case "changed":
21022
+ return it.new;
21023
+ }
21024
+ };
20831
21025
  columnSchema = objectType({
20832
21026
  name: stringType(),
20833
21027
  type: stringType(),
@@ -20840,7 +21034,7 @@ var init_snapshotsDiffer = __esm({
20840
21034
  alteredColumnSchema = objectType({
20841
21035
  name: makeSelfOrChanged(stringType()),
20842
21036
  type: makeChanged(stringType()).optional(),
20843
- default: makePatched(stringType()).optional(),
21037
+ default: makePatched(anyType()).optional(),
20844
21038
  notNull: makePatched(booleanType()).optional()
20845
21039
  }).strict();
20846
21040
  enumSchema2 = objectType({
@@ -20862,7 +21056,7 @@ var init_snapshotsDiffer = __esm({
20862
21056
  }).strict();
20863
21057
  alteredTableScheme = objectType({
20864
21058
  name: stringType(),
20865
- schema: makePatched(stringType()).optional(),
21059
+ schema: makeSelfOrPatched(stringType()),
20866
21060
  deleted: columnSchema.array(),
20867
21061
  added: columnSchema.array(),
20868
21062
  altered: alteredColumnSchema.array(),
@@ -20897,25 +21091,32 @@ var init_snapshotsDiffer = __esm({
20897
21091
  addedSchemas: stringType().array(),
20898
21092
  deletedSchemas: stringType().array()
20899
21093
  }).strict();
20900
- applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver) => {
21094
+ applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver2, tablesResolver2, columnsResolver2) => {
20901
21095
  var _a, _b, _c, _d;
20902
21096
  const diffResult = applyJsonDiff(json1, json2);
20903
21097
  if (Object.keys(diffResult).length === 0) {
20904
- return "";
21098
+ return { statements: [], sql: "" };
20905
21099
  }
20906
21100
  const typedResult = diffResultScheme.parse(diffResult);
20907
21101
  const {
20908
21102
  created: createdSchemas,
20909
21103
  deleted: deletedSchemas,
20910
21104
  renamed: renamedSchemas
20911
- } = await schemasResolver({
21105
+ } = await schemasResolver2({
20912
21106
  created: typedResult.addedSchemas.map((it) => ({ name: it })),
20913
21107
  deleted: typedResult.deletedSchemas.map((it) => ({ name: it }))
20914
21108
  });
20915
- const { created, deleted, renamed } = await tablesResolver({
21109
+ const { created, deleted, renamed } = await tablesResolver2({
20916
21110
  created: typedResult.addedTables,
20917
21111
  deleted: typedResult.deletedTables
20918
21112
  });
21113
+ const rSchemas = renamedSchemas.map((it) => ({
21114
+ from: it.from.name,
21115
+ to: it.to.name
21116
+ }));
21117
+ const rTables = renamed.map((it) => {
21118
+ return { from: it.from, to: it.to };
21119
+ });
20919
21120
  const jsonStatements = [];
20920
21121
  const jsonSQLiteCreateTables = created.map((it) => {
20921
21122
  return prepareSQLiteCreateTable(it);
@@ -20924,7 +21125,7 @@ var init_snapshotsDiffer = __esm({
20924
21125
  return prepareCreateTableJson(it);
20925
21126
  });
20926
21127
  const jsonCreateIndexesForCreatedTables = created.map((it) => {
20927
- return prepareCreateIndexesJson(it.name, it.indexes);
21128
+ return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
20928
21129
  }).flat();
20929
21130
  const jsonDropTables = deleted.map((it) => {
20930
21131
  return prepareDropTableJson(it);
@@ -20941,13 +21142,14 @@ var init_snapshotsDiffer = __esm({
20941
21142
  const jsonRenameColumnsStatements = [];
20942
21143
  const allAlteredResolved = [];
20943
21144
  for (const table4 of allAltered) {
20944
- const result = await columnsResolver({
21145
+ const result = await columnsResolver2({
20945
21146
  tableName: table4.name,
20946
21147
  created: table4.added,
20947
21148
  deleted: table4.deleted
20948
21149
  });
21150
+ const schema4 = valueFromSelfOrPatchedNew(table4.schema);
20949
21151
  jsonRenameColumnsStatements.push(
20950
- ...prepareRenameColumns(table4.name, result.renamed)
21152
+ ...prepareRenameColumns(table4.name, schema4, result.renamed)
20951
21153
  );
20952
21154
  const renamedColumnsAltered = result.renamed.map(
20953
21155
  (it) => alteredColumnSchema.parse(diffForRenamedColumn(it.from, it.to))
@@ -20989,7 +21191,7 @@ var init_snapshotsDiffer = __esm({
20989
21191
  it.name,
20990
21192
  it.alteredCompositePKs
20991
21193
  );
20992
- if (it.schema) {
21194
+ if (it.schema && typeof it.schema !== "string") {
20993
21195
  switch (it.schema.type) {
20994
21196
  case "added": {
20995
21197
  jsonSetTableSchemas.push({
@@ -21022,38 +21224,56 @@ var init_snapshotsDiffer = __esm({
21022
21224
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
21023
21225
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
21024
21226
  });
21227
+ const rColumns = jsonRenameColumnsStatements.map((it) => {
21228
+ const tableName = it.tableName;
21229
+ const schema4 = it.schema;
21230
+ return {
21231
+ from: { schema: schema4, table: tableName, column: it.oldColumnName },
21232
+ to: { schema: schema4, table: tableName, column: it.newColumnName }
21233
+ };
21234
+ });
21025
21235
  const jsonTableAlternations = allAlteredResolved.map((it) => {
21236
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21026
21237
  return prepareAlterTableColumnsJson(
21027
21238
  it.name,
21239
+ schema4,
21028
21240
  it.deleted,
21029
21241
  it.added,
21030
21242
  it.altered,
21031
21243
  it.addedForeignKeys,
21032
21244
  dialect6
21033
21245
  );
21034
- }).flat().reduce((res, it) => {
21035
- res.createColumns.push(...it.addColumns);
21036
- res.dropColumns.push(...it.dropColumns);
21037
- res.alterColumns.push(...it.alterColumns);
21038
- return res;
21039
- }, { createColumns: [], dropColumns: [], alterColumns: [] });
21246
+ }).flat().reduce(
21247
+ (res, it) => {
21248
+ res.createColumns.push(...it.addColumns);
21249
+ res.dropColumns.push(...it.dropColumns);
21250
+ res.alterColumns.push(...it.alterColumns);
21251
+ return res;
21252
+ },
21253
+ { createColumns: [], dropColumns: [], alterColumns: [] }
21254
+ );
21040
21255
  const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
21041
- return prepareCreateIndexesJson(it.name, it.addedIndexes || {});
21256
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21257
+ return prepareCreateIndexesJson(it.name, schema4, it.addedIndexes || {});
21042
21258
  }).flat();
21043
21259
  const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
21044
- return prepareDropIndexesJson(it.name, it.deletedIndexes || {});
21260
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21261
+ return prepareDropIndexesJson(it.name, schema4, it.deletedIndexes || {});
21045
21262
  }).flat();
21046
21263
  const jsonCreateReferencesForCreatedTables = created.map((it) => {
21047
- return prepareCreateReferencesJson(it.name, it.foreignKeys);
21264
+ return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
21048
21265
  }).flat();
21049
21266
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
21050
- const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, it.addedForeignKeys) : [];
21267
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21268
+ const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, schema4, it.addedForeignKeys) : [];
21051
21269
  const forAltered = prepareDropReferencesJson(
21052
21270
  it.name,
21271
+ schema4,
21053
21272
  it.deletedForeignKeys
21054
21273
  );
21055
21274
  const alteredFKs = prepareAlterReferencesJson(
21056
21275
  it.name,
21276
+ schema4,
21057
21277
  it.alteredForeignKeys
21058
21278
  );
21059
21279
  return [...forAdded, ...forAltered, ...alteredFKs];
@@ -21115,11 +21335,1333 @@ var init_snapshotsDiffer = __esm({
21115
21335
  jsonStatements.push(...jsonRemoveTableFromSchemas);
21116
21336
  jsonStatements.push(...dropSchemas);
21117
21337
  const sqlStatements = fromJson(jsonStatements, dialect6);
21118
- return sqlStatements.join("\n");
21338
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
21339
+ return { statements: jsonStatements, sql: sqlStatements.join("\n"), _meta };
21119
21340
  };
21120
21341
  }
21121
21342
  });
21122
21343
 
21344
+ // src/utils/words.ts
21345
+ var prepareMigrationMetadata, adjectives, heroes;
21346
+ var init_words = __esm({
21347
+ "src/utils/words.ts"() {
21348
+ prepareMigrationMetadata = (idx) => {
21349
+ const prefix = idx.toFixed(0).padStart(4, "0");
21350
+ const suffix = `${adjectives.random()}_${heroes.random()}`;
21351
+ const tag = `${prefix}_${suffix}`;
21352
+ return { prefix, suffix, tag };
21353
+ };
21354
+ adjectives = [
21355
+ "abandoned",
21356
+ "aberrant",
21357
+ "abnormal",
21358
+ "absent",
21359
+ "absurd",
21360
+ "acoustic",
21361
+ "adorable",
21362
+ "amazing",
21363
+ "ambiguous",
21364
+ "ambitious",
21365
+ "amused",
21366
+ "amusing",
21367
+ "ancient",
21368
+ "aromatic",
21369
+ "aspiring",
21370
+ "awesome",
21371
+ "bent",
21372
+ "big",
21373
+ "bitter",
21374
+ "bizarre",
21375
+ "black",
21376
+ "blue",
21377
+ "blushing",
21378
+ "bored",
21379
+ "boring",
21380
+ "bouncy",
21381
+ "brainy",
21382
+ "brave",
21383
+ "breezy",
21384
+ "brief",
21385
+ "bright",
21386
+ "broad",
21387
+ "broken",
21388
+ "brown",
21389
+ "bumpy",
21390
+ "burly",
21391
+ "busy",
21392
+ "calm",
21393
+ "careful",
21394
+ "careless",
21395
+ "certain",
21396
+ "charming",
21397
+ "cheerful",
21398
+ "chemical",
21399
+ "chief",
21400
+ "chilly",
21401
+ "chubby",
21402
+ "chunky",
21403
+ "clammy",
21404
+ "classy",
21405
+ "clean",
21406
+ "clear",
21407
+ "clever",
21408
+ "cloudy",
21409
+ "closed",
21410
+ "clumsy",
21411
+ "cold",
21412
+ "colorful",
21413
+ "colossal",
21414
+ "common",
21415
+ "complete",
21416
+ "complex",
21417
+ "concerned",
21418
+ "condemned",
21419
+ "confused",
21420
+ "conscious",
21421
+ "cooing",
21422
+ "cool",
21423
+ "crazy",
21424
+ "cuddly",
21425
+ "cultured",
21426
+ "curious",
21427
+ "curly",
21428
+ "curved",
21429
+ "curvy",
21430
+ "cute",
21431
+ "cynical",
21432
+ "daffy",
21433
+ "daily",
21434
+ "damp",
21435
+ "dapper",
21436
+ "dark",
21437
+ "dashing",
21438
+ "dazzling",
21439
+ "dear",
21440
+ "deep",
21441
+ "demonic",
21442
+ "dizzy",
21443
+ "dry",
21444
+ "dusty",
21445
+ "eager",
21446
+ "early",
21447
+ "easy",
21448
+ "elite",
21449
+ "eminent",
21450
+ "empty",
21451
+ "equal",
21452
+ "even",
21453
+ "exotic",
21454
+ "fair",
21455
+ "faithful",
21456
+ "familiar",
21457
+ "famous",
21458
+ "fancy",
21459
+ "fantastic",
21460
+ "far",
21461
+ "fast",
21462
+ "fat",
21463
+ "faulty",
21464
+ "fearless",
21465
+ "fine",
21466
+ "first",
21467
+ "fixed",
21468
+ "flaky",
21469
+ "flashy",
21470
+ "flat",
21471
+ "flawless",
21472
+ "flimsy",
21473
+ "flippant",
21474
+ "flowery",
21475
+ "fluffy",
21476
+ "foamy",
21477
+ "free",
21478
+ "freezing",
21479
+ "fresh",
21480
+ "friendly",
21481
+ "funny",
21482
+ "furry",
21483
+ "futuristic",
21484
+ "fuzzy",
21485
+ "giant",
21486
+ "gifted",
21487
+ "gigantic",
21488
+ "glamorous",
21489
+ "glorious",
21490
+ "glossy",
21491
+ "good",
21492
+ "goofy",
21493
+ "gorgeous",
21494
+ "graceful",
21495
+ "gray",
21496
+ "great",
21497
+ "greedy",
21498
+ "green",
21499
+ "grey",
21500
+ "groovy",
21501
+ "handy",
21502
+ "happy",
21503
+ "hard",
21504
+ "harsh",
21505
+ "heavy",
21506
+ "hesitant",
21507
+ "high",
21508
+ "hot",
21509
+ "huge",
21510
+ "icy",
21511
+ "illegal",
21512
+ "jazzy",
21513
+ "jittery",
21514
+ "keen",
21515
+ "kind",
21516
+ "known",
21517
+ "lame",
21518
+ "large",
21519
+ "last",
21520
+ "late",
21521
+ "lazy",
21522
+ "lean",
21523
+ "left",
21524
+ "legal",
21525
+ "lethal",
21526
+ "light",
21527
+ "little",
21528
+ "lively",
21529
+ "living",
21530
+ "lonely",
21531
+ "long",
21532
+ "loose",
21533
+ "loud",
21534
+ "lovely",
21535
+ "loving",
21536
+ "low",
21537
+ "lowly",
21538
+ "lucky",
21539
+ "lumpy",
21540
+ "lush",
21541
+ "luxuriant",
21542
+ "lying",
21543
+ "lyrical",
21544
+ "magenta",
21545
+ "magical",
21546
+ "majestic",
21547
+ "many",
21548
+ "massive",
21549
+ "married",
21550
+ "marvelous",
21551
+ "material",
21552
+ "mature",
21553
+ "mean",
21554
+ "medical",
21555
+ "melodic",
21556
+ "melted",
21557
+ "messy",
21558
+ "mighty",
21559
+ "military",
21560
+ "milky",
21561
+ "minor",
21562
+ "misty",
21563
+ "mixed",
21564
+ "moaning",
21565
+ "modern",
21566
+ "motionless",
21567
+ "mushy",
21568
+ "mute",
21569
+ "mysterious",
21570
+ "naive",
21571
+ "nappy",
21572
+ "narrow",
21573
+ "nasty",
21574
+ "natural",
21575
+ "neat",
21576
+ "nebulous",
21577
+ "needy",
21578
+ "nervous",
21579
+ "new",
21580
+ "next",
21581
+ "nice",
21582
+ "nifty",
21583
+ "noisy",
21584
+ "normal",
21585
+ "nostalgic",
21586
+ "nosy",
21587
+ "numerous",
21588
+ "odd",
21589
+ "old",
21590
+ "omniscient",
21591
+ "open",
21592
+ "opposite",
21593
+ "optimal",
21594
+ "orange",
21595
+ "ordinary",
21596
+ "organic",
21597
+ "outgoing",
21598
+ "outstanding",
21599
+ "oval",
21600
+ "overconfident",
21601
+ "overjoyed",
21602
+ "overrated",
21603
+ "pale",
21604
+ "panoramic",
21605
+ "parallel",
21606
+ "parched",
21607
+ "past",
21608
+ "peaceful",
21609
+ "perfect",
21610
+ "perpetual",
21611
+ "petite",
21612
+ "pink",
21613
+ "plain",
21614
+ "polite",
21615
+ "powerful",
21616
+ "premium",
21617
+ "pretty",
21618
+ "previous",
21619
+ "productive",
21620
+ "public",
21621
+ "purple",
21622
+ "puzzling",
21623
+ "quick",
21624
+ "quiet",
21625
+ "rainy",
21626
+ "rapid",
21627
+ "rare",
21628
+ "real",
21629
+ "red",
21630
+ "redundant",
21631
+ "reflective",
21632
+ "regular",
21633
+ "remarkable",
21634
+ "rich",
21635
+ "right",
21636
+ "robust",
21637
+ "romantic",
21638
+ "round",
21639
+ "sad",
21640
+ "safe",
21641
+ "salty",
21642
+ "same",
21643
+ "secret",
21644
+ "serious",
21645
+ "shallow",
21646
+ "sharp",
21647
+ "shiny",
21648
+ "shocking",
21649
+ "short",
21650
+ "silent",
21651
+ "silky",
21652
+ "silly",
21653
+ "simple",
21654
+ "skinny",
21655
+ "sleepy",
21656
+ "slim",
21657
+ "slimy",
21658
+ "slippery",
21659
+ "sloppy",
21660
+ "slow",
21661
+ "small",
21662
+ "smart",
21663
+ "smiling",
21664
+ "smooth",
21665
+ "soft",
21666
+ "solid",
21667
+ "sour",
21668
+ "sparkling",
21669
+ "special",
21670
+ "spicy",
21671
+ "spooky",
21672
+ "spotty",
21673
+ "square",
21674
+ "stale",
21675
+ "steady",
21676
+ "steep",
21677
+ "sticky",
21678
+ "stiff",
21679
+ "stormy",
21680
+ "strange",
21681
+ "striped",
21682
+ "strong",
21683
+ "sturdy",
21684
+ "sudden",
21685
+ "superb",
21686
+ "supreme",
21687
+ "sweet",
21688
+ "swift",
21689
+ "talented",
21690
+ "tan",
21691
+ "tearful",
21692
+ "tense",
21693
+ "thankful",
21694
+ "thick",
21695
+ "thin",
21696
+ "third",
21697
+ "tidy",
21698
+ "tiny",
21699
+ "tired",
21700
+ "tiresome",
21701
+ "tough",
21702
+ "tranquil",
21703
+ "tricky",
21704
+ "true",
21705
+ "typical",
21706
+ "uneven",
21707
+ "unique",
21708
+ "unknown",
21709
+ "unusual",
21710
+ "useful",
21711
+ "vengeful",
21712
+ "violet",
21713
+ "volatile",
21714
+ "wakeful",
21715
+ "wandering",
21716
+ "warm",
21717
+ "watery",
21718
+ "wealthy",
21719
+ "wet",
21720
+ "white",
21721
+ "whole",
21722
+ "wide",
21723
+ "wild",
21724
+ "windy",
21725
+ "wise",
21726
+ "wonderful",
21727
+ "wooden",
21728
+ "woozy",
21729
+ "workable",
21730
+ "worried",
21731
+ "worthless",
21732
+ "yellow",
21733
+ "yielding",
21734
+ "young",
21735
+ "youthful",
21736
+ "yummy",
21737
+ "zippy"
21738
+ ];
21739
+ heroes = [
21740
+ "aaron_stack",
21741
+ "abomination",
21742
+ "absorbing_man",
21743
+ "adam_destine",
21744
+ "adam_warlock",
21745
+ "agent_brand",
21746
+ "agent_zero",
21747
+ "albert_cleary",
21748
+ "alex_power",
21749
+ "alex_wilder",
21750
+ "alice",
21751
+ "amazoness",
21752
+ "amphibian",
21753
+ "angel",
21754
+ "anita_blake",
21755
+ "annihilus",
21756
+ "anthem",
21757
+ "apocalypse",
21758
+ "aqueduct",
21759
+ "arachne",
21760
+ "archangel",
21761
+ "arclight",
21762
+ "ares",
21763
+ "argent",
21764
+ "avengers",
21765
+ "azazel",
21766
+ "banshee",
21767
+ "baron_strucker",
21768
+ "baron_zemo",
21769
+ "barracuda",
21770
+ "bastion",
21771
+ "beast",
21772
+ "bedlam",
21773
+ "ben_grimm",
21774
+ "ben_parker",
21775
+ "ben_urich",
21776
+ "betty_brant",
21777
+ "betty_ross",
21778
+ "beyonder",
21779
+ "big_bertha",
21780
+ "bill_hollister",
21781
+ "bishop",
21782
+ "black_bird",
21783
+ "black_bolt",
21784
+ "black_cat",
21785
+ "black_crow",
21786
+ "black_knight",
21787
+ "black_panther",
21788
+ "black_queen",
21789
+ "black_tarantula",
21790
+ "black_tom",
21791
+ "black_widow",
21792
+ "blackheart",
21793
+ "blacklash",
21794
+ "blade",
21795
+ "blazing_skull",
21796
+ "blindfold",
21797
+ "blink",
21798
+ "blizzard",
21799
+ "blob",
21800
+ "blockbuster",
21801
+ "blonde_phantom",
21802
+ "bloodaxe",
21803
+ "bloodscream",
21804
+ "bloodstorm",
21805
+ "bloodstrike",
21806
+ "blue_blade",
21807
+ "blue_marvel",
21808
+ "blue_shield",
21809
+ "blur",
21810
+ "boom_boom",
21811
+ "boomer",
21812
+ "boomerang",
21813
+ "bromley",
21814
+ "brood",
21815
+ "brother_voodoo",
21816
+ "bruce_banner",
21817
+ "bucky",
21818
+ "bug",
21819
+ "bulldozer",
21820
+ "bullseye",
21821
+ "bushwacker",
21822
+ "butterfly",
21823
+ "cable",
21824
+ "callisto",
21825
+ "calypso",
21826
+ "cammi",
21827
+ "cannonball",
21828
+ "captain_america",
21829
+ "captain_britain",
21830
+ "captain_cross",
21831
+ "captain_flint",
21832
+ "captain_marvel",
21833
+ "captain_midlands",
21834
+ "captain_stacy",
21835
+ "captain_universe",
21836
+ "cardiac",
21837
+ "caretaker",
21838
+ "cargill",
21839
+ "carlie_cooper",
21840
+ "carmella_unuscione",
21841
+ "carnage",
21842
+ "cassandra_nova",
21843
+ "catseye",
21844
+ "celestials",
21845
+ "centennial",
21846
+ "cerebro",
21847
+ "cerise",
21848
+ "chamber",
21849
+ "chameleon",
21850
+ "champions",
21851
+ "changeling",
21852
+ "charles_xavier",
21853
+ "chat",
21854
+ "chimera",
21855
+ "christian_walker",
21856
+ "chronomancer",
21857
+ "clea",
21858
+ "clint_barton",
21859
+ "cloak",
21860
+ "cobalt_man",
21861
+ "colleen_wing",
21862
+ "colonel_america",
21863
+ "colossus",
21864
+ "corsair",
21865
+ "crusher_hogan",
21866
+ "crystal",
21867
+ "cyclops",
21868
+ "dagger",
21869
+ "daimon_hellstrom",
21870
+ "dakota_north",
21871
+ "daredevil",
21872
+ "dark_beast",
21873
+ "dark_phoenix",
21874
+ "darkhawk",
21875
+ "darkstar",
21876
+ "darwin",
21877
+ "dazzler",
21878
+ "deadpool",
21879
+ "deathbird",
21880
+ "deathstrike",
21881
+ "demogoblin",
21882
+ "devos",
21883
+ "dexter_bennett",
21884
+ "diamondback",
21885
+ "doctor_doom",
21886
+ "doctor_faustus",
21887
+ "doctor_octopus",
21888
+ "doctor_spectrum",
21889
+ "doctor_strange",
21890
+ "domino",
21891
+ "donald_blake",
21892
+ "doomsday",
21893
+ "doorman",
21894
+ "dorian_gray",
21895
+ "dormammu",
21896
+ "dracula",
21897
+ "dragon_lord",
21898
+ "dragon_man",
21899
+ "drax",
21900
+ "dreadnoughts",
21901
+ "dreaming_celestial",
21902
+ "dust",
21903
+ "earthquake",
21904
+ "echo",
21905
+ "eddie_brock",
21906
+ "edwin_jarvis",
21907
+ "ego",
21908
+ "electro",
21909
+ "elektra",
21910
+ "emma_frost",
21911
+ "enchantress",
21912
+ "ender_wiggin",
21913
+ "energizer",
21914
+ "epoch",
21915
+ "eternals",
21916
+ "eternity",
21917
+ "excalibur",
21918
+ "exiles",
21919
+ "exodus",
21920
+ "expediter",
21921
+ "ezekiel",
21922
+ "ezekiel_stane",
21923
+ "fabian_cortez",
21924
+ "falcon",
21925
+ "fallen_one",
21926
+ "famine",
21927
+ "fantastic_four",
21928
+ "fat_cobra",
21929
+ "felicia_hardy",
21930
+ "fenris",
21931
+ "firebird",
21932
+ "firebrand",
21933
+ "firedrake",
21934
+ "firelord",
21935
+ "firestar",
21936
+ "fixer",
21937
+ "flatman",
21938
+ "forge",
21939
+ "forgotten_one",
21940
+ "frank_castle",
21941
+ "franklin_richards",
21942
+ "franklin_storm",
21943
+ "freak",
21944
+ "frightful_four",
21945
+ "frog_thor",
21946
+ "gabe_jones",
21947
+ "galactus",
21948
+ "gambit",
21949
+ "gamma_corps",
21950
+ "gamora",
21951
+ "gargoyle",
21952
+ "garia",
21953
+ "gateway",
21954
+ "gauntlet",
21955
+ "genesis",
21956
+ "george_stacy",
21957
+ "gertrude_yorkes",
21958
+ "ghost_rider",
21959
+ "giant_girl",
21960
+ "giant_man",
21961
+ "gideon",
21962
+ "gladiator",
21963
+ "glorian",
21964
+ "goblin_queen",
21965
+ "golden_guardian",
21966
+ "goliath",
21967
+ "gorgon",
21968
+ "gorilla_man",
21969
+ "grandmaster",
21970
+ "gravity",
21971
+ "green_goblin",
21972
+ "gressill",
21973
+ "grey_gargoyle",
21974
+ "greymalkin",
21975
+ "grim_reaper",
21976
+ "groot",
21977
+ "guardian",
21978
+ "guardsmen",
21979
+ "gunslinger",
21980
+ "gwen_stacy",
21981
+ "hairball",
21982
+ "hammerhead",
21983
+ "hannibal_king",
21984
+ "hardball",
21985
+ "harpoon",
21986
+ "harrier",
21987
+ "harry_osborn",
21988
+ "havok",
21989
+ "hawkeye",
21990
+ "hedge_knight",
21991
+ "hellcat",
21992
+ "hellfire_club",
21993
+ "hellion",
21994
+ "hemingway",
21995
+ "hercules",
21996
+ "hex",
21997
+ "hiroim",
21998
+ "hitman",
21999
+ "hobgoblin",
22000
+ "hulk",
22001
+ "human_cannonball",
22002
+ "human_fly",
22003
+ "human_robot",
22004
+ "human_torch",
22005
+ "husk",
22006
+ "hydra",
22007
+ "iceman",
22008
+ "ikaris",
22009
+ "imperial_guard",
22010
+ "impossible_man",
22011
+ "inertia",
22012
+ "infant_terrible",
22013
+ "inhumans",
22014
+ "ink",
22015
+ "invaders",
22016
+ "invisible_woman",
22017
+ "iron_fist",
22018
+ "iron_lad",
22019
+ "iron_man",
22020
+ "iron_monger",
22021
+ "iron_patriot",
22022
+ "ironclad",
22023
+ "jack_flag",
22024
+ "jack_murdock",
22025
+ "jack_power",
22026
+ "jackal",
22027
+ "jackpot",
22028
+ "james_howlett",
22029
+ "jamie_braddock",
22030
+ "jane_foster",
22031
+ "jasper_sitwell",
22032
+ "jazinda",
22033
+ "jean_grey",
22034
+ "jetstream",
22035
+ "jigsaw",
22036
+ "jimmy_woo",
22037
+ "jocasta",
22038
+ "johnny_blaze",
22039
+ "johnny_storm",
22040
+ "joseph",
22041
+ "joshua_kane",
22042
+ "joystick",
22043
+ "jubilee",
22044
+ "juggernaut",
22045
+ "junta",
22046
+ "justice",
22047
+ "justin_hammer",
22048
+ "kabuki",
22049
+ "kang",
22050
+ "karen_page",
22051
+ "karma",
22052
+ "karnak",
22053
+ "kat_farrell",
22054
+ "kate_bishop",
22055
+ "katie_power",
22056
+ "ken_ellis",
22057
+ "khan",
22058
+ "kid_colt",
22059
+ "killer_shrike",
22060
+ "killmonger",
22061
+ "killraven",
22062
+ "king_bedlam",
22063
+ "king_cobra",
22064
+ "kingpin",
22065
+ "kinsey_walden",
22066
+ "kitty_pryde",
22067
+ "klaw",
22068
+ "komodo",
22069
+ "korath",
22070
+ "korg",
22071
+ "korvac",
22072
+ "kree",
22073
+ "krista_starr",
22074
+ "kronos",
22075
+ "kulan_gath",
22076
+ "kylun",
22077
+ "la_nuit",
22078
+ "lady_bullseye",
22079
+ "lady_deathstrike",
22080
+ "lady_mastermind",
22081
+ "lady_ursula",
22082
+ "lady_vermin",
22083
+ "lake",
22084
+ "landau",
22085
+ "layla_miller",
22086
+ "leader",
22087
+ "leech",
22088
+ "legion",
22089
+ "lenny_balinger",
22090
+ "leo",
22091
+ "leopardon",
22092
+ "leper_queen",
22093
+ "lester",
22094
+ "lethal_legion",
22095
+ "lifeguard",
22096
+ "lightspeed",
22097
+ "lila_cheney",
22098
+ "lilandra",
22099
+ "lilith",
22100
+ "lily_hollister",
22101
+ "lionheart",
22102
+ "living_lightning",
22103
+ "living_mummy",
22104
+ "living_tribunal",
22105
+ "liz_osborn",
22106
+ "lizard",
22107
+ "loa",
22108
+ "lockheed",
22109
+ "lockjaw",
22110
+ "logan",
22111
+ "loki",
22112
+ "loners",
22113
+ "longshot",
22114
+ "lord_hawal",
22115
+ "lord_tyger",
22116
+ "lorna_dane",
22117
+ "luckman",
22118
+ "lucky_pierre",
22119
+ "luke_cage",
22120
+ "luminals",
22121
+ "lyja",
22122
+ "ma_gnuci",
22123
+ "mac_gargan",
22124
+ "mach_iv",
22125
+ "machine_man",
22126
+ "mad_thinker",
22127
+ "madame_hydra",
22128
+ "madame_masque",
22129
+ "madame_web",
22130
+ "maddog",
22131
+ "madelyne_pryor",
22132
+ "madripoor",
22133
+ "madrox",
22134
+ "maelstrom",
22135
+ "maestro",
22136
+ "magdalene",
22137
+ "maggott",
22138
+ "magik",
22139
+ "maginty",
22140
+ "magma",
22141
+ "magneto",
22142
+ "magus",
22143
+ "major_mapleleaf",
22144
+ "makkari",
22145
+ "malcolm_colcord",
22146
+ "malice",
22147
+ "mandarin",
22148
+ "mandrill",
22149
+ "mandroid",
22150
+ "manta",
22151
+ "mantis",
22152
+ "marauders",
22153
+ "maria_hill",
22154
+ "mariko_yashida",
22155
+ "marrow",
22156
+ "marten_broadcloak",
22157
+ "martin_li",
22158
+ "marvel_apes",
22159
+ "marvel_boy",
22160
+ "marvel_zombies",
22161
+ "marvex",
22162
+ "masked_marvel",
22163
+ "masque",
22164
+ "master_chief",
22165
+ "master_mold",
22166
+ "mastermind",
22167
+ "mathemanic",
22168
+ "matthew_murdock",
22169
+ "mattie_franklin",
22170
+ "mauler",
22171
+ "maverick",
22172
+ "maximus",
22173
+ "may_parker",
22174
+ "medusa",
22175
+ "meggan",
22176
+ "meltdown",
22177
+ "menace",
22178
+ "mentallo",
22179
+ "mentor",
22180
+ "mephisto",
22181
+ "mephistopheles",
22182
+ "mercury",
22183
+ "mesmero",
22184
+ "metal_master",
22185
+ "meteorite",
22186
+ "micro/macro",
22187
+ "microbe",
22188
+ "microchip",
22189
+ "micromax",
22190
+ "midnight",
22191
+ "miek",
22192
+ "mikhail_rasputin",
22193
+ "millenium_guard",
22194
+ "mimic",
22195
+ "mindworm",
22196
+ "miracleman",
22197
+ "miss_america",
22198
+ "mister_fear",
22199
+ "mister_sinister",
22200
+ "misty_knight",
22201
+ "mockingbird",
22202
+ "moira_mactaggert",
22203
+ "mojo",
22204
+ "mole_man",
22205
+ "molecule_man",
22206
+ "molly_hayes",
22207
+ "molten_man",
22208
+ "mongoose",
22209
+ "mongu",
22210
+ "monster_badoon",
22211
+ "moon_knight",
22212
+ "moondragon",
22213
+ "moonstone",
22214
+ "morbius",
22215
+ "mordo",
22216
+ "morg",
22217
+ "morgan_stark",
22218
+ "morlocks",
22219
+ "morlun",
22220
+ "morph",
22221
+ "mother_askani",
22222
+ "mulholland_black",
22223
+ "multiple_man",
22224
+ "mysterio",
22225
+ "mystique",
22226
+ "namor",
22227
+ "namora",
22228
+ "namorita",
22229
+ "naoko",
22230
+ "natasha_romanoff",
22231
+ "nebula",
22232
+ "nehzno",
22233
+ "nekra",
22234
+ "nemesis",
22235
+ "network",
22236
+ "newton_destine",
22237
+ "next_avengers",
22238
+ "nextwave",
22239
+ "nick_fury",
22240
+ "nico_minoru",
22241
+ "nicolaos",
22242
+ "night_nurse",
22243
+ "night_thrasher",
22244
+ "nightcrawler",
22245
+ "nighthawk",
22246
+ "nightmare",
22247
+ "nightshade",
22248
+ "nitro",
22249
+ "nocturne",
22250
+ "nomad",
22251
+ "norman_osborn",
22252
+ "norrin_radd",
22253
+ "northstar",
22254
+ "nova",
22255
+ "nuke",
22256
+ "obadiah_stane",
22257
+ "odin",
22258
+ "ogun",
22259
+ "old_lace",
22260
+ "omega_flight",
22261
+ "omega_red",
22262
+ "omega_sentinel",
22263
+ "onslaught",
22264
+ "oracle",
22265
+ "orphan",
22266
+ "otto_octavius",
22267
+ "outlaw_kid",
22268
+ "overlord",
22269
+ "owl",
22270
+ "ozymandias",
22271
+ "paibok",
22272
+ "paladin",
22273
+ "pandemic",
22274
+ "paper_doll",
22275
+ "patch",
22276
+ "patriot",
22277
+ "payback",
22278
+ "penance",
22279
+ "pepper_potts",
22280
+ "pestilence",
22281
+ "pet_avengers",
22282
+ "pete_wisdom",
22283
+ "peter_parker",
22284
+ "peter_quill",
22285
+ "phalanx",
22286
+ "phantom_reporter",
22287
+ "phil_sheldon",
22288
+ "photon",
22289
+ "piledriver",
22290
+ "pixie",
22291
+ "plazm",
22292
+ "polaris",
22293
+ "post",
22294
+ "power_man",
22295
+ "power_pack",
22296
+ "praxagora",
22297
+ "preak",
22298
+ "pretty_boy",
22299
+ "pride",
22300
+ "prima",
22301
+ "princess_powerful",
22302
+ "prism",
22303
+ "prodigy",
22304
+ "proemial_gods",
22305
+ "professor_monster",
22306
+ "proteus",
22307
+ "proudstar",
22308
+ "prowler",
22309
+ "psylocke",
22310
+ "psynapse",
22311
+ "puck",
22312
+ "puff_adder",
22313
+ "puma",
22314
+ "punisher",
22315
+ "puppet_master",
22316
+ "purifiers",
22317
+ "purple_man",
22318
+ "pyro",
22319
+ "quasar",
22320
+ "quasimodo",
22321
+ "queen_noir",
22322
+ "quentin_quire",
22323
+ "quicksilver",
22324
+ "rachel_grey",
22325
+ "radioactive_man",
22326
+ "rafael_vega",
22327
+ "rage",
22328
+ "raider",
22329
+ "randall",
22330
+ "randall_flagg",
22331
+ "random",
22332
+ "rattler",
22333
+ "ravenous",
22334
+ "rawhide_kid",
22335
+ "raza",
22336
+ "reaper",
22337
+ "reavers",
22338
+ "red_ghost",
22339
+ "red_hulk",
22340
+ "red_shift",
22341
+ "red_skull",
22342
+ "red_wolf",
22343
+ "redwing",
22344
+ "reptil",
22345
+ "retro_girl",
22346
+ "revanche",
22347
+ "rhino",
22348
+ "rhodey",
22349
+ "richard_fisk",
22350
+ "rick_jones",
22351
+ "ricochet",
22352
+ "rictor",
22353
+ "riptide",
22354
+ "risque",
22355
+ "robbie_robertson",
22356
+ "robin_chapel",
22357
+ "rocket_raccoon",
22358
+ "rocket_racer",
22359
+ "rockslide",
22360
+ "rogue",
22361
+ "roland_deschain",
22362
+ "romulus",
22363
+ "ronan",
22364
+ "roughhouse",
22365
+ "roulette",
22366
+ "roxanne_simpson",
22367
+ "rumiko_fujikawa",
22368
+ "runaways",
22369
+ "russian",
22370
+ "sabra",
22371
+ "sabretooth",
22372
+ "sage",
22373
+ "sally_floyd",
22374
+ "salo",
22375
+ "sandman",
22376
+ "santa_claus",
22377
+ "saracen",
22378
+ "sasquatch",
22379
+ "satana",
22380
+ "sauron",
22381
+ "scalphunter",
22382
+ "scarecrow",
22383
+ "scarlet_spider",
22384
+ "scarlet_witch",
22385
+ "scorpion",
22386
+ "scourge",
22387
+ "scrambler",
22388
+ "scream",
22389
+ "screwball",
22390
+ "sebastian_shaw",
22391
+ "secret_warriors",
22392
+ "selene",
22393
+ "senator_kelly",
22394
+ "sentinel",
22395
+ "sentinels",
22396
+ "sentry",
22397
+ "ser_duncan",
22398
+ "serpent_society",
22399
+ "sersi",
22400
+ "shadow_king",
22401
+ "shadowcat",
22402
+ "shaman",
22403
+ "shape",
22404
+ "shard",
22405
+ "sharon_carter",
22406
+ "sharon_ventura",
22407
+ "shatterstar",
22408
+ "shen",
22409
+ "sheva_callister",
22410
+ "shinko_yamashiro",
22411
+ "shinobi_shaw",
22412
+ "shiva",
22413
+ "shiver_man",
22414
+ "shocker",
22415
+ "shockwave",
22416
+ "shooting_star",
22417
+ "shotgun",
22418
+ "shriek",
22419
+ "silhouette",
22420
+ "silk_fever",
22421
+ "silver_centurion",
22422
+ "silver_fox",
22423
+ "silver_sable",
22424
+ "silver_samurai",
22425
+ "silver_surfer",
22426
+ "silverclaw",
22427
+ "silvermane",
22428
+ "sinister_six",
22429
+ "sir_ram",
22430
+ "siren",
22431
+ "sister_grimm",
22432
+ "skaar",
22433
+ "skin",
22434
+ "skreet",
22435
+ "skrulls",
22436
+ "skullbuster",
22437
+ "slapstick",
22438
+ "slayback",
22439
+ "sleeper",
22440
+ "sleepwalker",
22441
+ "slipstream",
22442
+ "slyde",
22443
+ "smasher",
22444
+ "smiling_tiger",
22445
+ "snowbird",
22446
+ "solo",
22447
+ "songbird",
22448
+ "spacker_dave",
22449
+ "spectrum",
22450
+ "speed",
22451
+ "speed_demon",
22452
+ "speedball",
22453
+ "spencer_smythe",
22454
+ "sphinx",
22455
+ "spiral",
22456
+ "spirit",
22457
+ "spitfire",
22458
+ "spot",
22459
+ "sprite",
22460
+ "spyke",
22461
+ "squadron_sinister",
22462
+ "squadron_supreme",
22463
+ "squirrel_girl",
22464
+ "star_brand",
22465
+ "starbolt",
22466
+ "stardust",
22467
+ "starfox",
22468
+ "starhawk",
22469
+ "starjammers",
22470
+ "stark_industries",
22471
+ "stature",
22472
+ "steel_serpent",
22473
+ "stellaris",
22474
+ "stepford_cuckoos",
22475
+ "stephen_strange",
22476
+ "steve_rogers",
22477
+ "stick",
22478
+ "stingray",
22479
+ "stone_men",
22480
+ "storm",
22481
+ "stranger",
22482
+ "strong_guy",
22483
+ "stryfe",
22484
+ "sue_storm",
22485
+ "sugar_man",
22486
+ "sumo",
22487
+ "sunfire",
22488
+ "sunset_bain",
22489
+ "sunspot",
22490
+ "supernaut",
22491
+ "supreme_intelligence",
22492
+ "surge",
22493
+ "susan_delgado",
22494
+ "swarm",
22495
+ "sway",
22496
+ "switch",
22497
+ "swordsman",
22498
+ "synch",
22499
+ "tag",
22500
+ "talisman",
22501
+ "talkback",
22502
+ "talon",
22503
+ "talos",
22504
+ "tana_nile",
22505
+ "tarantula",
22506
+ "tarot",
22507
+ "taskmaster",
22508
+ "tattoo",
22509
+ "ted_forrester",
22510
+ "tempest",
22511
+ "tenebrous",
22512
+ "terrax",
22513
+ "terror",
22514
+ "texas_twister",
22515
+ "thaddeus_ross",
22516
+ "thanos",
22517
+ "the_anarchist",
22518
+ "the_call",
22519
+ "the_captain",
22520
+ "the_enforcers",
22521
+ "the_executioner",
22522
+ "the_fallen",
22523
+ "the_fury",
22524
+ "the_hand",
22525
+ "the_hood",
22526
+ "the_hunter",
22527
+ "the_initiative",
22528
+ "the_leader",
22529
+ "the_liberteens",
22530
+ "the_order",
22531
+ "the_phantom",
22532
+ "the_professor",
22533
+ "the_renegades",
22534
+ "the_santerians",
22535
+ "the_spike",
22536
+ "the_stranger",
22537
+ "the_twelve",
22538
+ "the_watchers",
22539
+ "thena",
22540
+ "thing",
22541
+ "thor",
22542
+ "thor_girl",
22543
+ "thunderball",
22544
+ "thunderbird",
22545
+ "thunderbolt",
22546
+ "thunderbolt_ross",
22547
+ "thunderbolts",
22548
+ "thundra",
22549
+ "tiger_shark",
22550
+ "tigra",
22551
+ "timeslip",
22552
+ "tinkerer",
22553
+ "titania",
22554
+ "titanium_man",
22555
+ "toad",
22556
+ "toad_men",
22557
+ "tomas",
22558
+ "tombstone",
22559
+ "tomorrow_man",
22560
+ "tony_stark",
22561
+ "toro",
22562
+ "toxin",
22563
+ "trauma",
22564
+ "triathlon",
22565
+ "trish_tilby",
22566
+ "triton",
22567
+ "true_believers",
22568
+ "turbo",
22569
+ "tusk",
22570
+ "tyger_tiger",
22571
+ "typhoid_mary",
22572
+ "tyrannus",
22573
+ "ulik",
22574
+ "ultimates",
22575
+ "ultimatum",
22576
+ "ultimo",
22577
+ "ultragirl",
22578
+ "ultron",
22579
+ "umar",
22580
+ "unicorn",
22581
+ "union_jack",
22582
+ "unus",
22583
+ "valeria_richards",
22584
+ "valkyrie",
22585
+ "vampiro",
22586
+ "vance_astro",
22587
+ "vanisher",
22588
+ "vapor",
22589
+ "vargas",
22590
+ "vector",
22591
+ "veda",
22592
+ "vengeance",
22593
+ "venom",
22594
+ "venus",
22595
+ "vermin",
22596
+ "vertigo",
22597
+ "victor_mancha",
22598
+ "vin_gonzales",
22599
+ "vindicator",
22600
+ "violations",
22601
+ "viper",
22602
+ "virginia_dare",
22603
+ "vision",
22604
+ "vivisector",
22605
+ "vulcan",
22606
+ "vulture",
22607
+ "wallflower",
22608
+ "wallop",
22609
+ "wallow",
22610
+ "war_machine",
22611
+ "warbird",
22612
+ "warbound",
22613
+ "warhawk",
22614
+ "warlock",
22615
+ "warpath",
22616
+ "warstar",
22617
+ "wasp",
22618
+ "weapon_omega",
22619
+ "wendell_rand",
22620
+ "wendell_vaughn",
22621
+ "wendigo",
22622
+ "whiplash",
22623
+ "whirlwind",
22624
+ "whistler",
22625
+ "white_queen",
22626
+ "white_tiger",
22627
+ "whizzer",
22628
+ "wiccan",
22629
+ "wild_child",
22630
+ "wild_pack",
22631
+ "wildside",
22632
+ "william_stryker",
22633
+ "wilson_fisk",
22634
+ "wind_dancer",
22635
+ "winter_soldier",
22636
+ "wither",
22637
+ "wolf_cub",
22638
+ "wolfpack",
22639
+ "wolfsbane",
22640
+ "wolverine",
22641
+ "wonder_man",
22642
+ "wong",
22643
+ "wraith",
22644
+ "wrecker",
22645
+ "wrecking_crew",
22646
+ "xavin",
22647
+ "xorn",
22648
+ "yellow_claw",
22649
+ "yellowjacket",
22650
+ "young_avengers",
22651
+ "zaladane",
22652
+ "zaran",
22653
+ "zarda",
22654
+ "zarek",
22655
+ "zeigeist",
22656
+ "zemo",
22657
+ "zodiak",
22658
+ "zombie",
22659
+ "zuras",
22660
+ "zzzax"
22661
+ ];
22662
+ }
22663
+ });
22664
+
21123
22665
  // src/cli/commands/migrate.ts
21124
22666
  var migrate_exports = {};
21125
22667
  __export(migrate_exports, {
@@ -21127,15 +22669,16 @@ __export(migrate_exports, {
21127
22669
  prepareAndMigratePg: () => prepareAndMigratePg,
21128
22670
  prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
21129
22671
  prepareSQL: () => prepareSQL,
21130
- prepareSnapshotFolderName: () => prepareSnapshotFolderName
22672
+ prepareSnapshotFolderName: () => prepareSnapshotFolderName,
22673
+ writeResult: () => writeResult
21131
22674
  });
21132
- var import_fs4, import_path2, import_hanji2, prepareAndMigratePg, prepareAndMigrateSqlite, prepareAndMigrateMySql, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
22675
+ var import_fs4, import_path3, import_hanji2, prepareAndMigratePg, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
21133
22676
  var init_migrate = __esm({
21134
22677
  "src/cli/commands/migrate.ts"() {
21135
22678
  import_fs4 = __toESM(require("fs"));
21136
22679
  init_migrationPreparator();
21137
22680
  init_snapshotsDiffer();
21138
- import_path2 = __toESM(require("path"));
22681
+ import_path3 = __toESM(require("path"));
21139
22682
  import_hanji2 = __toESM(require_hanji());
21140
22683
  init_views();
21141
22684
  init_source();
@@ -21143,68 +22686,68 @@ var init_migrate = __esm({
21143
22686
  init_sqliteSchema();
21144
22687
  init_mysqlSchema();
21145
22688
  init_utils();
22689
+ init_words();
21146
22690
  prepareAndMigratePg = async (config) => {
21147
22691
  const outFolder = config.out;
21148
22692
  const schemaPath = config.schema;
21149
22693
  try {
21150
- const { migrationFolders } = prepareMigrationFolder(outFolder, "pg");
21151
- const { prev, cur } = preparePgMigrationSnapshot(
21152
- migrationFolders,
21153
- outFolder,
21154
- schemaPath
21155
- );
22694
+ assertV1OutFolder(outFolder, "pg");
22695
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
22696
+ const { prev, cur } = preparePgMigrationSnapshot(snapshots, schemaPath);
21156
22697
  const validatedPrev = pgSchema.parse(prev);
21157
22698
  const validatedCur = pgSchema.parse(cur);
21158
22699
  const squashedPrev = squashPgScheme(validatedPrev);
21159
22700
  const squashedCur = squashPgScheme(validatedCur);
21160
- const sql = await prepareSQL(squashedPrev, squashedCur, "pg");
21161
- writeResult(cur, sql, outFolder);
22701
+ const { statements, sql, _meta } = await prepareSQL(
22702
+ squashedPrev,
22703
+ squashedCur,
22704
+ "pg"
22705
+ );
22706
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21162
22707
  } catch (e) {
21163
22708
  console.error(e);
21164
22709
  }
21165
22710
  };
21166
- prepareAndMigrateSqlite = async (config) => {
22711
+ prepareAndMigrateMySql = async (config) => {
21167
22712
  const outFolder = config.out;
21168
22713
  const schemaPath = config.schema;
21169
22714
  try {
21170
- const { migrationFolders } = prepareMigrationFolder(outFolder, "sqlite");
21171
- const { prev, cur } = prepareSqliteMigrationSnapshot(
21172
- migrationFolders,
21173
- outFolder,
21174
- schemaPath
22715
+ assertV1OutFolder(outFolder, "mysql");
22716
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "mysql");
22717
+ const { prev, cur } = prepareMySqlMigrationSnapshot(snapshots, schemaPath);
22718
+ const validatedPrev = mysqlSchema.parse(prev);
22719
+ const validatedCur = mysqlSchema.parse(cur);
22720
+ const squashedPrev = squashMysqlScheme(validatedPrev);
22721
+ const squashedCur = squashMysqlScheme(validatedCur);
22722
+ const { sql, _meta } = await prepareSQL(
22723
+ squashedPrev,
22724
+ squashedCur,
22725
+ "sqlite"
21175
22726
  );
21176
- const validatedPrev = sqliteSchema.parse(prev);
21177
- const validatedCur = sqliteSchema.parse(cur);
21178
- const squashedPrev = squashSqliteScheme(validatedPrev);
21179
- const squashedCur = squashSqliteScheme(validatedCur);
21180
- const sql = await prepareSQL(squashedPrev, squashedCur, "sqlite");
21181
- writeResult(cur, sql, outFolder);
22727
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21182
22728
  } catch (e) {
21183
22729
  console.error(e);
21184
22730
  }
21185
22731
  };
21186
- prepareAndMigrateMySql = async (config) => {
22732
+ prepareAndMigrateSqlite = async (config) => {
21187
22733
  const outFolder = config.out;
21188
22734
  const schemaPath = config.schema;
21189
22735
  try {
21190
- const { migrationFolders } = prepareMigrationFolder(outFolder, "mysql");
21191
- const { prev, cur } = prepareMySqlMigrationSnapshot(
21192
- migrationFolders,
21193
- outFolder,
21194
- schemaPath
21195
- );
21196
- const validatedPrev = mysqlSchema.parse(prev);
21197
- const validatedCur = mysqlSchema.parse(cur);
21198
- const squashedPrev = squashMysqlScheme(validatedPrev);
21199
- const squashedCur = squashMysqlScheme(validatedCur);
21200
- const sql = await prepareSQL(squashedPrev, squashedCur, "mysql");
21201
- writeResult(cur, sql, outFolder);
22736
+ assertV1OutFolder(outFolder, "sqlite");
22737
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
22738
+ const { prev, cur } = prepareSqliteMigrationSnapshot(snapshots, schemaPath);
22739
+ const validatedPrev = sqliteSchema.parse(prev);
22740
+ const validatedCur = sqliteSchema.parse(cur);
22741
+ const squashedPrev = squashSqliteScheme(validatedPrev);
22742
+ const squashedCur = squashSqliteScheme(validatedCur);
22743
+ const { sql, _meta } = await prepareSQL(squashedPrev, squashedCur, "mysql");
22744
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21202
22745
  } catch (e) {
21203
22746
  console.error(e);
21204
22747
  }
21205
22748
  };
21206
22749
  prepareSQL = async (prev, cur, dialect6) => {
21207
- const schemasResolver = async (input) => {
22750
+ const schemasResolver2 = async (input) => {
21208
22751
  try {
21209
22752
  const { created, deleted, renamed } = await promptSchemasConflict(
21210
22753
  input.created,
@@ -21216,7 +22759,7 @@ var init_migrate = __esm({
21216
22759
  throw e;
21217
22760
  }
21218
22761
  };
21219
- const tablesResolver = async (input) => {
22762
+ const tablesResolver2 = async (input) => {
21220
22763
  try {
21221
22764
  const { created, deleted, renamed } = await promptTablesConflict(
21222
22765
  input.created,
@@ -21228,7 +22771,7 @@ var init_migrate = __esm({
21228
22771
  throw e;
21229
22772
  }
21230
22773
  };
21231
- const columnsResolver = async (input) => {
22774
+ const columnsResolver2 = async (input) => {
21232
22775
  const result = await promptColumnsConflicts(
21233
22776
  input.tableName,
21234
22777
  input.created,
@@ -21245,9 +22788,9 @@ var init_migrate = __esm({
21245
22788
  prev,
21246
22789
  cur,
21247
22790
  dialect6,
21248
- schemasResolver,
21249
- tablesResolver,
21250
- columnsResolver
22791
+ schemasResolver2,
22792
+ tablesResolver2,
22793
+ columnsResolver2
21251
22794
  );
21252
22795
  };
21253
22796
  promptColumnsConflicts = async (tableName, newColumns, missingColumns) => {
@@ -21382,24 +22925,34 @@ var init_migrate = __esm({
21382
22925
  result.deleted.push(...leftMissing);
21383
22926
  return result;
21384
22927
  };
21385
- writeResult = (cur, sql, outFolder) => {
22928
+ writeResult = (cur, sql, idx, journal, _meta, outFolder) => {
21386
22929
  console.log(schema(cur));
21387
22930
  if (sql.length === 0) {
21388
22931
  console.log("No schema changes, nothing to migrate \u{1F634}");
21389
22932
  return;
21390
22933
  }
22934
+ const { prefix, tag } = prepareMigrationMetadata(idx);
21391
22935
  const toSave = JSON.parse(JSON.stringify(cur));
21392
- const folderName = prepareSnapshotFolderName();
21393
- const migrationFolderPath = `./${outFolder}/${folderName}`;
21394
- import_fs4.default.mkdirSync(migrationFolderPath);
22936
+ toSave["_meta"] = _meta;
22937
+ const metaFolderPath = (0, import_path3.join)(outFolder, "meta");
22938
+ const metaJournal = (0, import_path3.join)(metaFolderPath, "_journal.json");
21395
22939
  import_fs4.default.writeFileSync(
21396
- `${migrationFolderPath}/snapshot.json`,
22940
+ (0, import_path3.join)(metaFolderPath, `${prefix}_snapshot.json`),
21397
22941
  JSON.stringify(toSave, null, 2)
21398
22942
  );
21399
- import_fs4.default.writeFileSync(`${migrationFolderPath}/migration.sql`, sql);
21400
- console.log(
21401
- source_default.bold.green("Done:"),
21402
- import_path2.default.join(`${migrationFolderPath}/migration.sql`)
22943
+ journal.entries.push({
22944
+ idx,
22945
+ when: +new Date(),
22946
+ tag
22947
+ });
22948
+ import_fs4.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
22949
+ import_fs4.default.writeFileSync(`${outFolder}/${tag}.sql`, sql);
22950
+ (0, import_hanji2.render)(
22951
+ `[${source_default.green(
22952
+ "\u2713"
22953
+ )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(
22954
+ import_path3.default.join(`${outFolder}/${tag}.sql`)
22955
+ )} \u{1F680}`
21403
22956
  );
21404
22957
  };
21405
22958
  prepareSnapshotFolderName = () => {
@@ -21436,6 +22989,9 @@ var init_utils2 = __esm({
21436
22989
  return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
21437
22990
  });
21438
22991
  };
22992
+ Array.prototype.random = function() {
22993
+ return this[~~(Math.random() * this.length)];
22994
+ };
21439
22995
  }
21440
22996
  });
21441
22997
 
@@ -22385,9 +23941,9 @@ var require_pg_types = __commonJS({
22385
23941
  }
22386
23942
  });
22387
23943
 
22388
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js
23944
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/defaults.js
22389
23945
  var require_defaults = __commonJS({
22390
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js"(exports, module2) {
23946
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/defaults.js"(exports, module2) {
22391
23947
  "use strict";
22392
23948
  module2.exports = {
22393
23949
  host: "localhost",
@@ -22424,9 +23980,9 @@ var require_defaults = __commonJS({
22424
23980
  }
22425
23981
  });
22426
23982
 
22427
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js
23983
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/utils.js
22428
23984
  var require_utils2 = __commonJS({
22429
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js"(exports, module2) {
23985
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/utils.js"(exports, module2) {
22430
23986
  "use strict";
22431
23987
  var crypto = require("crypto");
22432
23988
  var defaults = require_defaults();
@@ -22562,9 +24118,9 @@ var require_utils2 = __commonJS({
22562
24118
  }
22563
24119
  });
22564
24120
 
22565
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js
24121
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/sasl.js
22566
24122
  var require_sasl = __commonJS({
22567
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js"(exports, module2) {
24123
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/sasl.js"(exports, module2) {
22568
24124
  "use strict";
22569
24125
  var crypto = require("crypto");
22570
24126
  function startSession(mechanisms) {
@@ -22586,6 +24142,9 @@ var require_sasl = __commonJS({
22586
24142
  if (typeof password !== "string") {
22587
24143
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string");
22588
24144
  }
24145
+ if (password === "") {
24146
+ throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string");
24147
+ }
22589
24148
  if (typeof serverData !== "string") {
22590
24149
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string");
22591
24150
  }
@@ -22596,7 +24155,7 @@ var require_sasl = __commonJS({
22596
24155
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
22597
24156
  }
22598
24157
  var saltBytes = Buffer.from(sv.salt, "base64");
22599
- var saltedPassword = Hi(password, saltBytes, sv.iteration);
24158
+ var saltedPassword = crypto.pbkdf2Sync(password, saltBytes, sv.iteration, 32, "sha256");
22600
24159
  var clientKey = hmacSha256(saltedPassword, "Client Key");
22601
24160
  var storedKey = sha256(clientKey);
22602
24161
  var clientFirstMessageBare = "n=*,r=" + session.clientNonce;
@@ -22708,15 +24267,6 @@ var require_sasl = __commonJS({
22708
24267
  function hmacSha256(key, msg) {
22709
24268
  return crypto.createHmac("sha256", key).update(msg).digest();
22710
24269
  }
22711
- function Hi(password, saltBytes, iterations) {
22712
- var ui1 = hmacSha256(password, Buffer.concat([saltBytes, Buffer.from([0, 0, 0, 1])]));
22713
- var ui = ui1;
22714
- for (var i = 0; i < iterations - 1; i++) {
22715
- ui1 = hmacSha256(password, ui1);
22716
- ui = xorBuffers(ui, ui1);
22717
- }
22718
- return ui;
22719
- }
22720
24270
  module2.exports = {
22721
24271
  startSession,
22722
24272
  continueSession,
@@ -22831,7 +24381,7 @@ var require_split2 = __commonJS({
22831
24381
  var require_helper = __commonJS({
22832
24382
  "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js"(exports, module2) {
22833
24383
  "use strict";
22834
- var path5 = require("path");
24384
+ var path4 = require("path");
22835
24385
  var Stream = require("stream").Stream;
22836
24386
  var split = require_split2();
22837
24387
  var util2 = require("util");
@@ -22870,7 +24420,7 @@ var require_helper = __commonJS({
22870
24420
  };
22871
24421
  module2.exports.getFileName = function(rawEnv) {
22872
24422
  var env2 = rawEnv || process.env;
22873
- var file = env2.PGPASSFILE || (isWin ? path5.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path5.join(env2.HOME || "./", ".pgpass"));
24423
+ var file = env2.PGPASSFILE || (isWin ? path4.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path4.join(env2.HOME || "./", ".pgpass"));
22874
24424
  return file;
22875
24425
  };
22876
24426
  module2.exports.usePgPass = function(stats, fname) {
@@ -22997,7 +24547,7 @@ var require_helper = __commonJS({
22997
24547
  var require_lib2 = __commonJS({
22998
24548
  "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js"(exports, module2) {
22999
24549
  "use strict";
23000
- var path5 = require("path");
24550
+ var path4 = require("path");
23001
24551
  var fs7 = require("fs");
23002
24552
  var helper = require_helper();
23003
24553
  module2.exports = function(connInfo, cb) {
@@ -23014,9 +24564,9 @@ var require_lib2 = __commonJS({
23014
24564
  }
23015
24565
  });
23016
24566
 
23017
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js
24567
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/type-overrides.js
23018
24568
  var require_type_overrides = __commonJS({
23019
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js"(exports, module2) {
24569
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/type-overrides.js"(exports, module2) {
23020
24570
  "use strict";
23021
24571
  var types = require_pg_types();
23022
24572
  function TypeOverrides(userTypes) {
@@ -23134,9 +24684,9 @@ var require_pg_connection_string = __commonJS({
23134
24684
  }
23135
24685
  });
23136
24686
 
23137
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js
24687
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection-parameters.js
23138
24688
  var require_connection_parameters = __commonJS({
23139
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
24689
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
23140
24690
  "use strict";
23141
24691
  var dns = require("dns");
23142
24692
  var defaults = require_defaults();
@@ -23273,9 +24823,9 @@ var require_connection_parameters = __commonJS({
23273
24823
  }
23274
24824
  });
23275
24825
 
23276
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js
24826
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/result.js
23277
24827
  var require_result = __commonJS({
23278
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js"(exports, module2) {
24828
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/result.js"(exports, module2) {
23279
24829
  "use strict";
23280
24830
  var types = require_pg_types();
23281
24831
  var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/;
@@ -23358,9 +24908,9 @@ var require_result = __commonJS({
23358
24908
  }
23359
24909
  });
23360
24910
 
23361
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js
24911
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/query.js
23362
24912
  var require_query = __commonJS({
23363
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js"(exports, module2) {
24913
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/query.js"(exports, module2) {
23364
24914
  "use strict";
23365
24915
  var { EventEmitter } = require("events");
23366
24916
  var Result = require_result();
@@ -23541,9 +25091,9 @@ var require_query = __commonJS({
23541
25091
  }
23542
25092
  });
23543
25093
 
23544
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/messages.js
25094
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/messages.js
23545
25095
  var require_messages = __commonJS({
23546
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/messages.js"(exports) {
25096
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/messages.js"(exports) {
23547
25097
  "use strict";
23548
25098
  Object.defineProperty(exports, "__esModule", { value: true });
23549
25099
  exports.NoticeMessage = exports.DataRowMessage = exports.CommandCompleteMessage = exports.ReadyForQueryMessage = exports.NotificationResponseMessage = exports.BackendKeyDataMessage = exports.AuthenticationMD5Password = exports.ParameterStatusMessage = exports.ParameterDescriptionMessage = exports.RowDescriptionMessage = exports.Field = exports.CopyResponse = exports.CopyDataMessage = exports.DatabaseError = exports.copyDone = exports.emptyQuery = exports.replicationStart = exports.portalSuspended = exports.noData = exports.closeComplete = exports.bindComplete = exports.parseComplete = void 0;
@@ -23706,9 +25256,9 @@ var require_messages = __commonJS({
23706
25256
  }
23707
25257
  });
23708
25258
 
23709
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-writer.js
25259
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-writer.js
23710
25260
  var require_buffer_writer = __commonJS({
23711
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-writer.js"(exports) {
25261
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-writer.js"(exports) {
23712
25262
  "use strict";
23713
25263
  Object.defineProperty(exports, "__esModule", { value: true });
23714
25264
  exports.Writer = void 0;
@@ -23787,9 +25337,9 @@ var require_buffer_writer = __commonJS({
23787
25337
  }
23788
25338
  });
23789
25339
 
23790
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/serializer.js
25340
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/serializer.js
23791
25341
  var require_serializer = __commonJS({
23792
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/serializer.js"(exports) {
25342
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/serializer.js"(exports) {
23793
25343
  "use strict";
23794
25344
  Object.defineProperty(exports, "__esModule", { value: true });
23795
25345
  exports.serialize = void 0;
@@ -23952,9 +25502,9 @@ var require_serializer = __commonJS({
23952
25502
  }
23953
25503
  });
23954
25504
 
23955
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-reader.js
25505
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-reader.js
23956
25506
  var require_buffer_reader = __commonJS({
23957
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-reader.js"(exports) {
25507
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-reader.js"(exports) {
23958
25508
  "use strict";
23959
25509
  Object.defineProperty(exports, "__esModule", { value: true });
23960
25510
  exports.BufferReader = void 0;
@@ -24007,9 +25557,9 @@ var require_buffer_reader = __commonJS({
24007
25557
  }
24008
25558
  });
24009
25559
 
24010
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js
25560
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/parser.js
24011
25561
  var require_parser = __commonJS({
24012
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js"(exports) {
25562
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/parser.js"(exports) {
24013
25563
  "use strict";
24014
25564
  var __importDefault = exports && exports.__importDefault || function(mod) {
24015
25565
  return mod && mod.__esModule ? mod : { "default": mod };
@@ -24302,9 +25852,9 @@ var require_parser = __commonJS({
24302
25852
  }
24303
25853
  });
24304
25854
 
24305
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/index.js
25855
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/index.js
24306
25856
  var require_dist = __commonJS({
24307
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/index.js"(exports) {
25857
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/index.js"(exports) {
24308
25858
  "use strict";
24309
25859
  Object.defineProperty(exports, "__esModule", { value: true });
24310
25860
  exports.DatabaseError = exports.serialize = exports.parse = void 0;
@@ -24326,9 +25876,9 @@ var require_dist = __commonJS({
24326
25876
  }
24327
25877
  });
24328
25878
 
24329
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js
25879
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection.js
24330
25880
  var require_connection = __commonJS({
24331
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js"(exports, module2) {
25881
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection.js"(exports, module2) {
24332
25882
  "use strict";
24333
25883
  var net = require("net");
24334
25884
  var EventEmitter = require("events").EventEmitter;
@@ -24341,6 +25891,9 @@ var require_connection = __commonJS({
24341
25891
  super();
24342
25892
  config = config || {};
24343
25893
  this.stream = config.stream || new net.Socket();
25894
+ if (typeof this.stream === "function") {
25895
+ this.stream = this.stream(config);
25896
+ }
24344
25897
  this._keepAlive = config.keepAlive;
24345
25898
  this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
24346
25899
  this.lastBuffer = false;
@@ -24469,7 +26022,6 @@ var require_connection = __commonJS({
24469
26022
  }
24470
26023
  sync() {
24471
26024
  this._ending = true;
24472
- this._send(flushBuffer);
24473
26025
  this._send(syncBuffer);
24474
26026
  }
24475
26027
  ref() {
@@ -24508,12 +26060,11 @@ var require_connection = __commonJS({
24508
26060
  }
24509
26061
  });
24510
26062
 
24511
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js
26063
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/client.js
24512
26064
  var require_client = __commonJS({
24513
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js"(exports, module2) {
26065
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/client.js"(exports, module2) {
24514
26066
  "use strict";
24515
26067
  var EventEmitter = require("events").EventEmitter;
24516
- var util2 = require("util");
24517
26068
  var utils = require_utils2();
24518
26069
  var sasl = require_sasl();
24519
26070
  var pgPass = require_lib2();
@@ -24709,17 +26260,29 @@ var require_client = __commonJS({
24709
26260
  }
24710
26261
  _handleAuthSASL(msg) {
24711
26262
  this._checkPgPass(() => {
24712
- this.saslSession = sasl.startSession(msg.mechanisms);
24713
- this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
26263
+ try {
26264
+ this.saslSession = sasl.startSession(msg.mechanisms);
26265
+ this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
26266
+ } catch (err2) {
26267
+ this.connection.emit("error", err2);
26268
+ }
24714
26269
  });
24715
26270
  }
24716
26271
  _handleAuthSASLContinue(msg) {
24717
- sasl.continueSession(this.saslSession, this.password, msg.data);
24718
- this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
26272
+ try {
26273
+ sasl.continueSession(this.saslSession, this.password, msg.data);
26274
+ this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
26275
+ } catch (err2) {
26276
+ this.connection.emit("error", err2);
26277
+ }
24719
26278
  }
24720
26279
  _handleAuthSASLFinal(msg) {
24721
- sasl.finalizeSession(this.saslSession, msg.data);
24722
- this.saslSession = null;
26280
+ try {
26281
+ sasl.finalizeSession(this.saslSession, msg.data);
26282
+ this.saslSession = null;
26283
+ } catch (err2) {
26284
+ this.connection.emit("error", err2);
26285
+ }
24723
26286
  }
24724
26287
  _handleBackendKeyData(msg) {
24725
26288
  this.processID = msg.processID;
@@ -24998,9 +26561,9 @@ var require_client = __commonJS({
24998
26561
  }
24999
26562
  });
25000
26563
 
25001
- // node_modules/.pnpm/pg-pool@3.5.2_pg@8.8.0/node_modules/pg-pool/index.js
26564
+ // node_modules/.pnpm/pg-pool@3.5.2_pg@8.9.0/node_modules/pg-pool/index.js
25002
26565
  var require_pg_pool = __commonJS({
25003
- "node_modules/.pnpm/pg-pool@3.5.2_pg@8.8.0/node_modules/pg-pool/index.js"(exports, module2) {
26566
+ "node_modules/.pnpm/pg-pool@3.5.2_pg@8.9.0/node_modules/pg-pool/index.js"(exports, module2) {
25004
26567
  "use strict";
25005
26568
  var EventEmitter = require("events").EventEmitter;
25006
26569
  var NOOP = function() {
@@ -25373,72 +26936,9 @@ var require_pg_pool = __commonJS({
25373
26936
  }
25374
26937
  });
25375
26938
 
25376
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json
25377
- var require_package = __commonJS({
25378
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json"(exports, module2) {
25379
- module2.exports = {
25380
- name: "pg",
25381
- version: "8.8.0",
25382
- description: "PostgreSQL client - pure javascript & libpq with the same API",
25383
- keywords: [
25384
- "database",
25385
- "libpq",
25386
- "pg",
25387
- "postgre",
25388
- "postgres",
25389
- "postgresql",
25390
- "rdbms"
25391
- ],
25392
- homepage: "https://github.com/brianc/node-postgres",
25393
- repository: {
25394
- type: "git",
25395
- url: "git://github.com/brianc/node-postgres.git",
25396
- directory: "packages/pg"
25397
- },
25398
- author: "Brian Carlson <brian.m.carlson@gmail.com>",
25399
- main: "./lib",
25400
- dependencies: {
25401
- "buffer-writer": "2.0.0",
25402
- "packet-reader": "1.0.0",
25403
- "pg-connection-string": "^2.5.0",
25404
- "pg-pool": "^3.5.2",
25405
- "pg-protocol": "^1.5.0",
25406
- "pg-types": "^2.1.0",
25407
- pgpass: "1.x"
25408
- },
25409
- devDependencies: {
25410
- async: "2.6.4",
25411
- bluebird: "3.5.2",
25412
- co: "4.6.0",
25413
- "pg-copy-streams": "0.3.0"
25414
- },
25415
- peerDependencies: {
25416
- "pg-native": ">=3.0.1"
25417
- },
25418
- peerDependenciesMeta: {
25419
- "pg-native": {
25420
- optional: true
25421
- }
25422
- },
25423
- scripts: {
25424
- test: "make test-all"
25425
- },
25426
- files: [
25427
- "lib",
25428
- "SPONSORS.md"
25429
- ],
25430
- license: "MIT",
25431
- engines: {
25432
- node: ">= 8.0.0"
25433
- },
25434
- gitHead: "c99fb2c127ddf8d712500db2c7b9a5491a178655"
25435
- };
25436
- }
25437
- });
25438
-
25439
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js
26939
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/query.js
25440
26940
  var require_query2 = __commonJS({
25441
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js"(exports, module2) {
26941
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/query.js"(exports, module2) {
25442
26942
  "use strict";
25443
26943
  var EventEmitter = require("events").EventEmitter;
25444
26944
  var util2 = require("util");
@@ -25577,13 +27077,12 @@ var require_query2 = __commonJS({
25577
27077
  }
25578
27078
  });
25579
27079
 
25580
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js
27080
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/client.js
25581
27081
  var require_client2 = __commonJS({
25582
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js"(exports, module2) {
27082
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/client.js"(exports, module2) {
25583
27083
  "use strict";
25584
27084
  var Native = require("pg-native");
25585
27085
  var TypeOverrides = require_type_overrides();
25586
- var pkg = require_package();
25587
27086
  var EventEmitter = require("events").EventEmitter;
25588
27087
  var util2 = require("util");
25589
27088
  var ConnectionParameters = require_connection_parameters();
@@ -25810,17 +27309,17 @@ var require_client2 = __commonJS({
25810
27309
  }
25811
27310
  });
25812
27311
 
25813
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js
27312
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/index.js
25814
27313
  var require_native = __commonJS({
25815
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js"(exports, module2) {
27314
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/index.js"(exports, module2) {
25816
27315
  "use strict";
25817
27316
  module2.exports = require_client2();
25818
27317
  }
25819
27318
  });
25820
27319
 
25821
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js
27320
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/index.js
25822
27321
  var require_lib3 = __commonJS({
25823
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js"(exports, module2) {
27322
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/index.js"(exports, module2) {
25824
27323
  "use strict";
25825
27324
  var Client = require_client();
25826
27325
  var defaults = require_defaults();
@@ -25898,7 +27397,8 @@ var init_introspect = __esm({
25898
27397
  "interval",
25899
27398
  "bigint",
25900
27399
  "bigserial",
25901
- "doublePrecision"
27400
+ "doublePrecision",
27401
+ "uuid"
25902
27402
  ]);
25903
27403
  objToStatement = (json) => {
25904
27404
  json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
@@ -25975,13 +27475,13 @@ var init_introspect = __esm({
25975
27475
  return `export const ${it.name.camelCase()} = pgEnum("${it.name}", [${values}])
25976
27476
  `;
25977
27477
  }).join("").concat("\n");
25978
- const schemaStatements = Object.entries(schemas).filter((it) => it[0] !== "public").map((it) => {
27478
+ const schemaStatements = Object.entries(schemas).map((it) => {
25979
27479
  return `export const ${it[1]} = pgSchema("${it[0]}");
25980
27480
  `;
25981
27481
  }).join();
25982
27482
  const tableStatements = Object.values(schema4.tables).map((table4) => {
25983
27483
  const schema5 = schemas[table4.schema];
25984
- const func = schema5 || schema5 === "public" ? "pgTable" : schema5;
27484
+ const func = schema5 ? schema5 : "pgTable";
25985
27485
  let statement = `export const ${table4.name.camelCase()} = ${func}("${table4.name}", {
25986
27486
  `;
25987
27487
  statement += createTableColumns(
@@ -26298,14 +27798,14 @@ var {
26298
27798
  } = import_index.default;
26299
27799
 
26300
27800
  // src/cli/index.ts
26301
- var import_fs8 = __toESM(require("fs"));
27801
+ var import_fs9 = __toESM(require("fs"));
26302
27802
  init_lib();
26303
27803
 
26304
27804
  // src/cli/commands/check.ts
26305
27805
  init_utils();
26306
27806
  var checkHandler = (out, dialect6) => {
26307
- const migrationFolders = prepareOutFolders(out);
26308
- const report = validateWithReport(out, migrationFolders, dialect6);
27807
+ const { snapshots } = prepareOutFolder(out, dialect6);
27808
+ const report = validateWithReport(snapshots, dialect6);
26309
27809
  if (report.nonLatest.length > 0) {
26310
27810
  console.log(
26311
27811
  report.nonLatest.map((it) => {
@@ -26341,7 +27841,7 @@ var checkHandler = (out, dialect6) => {
26341
27841
  // src/cli/index.ts
26342
27842
  var import_hanji4 = __toESM(require_hanji());
26343
27843
  init_views();
26344
- var import_path6 = __toESM(require("path"));
27844
+ var import_path7 = __toESM(require("path"));
26345
27845
 
26346
27846
  // src/cli/utils.ts
26347
27847
  init_views();
@@ -26375,8 +27875,8 @@ var assertPgVersion = () => {
26375
27875
  };
26376
27876
  var pgVersions = () => {
26377
27877
  try {
26378
- const { apiVersion, npmVersion } = require("drizzle-orm/utils");
26379
- return { apiVersion, npmVersion };
27878
+ const { compatibilityVersion, npmVersion } = require("drizzle-orm/version");
27879
+ return { compatibilityVersion, npmVersion };
26380
27880
  } catch (e) {
26381
27881
  return {};
26382
27882
  }
@@ -26388,7 +27888,7 @@ init_source();
26388
27888
  // package.json
26389
27889
  var package_default = {
26390
27890
  name: "drizzle-kit",
26391
- version: "0.16.8",
27891
+ version: "0.16.9",
26392
27892
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
26393
27893
  author: "Alex Blokh <aleksandrblokh@gmail.com>",
26394
27894
  license: "MIT",
@@ -26411,7 +27911,8 @@ var package_default = {
26411
27911
  test: "ava test",
26412
27912
  build: "esbuild ./src/cli/index.ts --bundle --platform=node --target=node10.4 --outfile=./dist/index.js --external:esbuild --external:drizzle-orm-pg --external:drizzle-orm-sqlite --external:drizzle-orm-mysql --external:drizzle-orm --external:pg-native",
26413
27913
  pack: "build && package",
26414
- tsc: "tsc"
27914
+ tsc: "tsc -p tsconfig.build.json",
27915
+ pub: "cp package.json readme.md dist/ && cd dist && npm publish"
26415
27916
  },
26416
27917
  ava: {
26417
27918
  files: [
@@ -26441,7 +27942,7 @@ var package_default = {
26441
27942
  "@typescript-eslint/parser": "^5.46.1",
26442
27943
  ava: "^5.1.0",
26443
27944
  dockerode: "^3.3.4",
26444
- "drizzle-orm": "0.17.0-31c94dd",
27945
+ "drizzle-orm": "0.17.6",
26445
27946
  esbuild: "^0.15.7",
26446
27947
  "esbuild-register": "^3.3.3",
26447
27948
  eslint: "^8.29.0",
@@ -26466,32 +27967,28 @@ init_utils();
26466
27967
  init_source();
26467
27968
  var import_crypto2 = require("crypto");
26468
27969
  var import_fs5 = require("fs");
26469
- var import_path3 = __toESM(require("path"));
26470
27970
  init_global();
26471
27971
  init_pgSchema();
26472
27972
  init_utils();
26473
27973
  var upPgHandler = (out) => {
26474
- const migrationFolders = prepareOutFolders(out);
26475
- const report = validateWithReport(out, migrationFolders, "pg");
27974
+ };
27975
+ var upPgHandlerV4 = (out) => {
27976
+ const snapshots = snapshotsPriorV4(out);
27977
+ const report = validateWithReport(snapshots, "pg");
26476
27978
  let prevId = originUUID;
26477
27979
  report.nonLatest.map((it) => ({
26478
- folder: it,
27980
+ path: it,
26479
27981
  raw: report.rawMap[it]
26480
27982
  })).forEach((it) => {
26481
- const folder = it.folder;
26482
- const result = updateToLatest(it.raw, prevId);
27983
+ const path4 = it.path;
27984
+ const result = updateUpToV4(it.raw, prevId);
26483
27985
  prevId = result.id;
26484
- console.log(
26485
- `[${source_default.green("\u2713")}] ${import_path3.default.join(out, folder, "snapshot.json")}`
26486
- );
26487
- (0, import_fs5.writeFileSync)(
26488
- import_path3.default.join(out, folder, "snapshot.json"),
26489
- JSON.stringify(result, null, 2)
26490
- );
27986
+ console.log(`[${source_default.green("\u2713")}] ${path4}`);
27987
+ (0, import_fs5.writeFileSync)(path4, JSON.stringify(result, null, 2));
26491
27988
  });
26492
27989
  console.log("Everything's fine \u{1F436}\u{1F525}");
26493
27990
  };
26494
- var updateToLatest = (json, prevId) => {
27991
+ var updateUpToV4 = (json, prevId) => {
26495
27992
  const version = Number(json["version"]);
26496
27993
  if (version === 1) {
26497
27994
  const v1 = pgSchemaV1.parse(json);
@@ -26509,7 +28006,7 @@ var updateToLatest = (json, prevId) => {
26509
28006
  if (version === 3) {
26510
28007
  return update3to4(pgSchemaV3.parse(json));
26511
28008
  }
26512
- return pgSchema.parse(json);
28009
+ return pgSchemaV4.parse(json);
26513
28010
  };
26514
28011
  var update1to2 = (json) => {
26515
28012
  const tables = Object.fromEntries(
@@ -26659,14 +28156,14 @@ var import_path4 = __toESM(require("path"));
26659
28156
  init_sqliteSchema();
26660
28157
  init_utils();
26661
28158
  var upSqliteHandler = (out) => {
26662
- const migrationFolders = prepareOutFolders(out);
26663
- const report = validateWithReport(out, migrationFolders, "sqlite");
28159
+ const { snapshots } = prepareOutFolder(out, "sqlite");
28160
+ const report = validateWithReport(snapshots, "sqlite");
26664
28161
  report.nonLatest.map((it) => ({
26665
28162
  folder: it,
26666
28163
  raw: report.rawMap[it]
26667
28164
  })).forEach((it) => {
26668
28165
  const folder = it.folder;
26669
- const result = updateToLatest2(it.raw);
28166
+ const result = updateToLatest(it.raw);
26670
28167
  console.log(
26671
28168
  `[${source_default.green("\u2713")}] ${import_path4.default.join(out, folder, "snapshot.json")}`
26672
28169
  );
@@ -26677,7 +28174,7 @@ var upSqliteHandler = (out) => {
26677
28174
  });
26678
28175
  console.log("Everything's fine \u{1F436}\u{1F525}");
26679
28176
  };
26680
- var updateToLatest2 = (json) => {
28177
+ var updateToLatest = (json) => {
26681
28178
  const version = Number(json["version"]);
26682
28179
  if (version === 3) {
26683
28180
  const v3 = sqliteSchemaV3.parse(json);
@@ -26707,14 +28204,14 @@ var import_path5 = __toESM(require("path"));
26707
28204
  init_mysqlSchema();
26708
28205
  init_utils();
26709
28206
  var upMysqlHandler = (out) => {
26710
- const migrationFolders = prepareOutFolders(out);
26711
- const report = validateWithReport(out, migrationFolders, "mysql");
28207
+ const { snapshots } = prepareOutFolder(out, "mysql");
28208
+ const report = validateWithReport(snapshots, "mysql");
26712
28209
  report.nonLatest.map((it) => ({
26713
28210
  folder: it,
26714
28211
  raw: report.rawMap[it]
26715
28212
  })).forEach((it) => {
26716
28213
  const folder = it.folder;
26717
- const result = updateToLatest3(it.raw);
28214
+ const result = updateToLatest2(it.raw);
26718
28215
  console.log(
26719
28216
  `[${source_default.green("\u2713")}] ${import_path5.default.join(out, folder, "snapshot.json")}`
26720
28217
  );
@@ -26725,7 +28222,7 @@ var upMysqlHandler = (out) => {
26725
28222
  });
26726
28223
  console.log("Everything's fine \u{1F436}\u{1F525}");
26727
28224
  };
26728
- var updateToLatest3 = (json) => {
28225
+ var updateToLatest2 = (json) => {
26729
28226
  const version = Number(json["version"]);
26730
28227
  if (version === 3) {
26731
28228
  const v3 = mysqlSchemaV3.parse(json);
@@ -26742,6 +28239,273 @@ var updateV3toV42 = (old) => {
26742
28239
  };
26743
28240
  };
26744
28241
 
28242
+ // src/cli/commands/upFolders.ts
28243
+ var import_fs8 = require("fs");
28244
+ var import_path6 = require("path");
28245
+ init_jsonDiffer();
28246
+ init_snapshotsDiffer();
28247
+ init_utils();
28248
+ init_words();
28249
+ init_pgSchema();
28250
+ var schemasResolver = (missingSchemas, newSchemas, sql) => {
28251
+ try {
28252
+ if (missingSchemas.length === 0 || newSchemas.length === 0) {
28253
+ return { created: newSchemas, renamed: [], deleted: missingSchemas };
28254
+ }
28255
+ const result = { created: [], renamed: [], deleted: [] };
28256
+ let index4 = 0;
28257
+ let leftMissing = [...missingSchemas];
28258
+ do {
28259
+ const created = newSchemas[index4];
28260
+ index4 += 1;
28261
+ const possibleRenames = leftMissing.map((it) => {
28262
+ return {
28263
+ value: it,
28264
+ sql: `ALTER SCHEMA "${it.name}" RENAME TO "${created.name}"`
28265
+ };
28266
+ });
28267
+ const renames = possibleRenames.filter((it) => {
28268
+ return sql.includes(it.sql);
28269
+ });
28270
+ if (renames.length > 1)
28271
+ throw new Error("wtf");
28272
+ if (renames.length === 0) {
28273
+ result.created.push(created);
28274
+ } else {
28275
+ const it = renames[0];
28276
+ result.renamed.push({ from: it.value, to: created });
28277
+ delete leftMissing[leftMissing.indexOf(it.value)];
28278
+ leftMissing = leftMissing.filter(Boolean);
28279
+ }
28280
+ } while (index4 < newSchemas.length);
28281
+ result.deleted.push(...leftMissing);
28282
+ return result;
28283
+ } catch (e) {
28284
+ console.error(e);
28285
+ throw e;
28286
+ }
28287
+ };
28288
+ var tablesResolver = (missingTables, newTables, sql) => {
28289
+ try {
28290
+ if (missingTables.length === 0 || newTables.length === 0) {
28291
+ return { created: newTables, renamed: [], deleted: missingTables };
28292
+ }
28293
+ const result = { created: [], renamed: [], deleted: [] };
28294
+ let index4 = 0;
28295
+ let leftMissing = [...missingTables];
28296
+ do {
28297
+ const created = newTables[index4];
28298
+ index4 += 1;
28299
+ const possibleRenames = leftMissing.map((it) => {
28300
+ const schemaPrefix = created.schema ? `"${created.schema}".` : "";
28301
+ return {
28302
+ value: it,
28303
+ sql: `ALTER TABLE ${schemaPrefix}"${it.name}" RENAME TO ${schemaPrefix}"${created.name}"`
28304
+ };
28305
+ });
28306
+ const renames = possibleRenames.filter((it) => {
28307
+ return sql.includes(it.sql);
28308
+ });
28309
+ if (renames.length > 1)
28310
+ throw new Error("wtf");
28311
+ if (renames.length === 0) {
28312
+ result.created.push(created);
28313
+ } else {
28314
+ const it = renames[0];
28315
+ result.renamed.push({ from: it.value, to: created });
28316
+ delete leftMissing[leftMissing.indexOf(it.value)];
28317
+ leftMissing = leftMissing.filter(Boolean);
28318
+ }
28319
+ } while (index4 < newTables.length);
28320
+ result.deleted.push(...leftMissing);
28321
+ return result;
28322
+ } catch (e) {
28323
+ console.error(e);
28324
+ throw e;
28325
+ }
28326
+ };
28327
+ var columnsResolver = (tableName, missingColumns, newColumns, sql) => {
28328
+ try {
28329
+ if (missingColumns.length === 0 || newColumns.length === 0) {
28330
+ return { created: newColumns, renamed: [], deleted: missingColumns };
28331
+ }
28332
+ const result = { created: [], renamed: [], deleted: [] };
28333
+ let index4 = 0;
28334
+ let leftMissing = [...missingColumns];
28335
+ do {
28336
+ const created = newColumns[index4];
28337
+ index4 += 1;
28338
+ const possibleRenames = leftMissing.map((it) => {
28339
+ return {
28340
+ value: it,
28341
+ sql: `ALTER TABLE ${tableName} RENAME COLUMN "${it.name}" TO "${created.name}"`
28342
+ };
28343
+ });
28344
+ const renames = possibleRenames.filter((it) => {
28345
+ return sql.includes(it.sql);
28346
+ });
28347
+ if (renames.length > 1)
28348
+ throw new Error("wtf");
28349
+ if (renames.length === 0) {
28350
+ result.created.push(created);
28351
+ } else {
28352
+ const it = renames[0];
28353
+ result.renamed.push({ from: it.value, to: created });
28354
+ delete leftMissing[leftMissing.indexOf(it.value)];
28355
+ leftMissing = leftMissing.filter(Boolean);
28356
+ }
28357
+ } while (index4 < newColumns.length);
28358
+ result.deleted.push(...leftMissing);
28359
+ return result;
28360
+ } catch (e) {
28361
+ console.error(e);
28362
+ throw e;
28363
+ }
28364
+ };
28365
+ var fullfill = (prev, cur, sql) => {
28366
+ const b = pgSchemaV4.parse(cur);
28367
+ if (!prev) {
28368
+ return {
28369
+ version: "5",
28370
+ dialect: b.dialect,
28371
+ id: b.id,
28372
+ prevId: b.prevId,
28373
+ tables: b.tables,
28374
+ enums: b.enums,
28375
+ schemas: b.schemas,
28376
+ _meta: {
28377
+ schemas: {},
28378
+ tables: {},
28379
+ columns: {}
28380
+ }
28381
+ };
28382
+ }
28383
+ const a = pgSchemaV4.parse(prev);
28384
+ const json1 = squashPgScheme(a);
28385
+ const json2 = squashPgScheme(b);
28386
+ const diffResult = applyJsonDiff(json1, json2);
28387
+ const parseResult = diffResultScheme.safeParse(diffResult);
28388
+ if (!parseResult.success) {
28389
+ parseResult.error.errors.forEach((it) => {
28390
+ console.error(it);
28391
+ });
28392
+ throw new Error();
28393
+ }
28394
+ const typedResult = parseResult.data;
28395
+ const { renamed: renamedSchemas } = schemasResolver(
28396
+ typedResult.deletedSchemas.map((it) => ({ name: it })),
28397
+ typedResult.addedSchemas.map((it) => ({ name: it })),
28398
+ sql
28399
+ );
28400
+ const { renamed } = tablesResolver(
28401
+ typedResult.deletedTables,
28402
+ typedResult.addedTables,
28403
+ sql
28404
+ );
28405
+ const renamedWithAlternations = Object.values(
28406
+ alteredTableScheme.array().parse(diffForRenamedTables(renamed))
28407
+ );
28408
+ const allAltered = typedResult.alteredTablesWithColumns.concat(
28409
+ renamedWithAlternations
28410
+ );
28411
+ const rSchemas = renamedSchemas.map((it) => ({ from: it.from.name, to: it.to.name }));
28412
+ const rTables = renamed.map((it) => {
28413
+ return { from: it.from, to: it.to };
28414
+ });
28415
+ const rColumns = allAltered.map((table4) => {
28416
+ const name = table4.name;
28417
+ const result = columnsResolver(name, table4.deleted, table4.added, sql);
28418
+ const tableName = table4.name;
28419
+ const schema4 = typeof table4.schema === "string" ? table4.schema : "";
28420
+ return result.renamed.map((it) => {
28421
+ return {
28422
+ from: { schema: schema4, table: tableName, column: it.from.name },
28423
+ to: { schema: schema4, table: tableName, column: it.to.name }
28424
+ };
28425
+ });
28426
+ }).flat();
28427
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
28428
+ const bpatched = {
28429
+ version: "5",
28430
+ dialect: b.dialect,
28431
+ id: b.id,
28432
+ prevId: b.prevId,
28433
+ tables: b.tables,
28434
+ enums: b.enums,
28435
+ schemas: b.schemas,
28436
+ _meta
28437
+ };
28438
+ pgSchema.parse(bpatched);
28439
+ return {
28440
+ version: "5",
28441
+ dialect: b.dialect,
28442
+ id: b.id,
28443
+ prevId: b.prevId,
28444
+ tables: b.tables,
28445
+ enums: b.enums,
28446
+ schemas: b.schemas,
28447
+ _meta
28448
+ };
28449
+ };
28450
+ var upgradeFolders = (dialect6, out) => {
28451
+ const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
28452
+ (it) => it.length === 14 && /^\d+$/.test(it)
28453
+ );
28454
+ oldMigrationFolders.sort();
28455
+ const res = oldMigrationFolders.reduce(
28456
+ (res2, it) => {
28457
+ const date = new Date();
28458
+ date.setUTCFullYear(Number(it.substring(0, 4)));
28459
+ date.setUTCMonth(Number(it.substring(4, 6)));
28460
+ date.setUTCDate(Number(it.substring(6, 8)));
28461
+ date.setUTCHours(Number(it.substring(8, 10)));
28462
+ date.setUTCMinutes(Number(it.substring(10, 12)));
28463
+ date.setUTCSeconds(Number(it.substring(12, 14)));
28464
+ const path4 = (0, import_path6.join)(out, it);
28465
+ const pathJson = (0, import_path6.join)(out, it, "snapshot.json");
28466
+ const pathSQL = (0, import_path6.join)(out, it, "migration.sql");
28467
+ const snapshot = JSON.parse((0, import_fs8.readFileSync)(pathJson).toString());
28468
+ const sql = (0, import_fs8.readFileSync)(pathSQL).toString();
28469
+ res2.entries.push({
28470
+ idx: res2.idx,
28471
+ json: snapshot,
28472
+ date,
28473
+ sql,
28474
+ path: path4
28475
+ });
28476
+ res2.idx += 1;
28477
+ return res2;
28478
+ },
28479
+ {
28480
+ entries: [],
28481
+ idx: 0
28482
+ }
28483
+ );
28484
+ const metaFolder = (0, import_path6.join)(`${out}`, "meta");
28485
+ if (!(0, import_fs8.existsSync)(metaFolder)) {
28486
+ (0, import_fs8.mkdirSync)(metaFolder, { recursive: true });
28487
+ }
28488
+ const journal = dryJournal(dialect6);
28489
+ let prev = void 0;
28490
+ res.entries.forEach((it) => {
28491
+ const { prefix, suffix, tag } = prepareMigrationMetadata(it.idx);
28492
+ journal.entries.push({
28493
+ idx: it.idx,
28494
+ when: +it.date,
28495
+ tag
28496
+ });
28497
+ const patchedJSON = fullfill(prev, it.json, it.sql);
28498
+ (0, import_fs8.writeFileSync)(
28499
+ (0, import_path6.join)(`${out}`, "meta", `${prefix}_snapshot.json`),
28500
+ JSON.stringify(patchedJSON)
28501
+ );
28502
+ (0, import_fs8.writeFileSync)((0, import_path6.join)(`${out}`, `${tag}.sql`), it.sql);
28503
+ (0, import_fs8.rmSync)(it.path, { recursive: true });
28504
+ prev = it.json;
28505
+ });
28506
+ (0, import_fs8.writeFileSync)((0, import_path6.join)(metaFolder, "_journal.json"), JSON.stringify(journal));
28507
+ };
28508
+
26745
28509
  // src/cli/index.ts
26746
28510
  var printVersions = () => {
26747
28511
  console.log(`${source_default.gray(versions())}
@@ -26750,13 +28514,13 @@ var printVersions = () => {
26750
28514
  var assertEitherConfigOrOut = (config, out) => {
26751
28515
  if (out)
26752
28516
  return out;
26753
- if (!(0, import_fs8.existsSync)(import_path6.default.join(import_path6.default.resolve(config)))) {
28517
+ if (!(0, import_fs9.existsSync)(import_path7.default.join(import_path7.default.resolve(config)))) {
26754
28518
  console.log(`${config} file does not exist`);
26755
28519
  process.exit(1);
26756
28520
  }
26757
28521
  console.log(`Reading ${config}`);
26758
28522
  const drizzleConfig = JSON.parse(
26759
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(config))).toString()
28523
+ import_fs9.default.readFileSync(import_path7.default.join(import_path7.default.resolve(config))).toString()
26760
28524
  );
26761
28525
  return drizzleConfig.out;
26762
28526
  };
@@ -26824,9 +28588,9 @@ var generateSqliteCommand = new Command("generate:sqlite").option("--schema <sch
26824
28588
  var prepareGenerateConfig = (options) => {
26825
28589
  const { schema: schema4, out, config } = options;
26826
28590
  if (!(schema4 || out)) {
26827
- const path5 = config != null ? config : "drizzle.config.json";
28591
+ const path4 = config != null ? config : "drizzle.config.json";
26828
28592
  const drizzleConfig = JSON.parse(
26829
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(path5))).toString()
28593
+ import_fs9.default.readFileSync(import_path7.default.join(import_path7.default.resolve(path4))).toString()
26830
28594
  );
26831
28595
  return drizzleConfig;
26832
28596
  }
@@ -26874,6 +28638,8 @@ var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).op
26874
28638
  process.exit(0);
26875
28639
  }
26876
28640
  assertPackages("drizzle-orm");
28641
+ upPgHandlerV4(out);
28642
+ upgradeFolders("pg", out);
26877
28643
  upPgHandler(out);
26878
28644
  });
26879
28645
  var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
@@ -26921,29 +28687,18 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
26921
28687
  console.log("Missing required params");
26922
28688
  return;
26923
28689
  }
26924
- const migrationFolders = prepareOutFolders(res.data.out);
26925
- const folderName = prepareSnapshotFolderName();
26926
- const migrationFolderPath = `./${res.data.out}/${folderName}`;
28690
+ const { snapshots, journal } = prepareOutFolder(res.data.out, "pg");
26927
28691
  const { schema: schema4, ts } = await pgIntrospect2(res.data);
26928
- const schemaFile = import_path6.default.join(res.data.out, "schema.ts");
26929
- (0, import_fs8.writeFileSync)(schemaFile, ts);
28692
+ const schemaFile = import_path7.default.join(res.data.out, "schema.ts");
28693
+ (0, import_fs9.writeFileSync)(schemaFile, ts);
26930
28694
  console.log();
26931
- if (migrationFolders.length === 0) {
26932
- import_fs8.default.mkdirSync(migrationFolderPath);
26933
- const snapshotFile = import_path6.default.join(migrationFolderPath, "snapshot.json");
26934
- (0, import_fs8.writeFileSync)(snapshotFile, JSON.stringify(schema4));
26935
- const sql = await prepareSQL(
28695
+ if (snapshots.length === 0) {
28696
+ const { sql, _meta } = await prepareSQL(
26936
28697
  squashPgScheme(dryPg),
26937
28698
  squashPgScheme(schema4),
26938
28699
  "pg"
26939
28700
  );
26940
- const sqlFile = import_path6.default.join(migrationFolderPath, "migration.sql");
26941
- (0, import_fs8.writeFileSync)(sqlFile, sql);
26942
- (0, import_hanji4.render)(
26943
- `[${source_default.green(
26944
- "\u2713"
26945
- )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(sqlFile)} \u{1F680}`
26946
- );
28701
+ writeResult(schema4, sql, 0, journal, _meta, res.data.out);
26947
28702
  } else {
26948
28703
  (0, import_hanji4.render)(
26949
28704
  `[${source_default.blue(