drizzle-kit 0.16.7 → 0.16.9-43ec28a

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 +2221 -472
  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,
@@ -12807,11 +12927,16 @@ var init_pgSerializer = __esm({
12807
12927
  schemas.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) => {
@@ -13024,11 +13149,16 @@ var init_pgSerializer = __esm({
13024
13149
  progressCallback("enums", Object.keys(enumsToReturn).length, "done");
13025
13150
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
13026
13151
  return {
13027
- version: "4",
13152
+ version: "5",
13028
13153
  dialect: "pg",
13029
13154
  tables: result,
13030
13155
  enums: enumsToReturn,
13031
- schemas: schemasObject
13156
+ schemas: schemasObject,
13157
+ _meta: {
13158
+ schemas: {},
13159
+ tables: {},
13160
+ columns: {}
13161
+ }
13032
13162
  };
13033
13163
  };
13034
13164
  }
@@ -13172,12 +13302,12 @@ var init_sqliteSerializer = __esm({
13172
13302
  });
13173
13303
 
13174
13304
  // src/serializer/index.ts
13175
- var import_fs2, import_node, import_path, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13305
+ var import_fs2, import_node, import_path2, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13176
13306
  var init_serializer = __esm({
13177
13307
  "src/serializer/index.ts"() {
13178
13308
  import_fs2 = __toESM(require("fs"));
13179
13309
  import_node = __toESM(require_node2());
13180
- import_path = __toESM(require("path"));
13310
+ import_path2 = __toESM(require("path"));
13181
13311
  safeRegister = () => {
13182
13312
  try {
13183
13313
  const { unregister } = (0, import_node.register)({
@@ -13190,8 +13320,8 @@ var init_serializer = __esm({
13190
13320
  } };
13191
13321
  }
13192
13322
  };
13193
- serializeMySql = (path5) => {
13194
- const filenames = prepareFilenames(path5);
13323
+ serializeMySql = (path4) => {
13324
+ const filenames = prepareFilenames(path4);
13195
13325
  const { unregister } = safeRegister();
13196
13326
  const { prepareFromMySqlImports: prepareFromMySqlImports2 } = (init_mysqlImports(), __toCommonJS(mysqlImports_exports));
13197
13327
  const { generateMySqlSnapshot: generateMySqlSnapshot2 } = (init_mysqlSerializer(), __toCommonJS(mysqlSerializer_exports));
@@ -13199,8 +13329,8 @@ var init_serializer = __esm({
13199
13329
  unregister();
13200
13330
  return generateMySqlSnapshot2(tables, enums, schemas);
13201
13331
  };
13202
- serializePg = (path5) => {
13203
- const filenames = prepareFilenames(path5);
13332
+ serializePg = (path4) => {
13333
+ const filenames = prepareFilenames(path4);
13204
13334
  const { unregister } = safeRegister();
13205
13335
  const { prepareFromPgImports: prepareFromPgImports2 } = (init_pgImports(), __toCommonJS(pgImports_exports));
13206
13336
  const { generatePgSnapshot: generatePgSnapshot2 } = (init_pgSerializer(), __toCommonJS(pgSerializer_exports));
@@ -13208,8 +13338,8 @@ var init_serializer = __esm({
13208
13338
  unregister();
13209
13339
  return generatePgSnapshot2(tables, enums, schemas);
13210
13340
  };
13211
- serializeSQLite = (path5) => {
13212
- const filenames = prepareFilenames(path5);
13341
+ serializeSQLite = (path4) => {
13342
+ const filenames = prepareFilenames(path4);
13213
13343
  const { unregister } = safeRegister();
13214
13344
  const { prepareFromSqliteImports: prepareFromSqliteImports2 } = (init_sqliteImports(), __toCommonJS(sqliteImports_exports));
13215
13345
  const { generateSqliteSnapshot: generateSqliteSnapshot2 } = (init_sqliteSerializer(), __toCommonJS(sqliteSerializer_exports));
@@ -13217,9 +13347,9 @@ var init_serializer = __esm({
13217
13347
  unregister();
13218
13348
  return generateSqliteSnapshot2(tables, enums);
13219
13349
  };
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));
13350
+ prepareFilenames = (path4) => {
13351
+ const fileName = import_fs2.default.lstatSync(path4).isDirectory() ? null : import_path2.default.resolve(path4);
13352
+ const filenames = fileName ? [fileName] : import_fs2.default.readdirSync(path4).map((it) => import_path2.default.join(import_path2.default.resolve(path4), it));
13223
13353
  return filenames;
13224
13354
  };
13225
13355
  }
@@ -13235,9 +13365,9 @@ var init_migrationPreparator = __esm({
13235
13365
  init_pgSchema();
13236
13366
  init_sqliteSchema();
13237
13367
  init_mysqlSchema();
13238
- prepareMySqlMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13368
+ prepareMySqlMigrationSnapshot = (migrationFolders, schemaPath) => {
13239
13369
  const prevSnapshot = mysqlSchema.parse(
13240
- preparePrevSnapshot(outFolder, migrationFolders, dryMySql)
13370
+ preparePrevSnapshot(migrationFolders, dryMySql)
13241
13371
  );
13242
13372
  const serialized = serializeMySql(schemaPath);
13243
13373
  const id = (0, import_crypto.randomUUID)();
@@ -13246,9 +13376,9 @@ var init_migrationPreparator = __esm({
13246
13376
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13247
13377
  return { prev: prevSnapshot, cur: result };
13248
13378
  };
13249
- prepareSqliteMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13379
+ prepareSqliteMigrationSnapshot = (snapshots, schemaPath) => {
13250
13380
  const prevSnapshot = sqliteSchema.parse(
13251
- preparePrevSnapshot(outFolder, migrationFolders, drySQLite)
13381
+ preparePrevSnapshot(snapshots, drySQLite)
13252
13382
  );
13253
13383
  const serialized = serializeSQLite(schemaPath);
13254
13384
  const id = (0, import_crypto.randomUUID)();
@@ -13263,10 +13393,8 @@ var init_migrationPreparator = __esm({
13263
13393
  };
13264
13394
  return { prev: prevSnapshot, cur: result };
13265
13395
  };
13266
- preparePgMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13267
- const prevSnapshot = pgSchema.parse(
13268
- preparePrevSnapshot(outFolder, migrationFolders, dryPg)
13269
- );
13396
+ preparePgMigrationSnapshot = (snapshots, schemaPath) => {
13397
+ const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
13270
13398
  const serialized = serializePg(schemaPath);
13271
13399
  const id = (0, import_crypto.randomUUID)();
13272
13400
  const idPrev = prevSnapshot.id;
@@ -13274,16 +13402,13 @@ var init_migrationPreparator = __esm({
13274
13402
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13275
13403
  return { prev: prevSnapshot, cur: result };
13276
13404
  };
13277
- preparePrevSnapshot = (outFolder, migrationFolders, defaultPrev) => {
13278
- const root = outFolder;
13405
+ preparePrevSnapshot = (snapshots, defaultPrev) => {
13279
13406
  let prevSnapshot;
13280
- if (migrationFolders.length === 0) {
13407
+ if (snapshots.length === 0) {
13281
13408
  prevSnapshot = defaultPrev;
13282
13409
  } else {
13283
- const lastSnapshotFolder = migrationFolders[migrationFolders.length - 1];
13284
- prevSnapshot = JSON.parse(
13285
- import_fs3.default.readFileSync(`${root}/${lastSnapshotFolder}/snapshot.json`).toString()
13286
- );
13410
+ const lastSnapshot = snapshots[snapshots.length - 1];
13411
+ prevSnapshot = JSON.parse(import_fs3.default.readFileSync(lastSnapshot).toString());
13287
13412
  }
13288
13413
  return prevSnapshot;
13289
13414
  };
@@ -13291,7 +13416,7 @@ var init_migrationPreparator = __esm({
13291
13416
  });
13292
13417
 
13293
13418
  // src/sqlgenerator.ts
13294
- var pgNativeTypes, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, convertors, fromJson;
13419
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, convertors, fromJson;
13295
13420
  var init_sqlgenerator = __esm({
13296
13421
  "src/sqlgenerator.ts"() {
13297
13422
  init_mysqlSchema();
@@ -13325,6 +13450,11 @@ var init_sqlgenerator = __esm({
13325
13450
  "bigserial",
13326
13451
  "double precision"
13327
13452
  ]);
13453
+ isPgNativeType = (it) => {
13454
+ if (pgNativeTypes.has(it))
13455
+ return true;
13456
+ return it.startsWith("varchar(") || it.startsWith("numeric(");
13457
+ };
13328
13458
  Convertor = class {
13329
13459
  };
13330
13460
  PgCreateTableConvertor = class extends Convertor {
@@ -13342,7 +13472,7 @@ var init_sqlgenerator = __esm({
13342
13472
  const primaryKeyStatement = column5.primaryKey ? "PRIMARY KEY" : "";
13343
13473
  const notNullStatement = column5.notNull ? "NOT NULL" : "";
13344
13474
  const defaultStatement = column5.default !== void 0 ? `DEFAULT ${column5.default}` : "";
13345
- const type = pgNativeTypes.has(column5.type) ? column5.type : `"${column5.type}"`;
13475
+ const type = isPgNativeType(column5.type) ? column5.type : `"${column5.type}"`;
13346
13476
  statement += " " + `"${column5.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
13347
13477
  statement += (i === columns.length - 1 ? "" : ",") + "\n";
13348
13478
  }
@@ -13472,7 +13602,7 @@ var init_sqlgenerator = __esm({
13472
13602
  return statement.type === "rename_table" && dialect6 === "pg";
13473
13603
  }
13474
13604
  convert(statement) {
13475
- const { tableNameFrom, tableNameTo, fromSchema: schema4 } = statement;
13605
+ const { tableNameFrom, tableNameTo, toSchema: schema4 } = statement;
13476
13606
  const from = schema4 ? `"${schema4}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
13477
13607
  const to = schema4 ? `"${schema4}"."${tableNameTo}"` : `"${tableNameTo}"`;
13478
13608
  return `ALTER TABLE ${from} RENAME TO ${to};`;
@@ -13561,7 +13691,7 @@ var init_sqlgenerator = __esm({
13561
13691
  const { tableName, column: column5 } = statement;
13562
13692
  const { name, type, notNull } = column5;
13563
13693
  const defaultStatement = `${column5.default !== void 0 ? `DEFAULT ${column5.default}` : ""}`;
13564
- const fixedType = pgNativeTypes.has(column5.type) ? column5.type : `"${column5.type}"`;
13694
+ const fixedType = isPgNativeType(column5.type) ? column5.type : `"${column5.type}"`;
13565
13695
  const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
13566
13696
  return `ALTER TABLE ${tableName} ADD COLUMN "${name}" ${fixedType} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim() + ";";
13567
13697
  }
@@ -17138,7 +17268,7 @@ var require_get = __commonJS({
17138
17268
  return lastId;
17139
17269
  },
17140
17270
  delete: function(id) {
17141
- var index4 = 0, set = map, i, args = cache[id], length = args.length, path5 = [];
17271
+ var index4 = 0, set = map, i, args = cache[id], length = args.length, path4 = [];
17142
17272
  if (length === 0) {
17143
17273
  delete set[length];
17144
17274
  } else if (set = set[length]) {
@@ -17147,7 +17277,7 @@ var require_get = __commonJS({
17147
17277
  if (i === -1) {
17148
17278
  return;
17149
17279
  }
17150
- path5.push(set, i);
17280
+ path4.push(set, i);
17151
17281
  set = set[1][i];
17152
17282
  ++index4;
17153
17283
  }
@@ -17158,9 +17288,9 @@ var require_get = __commonJS({
17158
17288
  id = set[1][i];
17159
17289
  set[0].splice(i, 1);
17160
17290
  set[1].splice(i, 1);
17161
- while (!set[0].length && path5.length) {
17162
- i = path5.pop();
17163
- set = path5.pop();
17291
+ while (!set[0].length && path4.length) {
17292
+ i = path4.pop();
17293
+ set = path4.pop();
17164
17294
  set[0].splice(i, 1);
17165
17295
  set[1].splice(i, 1);
17166
17296
  }
@@ -17252,13 +17382,13 @@ var require_get_fixed = __commonJS({
17252
17382
  return lastId;
17253
17383
  },
17254
17384
  delete: function(id) {
17255
- var index4 = 0, set = map, i, path5 = [], args = cache[id];
17385
+ var index4 = 0, set = map, i, path4 = [], args = cache[id];
17256
17386
  while (index4 < length - 1) {
17257
17387
  i = indexOf.call(set[0], args[index4]);
17258
17388
  if (i === -1) {
17259
17389
  return;
17260
17390
  }
17261
- path5.push(set, i);
17391
+ path4.push(set, i);
17262
17392
  set = set[1][i];
17263
17393
  ++index4;
17264
17394
  }
@@ -17269,9 +17399,9 @@ var require_get_fixed = __commonJS({
17269
17399
  id = set[1][i];
17270
17400
  set[0].splice(i, 1);
17271
17401
  set[1].splice(i, 1);
17272
- while (!set[0].length && path5.length) {
17273
- i = path5.pop();
17274
- set = path5.pop();
17402
+ while (!set[0].length && path4.length) {
17403
+ i = path4.pop();
17404
+ set = path4.pop();
17275
17405
  set[0].splice(i, 1);
17276
17406
  set[1].splice(i, 1);
17277
17407
  }
@@ -18836,7 +18966,7 @@ var require_bare = __commonJS({
18836
18966
  var sgr = require_sgr();
18837
18967
  var supportsColor2 = require_supports_color2();
18838
18968
  var mods = sgr.mods;
18839
- var join = Array.prototype.join;
18969
+ var join4 = Array.prototype.join;
18840
18970
  var defineProperty = Object.defineProperty;
18841
18971
  var max = Math.max;
18842
18972
  var min = Math.min;
@@ -18890,7 +19020,7 @@ var require_bare = __commonJS({
18890
19020
  getFn = function() {
18891
19021
  return setPrototypeOf(
18892
19022
  function self2() {
18893
- var start = "", end = "", msg = join.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
19023
+ var start = "", end = "", msg = join4.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
18894
19024
  forEach(
18895
19025
  conf,
18896
19026
  function(mod, key) {
@@ -20321,7 +20451,7 @@ function diffForRenamedTable(t1, t2) {
20321
20451
  t1.name = t2.name;
20322
20452
  const diffed = (0, import_json_diff.diff)(t1, t2) || {};
20323
20453
  diffed.name = t2.name;
20324
- return findAlternationsInTable(diffed);
20454
+ return findAlternationsInTable(diffed, t2.schema);
20325
20455
  }
20326
20456
  function diffForRenamedColumn(t1, t2) {
20327
20457
  const renamed = { ...t1, name: t2.name };
@@ -20335,6 +20465,10 @@ function applyJsonDiff(json1, json2) {
20335
20465
  json2 = JSON.parse(JSON.stringify(json2));
20336
20466
  const rawDiff = (0, import_json_diff.diff)(json1, json2);
20337
20467
  const difference = rawDiff;
20468
+ const tableToSchema = Object.entries(json2.tables).reduce((res, it) => {
20469
+ res[it[0]] = it[1].schema;
20470
+ return res;
20471
+ }, {});
20338
20472
  if (!difference)
20339
20473
  return {};
20340
20474
  difference.tables = (_a = difference.tables) != null ? _a : {};
@@ -20364,7 +20498,7 @@ function applyJsonDiff(json1, json2) {
20364
20498
  const schemasEntries = Object.entries(difference.schemas);
20365
20499
  const addedSchemas = schemasEntries.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
20366
20500
  const deletedSchemas = schemasEntries.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
20367
- const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4));
20501
+ const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4, tableToSchema[table4.name]));
20368
20502
  return {
20369
20503
  addedTables,
20370
20504
  deletedTables,
@@ -20381,10 +20515,13 @@ var init_jsonDiffer = __esm({
20381
20515
  "src/jsonDiffer.js"() {
20382
20516
  import_json_diff = __toESM(require_lib());
20383
20517
  "use-strict";
20384
- findAlternationsInTable = (table4) => {
20518
+ findAlternationsInTable = (table4, tableSchema) => {
20385
20519
  var _a;
20386
20520
  const columns = (_a = table4.columns) != null ? _a : {};
20387
- let schema4;
20521
+ let schema4 = {
20522
+ type: "none",
20523
+ value: tableSchema
20524
+ };
20388
20525
  if ("schema" in table4) {
20389
20526
  if (table4.schema.__new) {
20390
20527
  schema4 = { type: "changed", old: table4.schema.__old, new: table4.schema.__new };
@@ -20521,7 +20658,8 @@ var init_jsonStatements = __esm({
20521
20658
  prepareDropTableJson = (table4) => {
20522
20659
  return {
20523
20660
  type: "drop_table",
20524
- tableName: table4.name
20661
+ tableName: table4.name,
20662
+ schema: table4.schema
20525
20663
  };
20526
20664
  };
20527
20665
  prepareRenameTableJson = (tableFrom, tableTo) => {
@@ -20574,20 +20712,21 @@ var init_jsonStatements = __esm({
20574
20712
  };
20575
20713
  });
20576
20714
  };
20577
- prepareRenameColumns = (tableName, pairs) => {
20715
+ prepareRenameColumns = (tableName, schema4, pairs) => {
20578
20716
  return pairs.map((it) => {
20579
20717
  return {
20580
20718
  type: "alter_table_rename_column",
20581
20719
  tableName,
20582
20720
  oldColumnName: it.from.name,
20583
- newColumnName: it.to.name
20721
+ newColumnName: it.to.name,
20722
+ schema: schema4
20584
20723
  };
20585
20724
  });
20586
20725
  };
20587
- prepareAlterTableColumnsJson = (tableName, deleted, added, altered, addedFk, dialect6) => {
20726
+ prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, dialect6) => {
20588
20727
  const addColumns = [];
20589
- const dropColumns = _prepareDropColumns(tableName, deleted);
20590
- const alterColumns = _prepareAlterColumns(tableName, altered);
20728
+ const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
20729
+ const alterColumns = _prepareAlterColumns(tableName, schema4, altered);
20591
20730
  if (dialect6 === "sqlite") {
20592
20731
  let jsonCreateFKStatements = Object.values(addedFk);
20593
20732
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -20597,25 +20736,27 @@ var init_jsonStatements = __esm({
20597
20736
  );
20598
20737
  addColumns.push(...sqliteAddColumns);
20599
20738
  } else {
20600
- addColumns.push(..._prepareAddColumns(tableName, added));
20739
+ addColumns.push(..._prepareAddColumns(tableName, schema4, added));
20601
20740
  }
20602
20741
  return { addColumns, dropColumns, alterColumns };
20603
20742
  };
20604
- _prepareDropColumns = (taleName, columns) => {
20743
+ _prepareDropColumns = (taleName, schema4, columns) => {
20605
20744
  return columns.map((it) => {
20606
20745
  return {
20607
20746
  type: "alter_table_drop_column",
20608
20747
  tableName: taleName,
20609
- columnName: it.name
20748
+ columnName: it.name,
20749
+ schema: schema4
20610
20750
  };
20611
20751
  });
20612
20752
  };
20613
- _prepareAddColumns = (tableName, columns) => {
20753
+ _prepareAddColumns = (tableName, schema4, columns) => {
20614
20754
  return columns.map((it) => {
20615
20755
  return {
20616
20756
  type: "alter_table_add_column",
20617
20757
  tableName,
20618
- column: it
20758
+ column: it,
20759
+ schema: schema4
20619
20760
  };
20620
20761
  });
20621
20762
  };
@@ -20635,7 +20776,7 @@ var init_jsonStatements = __esm({
20635
20776
  };
20636
20777
  });
20637
20778
  };
20638
- _prepareAlterColumns = (tableName, columns) => {
20779
+ _prepareAlterColumns = (tableName, schema4, columns) => {
20639
20780
  var _a, _b, _c, _d, _e, _f, _g;
20640
20781
  let statements = [];
20641
20782
  for (const column5 of columns) {
@@ -20645,7 +20786,8 @@ var init_jsonStatements = __esm({
20645
20786
  type: "alter_table_rename_column",
20646
20787
  tableName,
20647
20788
  oldColumnName: column5.name.old,
20648
- newColumnName: column5.name.new
20789
+ newColumnName: column5.name.new,
20790
+ schema: schema4
20649
20791
  });
20650
20792
  }
20651
20793
  if (((_a = column5.type) == null ? void 0 : _a.type) === "changed") {
@@ -20653,7 +20795,8 @@ var init_jsonStatements = __esm({
20653
20795
  type: "alter_table_alter_column_set_type",
20654
20796
  tableName,
20655
20797
  columnName,
20656
- newDataType: column5.type.new
20798
+ newDataType: column5.type.new,
20799
+ schema: schema4
20657
20800
  });
20658
20801
  }
20659
20802
  if (((_b = column5.default) == null ? void 0 : _b.type) === "added") {
@@ -20661,7 +20804,8 @@ var init_jsonStatements = __esm({
20661
20804
  type: "alter_table_alter_column_set_default",
20662
20805
  tableName,
20663
20806
  columnName,
20664
- newDefaultValue: column5.default.value
20807
+ newDefaultValue: column5.default.value,
20808
+ schema: schema4
20665
20809
  });
20666
20810
  }
20667
20811
  if (((_c = column5.default) == null ? void 0 : _c.type) === "changed") {
@@ -20669,21 +20813,24 @@ var init_jsonStatements = __esm({
20669
20813
  type: "alter_table_alter_column_set_default",
20670
20814
  tableName,
20671
20815
  columnName,
20672
- newDefaultValue: column5.default.new
20816
+ newDefaultValue: column5.default.new,
20817
+ schema: schema4
20673
20818
  });
20674
20819
  }
20675
20820
  if (((_d = column5.default) == null ? void 0 : _d.type) === "deleted") {
20676
20821
  statements.push({
20677
20822
  type: "alter_table_alter_column_drop_default",
20678
20823
  tableName,
20679
- columnName
20824
+ columnName,
20825
+ schema: schema4
20680
20826
  });
20681
20827
  }
20682
20828
  if (((_e = column5.notNull) == null ? void 0 : _e.type) === "added") {
20683
20829
  statements.push({
20684
20830
  type: "alter_table_alter_column_set_notnull",
20685
20831
  tableName,
20686
- columnName
20832
+ columnName,
20833
+ schema: schema4
20687
20834
  });
20688
20835
  }
20689
20836
  if (((_f = column5.notNull) == null ? void 0 : _f.type) === "changed") {
@@ -20691,62 +20838,69 @@ var init_jsonStatements = __esm({
20691
20838
  statements.push({
20692
20839
  type,
20693
20840
  tableName,
20694
- columnName
20841
+ columnName,
20842
+ schema: schema4
20695
20843
  });
20696
20844
  }
20697
20845
  if (((_g = column5.notNull) == null ? void 0 : _g.type) === "deleted") {
20698
20846
  statements.push({
20699
20847
  type: "alter_table_alter_column_drop_notnull",
20700
20848
  tableName,
20701
- columnName
20849
+ columnName,
20850
+ schema: schema4
20702
20851
  });
20703
20852
  }
20704
20853
  }
20705
20854
  return statements;
20706
20855
  };
20707
- prepareCreateIndexesJson = (tableName, indexes) => {
20856
+ prepareCreateIndexesJson = (tableName, schema4, indexes) => {
20708
20857
  return Object.values(indexes).map((indexData) => {
20709
20858
  return {
20710
20859
  type: "create_index",
20711
20860
  tableName,
20712
- data: indexData
20861
+ data: indexData,
20862
+ schema: schema4
20713
20863
  };
20714
20864
  });
20715
20865
  };
20716
- prepareCreateReferencesJson = (tableName, foreignKeys) => {
20866
+ prepareCreateReferencesJson = (tableName, schema4, foreignKeys) => {
20717
20867
  return Object.values(foreignKeys).map((fkData) => {
20718
20868
  return {
20719
20869
  type: "create_reference",
20720
20870
  tableName,
20721
- data: fkData
20871
+ data: fkData,
20872
+ schema: schema4
20722
20873
  };
20723
20874
  });
20724
20875
  };
20725
- prepareDropReferencesJson = (tableName, foreignKeys) => {
20876
+ prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
20726
20877
  return Object.values(foreignKeys).map((fkData) => {
20727
20878
  return {
20728
20879
  type: "delete_reference",
20729
20880
  tableName,
20730
- data: fkData
20881
+ data: fkData,
20882
+ schema: schema4
20731
20883
  };
20732
20884
  });
20733
20885
  };
20734
- prepareAlterReferencesJson = (tableName, foreignKeys) => {
20886
+ prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
20735
20887
  return Object.values(foreignKeys).map((fkData) => {
20736
20888
  return {
20737
20889
  type: "alter_reference",
20738
20890
  tableName,
20739
20891
  data: fkData.__new,
20740
- oldFkey: fkData.__old
20892
+ oldFkey: fkData.__old,
20893
+ schema: schema4
20741
20894
  };
20742
20895
  });
20743
20896
  };
20744
- prepareDropIndexesJson = (tableName, indexes) => {
20897
+ prepareDropIndexesJson = (tableName, schema4, indexes) => {
20745
20898
  return Object.values(indexes).map((indexData) => {
20746
20899
  return {
20747
20900
  type: "drop_index",
20748
20901
  tableName,
20749
- data: indexData
20902
+ data: indexData,
20903
+ schema: schema4
20750
20904
  };
20751
20905
  });
20752
20906
  };
@@ -20782,13 +20936,14 @@ var init_jsonStatements = __esm({
20782
20936
  });
20783
20937
 
20784
20938
  // src/snapshotsDiffer.ts
20785
- var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20939
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, valueFromSelfOrPatchedNew, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20786
20940
  var init_snapshotsDiffer = __esm({
20787
20941
  "src/snapshotsDiffer.ts"() {
20788
20942
  init_sqlgenerator();
20789
20943
  init_lib();
20790
20944
  init_jsonDiffer();
20791
20945
  init_jsonStatements();
20946
+ init_utils();
20792
20947
  makeChanged = (schema4) => {
20793
20948
  return objectType({
20794
20949
  type: enumType(["changed"]),
@@ -20809,20 +20964,53 @@ var init_snapshotsDiffer = __esm({
20809
20964
  makePatched = (schema4) => {
20810
20965
  return unionType([
20811
20966
  objectType({
20812
- type: enumType(["added"]),
20967
+ type: literalType("added"),
20813
20968
  value: schema4
20814
20969
  }),
20815
20970
  objectType({
20816
- type: enumType(["deleted"]),
20971
+ type: literalType("deleted"),
20817
20972
  value: schema4
20818
20973
  }),
20819
20974
  objectType({
20820
- type: enumType(["changed"]),
20975
+ type: literalType("changed"),
20821
20976
  old: schema4,
20822
20977
  new: schema4
20823
20978
  })
20824
20979
  ]);
20825
20980
  };
20981
+ makeSelfOrPatched = (schema4) => {
20982
+ return unionType([
20983
+ objectType({
20984
+ type: literalType("none"),
20985
+ value: schema4
20986
+ }),
20987
+ objectType({
20988
+ type: literalType("added"),
20989
+ value: schema4
20990
+ }),
20991
+ objectType({
20992
+ type: literalType("deleted"),
20993
+ value: schema4
20994
+ }),
20995
+ objectType({
20996
+ type: literalType("changed"),
20997
+ old: schema4,
20998
+ new: schema4
20999
+ })
21000
+ ]);
21001
+ };
21002
+ valueFromSelfOrPatchedNew = (it) => {
21003
+ switch (it.type) {
21004
+ case "none":
21005
+ return it.value;
21006
+ case "added":
21007
+ return it.value;
21008
+ case "deleted":
21009
+ return it.value;
21010
+ case "changed":
21011
+ return it.new;
21012
+ }
21013
+ };
20826
21014
  columnSchema = objectType({
20827
21015
  name: stringType(),
20828
21016
  type: stringType(),
@@ -20835,7 +21023,7 @@ var init_snapshotsDiffer = __esm({
20835
21023
  alteredColumnSchema = objectType({
20836
21024
  name: makeSelfOrChanged(stringType()),
20837
21025
  type: makeChanged(stringType()).optional(),
20838
- default: makePatched(stringType()).optional(),
21026
+ default: makePatched(anyType()).optional(),
20839
21027
  notNull: makePatched(booleanType()).optional()
20840
21028
  }).strict();
20841
21029
  enumSchema2 = objectType({
@@ -20857,7 +21045,7 @@ var init_snapshotsDiffer = __esm({
20857
21045
  }).strict();
20858
21046
  alteredTableScheme = objectType({
20859
21047
  name: stringType(),
20860
- schema: makePatched(stringType()).optional(),
21048
+ schema: makeSelfOrPatched(stringType()),
20861
21049
  deleted: columnSchema.array(),
20862
21050
  added: columnSchema.array(),
20863
21051
  altered: alteredColumnSchema.array(),
@@ -20892,25 +21080,32 @@ var init_snapshotsDiffer = __esm({
20892
21080
  addedSchemas: stringType().array(),
20893
21081
  deletedSchemas: stringType().array()
20894
21082
  }).strict();
20895
- applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver) => {
21083
+ applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver2, tablesResolver2, columnsResolver2) => {
20896
21084
  var _a, _b, _c, _d;
20897
21085
  const diffResult = applyJsonDiff(json1, json2);
20898
21086
  if (Object.keys(diffResult).length === 0) {
20899
- return "";
21087
+ return { statements: [], sql: "" };
20900
21088
  }
20901
21089
  const typedResult = diffResultScheme.parse(diffResult);
20902
21090
  const {
20903
21091
  created: createdSchemas,
20904
21092
  deleted: deletedSchemas,
20905
21093
  renamed: renamedSchemas
20906
- } = await schemasResolver({
21094
+ } = await schemasResolver2({
20907
21095
  created: typedResult.addedSchemas.map((it) => ({ name: it })),
20908
21096
  deleted: typedResult.deletedSchemas.map((it) => ({ name: it }))
20909
21097
  });
20910
- const { created, deleted, renamed } = await tablesResolver({
21098
+ const { created, deleted, renamed } = await tablesResolver2({
20911
21099
  created: typedResult.addedTables,
20912
21100
  deleted: typedResult.deletedTables
20913
21101
  });
21102
+ const rSchemas = renamedSchemas.map((it) => ({
21103
+ from: it.from.name,
21104
+ to: it.to.name
21105
+ }));
21106
+ const rTables = renamed.map((it) => {
21107
+ return { from: it.from, to: it.to };
21108
+ });
20914
21109
  const jsonStatements = [];
20915
21110
  const jsonSQLiteCreateTables = created.map((it) => {
20916
21111
  return prepareSQLiteCreateTable(it);
@@ -20919,7 +21114,7 @@ var init_snapshotsDiffer = __esm({
20919
21114
  return prepareCreateTableJson(it);
20920
21115
  });
20921
21116
  const jsonCreateIndexesForCreatedTables = created.map((it) => {
20922
- return prepareCreateIndexesJson(it.name, it.indexes);
21117
+ return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
20923
21118
  }).flat();
20924
21119
  const jsonDropTables = deleted.map((it) => {
20925
21120
  return prepareDropTableJson(it);
@@ -20936,13 +21131,14 @@ var init_snapshotsDiffer = __esm({
20936
21131
  const jsonRenameColumnsStatements = [];
20937
21132
  const allAlteredResolved = [];
20938
21133
  for (const table4 of allAltered) {
20939
- const result = await columnsResolver({
21134
+ const result = await columnsResolver2({
20940
21135
  tableName: table4.name,
20941
21136
  created: table4.added,
20942
21137
  deleted: table4.deleted
20943
21138
  });
21139
+ const schema4 = valueFromSelfOrPatchedNew(table4.schema);
20944
21140
  jsonRenameColumnsStatements.push(
20945
- ...prepareRenameColumns(table4.name, result.renamed)
21141
+ ...prepareRenameColumns(table4.name, schema4, result.renamed)
20946
21142
  );
20947
21143
  const renamedColumnsAltered = result.renamed.map(
20948
21144
  (it) => alteredColumnSchema.parse(diffForRenamedColumn(it.from, it.to))
@@ -20984,7 +21180,7 @@ var init_snapshotsDiffer = __esm({
20984
21180
  it.name,
20985
21181
  it.alteredCompositePKs
20986
21182
  );
20987
- if (it.schema) {
21183
+ if (it.schema && typeof it.schema !== "string") {
20988
21184
  switch (it.schema.type) {
20989
21185
  case "added": {
20990
21186
  jsonSetTableSchemas.push({
@@ -21017,38 +21213,56 @@ var init_snapshotsDiffer = __esm({
21017
21213
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
21018
21214
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
21019
21215
  });
21216
+ const rColumns = jsonRenameColumnsStatements.map((it) => {
21217
+ const tableName = it.tableName;
21218
+ const schema4 = it.schema;
21219
+ return {
21220
+ from: { schema: schema4, table: tableName, column: it.oldColumnName },
21221
+ to: { schema: schema4, table: tableName, column: it.newColumnName }
21222
+ };
21223
+ });
21020
21224
  const jsonTableAlternations = allAlteredResolved.map((it) => {
21225
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21021
21226
  return prepareAlterTableColumnsJson(
21022
21227
  it.name,
21228
+ schema4,
21023
21229
  it.deleted,
21024
21230
  it.added,
21025
21231
  it.altered,
21026
21232
  it.addedForeignKeys,
21027
21233
  dialect6
21028
21234
  );
21029
- }).flat().reduce((res, it) => {
21030
- res.createColumns.push(...it.addColumns);
21031
- res.dropColumns.push(...it.dropColumns);
21032
- res.alterColumns.push(...it.alterColumns);
21033
- return res;
21034
- }, { createColumns: [], dropColumns: [], alterColumns: [] });
21235
+ }).flat().reduce(
21236
+ (res, it) => {
21237
+ res.createColumns.push(...it.addColumns);
21238
+ res.dropColumns.push(...it.dropColumns);
21239
+ res.alterColumns.push(...it.alterColumns);
21240
+ return res;
21241
+ },
21242
+ { createColumns: [], dropColumns: [], alterColumns: [] }
21243
+ );
21035
21244
  const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
21036
- return prepareCreateIndexesJson(it.name, it.addedIndexes || {});
21245
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21246
+ return prepareCreateIndexesJson(it.name, schema4, it.addedIndexes || {});
21037
21247
  }).flat();
21038
21248
  const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
21039
- return prepareDropIndexesJson(it.name, it.deletedIndexes || {});
21249
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21250
+ return prepareDropIndexesJson(it.name, schema4, it.deletedIndexes || {});
21040
21251
  }).flat();
21041
21252
  const jsonCreateReferencesForCreatedTables = created.map((it) => {
21042
- return prepareCreateReferencesJson(it.name, it.foreignKeys);
21253
+ return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
21043
21254
  }).flat();
21044
21255
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
21045
- const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, it.addedForeignKeys) : [];
21256
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21257
+ const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, schema4, it.addedForeignKeys) : [];
21046
21258
  const forAltered = prepareDropReferencesJson(
21047
21259
  it.name,
21260
+ schema4,
21048
21261
  it.deletedForeignKeys
21049
21262
  );
21050
21263
  const alteredFKs = prepareAlterReferencesJson(
21051
21264
  it.name,
21265
+ schema4,
21052
21266
  it.alteredForeignKeys
21053
21267
  );
21054
21268
  return [...forAdded, ...forAltered, ...alteredFKs];
@@ -21110,11 +21324,1334 @@ var init_snapshotsDiffer = __esm({
21110
21324
  jsonStatements.push(...jsonRemoveTableFromSchemas);
21111
21325
  jsonStatements.push(...dropSchemas);
21112
21326
  const sqlStatements = fromJson(jsonStatements, dialect6);
21113
- return sqlStatements.join("\n");
21327
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
21328
+ return { statements: jsonStatements, sql: sqlStatements.join("\n"), _meta };
21114
21329
  };
21115
21330
  }
21116
21331
  });
21117
21332
 
21333
+ // src/utils/words.ts
21334
+ var prepareMigrationMetadata, adjectives, heroes;
21335
+ var init_words = __esm({
21336
+ "src/utils/words.ts"() {
21337
+ prepareMigrationMetadata = (idx) => {
21338
+ const prefix = idx.toFixed(0).padStart(4, "0");
21339
+ const suffix = `${adjectives.random()}_${heroes.random()}`;
21340
+ const tag = `${prefix}_${suffix}`;
21341
+ return { prefix, suffix, tag };
21342
+ };
21343
+ adjectives = [
21344
+ "abandoned",
21345
+ "aberrant",
21346
+ "abnormal",
21347
+ "absent",
21348
+ "absurd",
21349
+ "acoustic",
21350
+ "adorable",
21351
+ "amazing",
21352
+ "ambiguous",
21353
+ "ambitious",
21354
+ "amused",
21355
+ "amusing",
21356
+ "ancient",
21357
+ "aromatic",
21358
+ "aspiring",
21359
+ "awesome",
21360
+ "bent",
21361
+ "big",
21362
+ "bitter",
21363
+ "bizarre",
21364
+ "black",
21365
+ "blue",
21366
+ "blushing",
21367
+ "bored",
21368
+ "boring",
21369
+ "bouncy",
21370
+ "brainy",
21371
+ "brave",
21372
+ "breezy",
21373
+ "brief",
21374
+ "bright",
21375
+ "broad",
21376
+ "broken",
21377
+ "brown",
21378
+ "bumpy",
21379
+ "burly",
21380
+ "busy",
21381
+ "calm",
21382
+ "careful",
21383
+ "careless",
21384
+ "certain",
21385
+ "charming",
21386
+ "cheerful",
21387
+ "chemical",
21388
+ "chief",
21389
+ "chilly",
21390
+ "chubby",
21391
+ "chunky",
21392
+ "clammy",
21393
+ "classy",
21394
+ "clean",
21395
+ "clear",
21396
+ "clever",
21397
+ "cloudy",
21398
+ "closed",
21399
+ "clumsy",
21400
+ "cold",
21401
+ "colorful",
21402
+ "colossal",
21403
+ "common",
21404
+ "complete",
21405
+ "complex",
21406
+ "concerned",
21407
+ "condemned",
21408
+ "confused",
21409
+ "conscious",
21410
+ "cooing",
21411
+ "cool",
21412
+ "crazy",
21413
+ "cuddly",
21414
+ "cultured",
21415
+ "curious",
21416
+ "curly",
21417
+ "curved",
21418
+ "curvy",
21419
+ "cute",
21420
+ "cynical",
21421
+ "daffy",
21422
+ "daily",
21423
+ "damp",
21424
+ "dapper",
21425
+ "dark",
21426
+ "dashing",
21427
+ "dazzling",
21428
+ "dear",
21429
+ "deep",
21430
+ "demonic",
21431
+ "dizzy",
21432
+ "dry",
21433
+ "dusty",
21434
+ "eager",
21435
+ "early",
21436
+ "easy",
21437
+ "elite",
21438
+ "eminent",
21439
+ "empty",
21440
+ "equal",
21441
+ "even",
21442
+ "exotic",
21443
+ "fair",
21444
+ "faithful",
21445
+ "familiar",
21446
+ "famous",
21447
+ "fancy",
21448
+ "fantastic",
21449
+ "far",
21450
+ "fast",
21451
+ "fat",
21452
+ "faulty",
21453
+ "fearless",
21454
+ "fine",
21455
+ "first",
21456
+ "fixed",
21457
+ "flaky",
21458
+ "flashy",
21459
+ "flat",
21460
+ "flawless",
21461
+ "flimsy",
21462
+ "flippant",
21463
+ "flowery",
21464
+ "fluffy",
21465
+ "foamy",
21466
+ "free",
21467
+ "freezing",
21468
+ "fresh",
21469
+ "friendly",
21470
+ "funny",
21471
+ "furry",
21472
+ "futuristic",
21473
+ "fuzzy",
21474
+ "giant",
21475
+ "gifted",
21476
+ "gigantic",
21477
+ "glamorous",
21478
+ "glorious",
21479
+ "glossy",
21480
+ "good",
21481
+ "goofy",
21482
+ "gorgeous",
21483
+ "graceful",
21484
+ "gray",
21485
+ "great",
21486
+ "greedy",
21487
+ "green",
21488
+ "grey",
21489
+ "groovy",
21490
+ "handy",
21491
+ "happy",
21492
+ "hard",
21493
+ "harsh",
21494
+ "heavy",
21495
+ "hesitant",
21496
+ "high",
21497
+ "hot",
21498
+ "huge",
21499
+ "icy",
21500
+ "illegal",
21501
+ "jazzy",
21502
+ "jittery",
21503
+ "keen",
21504
+ "kind",
21505
+ "known",
21506
+ "lame",
21507
+ "large",
21508
+ "last",
21509
+ "late",
21510
+ "lazy",
21511
+ "lean",
21512
+ "left",
21513
+ "legal",
21514
+ "lethal",
21515
+ "light",
21516
+ "little",
21517
+ "lively",
21518
+ "living",
21519
+ "lonely",
21520
+ "long",
21521
+ "loose",
21522
+ "loud",
21523
+ "lovely",
21524
+ "loving",
21525
+ "low",
21526
+ "lowly",
21527
+ "lucky",
21528
+ "lumpy",
21529
+ "lush",
21530
+ "luxuriant",
21531
+ "lying",
21532
+ "lyrical",
21533
+ "magenta",
21534
+ "magical",
21535
+ "majestic",
21536
+ "many",
21537
+ "massive",
21538
+ "married",
21539
+ "marvelous",
21540
+ "material",
21541
+ "mature",
21542
+ "mean",
21543
+ "medical",
21544
+ "melodic",
21545
+ "melted",
21546
+ "messy",
21547
+ "mighty",
21548
+ "military",
21549
+ "milky",
21550
+ "minor",
21551
+ "misty",
21552
+ "mixed",
21553
+ "moaning",
21554
+ "modern",
21555
+ "motionless",
21556
+ "mushy",
21557
+ "mute",
21558
+ "mysterious",
21559
+ "naive",
21560
+ "nappy",
21561
+ "narrow",
21562
+ "nasty",
21563
+ "natural",
21564
+ "neat",
21565
+ "nebulous",
21566
+ "needy",
21567
+ "nervous",
21568
+ "new",
21569
+ "next",
21570
+ "nice",
21571
+ "nifty",
21572
+ "noisy",
21573
+ "normal",
21574
+ "nostalgic",
21575
+ "nosy",
21576
+ "numerous",
21577
+ "odd",
21578
+ "old",
21579
+ "omniscient",
21580
+ "open",
21581
+ "opposite",
21582
+ "optimal",
21583
+ "orange",
21584
+ "ordinary",
21585
+ "organic",
21586
+ "outgoing",
21587
+ "outstanding",
21588
+ "oval",
21589
+ "overconfident",
21590
+ "overjoyed",
21591
+ "overrated",
21592
+ "pale",
21593
+ "panoramic",
21594
+ "parallel",
21595
+ "parched",
21596
+ "past",
21597
+ "peaceful",
21598
+ "perfect",
21599
+ "perpetual",
21600
+ "petite",
21601
+ "pink",
21602
+ "plain",
21603
+ "polite",
21604
+ "powerful",
21605
+ "premium",
21606
+ "pretty",
21607
+ "previous",
21608
+ "productive",
21609
+ "public",
21610
+ "purple",
21611
+ "puzzling",
21612
+ "quick",
21613
+ "quiet",
21614
+ "rainy",
21615
+ "rapid",
21616
+ "rare",
21617
+ "real",
21618
+ "red",
21619
+ "redundant",
21620
+ "reflective",
21621
+ "regular",
21622
+ "remarkable",
21623
+ "rich",
21624
+ "right",
21625
+ "robust",
21626
+ "romantic",
21627
+ "round",
21628
+ "sad",
21629
+ "safe",
21630
+ "salty",
21631
+ "same",
21632
+ "secret",
21633
+ "serious",
21634
+ "shallow",
21635
+ "sharp",
21636
+ "shiny",
21637
+ "shocking",
21638
+ "short",
21639
+ "silent",
21640
+ "silky",
21641
+ "silly",
21642
+ "simple",
21643
+ "skinny",
21644
+ "sleepy",
21645
+ "slim",
21646
+ "slimy",
21647
+ "slippery",
21648
+ "sloppy",
21649
+ "slow",
21650
+ "small",
21651
+ "smart",
21652
+ "smiling",
21653
+ "smooth",
21654
+ "soft",
21655
+ "solid",
21656
+ "sour",
21657
+ "sparkling",
21658
+ "special",
21659
+ "spicy",
21660
+ "spooky",
21661
+ "spotty",
21662
+ "square",
21663
+ "stale",
21664
+ "steady",
21665
+ "steep",
21666
+ "sticky",
21667
+ "stiff",
21668
+ "stormy",
21669
+ "strange",
21670
+ "striped",
21671
+ "strong",
21672
+ "sturdy",
21673
+ "sudden",
21674
+ "superb",
21675
+ "supreme",
21676
+ "sweet",
21677
+ "swift",
21678
+ "talented",
21679
+ "tan",
21680
+ "tearful",
21681
+ "tense",
21682
+ "thankful",
21683
+ "thick",
21684
+ "thin",
21685
+ "third",
21686
+ "tidy",
21687
+ "tiny",
21688
+ "tired",
21689
+ "tiresome",
21690
+ "tough",
21691
+ "tranquil",
21692
+ "tricky",
21693
+ "true",
21694
+ "typical",
21695
+ "uneven",
21696
+ "unique",
21697
+ "unknown",
21698
+ "unusual",
21699
+ "useful",
21700
+ "vengeful",
21701
+ "violet",
21702
+ "volatile",
21703
+ "wakeful",
21704
+ "wandering",
21705
+ "warm",
21706
+ "watery",
21707
+ "wealthy",
21708
+ "wet",
21709
+ "white",
21710
+ "whole",
21711
+ "wide",
21712
+ "wild",
21713
+ "windy",
21714
+ "wise",
21715
+ "wonderful",
21716
+ "wooden",
21717
+ "woozy",
21718
+ "workable",
21719
+ "worried",
21720
+ "worthless",
21721
+ "yellow",
21722
+ "yielding",
21723
+ "young",
21724
+ "youthful",
21725
+ "yummy",
21726
+ "zippy"
21727
+ ];
21728
+ heroes = [
21729
+ "aaron_stack",
21730
+ "abomination",
21731
+ "absorbing_man",
21732
+ "adam_destine",
21733
+ "adam_warlock",
21734
+ "agent_brand",
21735
+ "agent_zero",
21736
+ "albert_cleary",
21737
+ "alex_power",
21738
+ "alex_wilder",
21739
+ "alice",
21740
+ "amazoness",
21741
+ "amphibian",
21742
+ "angel",
21743
+ "anita_blake",
21744
+ "annihilus",
21745
+ "anthem",
21746
+ "apocalypse",
21747
+ "aqueduct",
21748
+ "arachne",
21749
+ "archangel",
21750
+ "arclight",
21751
+ "ares",
21752
+ "argent",
21753
+ "avengers",
21754
+ "azazel",
21755
+ "banshee",
21756
+ "baron_strucker",
21757
+ "baron_zemo",
21758
+ "barracuda",
21759
+ "bastion",
21760
+ "beast",
21761
+ "bedlam",
21762
+ "ben_grimm",
21763
+ "ben_parker",
21764
+ "ben_urich",
21765
+ "betty_brant",
21766
+ "betty_ross",
21767
+ "beyonder",
21768
+ "big_bertha",
21769
+ "bill_hollister",
21770
+ "bishop",
21771
+ "black_bird",
21772
+ "black_bolt",
21773
+ "black_cat",
21774
+ "black_crow",
21775
+ "black_knight",
21776
+ "black_panther",
21777
+ "black_queen",
21778
+ "black_tarantula",
21779
+ "black_tom",
21780
+ "black_widow",
21781
+ "blackheart",
21782
+ "blacklash",
21783
+ "blade",
21784
+ "blazing_skull",
21785
+ "blindfold",
21786
+ "blink",
21787
+ "blizzard",
21788
+ "blob",
21789
+ "blockbuster",
21790
+ "blonde_phantom",
21791
+ "bloodaxe",
21792
+ "bloodscream",
21793
+ "bloodstorm",
21794
+ "bloodstrike",
21795
+ "blue_blade",
21796
+ "blue_marvel",
21797
+ "blue_shield",
21798
+ "blur",
21799
+ "boom_boom",
21800
+ "boomer",
21801
+ "boomerang",
21802
+ "bromley",
21803
+ "brood",
21804
+ "brother_voodoo",
21805
+ "bruce_banner",
21806
+ "bucky",
21807
+ "bug",
21808
+ "bulldozer",
21809
+ "bullseye",
21810
+ "bushwacker",
21811
+ "butterfly",
21812
+ "cable",
21813
+ "callisto",
21814
+ "calypso",
21815
+ "cammi",
21816
+ "cannonball",
21817
+ "captain_america",
21818
+ "captain_britain",
21819
+ "captain_cross",
21820
+ "captain_flint",
21821
+ "captain_marvel",
21822
+ "captain_midlands",
21823
+ "captain_stacy",
21824
+ "captain_universe",
21825
+ "cardiac",
21826
+ "caretaker",
21827
+ "cargill",
21828
+ "carlie_cooper",
21829
+ "carmella_unuscione",
21830
+ "carnage",
21831
+ "cassandra_nova",
21832
+ "catseye",
21833
+ "celestials",
21834
+ "centennial",
21835
+ "cerebro",
21836
+ "cerise",
21837
+ "chamber",
21838
+ "chameleon",
21839
+ "champions",
21840
+ "changeling",
21841
+ "charles_xavier",
21842
+ "chat",
21843
+ "chimera",
21844
+ "christian_walker",
21845
+ "chronomancer",
21846
+ "clea",
21847
+ "clint_barton",
21848
+ "cloak",
21849
+ "cobalt_man",
21850
+ "colleen_wing",
21851
+ "colonel_america",
21852
+ "colossus",
21853
+ "corsair",
21854
+ "crusher_hogan",
21855
+ "crystal",
21856
+ "cyclops",
21857
+ "dagger",
21858
+ "daimon_hellstrom",
21859
+ "dakota_north",
21860
+ "daredevil",
21861
+ "dark_beast",
21862
+ "dark_phoenix",
21863
+ "darkhawk",
21864
+ "darkstar",
21865
+ "darwin",
21866
+ "dazzler",
21867
+ "deadpool",
21868
+ "deathbird",
21869
+ "deathstrike",
21870
+ "demogoblin",
21871
+ "devos",
21872
+ "dexter_bennett",
21873
+ "diamondback",
21874
+ "doctor_doom",
21875
+ "doctor_faustus",
21876
+ "doctor_octopus",
21877
+ "doctor_spectrum",
21878
+ "doctor_strange",
21879
+ "domino",
21880
+ "donald_blake",
21881
+ "doomsday",
21882
+ "doorman",
21883
+ "dorian_gray",
21884
+ "dormammu",
21885
+ "dracula",
21886
+ "dragon_lord",
21887
+ "dragon_man",
21888
+ "drax",
21889
+ "dreadnoughts",
21890
+ "dreaming_celestial",
21891
+ "dust",
21892
+ "earthquake",
21893
+ "echo",
21894
+ "eddie_brock",
21895
+ "edwin_jarvis",
21896
+ "ego",
21897
+ "electro",
21898
+ "elektra",
21899
+ "emma_frost",
21900
+ "enchantress",
21901
+ "ender_wiggin",
21902
+ "energizer",
21903
+ "epoch",
21904
+ "eternals",
21905
+ "eternity",
21906
+ "excalibur",
21907
+ "exiles",
21908
+ "exodus",
21909
+ "expediter",
21910
+ "ezekiel",
21911
+ "ezekiel_stane",
21912
+ "fabian_cortez",
21913
+ "falcon",
21914
+ "fallen_one",
21915
+ "famine",
21916
+ "fantastic_four",
21917
+ "fat_cobra",
21918
+ "felicia_hardy",
21919
+ "fenris",
21920
+ "firebird",
21921
+ "firebrand",
21922
+ "firedrake",
21923
+ "firelord",
21924
+ "firestar",
21925
+ "fixer",
21926
+ "flatman",
21927
+ "forge",
21928
+ "forgotten_one",
21929
+ "frank_castle",
21930
+ "franklin_richards",
21931
+ "franklin_storm",
21932
+ "freak",
21933
+ "frightful_four",
21934
+ "frog_thor",
21935
+ "gabe_jones",
21936
+ "galactus",
21937
+ "gambit",
21938
+ "gamma_corps",
21939
+ "gamora",
21940
+ "gargoyle",
21941
+ "garia",
21942
+ "gateway",
21943
+ "gauntlet",
21944
+ "genesis",
21945
+ "george_stacy",
21946
+ "gertrude_yorkes",
21947
+ "ghost_rider",
21948
+ "giant_girl",
21949
+ "giant_man",
21950
+ "gideon",
21951
+ "gladiator",
21952
+ "glorian",
21953
+ "goblin_queen",
21954
+ "golden_guardian",
21955
+ "goliath",
21956
+ "gorgon",
21957
+ "gorilla_man",
21958
+ "grandmaster",
21959
+ "gravity",
21960
+ "green_goblin",
21961
+ "gressill",
21962
+ "grey_gargoyle",
21963
+ "greymalkin",
21964
+ "grim_reaper",
21965
+ "groot",
21966
+ "guardian",
21967
+ "guardsmen",
21968
+ "gunslinger",
21969
+ "gwen_stacy",
21970
+ "hairball",
21971
+ "hammerhead",
21972
+ "hannibal_king",
21973
+ "hardball",
21974
+ "harpoon",
21975
+ "harrier",
21976
+ "harry_osborn",
21977
+ "havok",
21978
+ "hawkeye",
21979
+ "hedge_knight",
21980
+ "hellcat",
21981
+ "hellfire_club",
21982
+ "hellion",
21983
+ "hemingway",
21984
+ "hercules",
21985
+ "hex",
21986
+ "hiroim",
21987
+ "hitman",
21988
+ "hobgoblin",
21989
+ "holocaust",
21990
+ "hulk",
21991
+ "human_cannonball",
21992
+ "human_fly",
21993
+ "human_robot",
21994
+ "human_torch",
21995
+ "husk",
21996
+ "hydra",
21997
+ "iceman",
21998
+ "ikaris",
21999
+ "imperial_guard",
22000
+ "impossible_man",
22001
+ "inertia",
22002
+ "infant_terrible",
22003
+ "inhumans",
22004
+ "ink",
22005
+ "invaders",
22006
+ "invisible_woman",
22007
+ "iron_fist",
22008
+ "iron_lad",
22009
+ "iron_man",
22010
+ "iron_monger",
22011
+ "iron_patriot",
22012
+ "ironclad",
22013
+ "jack_flag",
22014
+ "jack_murdock",
22015
+ "jack_power",
22016
+ "jackal",
22017
+ "jackpot",
22018
+ "james_howlett",
22019
+ "jamie_braddock",
22020
+ "jane_foster",
22021
+ "jasper_sitwell",
22022
+ "jazinda",
22023
+ "jean_grey",
22024
+ "jetstream",
22025
+ "jigsaw",
22026
+ "jimmy_woo",
22027
+ "jocasta",
22028
+ "johnny_blaze",
22029
+ "johnny_storm",
22030
+ "joseph",
22031
+ "joshua_kane",
22032
+ "joystick",
22033
+ "jubilee",
22034
+ "juggernaut",
22035
+ "junta",
22036
+ "justice",
22037
+ "justin_hammer",
22038
+ "kabuki",
22039
+ "kang",
22040
+ "karen_page",
22041
+ "karma",
22042
+ "karnak",
22043
+ "kat_farrell",
22044
+ "kate_bishop",
22045
+ "katie_power",
22046
+ "ken_ellis",
22047
+ "khan",
22048
+ "kid_colt",
22049
+ "killer_shrike",
22050
+ "killmonger",
22051
+ "killraven",
22052
+ "king_bedlam",
22053
+ "king_cobra",
22054
+ "kingpin",
22055
+ "kinsey_walden",
22056
+ "kitty_pryde",
22057
+ "klaw",
22058
+ "komodo",
22059
+ "korath",
22060
+ "korg",
22061
+ "korvac",
22062
+ "kree",
22063
+ "krista_starr",
22064
+ "kronos",
22065
+ "kulan_gath",
22066
+ "kylun",
22067
+ "la_nuit",
22068
+ "lady_bullseye",
22069
+ "lady_deathstrike",
22070
+ "lady_mastermind",
22071
+ "lady_ursula",
22072
+ "lady_vermin",
22073
+ "lake",
22074
+ "landau",
22075
+ "layla_miller",
22076
+ "leader",
22077
+ "leech",
22078
+ "legion",
22079
+ "lenny_balinger",
22080
+ "leo",
22081
+ "leopardon",
22082
+ "leper_queen",
22083
+ "lester",
22084
+ "lethal_legion",
22085
+ "lifeguard",
22086
+ "lightspeed",
22087
+ "lila_cheney",
22088
+ "lilandra",
22089
+ "lilith",
22090
+ "lily_hollister",
22091
+ "lionheart",
22092
+ "living_lightning",
22093
+ "living_mummy",
22094
+ "living_tribunal",
22095
+ "liz_osborn",
22096
+ "lizard",
22097
+ "loa",
22098
+ "lockheed",
22099
+ "lockjaw",
22100
+ "logan",
22101
+ "loki",
22102
+ "loners",
22103
+ "longshot",
22104
+ "lord_hawal",
22105
+ "lord_tyger",
22106
+ "lorna_dane",
22107
+ "luckman",
22108
+ "lucky_pierre",
22109
+ "luke_cage",
22110
+ "luminals",
22111
+ "lyja",
22112
+ "ma_gnuci",
22113
+ "mac_gargan",
22114
+ "mach_iv",
22115
+ "machine_man",
22116
+ "mad_thinker",
22117
+ "madame_hydra",
22118
+ "madame_masque",
22119
+ "madame_web",
22120
+ "maddog",
22121
+ "madelyne_pryor",
22122
+ "madripoor",
22123
+ "madrox",
22124
+ "maelstrom",
22125
+ "maestro",
22126
+ "magdalene",
22127
+ "maggott",
22128
+ "magik",
22129
+ "maginty",
22130
+ "magma",
22131
+ "magneto",
22132
+ "magus",
22133
+ "major_mapleleaf",
22134
+ "makkari",
22135
+ "malcolm_colcord",
22136
+ "malice",
22137
+ "mandarin",
22138
+ "mandrill",
22139
+ "mandroid",
22140
+ "manta",
22141
+ "mantis",
22142
+ "marauders",
22143
+ "maria_hill",
22144
+ "mariko_yashida",
22145
+ "marrow",
22146
+ "marten_broadcloak",
22147
+ "martin_li",
22148
+ "marvel_apes",
22149
+ "marvel_boy",
22150
+ "marvel_zombies",
22151
+ "marvex",
22152
+ "masked_marvel",
22153
+ "masque",
22154
+ "master_chief",
22155
+ "master_mold",
22156
+ "mastermind",
22157
+ "mathemanic",
22158
+ "matthew_murdock",
22159
+ "mattie_franklin",
22160
+ "mauler",
22161
+ "maverick",
22162
+ "maximus",
22163
+ "may_parker",
22164
+ "medusa",
22165
+ "meggan",
22166
+ "meltdown",
22167
+ "menace",
22168
+ "mentallo",
22169
+ "mentor",
22170
+ "mephisto",
22171
+ "mephistopheles",
22172
+ "mercury",
22173
+ "mesmero",
22174
+ "metal_master",
22175
+ "meteorite",
22176
+ "micro/macro",
22177
+ "microbe",
22178
+ "microchip",
22179
+ "micromax",
22180
+ "midnight",
22181
+ "miek",
22182
+ "mikhail_rasputin",
22183
+ "millenium_guard",
22184
+ "mimic",
22185
+ "mindworm",
22186
+ "miracleman",
22187
+ "miss_america",
22188
+ "mister_fear",
22189
+ "mister_sinister",
22190
+ "misty_knight",
22191
+ "mockingbird",
22192
+ "moira_mactaggert",
22193
+ "mojo",
22194
+ "mole_man",
22195
+ "molecule_man",
22196
+ "molly_hayes",
22197
+ "molten_man",
22198
+ "mongoose",
22199
+ "mongu",
22200
+ "monster_badoon",
22201
+ "moon_knight",
22202
+ "moondragon",
22203
+ "moonstone",
22204
+ "morbius",
22205
+ "mordo",
22206
+ "morg",
22207
+ "morgan_stark",
22208
+ "morlocks",
22209
+ "morlun",
22210
+ "morph",
22211
+ "mother_askani",
22212
+ "mulholland_black",
22213
+ "multiple_man",
22214
+ "mysterio",
22215
+ "mystique",
22216
+ "namor",
22217
+ "namora",
22218
+ "namorita",
22219
+ "naoko",
22220
+ "natasha_romanoff",
22221
+ "nebula",
22222
+ "nehzno",
22223
+ "nekra",
22224
+ "nemesis",
22225
+ "network",
22226
+ "newton_destine",
22227
+ "next_avengers",
22228
+ "nextwave",
22229
+ "nick_fury",
22230
+ "nico_minoru",
22231
+ "nicolaos",
22232
+ "night_nurse",
22233
+ "night_thrasher",
22234
+ "nightcrawler",
22235
+ "nighthawk",
22236
+ "nightmare",
22237
+ "nightshade",
22238
+ "nitro",
22239
+ "nocturne",
22240
+ "nomad",
22241
+ "norman_osborn",
22242
+ "norrin_radd",
22243
+ "northstar",
22244
+ "nova",
22245
+ "nuke",
22246
+ "obadiah_stane",
22247
+ "odin",
22248
+ "ogun",
22249
+ "old_lace",
22250
+ "omega_flight",
22251
+ "omega_red",
22252
+ "omega_sentinel",
22253
+ "onslaught",
22254
+ "oracle",
22255
+ "orphan",
22256
+ "otto_octavius",
22257
+ "outlaw_kid",
22258
+ "overlord",
22259
+ "owl",
22260
+ "ozymandias",
22261
+ "paibok",
22262
+ "paladin",
22263
+ "pandemic",
22264
+ "paper_doll",
22265
+ "patch",
22266
+ "patriot",
22267
+ "payback",
22268
+ "penance",
22269
+ "pepper_potts",
22270
+ "pestilence",
22271
+ "pet_avengers",
22272
+ "pete_wisdom",
22273
+ "peter_parker",
22274
+ "peter_quill",
22275
+ "phalanx",
22276
+ "phantom_reporter",
22277
+ "phil_sheldon",
22278
+ "photon",
22279
+ "piledriver",
22280
+ "pixie",
22281
+ "plazm",
22282
+ "polaris",
22283
+ "post",
22284
+ "power_man",
22285
+ "power_pack",
22286
+ "praxagora",
22287
+ "preak",
22288
+ "pretty_boy",
22289
+ "pride",
22290
+ "prima",
22291
+ "princess_powerful",
22292
+ "prism",
22293
+ "prodigy",
22294
+ "proemial_gods",
22295
+ "professor_monster",
22296
+ "proteus",
22297
+ "proudstar",
22298
+ "prowler",
22299
+ "psylocke",
22300
+ "psynapse",
22301
+ "puck",
22302
+ "puff_adder",
22303
+ "puma",
22304
+ "punisher",
22305
+ "puppet_master",
22306
+ "purifiers",
22307
+ "purple_man",
22308
+ "pyro",
22309
+ "quasar",
22310
+ "quasimodo",
22311
+ "queen_noir",
22312
+ "quentin_quire",
22313
+ "quicksilver",
22314
+ "rachel_grey",
22315
+ "radioactive_man",
22316
+ "rafael_vega",
22317
+ "rage",
22318
+ "raider",
22319
+ "randall",
22320
+ "randall_flagg",
22321
+ "random",
22322
+ "rattler",
22323
+ "ravenous",
22324
+ "rawhide_kid",
22325
+ "raza",
22326
+ "reaper",
22327
+ "reavers",
22328
+ "red_ghost",
22329
+ "red_hulk",
22330
+ "red_shift",
22331
+ "red_skull",
22332
+ "red_wolf",
22333
+ "redwing",
22334
+ "reptil",
22335
+ "retro_girl",
22336
+ "revanche",
22337
+ "rhino",
22338
+ "rhodey",
22339
+ "richard_fisk",
22340
+ "rick_jones",
22341
+ "ricochet",
22342
+ "rictor",
22343
+ "riptide",
22344
+ "risque",
22345
+ "robbie_robertson",
22346
+ "robin_chapel",
22347
+ "rocket_raccoon",
22348
+ "rocket_racer",
22349
+ "rockslide",
22350
+ "rogue",
22351
+ "roland_deschain",
22352
+ "romulus",
22353
+ "ronan",
22354
+ "roughhouse",
22355
+ "roulette",
22356
+ "roxanne_simpson",
22357
+ "rumiko_fujikawa",
22358
+ "runaways",
22359
+ "russian",
22360
+ "sabra",
22361
+ "sabretooth",
22362
+ "sage",
22363
+ "sally_floyd",
22364
+ "salo",
22365
+ "sandman",
22366
+ "santa_claus",
22367
+ "saracen",
22368
+ "sasquatch",
22369
+ "satana",
22370
+ "sauron",
22371
+ "scalphunter",
22372
+ "scarecrow",
22373
+ "scarlet_spider",
22374
+ "scarlet_witch",
22375
+ "scorpion",
22376
+ "scourge",
22377
+ "scrambler",
22378
+ "scream",
22379
+ "screwball",
22380
+ "sebastian_shaw",
22381
+ "secret_warriors",
22382
+ "selene",
22383
+ "senator_kelly",
22384
+ "sentinel",
22385
+ "sentinels",
22386
+ "sentry",
22387
+ "ser_duncan",
22388
+ "serpent_society",
22389
+ "sersi",
22390
+ "shadow_king",
22391
+ "shadowcat",
22392
+ "shaman",
22393
+ "shape",
22394
+ "shard",
22395
+ "sharon_carter",
22396
+ "sharon_ventura",
22397
+ "shatterstar",
22398
+ "shen",
22399
+ "sheva_callister",
22400
+ "shinko_yamashiro",
22401
+ "shinobi_shaw",
22402
+ "shiva",
22403
+ "shiver_man",
22404
+ "shocker",
22405
+ "shockwave",
22406
+ "shooting_star",
22407
+ "shotgun",
22408
+ "shriek",
22409
+ "silhouette",
22410
+ "silk_fever",
22411
+ "silver_centurion",
22412
+ "silver_fox",
22413
+ "silver_sable",
22414
+ "silver_samurai",
22415
+ "silver_surfer",
22416
+ "silverclaw",
22417
+ "silvermane",
22418
+ "sinister_six",
22419
+ "sir_ram",
22420
+ "siren",
22421
+ "sister_grimm",
22422
+ "skaar",
22423
+ "skin",
22424
+ "skreet",
22425
+ "skrulls",
22426
+ "skullbuster",
22427
+ "slapstick",
22428
+ "slayback",
22429
+ "sleeper",
22430
+ "sleepwalker",
22431
+ "slipstream",
22432
+ "slyde",
22433
+ "smasher",
22434
+ "smiling_tiger",
22435
+ "snowbird",
22436
+ "solo",
22437
+ "songbird",
22438
+ "spacker_dave",
22439
+ "spectrum",
22440
+ "speed",
22441
+ "speed_demon",
22442
+ "speedball",
22443
+ "spencer_smythe",
22444
+ "sphinx",
22445
+ "spiral",
22446
+ "spirit",
22447
+ "spitfire",
22448
+ "spot",
22449
+ "sprite",
22450
+ "spyke",
22451
+ "squadron_sinister",
22452
+ "squadron_supreme",
22453
+ "squirrel_girl",
22454
+ "star_brand",
22455
+ "starbolt",
22456
+ "stardust",
22457
+ "starfox",
22458
+ "starhawk",
22459
+ "starjammers",
22460
+ "stark_industries",
22461
+ "stature",
22462
+ "steel_serpent",
22463
+ "stellaris",
22464
+ "stepford_cuckoos",
22465
+ "stephen_strange",
22466
+ "steve_rogers",
22467
+ "stick",
22468
+ "stingray",
22469
+ "stone_men",
22470
+ "storm",
22471
+ "stranger",
22472
+ "strong_guy",
22473
+ "stryfe",
22474
+ "sue_storm",
22475
+ "sugar_man",
22476
+ "sumo",
22477
+ "sunfire",
22478
+ "sunset_bain",
22479
+ "sunspot",
22480
+ "supernaut",
22481
+ "supreme_intelligence",
22482
+ "surge",
22483
+ "susan_delgado",
22484
+ "swarm",
22485
+ "sway",
22486
+ "switch",
22487
+ "swordsman",
22488
+ "synch",
22489
+ "tag",
22490
+ "talisman",
22491
+ "talkback",
22492
+ "talon",
22493
+ "talos",
22494
+ "tana_nile",
22495
+ "tarantula",
22496
+ "tarot",
22497
+ "taskmaster",
22498
+ "tattoo",
22499
+ "ted_forrester",
22500
+ "tempest",
22501
+ "tenebrous",
22502
+ "terrax",
22503
+ "terror",
22504
+ "texas_twister",
22505
+ "thaddeus_ross",
22506
+ "thanos",
22507
+ "the_anarchist",
22508
+ "the_call",
22509
+ "the_captain",
22510
+ "the_enforcers",
22511
+ "the_executioner",
22512
+ "the_fallen",
22513
+ "the_fury",
22514
+ "the_hand",
22515
+ "the_hood",
22516
+ "the_hunter",
22517
+ "the_initiative",
22518
+ "the_leader",
22519
+ "the_liberteens",
22520
+ "the_order",
22521
+ "the_phantom",
22522
+ "the_professor",
22523
+ "the_renegades",
22524
+ "the_santerians",
22525
+ "the_spike",
22526
+ "the_stranger",
22527
+ "the_twelve",
22528
+ "the_watchers",
22529
+ "thena",
22530
+ "thing",
22531
+ "thor",
22532
+ "thor_girl",
22533
+ "thunderball",
22534
+ "thunderbird",
22535
+ "thunderbolt",
22536
+ "thunderbolt_ross",
22537
+ "thunderbolts",
22538
+ "thundra",
22539
+ "tiger_shark",
22540
+ "tigra",
22541
+ "timeslip",
22542
+ "tinkerer",
22543
+ "titania",
22544
+ "titanium_man",
22545
+ "toad",
22546
+ "toad_men",
22547
+ "tomas",
22548
+ "tombstone",
22549
+ "tomorrow_man",
22550
+ "tony_stark",
22551
+ "toro",
22552
+ "toxin",
22553
+ "trauma",
22554
+ "triathlon",
22555
+ "trish_tilby",
22556
+ "triton",
22557
+ "true_believers",
22558
+ "turbo",
22559
+ "tusk",
22560
+ "tyger_tiger",
22561
+ "typhoid_mary",
22562
+ "tyrannus",
22563
+ "ulik",
22564
+ "ultimates",
22565
+ "ultimatum",
22566
+ "ultimo",
22567
+ "ultragirl",
22568
+ "ultron",
22569
+ "umar",
22570
+ "unicorn",
22571
+ "union_jack",
22572
+ "unus",
22573
+ "valeria_richards",
22574
+ "valkyrie",
22575
+ "vampiro",
22576
+ "vance_astro",
22577
+ "vanisher",
22578
+ "vapor",
22579
+ "vargas",
22580
+ "vector",
22581
+ "veda",
22582
+ "vengeance",
22583
+ "venom",
22584
+ "venus",
22585
+ "vermin",
22586
+ "vertigo",
22587
+ "victor_mancha",
22588
+ "vin_gonzales",
22589
+ "vindicator",
22590
+ "violations",
22591
+ "viper",
22592
+ "virginia_dare",
22593
+ "vision",
22594
+ "vivisector",
22595
+ "vulcan",
22596
+ "vulture",
22597
+ "wallflower",
22598
+ "wallop",
22599
+ "wallow",
22600
+ "war_machine",
22601
+ "warbird",
22602
+ "warbound",
22603
+ "warhawk",
22604
+ "warlock",
22605
+ "warpath",
22606
+ "warstar",
22607
+ "wasp",
22608
+ "weapon_omega",
22609
+ "wendell_rand",
22610
+ "wendell_vaughn",
22611
+ "wendigo",
22612
+ "whiplash",
22613
+ "whirlwind",
22614
+ "whistler",
22615
+ "white_queen",
22616
+ "white_tiger",
22617
+ "whizzer",
22618
+ "wiccan",
22619
+ "wild_child",
22620
+ "wild_pack",
22621
+ "wildside",
22622
+ "william_stryker",
22623
+ "wilson_fisk",
22624
+ "wind_dancer",
22625
+ "winter_soldier",
22626
+ "wither",
22627
+ "wolf_cub",
22628
+ "wolfpack",
22629
+ "wolfsbane",
22630
+ "wolverine",
22631
+ "wonder_man",
22632
+ "wong",
22633
+ "wraith",
22634
+ "wrecker",
22635
+ "wrecking_crew",
22636
+ "xavin",
22637
+ "xorn",
22638
+ "yellow_claw",
22639
+ "yellowjacket",
22640
+ "young_avengers",
22641
+ "zaladane",
22642
+ "zaran",
22643
+ "zarda",
22644
+ "zarek",
22645
+ "zeigeist",
22646
+ "zemo",
22647
+ "zodiak",
22648
+ "zombie",
22649
+ "zuras",
22650
+ "zzzax"
22651
+ ];
22652
+ }
22653
+ });
22654
+
21118
22655
  // src/cli/commands/migrate.ts
21119
22656
  var migrate_exports = {};
21120
22657
  __export(migrate_exports, {
@@ -21122,15 +22659,16 @@ __export(migrate_exports, {
21122
22659
  prepareAndMigratePg: () => prepareAndMigratePg,
21123
22660
  prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
21124
22661
  prepareSQL: () => prepareSQL,
21125
- prepareSnapshotFolderName: () => prepareSnapshotFolderName
22662
+ prepareSnapshotFolderName: () => prepareSnapshotFolderName,
22663
+ writeResult: () => writeResult
21126
22664
  });
21127
- var import_fs4, import_path2, import_hanji2, prepareAndMigratePg, prepareAndMigrateSqlite, prepareAndMigrateMySql, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
22665
+ var import_fs4, import_path3, import_hanji2, prepareAndMigratePg, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
21128
22666
  var init_migrate = __esm({
21129
22667
  "src/cli/commands/migrate.ts"() {
21130
22668
  import_fs4 = __toESM(require("fs"));
21131
22669
  init_migrationPreparator();
21132
22670
  init_snapshotsDiffer();
21133
- import_path2 = __toESM(require("path"));
22671
+ import_path3 = __toESM(require("path"));
21134
22672
  import_hanji2 = __toESM(require_hanji());
21135
22673
  init_views();
21136
22674
  init_source();
@@ -21138,68 +22676,68 @@ var init_migrate = __esm({
21138
22676
  init_sqliteSchema();
21139
22677
  init_mysqlSchema();
21140
22678
  init_utils();
22679
+ init_words();
21141
22680
  prepareAndMigratePg = async (config) => {
21142
22681
  const outFolder = config.out;
21143
22682
  const schemaPath = config.schema;
21144
22683
  try {
21145
- const { migrationFolders } = prepareMigrationFolder(outFolder, "pg");
21146
- const { prev, cur } = preparePgMigrationSnapshot(
21147
- migrationFolders,
21148
- outFolder,
21149
- schemaPath
21150
- );
22684
+ assertV1OutFolder(outFolder, "pg");
22685
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
22686
+ const { prev, cur } = preparePgMigrationSnapshot(snapshots, schemaPath);
21151
22687
  const validatedPrev = pgSchema.parse(prev);
21152
22688
  const validatedCur = pgSchema.parse(cur);
21153
22689
  const squashedPrev = squashPgScheme(validatedPrev);
21154
22690
  const squashedCur = squashPgScheme(validatedCur);
21155
- const sql = await prepareSQL(squashedPrev, squashedCur, "pg");
21156
- writeResult(cur, sql, outFolder);
22691
+ const { statements, sql, _meta } = await prepareSQL(
22692
+ squashedPrev,
22693
+ squashedCur,
22694
+ "pg"
22695
+ );
22696
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21157
22697
  } catch (e) {
21158
22698
  console.error(e);
21159
22699
  }
21160
22700
  };
21161
- prepareAndMigrateSqlite = async (config) => {
22701
+ prepareAndMigrateMySql = async (config) => {
21162
22702
  const outFolder = config.out;
21163
22703
  const schemaPath = config.schema;
21164
22704
  try {
21165
- const { migrationFolders } = prepareMigrationFolder(outFolder, "sqlite");
21166
- const { prev, cur } = prepareSqliteMigrationSnapshot(
21167
- migrationFolders,
21168
- outFolder,
21169
- schemaPath
22705
+ assertV1OutFolder(outFolder, "mysql");
22706
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "mysql");
22707
+ const { prev, cur } = prepareMySqlMigrationSnapshot(snapshots, schemaPath);
22708
+ const validatedPrev = mysqlSchema.parse(prev);
22709
+ const validatedCur = mysqlSchema.parse(cur);
22710
+ const squashedPrev = squashMysqlScheme(validatedPrev);
22711
+ const squashedCur = squashMysqlScheme(validatedCur);
22712
+ const { sql, _meta } = await prepareSQL(
22713
+ squashedPrev,
22714
+ squashedCur,
22715
+ "sqlite"
21170
22716
  );
21171
- const validatedPrev = sqliteSchema.parse(prev);
21172
- const validatedCur = sqliteSchema.parse(cur);
21173
- const squashedPrev = squashSqliteScheme(validatedPrev);
21174
- const squashedCur = squashSqliteScheme(validatedCur);
21175
- const sql = await prepareSQL(squashedPrev, squashedCur, "sqlite");
21176
- writeResult(cur, sql, outFolder);
22717
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21177
22718
  } catch (e) {
21178
22719
  console.error(e);
21179
22720
  }
21180
22721
  };
21181
- prepareAndMigrateMySql = async (config) => {
22722
+ prepareAndMigrateSqlite = async (config) => {
21182
22723
  const outFolder = config.out;
21183
22724
  const schemaPath = config.schema;
21184
22725
  try {
21185
- const { migrationFolders } = prepareMigrationFolder(outFolder, "mysql");
21186
- const { prev, cur } = prepareMySqlMigrationSnapshot(
21187
- migrationFolders,
21188
- outFolder,
21189
- schemaPath
21190
- );
21191
- const validatedPrev = mysqlSchema.parse(prev);
21192
- const validatedCur = mysqlSchema.parse(cur);
21193
- const squashedPrev = squashMysqlScheme(validatedPrev);
21194
- const squashedCur = squashMysqlScheme(validatedCur);
21195
- const sql = await prepareSQL(squashedPrev, squashedCur, "mysql");
21196
- writeResult(cur, sql, outFolder);
22726
+ assertV1OutFolder(outFolder, "sqlite");
22727
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
22728
+ const { prev, cur } = prepareSqliteMigrationSnapshot(snapshots, schemaPath);
22729
+ const validatedPrev = sqliteSchema.parse(prev);
22730
+ const validatedCur = sqliteSchema.parse(cur);
22731
+ const squashedPrev = squashSqliteScheme(validatedPrev);
22732
+ const squashedCur = squashSqliteScheme(validatedCur);
22733
+ const { sql, _meta } = await prepareSQL(squashedPrev, squashedCur, "mysql");
22734
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21197
22735
  } catch (e) {
21198
22736
  console.error(e);
21199
22737
  }
21200
22738
  };
21201
22739
  prepareSQL = async (prev, cur, dialect6) => {
21202
- const schemasResolver = async (input) => {
22740
+ const schemasResolver2 = async (input) => {
21203
22741
  try {
21204
22742
  const { created, deleted, renamed } = await promptSchemasConflict(
21205
22743
  input.created,
@@ -21211,7 +22749,7 @@ var init_migrate = __esm({
21211
22749
  throw e;
21212
22750
  }
21213
22751
  };
21214
- const tablesResolver = async (input) => {
22752
+ const tablesResolver2 = async (input) => {
21215
22753
  try {
21216
22754
  const { created, deleted, renamed } = await promptTablesConflict(
21217
22755
  input.created,
@@ -21223,7 +22761,7 @@ var init_migrate = __esm({
21223
22761
  throw e;
21224
22762
  }
21225
22763
  };
21226
- const columnsResolver = async (input) => {
22764
+ const columnsResolver2 = async (input) => {
21227
22765
  const result = await promptColumnsConflicts(
21228
22766
  input.tableName,
21229
22767
  input.created,
@@ -21240,9 +22778,9 @@ var init_migrate = __esm({
21240
22778
  prev,
21241
22779
  cur,
21242
22780
  dialect6,
21243
- schemasResolver,
21244
- tablesResolver,
21245
- columnsResolver
22781
+ schemasResolver2,
22782
+ tablesResolver2,
22783
+ columnsResolver2
21246
22784
  );
21247
22785
  };
21248
22786
  promptColumnsConflicts = async (tableName, newColumns, missingColumns) => {
@@ -21377,24 +22915,34 @@ var init_migrate = __esm({
21377
22915
  result.deleted.push(...leftMissing);
21378
22916
  return result;
21379
22917
  };
21380
- writeResult = (cur, sql, outFolder) => {
22918
+ writeResult = (cur, sql, idx, journal, _meta, outFolder) => {
21381
22919
  console.log(schema(cur));
21382
22920
  if (sql.length === 0) {
21383
22921
  console.log("No schema changes, nothing to migrate \u{1F634}");
21384
22922
  return;
21385
22923
  }
22924
+ const { prefix, tag } = prepareMigrationMetadata(idx);
21386
22925
  const toSave = JSON.parse(JSON.stringify(cur));
21387
- const folderName = prepareSnapshotFolderName();
21388
- const migrationFolderPath = `./${outFolder}/${folderName}`;
21389
- import_fs4.default.mkdirSync(migrationFolderPath);
22926
+ toSave["_meta"] = _meta;
22927
+ const metaFolderPath = (0, import_path3.join)(outFolder, "meta");
22928
+ const metaJournal = (0, import_path3.join)(metaFolderPath, "_journal.json");
21390
22929
  import_fs4.default.writeFileSync(
21391
- `${migrationFolderPath}/snapshot.json`,
22930
+ (0, import_path3.join)(metaFolderPath, `${prefix}_snapshot.json`),
21392
22931
  JSON.stringify(toSave, null, 2)
21393
22932
  );
21394
- import_fs4.default.writeFileSync(`${migrationFolderPath}/migration.sql`, sql);
21395
- console.log(
21396
- source_default.bold.green("Done:"),
21397
- import_path2.default.join(`${migrationFolderPath}/migration.sql`)
22933
+ journal.entries.push({
22934
+ idx,
22935
+ when: +new Date(),
22936
+ tag
22937
+ });
22938
+ import_fs4.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
22939
+ import_fs4.default.writeFileSync(`${outFolder}/${tag}.sql`, sql);
22940
+ (0, import_hanji2.render)(
22941
+ `[${source_default.green(
22942
+ "\u2713"
22943
+ )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(
22944
+ import_path3.default.join(`${outFolder}/${tag}.sql`)
22945
+ )} \u{1F680}`
21398
22946
  );
21399
22947
  };
21400
22948
  prepareSnapshotFolderName = () => {
@@ -21431,6 +22979,9 @@ var init_utils2 = __esm({
21431
22979
  return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
21432
22980
  });
21433
22981
  };
22982
+ Array.prototype.random = function() {
22983
+ return this[~~(Math.random() * this.length)];
22984
+ };
21434
22985
  }
21435
22986
  });
21436
22987
 
@@ -22380,9 +23931,9 @@ var require_pg_types = __commonJS({
22380
23931
  }
22381
23932
  });
22382
23933
 
22383
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js
23934
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/defaults.js
22384
23935
  var require_defaults = __commonJS({
22385
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/defaults.js"(exports, module2) {
23936
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/defaults.js"(exports, module2) {
22386
23937
  "use strict";
22387
23938
  module2.exports = {
22388
23939
  host: "localhost",
@@ -22419,9 +23970,9 @@ var require_defaults = __commonJS({
22419
23970
  }
22420
23971
  });
22421
23972
 
22422
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js
23973
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/utils.js
22423
23974
  var require_utils2 = __commonJS({
22424
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/utils.js"(exports, module2) {
23975
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/utils.js"(exports, module2) {
22425
23976
  "use strict";
22426
23977
  var crypto = require("crypto");
22427
23978
  var defaults = require_defaults();
@@ -22557,9 +24108,9 @@ var require_utils2 = __commonJS({
22557
24108
  }
22558
24109
  });
22559
24110
 
22560
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js
24111
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/sasl.js
22561
24112
  var require_sasl = __commonJS({
22562
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/sasl.js"(exports, module2) {
24113
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/sasl.js"(exports, module2) {
22563
24114
  "use strict";
22564
24115
  var crypto = require("crypto");
22565
24116
  function startSession(mechanisms) {
@@ -22581,6 +24132,9 @@ var require_sasl = __commonJS({
22581
24132
  if (typeof password !== "string") {
22582
24133
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string");
22583
24134
  }
24135
+ if (password === "") {
24136
+ throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a non-empty string");
24137
+ }
22584
24138
  if (typeof serverData !== "string") {
22585
24139
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: serverData must be a string");
22586
24140
  }
@@ -22591,7 +24145,7 @@ var require_sasl = __commonJS({
22591
24145
  throw new Error("SASL: SCRAM-SERVER-FIRST-MESSAGE: server nonce is too short");
22592
24146
  }
22593
24147
  var saltBytes = Buffer.from(sv.salt, "base64");
22594
- var saltedPassword = Hi(password, saltBytes, sv.iteration);
24148
+ var saltedPassword = crypto.pbkdf2Sync(password, saltBytes, sv.iteration, 32, "sha256");
22595
24149
  var clientKey = hmacSha256(saltedPassword, "Client Key");
22596
24150
  var storedKey = sha256(clientKey);
22597
24151
  var clientFirstMessageBare = "n=*,r=" + session.clientNonce;
@@ -22703,15 +24257,6 @@ var require_sasl = __commonJS({
22703
24257
  function hmacSha256(key, msg) {
22704
24258
  return crypto.createHmac("sha256", key).update(msg).digest();
22705
24259
  }
22706
- function Hi(password, saltBytes, iterations) {
22707
- var ui1 = hmacSha256(password, Buffer.concat([saltBytes, Buffer.from([0, 0, 0, 1])]));
22708
- var ui = ui1;
22709
- for (var i = 0; i < iterations - 1; i++) {
22710
- ui1 = hmacSha256(password, ui1);
22711
- ui = xorBuffers(ui, ui1);
22712
- }
22713
- return ui;
22714
- }
22715
24260
  module2.exports = {
22716
24261
  startSession,
22717
24262
  continueSession,
@@ -22826,7 +24371,7 @@ var require_split2 = __commonJS({
22826
24371
  var require_helper = __commonJS({
22827
24372
  "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/helper.js"(exports, module2) {
22828
24373
  "use strict";
22829
- var path5 = require("path");
24374
+ var path4 = require("path");
22830
24375
  var Stream = require("stream").Stream;
22831
24376
  var split = require_split2();
22832
24377
  var util2 = require("util");
@@ -22865,7 +24410,7 @@ var require_helper = __commonJS({
22865
24410
  };
22866
24411
  module2.exports.getFileName = function(rawEnv) {
22867
24412
  var env2 = rawEnv || process.env;
22868
- var file = env2.PGPASSFILE || (isWin ? path5.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path5.join(env2.HOME || "./", ".pgpass"));
24413
+ var file = env2.PGPASSFILE || (isWin ? path4.join(env2.APPDATA || "./", "postgresql", "pgpass.conf") : path4.join(env2.HOME || "./", ".pgpass"));
22869
24414
  return file;
22870
24415
  };
22871
24416
  module2.exports.usePgPass = function(stats, fname) {
@@ -22992,7 +24537,7 @@ var require_helper = __commonJS({
22992
24537
  var require_lib2 = __commonJS({
22993
24538
  "node_modules/.pnpm/pgpass@1.0.5/node_modules/pgpass/lib/index.js"(exports, module2) {
22994
24539
  "use strict";
22995
- var path5 = require("path");
24540
+ var path4 = require("path");
22996
24541
  var fs7 = require("fs");
22997
24542
  var helper = require_helper();
22998
24543
  module2.exports = function(connInfo, cb) {
@@ -23009,9 +24554,9 @@ var require_lib2 = __commonJS({
23009
24554
  }
23010
24555
  });
23011
24556
 
23012
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js
24557
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/type-overrides.js
23013
24558
  var require_type_overrides = __commonJS({
23014
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/type-overrides.js"(exports, module2) {
24559
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/type-overrides.js"(exports, module2) {
23015
24560
  "use strict";
23016
24561
  var types = require_pg_types();
23017
24562
  function TypeOverrides(userTypes) {
@@ -23129,9 +24674,9 @@ var require_pg_connection_string = __commonJS({
23129
24674
  }
23130
24675
  });
23131
24676
 
23132
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js
24677
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection-parameters.js
23133
24678
  var require_connection_parameters = __commonJS({
23134
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
24679
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection-parameters.js"(exports, module2) {
23135
24680
  "use strict";
23136
24681
  var dns = require("dns");
23137
24682
  var defaults = require_defaults();
@@ -23268,9 +24813,9 @@ var require_connection_parameters = __commonJS({
23268
24813
  }
23269
24814
  });
23270
24815
 
23271
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js
24816
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/result.js
23272
24817
  var require_result = __commonJS({
23273
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/result.js"(exports, module2) {
24818
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/result.js"(exports, module2) {
23274
24819
  "use strict";
23275
24820
  var types = require_pg_types();
23276
24821
  var matchRegexp = /^([A-Za-z]+)(?: (\d+))?(?: (\d+))?/;
@@ -23353,9 +24898,9 @@ var require_result = __commonJS({
23353
24898
  }
23354
24899
  });
23355
24900
 
23356
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js
24901
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/query.js
23357
24902
  var require_query = __commonJS({
23358
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/query.js"(exports, module2) {
24903
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/query.js"(exports, module2) {
23359
24904
  "use strict";
23360
24905
  var { EventEmitter } = require("events");
23361
24906
  var Result = require_result();
@@ -23536,9 +25081,9 @@ var require_query = __commonJS({
23536
25081
  }
23537
25082
  });
23538
25083
 
23539
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/messages.js
25084
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/messages.js
23540
25085
  var require_messages = __commonJS({
23541
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/messages.js"(exports) {
25086
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/messages.js"(exports) {
23542
25087
  "use strict";
23543
25088
  Object.defineProperty(exports, "__esModule", { value: true });
23544
25089
  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;
@@ -23701,9 +25246,9 @@ var require_messages = __commonJS({
23701
25246
  }
23702
25247
  });
23703
25248
 
23704
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-writer.js
25249
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-writer.js
23705
25250
  var require_buffer_writer = __commonJS({
23706
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-writer.js"(exports) {
25251
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-writer.js"(exports) {
23707
25252
  "use strict";
23708
25253
  Object.defineProperty(exports, "__esModule", { value: true });
23709
25254
  exports.Writer = void 0;
@@ -23782,9 +25327,9 @@ var require_buffer_writer = __commonJS({
23782
25327
  }
23783
25328
  });
23784
25329
 
23785
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/serializer.js
25330
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/serializer.js
23786
25331
  var require_serializer = __commonJS({
23787
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/serializer.js"(exports) {
25332
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/serializer.js"(exports) {
23788
25333
  "use strict";
23789
25334
  Object.defineProperty(exports, "__esModule", { value: true });
23790
25335
  exports.serialize = void 0;
@@ -23947,9 +25492,9 @@ var require_serializer = __commonJS({
23947
25492
  }
23948
25493
  });
23949
25494
 
23950
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-reader.js
25495
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-reader.js
23951
25496
  var require_buffer_reader = __commonJS({
23952
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/buffer-reader.js"(exports) {
25497
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/buffer-reader.js"(exports) {
23953
25498
  "use strict";
23954
25499
  Object.defineProperty(exports, "__esModule", { value: true });
23955
25500
  exports.BufferReader = void 0;
@@ -24002,9 +25547,9 @@ var require_buffer_reader = __commonJS({
24002
25547
  }
24003
25548
  });
24004
25549
 
24005
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js
25550
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/parser.js
24006
25551
  var require_parser = __commonJS({
24007
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/parser.js"(exports) {
25552
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/parser.js"(exports) {
24008
25553
  "use strict";
24009
25554
  var __importDefault = exports && exports.__importDefault || function(mod) {
24010
25555
  return mod && mod.__esModule ? mod : { "default": mod };
@@ -24297,9 +25842,9 @@ var require_parser = __commonJS({
24297
25842
  }
24298
25843
  });
24299
25844
 
24300
- // node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/index.js
25845
+ // node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/index.js
24301
25846
  var require_dist = __commonJS({
24302
- "node_modules/.pnpm/pg-protocol@1.5.0/node_modules/pg-protocol/dist/index.js"(exports) {
25847
+ "node_modules/.pnpm/pg-protocol@1.6.0/node_modules/pg-protocol/dist/index.js"(exports) {
24303
25848
  "use strict";
24304
25849
  Object.defineProperty(exports, "__esModule", { value: true });
24305
25850
  exports.DatabaseError = exports.serialize = exports.parse = void 0;
@@ -24321,9 +25866,9 @@ var require_dist = __commonJS({
24321
25866
  }
24322
25867
  });
24323
25868
 
24324
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js
25869
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection.js
24325
25870
  var require_connection = __commonJS({
24326
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/connection.js"(exports, module2) {
25871
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/connection.js"(exports, module2) {
24327
25872
  "use strict";
24328
25873
  var net = require("net");
24329
25874
  var EventEmitter = require("events").EventEmitter;
@@ -24336,6 +25881,9 @@ var require_connection = __commonJS({
24336
25881
  super();
24337
25882
  config = config || {};
24338
25883
  this.stream = config.stream || new net.Socket();
25884
+ if (typeof this.stream === "function") {
25885
+ this.stream = this.stream(config);
25886
+ }
24339
25887
  this._keepAlive = config.keepAlive;
24340
25888
  this._keepAliveInitialDelayMillis = config.keepAliveInitialDelayMillis;
24341
25889
  this.lastBuffer = false;
@@ -24464,7 +26012,6 @@ var require_connection = __commonJS({
24464
26012
  }
24465
26013
  sync() {
24466
26014
  this._ending = true;
24467
- this._send(flushBuffer);
24468
26015
  this._send(syncBuffer);
24469
26016
  }
24470
26017
  ref() {
@@ -24503,12 +26050,11 @@ var require_connection = __commonJS({
24503
26050
  }
24504
26051
  });
24505
26052
 
24506
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js
26053
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/client.js
24507
26054
  var require_client = __commonJS({
24508
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/client.js"(exports, module2) {
26055
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/client.js"(exports, module2) {
24509
26056
  "use strict";
24510
26057
  var EventEmitter = require("events").EventEmitter;
24511
- var util2 = require("util");
24512
26058
  var utils = require_utils2();
24513
26059
  var sasl = require_sasl();
24514
26060
  var pgPass = require_lib2();
@@ -24704,17 +26250,29 @@ var require_client = __commonJS({
24704
26250
  }
24705
26251
  _handleAuthSASL(msg) {
24706
26252
  this._checkPgPass(() => {
24707
- this.saslSession = sasl.startSession(msg.mechanisms);
24708
- this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
26253
+ try {
26254
+ this.saslSession = sasl.startSession(msg.mechanisms);
26255
+ this.connection.sendSASLInitialResponseMessage(this.saslSession.mechanism, this.saslSession.response);
26256
+ } catch (err2) {
26257
+ this.connection.emit("error", err2);
26258
+ }
24709
26259
  });
24710
26260
  }
24711
26261
  _handleAuthSASLContinue(msg) {
24712
- sasl.continueSession(this.saslSession, this.password, msg.data);
24713
- this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
26262
+ try {
26263
+ sasl.continueSession(this.saslSession, this.password, msg.data);
26264
+ this.connection.sendSCRAMClientFinalMessage(this.saslSession.response);
26265
+ } catch (err2) {
26266
+ this.connection.emit("error", err2);
26267
+ }
24714
26268
  }
24715
26269
  _handleAuthSASLFinal(msg) {
24716
- sasl.finalizeSession(this.saslSession, msg.data);
24717
- this.saslSession = null;
26270
+ try {
26271
+ sasl.finalizeSession(this.saslSession, msg.data);
26272
+ this.saslSession = null;
26273
+ } catch (err2) {
26274
+ this.connection.emit("error", err2);
26275
+ }
24718
26276
  }
24719
26277
  _handleBackendKeyData(msg) {
24720
26278
  this.processID = msg.processID;
@@ -24993,9 +26551,9 @@ var require_client = __commonJS({
24993
26551
  }
24994
26552
  });
24995
26553
 
24996
- // node_modules/.pnpm/pg-pool@3.5.2_pg@8.8.0/node_modules/pg-pool/index.js
26554
+ // node_modules/.pnpm/pg-pool@3.5.2_pg@8.9.0/node_modules/pg-pool/index.js
24997
26555
  var require_pg_pool = __commonJS({
24998
- "node_modules/.pnpm/pg-pool@3.5.2_pg@8.8.0/node_modules/pg-pool/index.js"(exports, module2) {
26556
+ "node_modules/.pnpm/pg-pool@3.5.2_pg@8.9.0/node_modules/pg-pool/index.js"(exports, module2) {
24999
26557
  "use strict";
25000
26558
  var EventEmitter = require("events").EventEmitter;
25001
26559
  var NOOP = function() {
@@ -25368,72 +26926,9 @@ var require_pg_pool = __commonJS({
25368
26926
  }
25369
26927
  });
25370
26928
 
25371
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json
25372
- var require_package = __commonJS({
25373
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/package.json"(exports, module2) {
25374
- module2.exports = {
25375
- name: "pg",
25376
- version: "8.8.0",
25377
- description: "PostgreSQL client - pure javascript & libpq with the same API",
25378
- keywords: [
25379
- "database",
25380
- "libpq",
25381
- "pg",
25382
- "postgre",
25383
- "postgres",
25384
- "postgresql",
25385
- "rdbms"
25386
- ],
25387
- homepage: "https://github.com/brianc/node-postgres",
25388
- repository: {
25389
- type: "git",
25390
- url: "git://github.com/brianc/node-postgres.git",
25391
- directory: "packages/pg"
25392
- },
25393
- author: "Brian Carlson <brian.m.carlson@gmail.com>",
25394
- main: "./lib",
25395
- dependencies: {
25396
- "buffer-writer": "2.0.0",
25397
- "packet-reader": "1.0.0",
25398
- "pg-connection-string": "^2.5.0",
25399
- "pg-pool": "^3.5.2",
25400
- "pg-protocol": "^1.5.0",
25401
- "pg-types": "^2.1.0",
25402
- pgpass: "1.x"
25403
- },
25404
- devDependencies: {
25405
- async: "2.6.4",
25406
- bluebird: "3.5.2",
25407
- co: "4.6.0",
25408
- "pg-copy-streams": "0.3.0"
25409
- },
25410
- peerDependencies: {
25411
- "pg-native": ">=3.0.1"
25412
- },
25413
- peerDependenciesMeta: {
25414
- "pg-native": {
25415
- optional: true
25416
- }
25417
- },
25418
- scripts: {
25419
- test: "make test-all"
25420
- },
25421
- files: [
25422
- "lib",
25423
- "SPONSORS.md"
25424
- ],
25425
- license: "MIT",
25426
- engines: {
25427
- node: ">= 8.0.0"
25428
- },
25429
- gitHead: "c99fb2c127ddf8d712500db2c7b9a5491a178655"
25430
- };
25431
- }
25432
- });
25433
-
25434
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js
26929
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/query.js
25435
26930
  var require_query2 = __commonJS({
25436
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/query.js"(exports, module2) {
26931
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/query.js"(exports, module2) {
25437
26932
  "use strict";
25438
26933
  var EventEmitter = require("events").EventEmitter;
25439
26934
  var util2 = require("util");
@@ -25572,13 +27067,12 @@ var require_query2 = __commonJS({
25572
27067
  }
25573
27068
  });
25574
27069
 
25575
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js
27070
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/client.js
25576
27071
  var require_client2 = __commonJS({
25577
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/client.js"(exports, module2) {
27072
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/client.js"(exports, module2) {
25578
27073
  "use strict";
25579
27074
  var Native = require("pg-native");
25580
27075
  var TypeOverrides = require_type_overrides();
25581
- var pkg = require_package();
25582
27076
  var EventEmitter = require("events").EventEmitter;
25583
27077
  var util2 = require("util");
25584
27078
  var ConnectionParameters = require_connection_parameters();
@@ -25805,17 +27299,17 @@ var require_client2 = __commonJS({
25805
27299
  }
25806
27300
  });
25807
27301
 
25808
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js
27302
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/index.js
25809
27303
  var require_native = __commonJS({
25810
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/native/index.js"(exports, module2) {
27304
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/native/index.js"(exports, module2) {
25811
27305
  "use strict";
25812
27306
  module2.exports = require_client2();
25813
27307
  }
25814
27308
  });
25815
27309
 
25816
- // node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js
27310
+ // node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/index.js
25817
27311
  var require_lib3 = __commonJS({
25818
- "node_modules/.pnpm/pg@8.8.0/node_modules/pg/lib/index.js"(exports, module2) {
27312
+ "node_modules/.pnpm/pg@8.9.0/node_modules/pg/lib/index.js"(exports, module2) {
25819
27313
  "use strict";
25820
27314
  var Client = require_client();
25821
27315
  var defaults = require_defaults();
@@ -26293,14 +27787,14 @@ var {
26293
27787
  } = import_index.default;
26294
27788
 
26295
27789
  // src/cli/index.ts
26296
- var import_fs8 = __toESM(require("fs"));
27790
+ var import_fs9 = __toESM(require("fs"));
26297
27791
  init_lib();
26298
27792
 
26299
27793
  // src/cli/commands/check.ts
26300
27794
  init_utils();
26301
27795
  var checkHandler = (out, dialect6) => {
26302
- const migrationFolders = prepareOutFolders(out);
26303
- const report = validateWithReport(out, migrationFolders, dialect6);
27796
+ const { snapshots } = prepareOutFolder(out, dialect6);
27797
+ const report = validateWithReport(snapshots, dialect6);
26304
27798
  if (report.nonLatest.length > 0) {
26305
27799
  console.log(
26306
27800
  report.nonLatest.map((it) => {
@@ -26336,7 +27830,7 @@ var checkHandler = (out, dialect6) => {
26336
27830
  // src/cli/index.ts
26337
27831
  var import_hanji4 = __toESM(require_hanji());
26338
27832
  init_views();
26339
- var import_path6 = __toESM(require("path"));
27833
+ var import_path7 = __toESM(require("path"));
26340
27834
 
26341
27835
  // src/cli/utils.ts
26342
27836
  init_views();
@@ -26370,8 +27864,8 @@ var assertPgVersion = () => {
26370
27864
  };
26371
27865
  var pgVersions = () => {
26372
27866
  try {
26373
- const { apiVersion, npmVersion } = require("drizzle-orm/utils");
26374
- return { apiVersion, npmVersion };
27867
+ const { compatibilityVersion, npmVersion } = require("drizzle-orm/version");
27868
+ return { compatibilityVersion, npmVersion };
26375
27869
  } catch (e) {
26376
27870
  return {};
26377
27871
  }
@@ -26383,7 +27877,7 @@ init_source();
26383
27877
  // package.json
26384
27878
  var package_default = {
26385
27879
  name: "drizzle-kit",
26386
- version: "0.16.7",
27880
+ version: "0.16.9",
26387
27881
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
26388
27882
  author: "Alex Blokh <aleksandrblokh@gmail.com>",
26389
27883
  license: "MIT",
@@ -26406,7 +27900,8 @@ var package_default = {
26406
27900
  test: "ava test",
26407
27901
  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",
26408
27902
  pack: "build && package",
26409
- tsc: "tsc"
27903
+ tsc: "tsc -p tsconfig.build.json",
27904
+ pub: "cp package.json readme.md dist/ && cd dist && npm publish"
26410
27905
  },
26411
27906
  ava: {
26412
27907
  files: [
@@ -26436,7 +27931,7 @@ var package_default = {
26436
27931
  "@typescript-eslint/parser": "^5.46.1",
26437
27932
  ava: "^5.1.0",
26438
27933
  dockerode: "^3.3.4",
26439
- "drizzle-orm": "0.17.0-31c94dd",
27934
+ "drizzle-orm": "0.17.6",
26440
27935
  esbuild: "^0.15.7",
26441
27936
  "esbuild-register": "^3.3.3",
26442
27937
  eslint: "^8.29.0",
@@ -26461,32 +27956,28 @@ init_utils();
26461
27956
  init_source();
26462
27957
  var import_crypto2 = require("crypto");
26463
27958
  var import_fs5 = require("fs");
26464
- var import_path3 = __toESM(require("path"));
26465
27959
  init_global();
26466
27960
  init_pgSchema();
26467
27961
  init_utils();
26468
27962
  var upPgHandler = (out) => {
26469
- const migrationFolders = prepareOutFolders(out);
26470
- const report = validateWithReport(out, migrationFolders, "pg");
27963
+ };
27964
+ var upPgHandlerV4 = (out) => {
27965
+ const snapshots = snapshotsPriorV4(out);
27966
+ const report = validateWithReport(snapshots, "pg");
26471
27967
  let prevId = originUUID;
26472
27968
  report.nonLatest.map((it) => ({
26473
- folder: it,
27969
+ path: it,
26474
27970
  raw: report.rawMap[it]
26475
27971
  })).forEach((it) => {
26476
- const folder = it.folder;
26477
- const result = updateToLatest(it.raw, prevId);
27972
+ const path4 = it.path;
27973
+ const result = updateUpToV4(it.raw, prevId);
26478
27974
  prevId = result.id;
26479
- console.log(
26480
- `[${source_default.green("\u2713")}] ${import_path3.default.join(out, folder, "snapshot.json")}`
26481
- );
26482
- (0, import_fs5.writeFileSync)(
26483
- import_path3.default.join(out, folder, "snapshot.json"),
26484
- JSON.stringify(result, null, 2)
26485
- );
27975
+ console.log(`[${source_default.green("\u2713")}] ${path4}`);
27976
+ (0, import_fs5.writeFileSync)(path4, JSON.stringify(result, null, 2));
26486
27977
  });
26487
27978
  console.log("Everything's fine \u{1F436}\u{1F525}");
26488
27979
  };
26489
- var updateToLatest = (json, prevId) => {
27980
+ var updateUpToV4 = (json, prevId) => {
26490
27981
  const version = Number(json["version"]);
26491
27982
  if (version === 1) {
26492
27983
  const v1 = pgSchemaV1.parse(json);
@@ -26504,7 +27995,7 @@ var updateToLatest = (json, prevId) => {
26504
27995
  if (version === 3) {
26505
27996
  return update3to4(pgSchemaV3.parse(json));
26506
27997
  }
26507
- return pgSchema.parse(json);
27998
+ return pgSchemaV4.parse(json);
26508
27999
  };
26509
28000
  var update1to2 = (json) => {
26510
28001
  const tables = Object.fromEntries(
@@ -26654,14 +28145,14 @@ var import_path4 = __toESM(require("path"));
26654
28145
  init_sqliteSchema();
26655
28146
  init_utils();
26656
28147
  var upSqliteHandler = (out) => {
26657
- const migrationFolders = prepareOutFolders(out);
26658
- const report = validateWithReport(out, migrationFolders, "sqlite");
28148
+ const { snapshots } = prepareOutFolder(out, "sqlite");
28149
+ const report = validateWithReport(snapshots, "sqlite");
26659
28150
  report.nonLatest.map((it) => ({
26660
28151
  folder: it,
26661
28152
  raw: report.rawMap[it]
26662
28153
  })).forEach((it) => {
26663
28154
  const folder = it.folder;
26664
- const result = updateToLatest2(it.raw);
28155
+ const result = updateToLatest(it.raw);
26665
28156
  console.log(
26666
28157
  `[${source_default.green("\u2713")}] ${import_path4.default.join(out, folder, "snapshot.json")}`
26667
28158
  );
@@ -26672,7 +28163,7 @@ var upSqliteHandler = (out) => {
26672
28163
  });
26673
28164
  console.log("Everything's fine \u{1F436}\u{1F525}");
26674
28165
  };
26675
- var updateToLatest2 = (json) => {
28166
+ var updateToLatest = (json) => {
26676
28167
  const version = Number(json["version"]);
26677
28168
  if (version === 3) {
26678
28169
  const v3 = sqliteSchemaV3.parse(json);
@@ -26702,14 +28193,14 @@ var import_path5 = __toESM(require("path"));
26702
28193
  init_mysqlSchema();
26703
28194
  init_utils();
26704
28195
  var upMysqlHandler = (out) => {
26705
- const migrationFolders = prepareOutFolders(out);
26706
- const report = validateWithReport(out, migrationFolders, "mysql");
28196
+ const { snapshots } = prepareOutFolder(out, "mysql");
28197
+ const report = validateWithReport(snapshots, "mysql");
26707
28198
  report.nonLatest.map((it) => ({
26708
28199
  folder: it,
26709
28200
  raw: report.rawMap[it]
26710
28201
  })).forEach((it) => {
26711
28202
  const folder = it.folder;
26712
- const result = updateToLatest3(it.raw);
28203
+ const result = updateToLatest2(it.raw);
26713
28204
  console.log(
26714
28205
  `[${source_default.green("\u2713")}] ${import_path5.default.join(out, folder, "snapshot.json")}`
26715
28206
  );
@@ -26720,7 +28211,7 @@ var upMysqlHandler = (out) => {
26720
28211
  });
26721
28212
  console.log("Everything's fine \u{1F436}\u{1F525}");
26722
28213
  };
26723
- var updateToLatest3 = (json) => {
28214
+ var updateToLatest2 = (json) => {
26724
28215
  const version = Number(json["version"]);
26725
28216
  if (version === 3) {
26726
28217
  const v3 = mysqlSchemaV3.parse(json);
@@ -26737,6 +28228,273 @@ var updateV3toV42 = (old) => {
26737
28228
  };
26738
28229
  };
26739
28230
 
28231
+ // src/cli/commands/upFolders.ts
28232
+ var import_fs8 = require("fs");
28233
+ var import_path6 = require("path");
28234
+ init_jsonDiffer();
28235
+ init_snapshotsDiffer();
28236
+ init_utils();
28237
+ init_words();
28238
+ init_pgSchema();
28239
+ var schemasResolver = (missingSchemas, newSchemas, sql) => {
28240
+ try {
28241
+ if (missingSchemas.length === 0 || newSchemas.length === 0) {
28242
+ return { created: newSchemas, renamed: [], deleted: missingSchemas };
28243
+ }
28244
+ const result = { created: [], renamed: [], deleted: [] };
28245
+ let index4 = 0;
28246
+ let leftMissing = [...missingSchemas];
28247
+ do {
28248
+ const created = newSchemas[index4];
28249
+ index4 += 1;
28250
+ const possibleRenames = leftMissing.map((it) => {
28251
+ return {
28252
+ value: it,
28253
+ sql: `ALTER SCHEMA "${it.name}" RENAME TO "${created.name}"`
28254
+ };
28255
+ });
28256
+ const renames = possibleRenames.filter((it) => {
28257
+ return sql.includes(it.sql);
28258
+ });
28259
+ if (renames.length > 1)
28260
+ throw new Error("wtf");
28261
+ if (renames.length === 0) {
28262
+ result.created.push(created);
28263
+ } else {
28264
+ const it = renames[0];
28265
+ result.renamed.push({ from: it.value, to: created });
28266
+ delete leftMissing[leftMissing.indexOf(it.value)];
28267
+ leftMissing = leftMissing.filter(Boolean);
28268
+ }
28269
+ } while (index4 < newSchemas.length);
28270
+ result.deleted.push(...leftMissing);
28271
+ return result;
28272
+ } catch (e) {
28273
+ console.error(e);
28274
+ throw e;
28275
+ }
28276
+ };
28277
+ var tablesResolver = (missingTables, newTables, sql) => {
28278
+ try {
28279
+ if (missingTables.length === 0 || newTables.length === 0) {
28280
+ return { created: newTables, renamed: [], deleted: missingTables };
28281
+ }
28282
+ const result = { created: [], renamed: [], deleted: [] };
28283
+ let index4 = 0;
28284
+ let leftMissing = [...missingTables];
28285
+ do {
28286
+ const created = newTables[index4];
28287
+ index4 += 1;
28288
+ const possibleRenames = leftMissing.map((it) => {
28289
+ const schemaPrefix = created.schema ? `"${created.schema}".` : "";
28290
+ return {
28291
+ value: it,
28292
+ sql: `ALTER TABLE ${schemaPrefix}"${it.name}" RENAME TO ${schemaPrefix}"${created.name}"`
28293
+ };
28294
+ });
28295
+ const renames = possibleRenames.filter((it) => {
28296
+ return sql.includes(it.sql);
28297
+ });
28298
+ if (renames.length > 1)
28299
+ throw new Error("wtf");
28300
+ if (renames.length === 0) {
28301
+ result.created.push(created);
28302
+ } else {
28303
+ const it = renames[0];
28304
+ result.renamed.push({ from: it.value, to: created });
28305
+ delete leftMissing[leftMissing.indexOf(it.value)];
28306
+ leftMissing = leftMissing.filter(Boolean);
28307
+ }
28308
+ } while (index4 < newTables.length);
28309
+ result.deleted.push(...leftMissing);
28310
+ return result;
28311
+ } catch (e) {
28312
+ console.error(e);
28313
+ throw e;
28314
+ }
28315
+ };
28316
+ var columnsResolver = (tableName, missingColumns, newColumns, sql) => {
28317
+ try {
28318
+ if (missingColumns.length === 0 || newColumns.length === 0) {
28319
+ return { created: newColumns, renamed: [], deleted: missingColumns };
28320
+ }
28321
+ const result = { created: [], renamed: [], deleted: [] };
28322
+ let index4 = 0;
28323
+ let leftMissing = [...missingColumns];
28324
+ do {
28325
+ const created = newColumns[index4];
28326
+ index4 += 1;
28327
+ const possibleRenames = leftMissing.map((it) => {
28328
+ return {
28329
+ value: it,
28330
+ sql: `ALTER TABLE ${tableName} RENAME COLUMN "${it.name}" TO "${created.name}"`
28331
+ };
28332
+ });
28333
+ const renames = possibleRenames.filter((it) => {
28334
+ return sql.includes(it.sql);
28335
+ });
28336
+ if (renames.length > 1)
28337
+ throw new Error("wtf");
28338
+ if (renames.length === 0) {
28339
+ result.created.push(created);
28340
+ } else {
28341
+ const it = renames[0];
28342
+ result.renamed.push({ from: it.value, to: created });
28343
+ delete leftMissing[leftMissing.indexOf(it.value)];
28344
+ leftMissing = leftMissing.filter(Boolean);
28345
+ }
28346
+ } while (index4 < newColumns.length);
28347
+ result.deleted.push(...leftMissing);
28348
+ return result;
28349
+ } catch (e) {
28350
+ console.error(e);
28351
+ throw e;
28352
+ }
28353
+ };
28354
+ var fullfill = (prev, cur, sql) => {
28355
+ const b = pgSchemaV4.parse(cur);
28356
+ if (!prev) {
28357
+ return {
28358
+ version: "5",
28359
+ dialect: b.dialect,
28360
+ id: b.id,
28361
+ prevId: b.prevId,
28362
+ tables: b.tables,
28363
+ enums: b.enums,
28364
+ schemas: b.schemas,
28365
+ _meta: {
28366
+ schemas: {},
28367
+ tables: {},
28368
+ columns: {}
28369
+ }
28370
+ };
28371
+ }
28372
+ const a = pgSchemaV4.parse(prev);
28373
+ const json1 = squashPgScheme(a);
28374
+ const json2 = squashPgScheme(b);
28375
+ const diffResult = applyJsonDiff(json1, json2);
28376
+ const parseResult = diffResultScheme.safeParse(diffResult);
28377
+ if (!parseResult.success) {
28378
+ parseResult.error.errors.forEach((it) => {
28379
+ console.error(it);
28380
+ });
28381
+ throw new Error();
28382
+ }
28383
+ const typedResult = parseResult.data;
28384
+ const { renamed: renamedSchemas } = schemasResolver(
28385
+ typedResult.deletedSchemas.map((it) => ({ name: it })),
28386
+ typedResult.addedSchemas.map((it) => ({ name: it })),
28387
+ sql
28388
+ );
28389
+ const { renamed } = tablesResolver(
28390
+ typedResult.deletedTables,
28391
+ typedResult.addedTables,
28392
+ sql
28393
+ );
28394
+ const renamedWithAlternations = Object.values(
28395
+ alteredTableScheme.array().parse(diffForRenamedTables(renamed))
28396
+ );
28397
+ const allAltered = typedResult.alteredTablesWithColumns.concat(
28398
+ renamedWithAlternations
28399
+ );
28400
+ const rSchemas = renamedSchemas.map((it) => ({ from: it.from.name, to: it.to.name }));
28401
+ const rTables = renamed.map((it) => {
28402
+ return { from: it.from, to: it.to };
28403
+ });
28404
+ const rColumns = allAltered.map((table4) => {
28405
+ const name = table4.name;
28406
+ const result = columnsResolver(name, table4.deleted, table4.added, sql);
28407
+ const tableName = table4.name;
28408
+ const schema4 = typeof table4.schema === "string" ? table4.schema : "";
28409
+ return result.renamed.map((it) => {
28410
+ return {
28411
+ from: { schema: schema4, table: tableName, column: it.from.name },
28412
+ to: { schema: schema4, table: tableName, column: it.to.name }
28413
+ };
28414
+ });
28415
+ }).flat();
28416
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
28417
+ const bpatched = {
28418
+ version: "5",
28419
+ dialect: b.dialect,
28420
+ id: b.id,
28421
+ prevId: b.prevId,
28422
+ tables: b.tables,
28423
+ enums: b.enums,
28424
+ schemas: b.schemas,
28425
+ _meta
28426
+ };
28427
+ pgSchema.parse(bpatched);
28428
+ return {
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
+ };
28439
+ var upgradeFolders = (dialect6, out) => {
28440
+ const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
28441
+ (it) => it.length === 14 && /^\d+$/.test(it)
28442
+ );
28443
+ oldMigrationFolders.sort();
28444
+ const res = oldMigrationFolders.reduce(
28445
+ (res2, it) => {
28446
+ const date = new Date();
28447
+ date.setUTCFullYear(Number(it.substring(0, 4)));
28448
+ date.setUTCMonth(Number(it.substring(4, 6)));
28449
+ date.setUTCDate(Number(it.substring(6, 8)));
28450
+ date.setUTCHours(Number(it.substring(8, 10)));
28451
+ date.setUTCMinutes(Number(it.substring(10, 12)));
28452
+ date.setUTCSeconds(Number(it.substring(12, 14)));
28453
+ const path4 = (0, import_path6.join)(out, it);
28454
+ const pathJson = (0, import_path6.join)(out, it, "snapshot.json");
28455
+ const pathSQL = (0, import_path6.join)(out, it, "migration.sql");
28456
+ const snapshot = JSON.parse((0, import_fs8.readFileSync)(pathJson).toString());
28457
+ const sql = (0, import_fs8.readFileSync)(pathSQL).toString();
28458
+ res2.entries.push({
28459
+ idx: res2.idx,
28460
+ json: snapshot,
28461
+ date,
28462
+ sql,
28463
+ path: path4
28464
+ });
28465
+ res2.idx += 1;
28466
+ return res2;
28467
+ },
28468
+ {
28469
+ entries: [],
28470
+ idx: 0
28471
+ }
28472
+ );
28473
+ const metaFolder = (0, import_path6.join)(`${out}`, "meta");
28474
+ if (!(0, import_fs8.existsSync)(metaFolder)) {
28475
+ (0, import_fs8.mkdirSync)(metaFolder, { recursive: true });
28476
+ }
28477
+ const journal = dryJournal(dialect6);
28478
+ let prev = void 0;
28479
+ res.entries.forEach((it) => {
28480
+ const { prefix, suffix, tag } = prepareMigrationMetadata(it.idx);
28481
+ journal.entries.push({
28482
+ idx: it.idx,
28483
+ when: +it.date,
28484
+ tag
28485
+ });
28486
+ const patchedJSON = fullfill(prev, it.json, it.sql);
28487
+ (0, import_fs8.writeFileSync)(
28488
+ (0, import_path6.join)(`${out}`, "meta", `${prefix}_snapshot.json`),
28489
+ JSON.stringify(patchedJSON)
28490
+ );
28491
+ (0, import_fs8.writeFileSync)((0, import_path6.join)(`${out}`, `${tag}.sql`), it.sql);
28492
+ (0, import_fs8.rmSync)(it.path, { recursive: true });
28493
+ prev = it.json;
28494
+ });
28495
+ (0, import_fs8.writeFileSync)((0, import_path6.join)(metaFolder, "_journal.json"), JSON.stringify(journal));
28496
+ };
28497
+
26740
28498
  // src/cli/index.ts
26741
28499
  var printVersions = () => {
26742
28500
  console.log(`${source_default.gray(versions())}
@@ -26745,13 +28503,13 @@ var printVersions = () => {
26745
28503
  var assertEitherConfigOrOut = (config, out) => {
26746
28504
  if (out)
26747
28505
  return out;
26748
- if (!(0, import_fs8.existsSync)(import_path6.default.join(import_path6.default.resolve(config)))) {
28506
+ if (!(0, import_fs9.existsSync)(import_path7.default.join(import_path7.default.resolve(config)))) {
26749
28507
  console.log(`${config} file does not exist`);
26750
28508
  process.exit(1);
26751
28509
  }
26752
28510
  console.log(`Reading ${config}`);
26753
28511
  const drizzleConfig = JSON.parse(
26754
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(config))).toString()
28512
+ import_fs9.default.readFileSync(import_path7.default.join(import_path7.default.resolve(config))).toString()
26755
28513
  );
26756
28514
  return drizzleConfig.out;
26757
28515
  };
@@ -26819,9 +28577,9 @@ var generateSqliteCommand = new Command("generate:sqlite").option("--schema <sch
26819
28577
  var prepareGenerateConfig = (options) => {
26820
28578
  const { schema: schema4, out, config } = options;
26821
28579
  if (!(schema4 || out)) {
26822
- const path5 = config != null ? config : "drizzle.config.json";
28580
+ const path4 = config != null ? config : "drizzle.config.json";
26823
28581
  const drizzleConfig = JSON.parse(
26824
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(path5))).toString()
28582
+ import_fs9.default.readFileSync(import_path7.default.join(import_path7.default.resolve(path4))).toString()
26825
28583
  );
26826
28584
  return drizzleConfig;
26827
28585
  }
@@ -26869,6 +28627,8 @@ var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).op
26869
28627
  process.exit(0);
26870
28628
  }
26871
28629
  assertPackages("drizzle-orm");
28630
+ upPgHandlerV4(out);
28631
+ upgradeFolders("pg", out);
26872
28632
  upPgHandler(out);
26873
28633
  });
26874
28634
  var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
@@ -26916,29 +28676,18 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
26916
28676
  console.log("Missing required params");
26917
28677
  return;
26918
28678
  }
26919
- const migrationFolders = prepareOutFolders(res.data.out);
26920
- const folderName = prepareSnapshotFolderName();
26921
- const migrationFolderPath = `./${res.data.out}/${folderName}`;
28679
+ const { snapshots, journal } = prepareOutFolder(res.data.out, "pg");
26922
28680
  const { schema: schema4, ts } = await pgIntrospect2(res.data);
26923
- const schemaFile = import_path6.default.join(res.data.out, "schema.ts");
26924
- (0, import_fs8.writeFileSync)(schemaFile, ts);
28681
+ const schemaFile = import_path7.default.join(res.data.out, "schema.ts");
28682
+ (0, import_fs9.writeFileSync)(schemaFile, ts);
26925
28683
  console.log();
26926
- if (migrationFolders.length === 0) {
26927
- import_fs8.default.mkdirSync(migrationFolderPath);
26928
- const snapshotFile = import_path6.default.join(migrationFolderPath, "snapshot.json");
26929
- (0, import_fs8.writeFileSync)(snapshotFile, JSON.stringify(schema4));
26930
- const sql = await prepareSQL(
28684
+ if (snapshots.length === 0) {
28685
+ const { sql, _meta } = await prepareSQL(
26931
28686
  squashPgScheme(dryPg),
26932
28687
  squashPgScheme(schema4),
26933
28688
  "pg"
26934
28689
  );
26935
- const sqlFile = import_path6.default.join(migrationFolderPath, "migration.sql");
26936
- (0, import_fs8.writeFileSync)(sqlFile, sql);
26937
- (0, import_hanji4.render)(
26938
- `[${source_default.green(
26939
- "\u2713"
26940
- )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(sqlFile)} \u{1F680}`
26941
- );
28690
+ writeResult(schema4, sql, 0, journal, _meta, res.data.out);
26942
28691
  } else {
26943
28692
  (0, import_hanji4.render)(
26944
28693
  `[${source_default.blue(