drizzle-kit 0.16.8 → 0.16.9

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 +2048 -255
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -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, 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,41 @@ 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);
6822
- }
6823
- const migrationFolders = (0, import_fs.readdirSync)(out).filter(
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(
6824
6876
  (it) => it.length === 14 && /^\d+$/.test(it)
6825
6877
  );
6826
- migrationFolders.sort();
6827
- return migrationFolders;
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);
6885
+ }
6886
+ };
6887
+ dryJournal = (dialect6) => {
6888
+ return {
6889
+ version: snapshotVersion,
6890
+ dialect: dialect6,
6891
+ entries: []
6892
+ };
6893
+ };
6894
+ prepareOutFolder = (out, dialect6) => {
6895
+ const meta = (0, import_path.join)(out, "meta");
6896
+ const journalPath = (0, import_path.join)(meta, "_journal.json");
6897
+ if (!(0, import_fs.existsSync)((0, import_path.join)(out, "meta"))) {
6898
+ (0, import_fs.mkdirSync)(meta, { recursive: true });
6899
+ (0, import_fs.writeFileSync)(journalPath, JSON.stringify(dryJournal(dialect6)));
6900
+ }
6901
+ const journal = JSON.parse((0, import_fs.readFileSync)(journalPath).toString());
6902
+ const snapshots = (0, import_fs.readdirSync)(meta).filter((it) => !it.startsWith("_")).map((it) => (0, import_path.join)(meta, it));
6903
+ snapshots.sort();
6904
+ return { meta, snapshots, journal };
6828
6905
  };
6829
6906
  mapValues = (obj, map) => {
6830
6907
  const result = Object.keys(obj).reduce(function(result2, key) {
@@ -6836,46 +6913,43 @@ var init_utils = __esm({
6836
6913
  validatorForDialect = (dialect6) => {
6837
6914
  switch (dialect6) {
6838
6915
  case "pg":
6839
- return { validator: backwardCompatiblePgSchema, version: 4 };
6916
+ return { validator: backwardCompatiblePgSchema, version: 5 };
6840
6917
  case "sqlite":
6841
6918
  return { validator: backwardCompatibleSqliteSchema, version: 4 };
6842
6919
  case "mysql":
6843
6920
  return { validator: backwardCompatibleMysqlSchema, version: 4 };
6844
6921
  }
6845
6922
  };
6846
- validateWithReport = (root, migrationFolders, dialect6) => {
6923
+ validateWithReport = (snapshots, dialect6) => {
6847
6924
  const { validator, version } = validatorForDialect(dialect6);
6848
- const result = migrationFolders.reduce(
6849
- (accum, folder) => {
6925
+ const result = snapshots.reduce(
6926
+ (accum, it) => {
6850
6927
  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;
6928
+ const raw = JSON.parse((0, import_fs.readFileSync)(`./${it}`).toString());
6929
+ accum.rawMap[it] = raw;
6856
6930
  if (raw["version"] && Number(raw["version"]) > version) {
6857
6931
  console.log(
6858
6932
  info(
6859
- `${folder}/snapshot.json is of unsupported version, please update drizzle-kit`
6933
+ `${it} snapshot is of unsupported version, please update drizzle-kit`
6860
6934
  )
6861
6935
  );
6862
6936
  process.exit(0);
6863
6937
  }
6864
6938
  const result2 = validator.safeParse(raw);
6865
6939
  if (!result2.success) {
6866
- accum.malformed.push(snapshotName);
6940
+ accum.malformed.push(it);
6867
6941
  return accum;
6868
6942
  }
6869
6943
  const snapshot = result2.data;
6870
6944
  if (snapshot.version !== String(version)) {
6871
- accum.nonLatest.push(folder);
6945
+ accum.nonLatest.push(it);
6872
6946
  return accum;
6873
6947
  }
6874
6948
  const idEntry = (_a = accum.idsMap[snapshot["prevId"]]) != null ? _a : {
6875
- parent: folder,
6949
+ parent: it,
6876
6950
  snapshots: []
6877
6951
  };
6878
- idEntry.snapshots.push(snapshotName);
6952
+ idEntry.snapshots.push(it);
6879
6953
  accum.idsMap[snapshot["prevId"]] = idEntry;
6880
6954
  return accum;
6881
6955
  },
@@ -6890,9 +6964,8 @@ var init_utils = __esm({
6890
6964
  return result;
6891
6965
  };
6892
6966
  prepareMigrationFolder = (outFolder = "drizzle", dialect6) => {
6893
- const root = outFolder;
6894
- const migrationFolders = prepareOutFolders(root);
6895
- const report = validateWithReport(root, migrationFolders, dialect6);
6967
+ const { snapshots, journal } = prepareOutFolder(outFolder, dialect6);
6968
+ const report = validateWithReport(snapshots, dialect6);
6896
6969
  if (report.nonLatest.length > 0) {
6897
6970
  console.log(
6898
6971
  report.nonLatest.map((it) => {
@@ -6923,7 +6996,41 @@ var init_utils = __esm({
6923
6996
  if (abort) {
6924
6997
  process.exit(0);
6925
6998
  }
6926
- return { migrationFolders };
6999
+ return { snapshots, journal };
7000
+ };
7001
+ prepareMigrationMeta = (schemas, tables, columns) => {
7002
+ const _meta = {
7003
+ schemas: {},
7004
+ tables: {},
7005
+ columns: {}
7006
+ };
7007
+ schemas.forEach((it) => {
7008
+ const from = schemaRenameKey(it.from);
7009
+ const to = schemaRenameKey(it.to);
7010
+ _meta.schemas[from] = to;
7011
+ });
7012
+ tables.forEach((it) => {
7013
+ const from = tableRenameKey(it.from);
7014
+ const to = tableRenameKey(it.to);
7015
+ _meta.tables[from] = to;
7016
+ });
7017
+ columns.forEach((it) => {
7018
+ const from = columnRenameKey(it.from.table, it.from.schema, it.from.column);
7019
+ const to = columnRenameKey(it.to.table, it.to.schema, it.to.column);
7020
+ _meta.columns[from] = to;
7021
+ });
7022
+ return _meta;
7023
+ };
7024
+ schemaRenameKey = (it) => {
7025
+ return it;
7026
+ };
7027
+ tableRenameKey = (it) => {
7028
+ const out = it.schema ? `"${it.schema}"."${it.name}"` : `"${it.name}"`;
7029
+ return out;
7030
+ };
7031
+ columnRenameKey = (table4, schema4, column5) => {
7032
+ const out = schema4 ? `"${schema4}"."${table4}"."${column5}"` : `"${table4}"."${column5}"`;
7033
+ return out;
6927
7034
  };
6928
7035
  }
6929
7036
  });
@@ -7878,7 +7985,7 @@ var require_node2 = __commonJS({
7878
7985
  return path5;
7879
7986
  }
7880
7987
  exports2.normalize = normalize;
7881
- function join2(aRoot, aPath) {
7988
+ function join22(aRoot, aPath) {
7882
7989
  if (aRoot === "") {
7883
7990
  aRoot = ".";
7884
7991
  }
@@ -7910,7 +8017,7 @@ var require_node2 = __commonJS({
7910
8017
  }
7911
8018
  return joined;
7912
8019
  }
7913
- exports2.join = join2;
8020
+ exports2.join = join22;
7914
8021
  exports2.isAbsolute = function(aPath) {
7915
8022
  return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
7916
8023
  };
@@ -8083,7 +8190,7 @@ var require_node2 = __commonJS({
8083
8190
  parsed.path = parsed.path.substring(0, index4 + 1);
8084
8191
  }
8085
8192
  }
8086
- sourceURL = join2(urlGenerate(parsed), sourceURL);
8193
+ sourceURL = join22(urlGenerate(parsed), sourceURL);
8087
8194
  }
8088
8195
  return normalize(sourceURL);
8089
8196
  }
@@ -9939,13 +10046,13 @@ var require_node2 = __commonJS({
9939
10046
  }
9940
10047
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
9941
10048
  try {
9942
- var info3 = gen[key](arg);
9943
- var value = info3.value;
10049
+ var info2 = gen[key](arg);
10050
+ var value = info2.value;
9944
10051
  } catch (error2) {
9945
10052
  reject(error2);
9946
10053
  return;
9947
10054
  }
9948
- if (info3.done) {
10055
+ if (info2.done) {
9949
10056
  resolve(value);
9950
10057
  } else {
9951
10058
  Promise.resolve(value).then(_next, _throw);
@@ -9973,7 +10080,7 @@ var require_node2 = __commonJS({
9973
10080
  resolve(data);
9974
10081
  });
9975
10082
  });
9976
- var readFileSync2 = (fp) => {
10083
+ var readFileSync3 = (fp) => {
9977
10084
  return _fs.default.readFileSync(fp, "utf8");
9978
10085
  };
9979
10086
  var pathExists = (fp) => new Promise((resolve) => {
@@ -10204,7 +10311,7 @@ var require_node2 = __commonJS({
10204
10311
  data: this.packageJsonCache.get(filepath)[options.packageKey]
10205
10312
  };
10206
10313
  }
10207
- const data = this.options.parseJSON(readFileSync2(filepath));
10314
+ const data = this.options.parseJSON(readFileSync3(filepath));
10208
10315
  return {
10209
10316
  path: filepath,
10210
10317
  data
@@ -10212,7 +10319,7 @@ var require_node2 = __commonJS({
10212
10319
  }
10213
10320
  return {
10214
10321
  path: filepath,
10215
- data: readFileSync2(filepath)
10322
+ data: readFileSync3(filepath)
10216
10323
  };
10217
10324
  }
10218
10325
  return {};
@@ -11819,34 +11926,34 @@ var require_node2 = __commonJS({
11819
11926
  var configAbsolutePath = walkForTsConfig(cwd);
11820
11927
  return configAbsolutePath ? path5.resolve(configAbsolutePath) : void 0;
11821
11928
  }
11822
- function walkForTsConfig(directory, existsSync3) {
11823
- if (existsSync3 === void 0) {
11824
- existsSync3 = fs32.existsSync;
11929
+ function walkForTsConfig(directory, existsSync4) {
11930
+ if (existsSync4 === void 0) {
11931
+ existsSync4 = fs32.existsSync;
11825
11932
  }
11826
11933
  var configPath = path5.join(directory, "./tsconfig.json");
11827
- if (existsSync3(configPath)) {
11934
+ if (existsSync4(configPath)) {
11828
11935
  return configPath;
11829
11936
  }
11830
11937
  var parentDirectory = path5.join(directory, "../");
11831
11938
  if (directory === parentDirectory) {
11832
11939
  return void 0;
11833
11940
  }
11834
- return walkForTsConfig(parentDirectory, existsSync3);
11941
+ return walkForTsConfig(parentDirectory, existsSync4);
11835
11942
  }
11836
11943
  exports2.walkForTsConfig = walkForTsConfig;
11837
- function loadTsconfig(configFilePath, existsSync3, readFileSync2) {
11838
- if (existsSync3 === void 0) {
11839
- existsSync3 = fs32.existsSync;
11944
+ function loadTsconfig(configFilePath, existsSync4, readFileSync3) {
11945
+ if (existsSync4 === void 0) {
11946
+ existsSync4 = fs32.existsSync;
11840
11947
  }
11841
- if (readFileSync2 === void 0) {
11842
- readFileSync2 = function(filename) {
11948
+ if (readFileSync3 === void 0) {
11949
+ readFileSync3 = function(filename) {
11843
11950
  return fs32.readFileSync(filename, "utf8");
11844
11951
  };
11845
11952
  }
11846
- if (!existsSync3(configFilePath)) {
11953
+ if (!existsSync4(configFilePath)) {
11847
11954
  return void 0;
11848
11955
  }
11849
- var configString = readFileSync2(configFilePath);
11956
+ var configString = readFileSync3(configFilePath);
11850
11957
  var cleanedJson = StripBom(configString);
11851
11958
  var config = JSON5.parse(cleanedJson);
11852
11959
  var extendedConfig = config.extends;
@@ -11856,10 +11963,10 @@ var require_node2 = __commonJS({
11856
11963
  }
11857
11964
  var currentDir = path5.dirname(configFilePath);
11858
11965
  var extendedConfigPath = path5.join(currentDir, extendedConfig);
11859
- if (extendedConfig.indexOf("/") !== -1 && extendedConfig.indexOf(".") !== -1 && !existsSync3(extendedConfigPath)) {
11966
+ if (extendedConfig.indexOf("/") !== -1 && extendedConfig.indexOf(".") !== -1 && !existsSync4(extendedConfigPath)) {
11860
11967
  extendedConfigPath = path5.join(currentDir, "node_modules", extendedConfig);
11861
11968
  }
11862
- var base = loadTsconfig(extendedConfigPath, existsSync3, readFileSync2) || {};
11969
+ var base = loadTsconfig(extendedConfigPath, existsSync4, readFileSync3) || {};
11863
11970
  if (base.compilerOptions && base.compilerOptions.baseUrl) {
11864
11971
  var extendsDir = path5.dirname(extendedConfig);
11865
11972
  base.compilerOptions.baseUrl = path5.join(extendsDir, base.compilerOptions.baseUrl);
@@ -12807,11 +12914,16 @@ var init_pgSerializer = __esm({
12807
12914
  schemas.map((it) => [it.schemaName, it.schemaName])
12808
12915
  );
12809
12916
  return {
12810
- version: "4",
12917
+ version: "5",
12811
12918
  dialect: "pg",
12812
12919
  tables: result,
12813
12920
  enums: enumsToReturn,
12814
- schemas: schemasObject
12921
+ schemas: schemasObject,
12922
+ _meta: {
12923
+ schemas: {},
12924
+ tables: {},
12925
+ columns: {}
12926
+ }
12815
12927
  };
12816
12928
  };
12817
12929
  fromDatabase = async (db, progressCallback) => {
@@ -13024,11 +13136,16 @@ var init_pgSerializer = __esm({
13024
13136
  progressCallback("enums", Object.keys(enumsToReturn).length, "done");
13025
13137
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
13026
13138
  return {
13027
- version: "4",
13139
+ version: "5",
13028
13140
  dialect: "pg",
13029
13141
  tables: result,
13030
13142
  enums: enumsToReturn,
13031
- schemas: schemasObject
13143
+ schemas: schemasObject,
13144
+ _meta: {
13145
+ schemas: {},
13146
+ tables: {},
13147
+ columns: {}
13148
+ }
13032
13149
  };
13033
13150
  };
13034
13151
  }
@@ -13172,12 +13289,12 @@ var init_sqliteSerializer = __esm({
13172
13289
  });
13173
13290
 
13174
13291
  // src/serializer/index.ts
13175
- var import_fs2, import_node, import_path, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13292
+ var import_fs2, import_node, import_path2, safeRegister, serializeMySql, serializePg, serializeSQLite, prepareFilenames;
13176
13293
  var init_serializer = __esm({
13177
13294
  "src/serializer/index.ts"() {
13178
13295
  import_fs2 = __toESM(require("fs"));
13179
13296
  import_node = __toESM(require_node2());
13180
- import_path = __toESM(require("path"));
13297
+ import_path2 = __toESM(require("path"));
13181
13298
  safeRegister = () => {
13182
13299
  try {
13183
13300
  const { unregister } = (0, import_node.register)({
@@ -13218,8 +13335,8 @@ var init_serializer = __esm({
13218
13335
  return generateSqliteSnapshot2(tables, enums);
13219
13336
  };
13220
13337
  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));
13338
+ const fileName = import_fs2.default.lstatSync(path5).isDirectory() ? null : import_path2.default.resolve(path5);
13339
+ const filenames = fileName ? [fileName] : import_fs2.default.readdirSync(path5).map((it) => import_path2.default.join(import_path2.default.resolve(path5), it));
13223
13340
  return filenames;
13224
13341
  };
13225
13342
  }
@@ -13235,9 +13352,9 @@ var init_migrationPreparator = __esm({
13235
13352
  init_pgSchema();
13236
13353
  init_sqliteSchema();
13237
13354
  init_mysqlSchema();
13238
- prepareMySqlMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13355
+ prepareMySqlMigrationSnapshot = (migrationFolders, schemaPath) => {
13239
13356
  const prevSnapshot = mysqlSchema.parse(
13240
- preparePrevSnapshot(outFolder, migrationFolders, dryMySql)
13357
+ preparePrevSnapshot(migrationFolders, dryMySql)
13241
13358
  );
13242
13359
  const serialized = serializeMySql(schemaPath);
13243
13360
  const id = (0, import_crypto.randomUUID)();
@@ -13246,9 +13363,9 @@ var init_migrationPreparator = __esm({
13246
13363
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13247
13364
  return { prev: prevSnapshot, cur: result };
13248
13365
  };
13249
- prepareSqliteMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13366
+ prepareSqliteMigrationSnapshot = (snapshots, schemaPath) => {
13250
13367
  const prevSnapshot = sqliteSchema.parse(
13251
- preparePrevSnapshot(outFolder, migrationFolders, drySQLite)
13368
+ preparePrevSnapshot(snapshots, drySQLite)
13252
13369
  );
13253
13370
  const serialized = serializeSQLite(schemaPath);
13254
13371
  const id = (0, import_crypto.randomUUID)();
@@ -13263,10 +13380,8 @@ var init_migrationPreparator = __esm({
13263
13380
  };
13264
13381
  return { prev: prevSnapshot, cur: result };
13265
13382
  };
13266
- preparePgMigrationSnapshot = (migrationFolders, outFolder = "drizzle", schemaPath) => {
13267
- const prevSnapshot = pgSchema.parse(
13268
- preparePrevSnapshot(outFolder, migrationFolders, dryPg)
13269
- );
13383
+ preparePgMigrationSnapshot = (snapshots, schemaPath) => {
13384
+ const prevSnapshot = pgSchema.parse(preparePrevSnapshot(snapshots, dryPg));
13270
13385
  const serialized = serializePg(schemaPath);
13271
13386
  const id = (0, import_crypto.randomUUID)();
13272
13387
  const idPrev = prevSnapshot.id;
@@ -13274,16 +13389,13 @@ var init_migrationPreparator = __esm({
13274
13389
  const result = { version, dialect: dialect6, id, prevId: idPrev, ...rest };
13275
13390
  return { prev: prevSnapshot, cur: result };
13276
13391
  };
13277
- preparePrevSnapshot = (outFolder, migrationFolders, defaultPrev) => {
13278
- const root = outFolder;
13392
+ preparePrevSnapshot = (snapshots, defaultPrev) => {
13279
13393
  let prevSnapshot;
13280
- if (migrationFolders.length === 0) {
13394
+ if (snapshots.length === 0) {
13281
13395
  prevSnapshot = defaultPrev;
13282
13396
  } else {
13283
- const lastSnapshotFolder = migrationFolders[migrationFolders.length - 1];
13284
- prevSnapshot = JSON.parse(
13285
- import_fs3.default.readFileSync(`${root}/${lastSnapshotFolder}/snapshot.json`).toString()
13286
- );
13397
+ const lastSnapshot = snapshots[snapshots.length - 1];
13398
+ prevSnapshot = JSON.parse(import_fs3.default.readFileSync(lastSnapshot).toString());
13287
13399
  }
13288
13400
  return prevSnapshot;
13289
13401
  };
@@ -13477,7 +13589,7 @@ var init_sqlgenerator = __esm({
13477
13589
  return statement.type === "rename_table" && dialect6 === "pg";
13478
13590
  }
13479
13591
  convert(statement) {
13480
- const { tableNameFrom, tableNameTo, fromSchema: schema4 } = statement;
13592
+ const { tableNameFrom, tableNameTo, toSchema: schema4 } = statement;
13481
13593
  const from = schema4 ? `"${schema4}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
13482
13594
  const to = schema4 ? `"${schema4}"."${tableNameTo}"` : `"${tableNameTo}"`;
13483
13595
  return `ALTER TABLE ${from} RENAME TO ${to};`;
@@ -18841,7 +18953,7 @@ var require_bare = __commonJS({
18841
18953
  var sgr = require_sgr();
18842
18954
  var supportsColor2 = require_supports_color2();
18843
18955
  var mods = sgr.mods;
18844
- var join = Array.prototype.join;
18956
+ var join4 = Array.prototype.join;
18845
18957
  var defineProperty = Object.defineProperty;
18846
18958
  var max = Math.max;
18847
18959
  var min = Math.min;
@@ -18895,7 +19007,7 @@ var require_bare = __commonJS({
18895
19007
  getFn = function() {
18896
19008
  return setPrototypeOf(
18897
19009
  function self2() {
18898
- var start = "", end = "", msg = join.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
19010
+ var start = "", end = "", msg = join4.call(arguments, " "), conf = self2._cliColorData, hasAnsi = sgr.hasCSI(msg);
18899
19011
  forEach(
18900
19012
  conf,
18901
19013
  function(mod, key) {
@@ -20326,7 +20438,7 @@ function diffForRenamedTable(t1, t2) {
20326
20438
  t1.name = t2.name;
20327
20439
  const diffed = (0, import_json_diff.diff)(t1, t2) || {};
20328
20440
  diffed.name = t2.name;
20329
- return findAlternationsInTable(diffed);
20441
+ return findAlternationsInTable(diffed, t2.schema);
20330
20442
  }
20331
20443
  function diffForRenamedColumn(t1, t2) {
20332
20444
  const renamed = { ...t1, name: t2.name };
@@ -20340,6 +20452,10 @@ function applyJsonDiff(json1, json2) {
20340
20452
  json2 = JSON.parse(JSON.stringify(json2));
20341
20453
  const rawDiff = (0, import_json_diff.diff)(json1, json2);
20342
20454
  const difference = rawDiff;
20455
+ const tableToSchema = Object.entries(json2.tables).reduce((res, it) => {
20456
+ res[it[0]] = it[1].schema;
20457
+ return res;
20458
+ }, {});
20343
20459
  if (!difference)
20344
20460
  return {};
20345
20461
  difference.tables = (_a = difference.tables) != null ? _a : {};
@@ -20369,7 +20485,7 @@ function applyJsonDiff(json1, json2) {
20369
20485
  const schemasEntries = Object.entries(difference.schemas);
20370
20486
  const addedSchemas = schemasEntries.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
20371
20487
  const deletedSchemas = schemasEntries.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
20372
- const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4));
20488
+ const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4, tableToSchema[table4.name]));
20373
20489
  return {
20374
20490
  addedTables,
20375
20491
  deletedTables,
@@ -20386,10 +20502,13 @@ var init_jsonDiffer = __esm({
20386
20502
  "src/jsonDiffer.js"() {
20387
20503
  import_json_diff = __toESM(require_lib());
20388
20504
  "use-strict";
20389
- findAlternationsInTable = (table4) => {
20505
+ findAlternationsInTable = (table4, tableSchema) => {
20390
20506
  var _a;
20391
20507
  const columns = (_a = table4.columns) != null ? _a : {};
20392
- let schema4;
20508
+ let schema4 = {
20509
+ type: "none",
20510
+ value: tableSchema
20511
+ };
20393
20512
  if ("schema" in table4) {
20394
20513
  if (table4.schema.__new) {
20395
20514
  schema4 = { type: "changed", old: table4.schema.__old, new: table4.schema.__new };
@@ -20526,7 +20645,8 @@ var init_jsonStatements = __esm({
20526
20645
  prepareDropTableJson = (table4) => {
20527
20646
  return {
20528
20647
  type: "drop_table",
20529
- tableName: table4.name
20648
+ tableName: table4.name,
20649
+ schema: table4.schema
20530
20650
  };
20531
20651
  };
20532
20652
  prepareRenameTableJson = (tableFrom, tableTo) => {
@@ -20579,20 +20699,21 @@ var init_jsonStatements = __esm({
20579
20699
  };
20580
20700
  });
20581
20701
  };
20582
- prepareRenameColumns = (tableName, pairs) => {
20702
+ prepareRenameColumns = (tableName, schema4, pairs) => {
20583
20703
  return pairs.map((it) => {
20584
20704
  return {
20585
20705
  type: "alter_table_rename_column",
20586
20706
  tableName,
20587
20707
  oldColumnName: it.from.name,
20588
- newColumnName: it.to.name
20708
+ newColumnName: it.to.name,
20709
+ schema: schema4
20589
20710
  };
20590
20711
  });
20591
20712
  };
20592
- prepareAlterTableColumnsJson = (tableName, deleted, added, altered, addedFk, dialect6) => {
20713
+ prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, dialect6) => {
20593
20714
  const addColumns = [];
20594
- const dropColumns = _prepareDropColumns(tableName, deleted);
20595
- const alterColumns = _prepareAlterColumns(tableName, altered);
20715
+ const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
20716
+ const alterColumns = _prepareAlterColumns(tableName, schema4, altered);
20596
20717
  if (dialect6 === "sqlite") {
20597
20718
  let jsonCreateFKStatements = Object.values(addedFk);
20598
20719
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -20602,25 +20723,27 @@ var init_jsonStatements = __esm({
20602
20723
  );
20603
20724
  addColumns.push(...sqliteAddColumns);
20604
20725
  } else {
20605
- addColumns.push(..._prepareAddColumns(tableName, added));
20726
+ addColumns.push(..._prepareAddColumns(tableName, schema4, added));
20606
20727
  }
20607
20728
  return { addColumns, dropColumns, alterColumns };
20608
20729
  };
20609
- _prepareDropColumns = (taleName, columns) => {
20730
+ _prepareDropColumns = (taleName, schema4, columns) => {
20610
20731
  return columns.map((it) => {
20611
20732
  return {
20612
20733
  type: "alter_table_drop_column",
20613
20734
  tableName: taleName,
20614
- columnName: it.name
20735
+ columnName: it.name,
20736
+ schema: schema4
20615
20737
  };
20616
20738
  });
20617
20739
  };
20618
- _prepareAddColumns = (tableName, columns) => {
20740
+ _prepareAddColumns = (tableName, schema4, columns) => {
20619
20741
  return columns.map((it) => {
20620
20742
  return {
20621
20743
  type: "alter_table_add_column",
20622
20744
  tableName,
20623
- column: it
20745
+ column: it,
20746
+ schema: schema4
20624
20747
  };
20625
20748
  });
20626
20749
  };
@@ -20640,7 +20763,7 @@ var init_jsonStatements = __esm({
20640
20763
  };
20641
20764
  });
20642
20765
  };
20643
- _prepareAlterColumns = (tableName, columns) => {
20766
+ _prepareAlterColumns = (tableName, schema4, columns) => {
20644
20767
  var _a, _b, _c, _d, _e, _f, _g;
20645
20768
  let statements = [];
20646
20769
  for (const column5 of columns) {
@@ -20650,7 +20773,8 @@ var init_jsonStatements = __esm({
20650
20773
  type: "alter_table_rename_column",
20651
20774
  tableName,
20652
20775
  oldColumnName: column5.name.old,
20653
- newColumnName: column5.name.new
20776
+ newColumnName: column5.name.new,
20777
+ schema: schema4
20654
20778
  });
20655
20779
  }
20656
20780
  if (((_a = column5.type) == null ? void 0 : _a.type) === "changed") {
@@ -20658,7 +20782,8 @@ var init_jsonStatements = __esm({
20658
20782
  type: "alter_table_alter_column_set_type",
20659
20783
  tableName,
20660
20784
  columnName,
20661
- newDataType: column5.type.new
20785
+ newDataType: column5.type.new,
20786
+ schema: schema4
20662
20787
  });
20663
20788
  }
20664
20789
  if (((_b = column5.default) == null ? void 0 : _b.type) === "added") {
@@ -20666,7 +20791,8 @@ var init_jsonStatements = __esm({
20666
20791
  type: "alter_table_alter_column_set_default",
20667
20792
  tableName,
20668
20793
  columnName,
20669
- newDefaultValue: column5.default.value
20794
+ newDefaultValue: column5.default.value,
20795
+ schema: schema4
20670
20796
  });
20671
20797
  }
20672
20798
  if (((_c = column5.default) == null ? void 0 : _c.type) === "changed") {
@@ -20674,21 +20800,24 @@ var init_jsonStatements = __esm({
20674
20800
  type: "alter_table_alter_column_set_default",
20675
20801
  tableName,
20676
20802
  columnName,
20677
- newDefaultValue: column5.default.new
20803
+ newDefaultValue: column5.default.new,
20804
+ schema: schema4
20678
20805
  });
20679
20806
  }
20680
20807
  if (((_d = column5.default) == null ? void 0 : _d.type) === "deleted") {
20681
20808
  statements.push({
20682
20809
  type: "alter_table_alter_column_drop_default",
20683
20810
  tableName,
20684
- columnName
20811
+ columnName,
20812
+ schema: schema4
20685
20813
  });
20686
20814
  }
20687
20815
  if (((_e = column5.notNull) == null ? void 0 : _e.type) === "added") {
20688
20816
  statements.push({
20689
20817
  type: "alter_table_alter_column_set_notnull",
20690
20818
  tableName,
20691
- columnName
20819
+ columnName,
20820
+ schema: schema4
20692
20821
  });
20693
20822
  }
20694
20823
  if (((_f = column5.notNull) == null ? void 0 : _f.type) === "changed") {
@@ -20696,62 +20825,69 @@ var init_jsonStatements = __esm({
20696
20825
  statements.push({
20697
20826
  type,
20698
20827
  tableName,
20699
- columnName
20828
+ columnName,
20829
+ schema: schema4
20700
20830
  });
20701
20831
  }
20702
20832
  if (((_g = column5.notNull) == null ? void 0 : _g.type) === "deleted") {
20703
20833
  statements.push({
20704
20834
  type: "alter_table_alter_column_drop_notnull",
20705
20835
  tableName,
20706
- columnName
20836
+ columnName,
20837
+ schema: schema4
20707
20838
  });
20708
20839
  }
20709
20840
  }
20710
20841
  return statements;
20711
20842
  };
20712
- prepareCreateIndexesJson = (tableName, indexes) => {
20843
+ prepareCreateIndexesJson = (tableName, schema4, indexes) => {
20713
20844
  return Object.values(indexes).map((indexData) => {
20714
20845
  return {
20715
20846
  type: "create_index",
20716
20847
  tableName,
20717
- data: indexData
20848
+ data: indexData,
20849
+ schema: schema4
20718
20850
  };
20719
20851
  });
20720
20852
  };
20721
- prepareCreateReferencesJson = (tableName, foreignKeys) => {
20853
+ prepareCreateReferencesJson = (tableName, schema4, foreignKeys) => {
20722
20854
  return Object.values(foreignKeys).map((fkData) => {
20723
20855
  return {
20724
20856
  type: "create_reference",
20725
20857
  tableName,
20726
- data: fkData
20858
+ data: fkData,
20859
+ schema: schema4
20727
20860
  };
20728
20861
  });
20729
20862
  };
20730
- prepareDropReferencesJson = (tableName, foreignKeys) => {
20863
+ prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
20731
20864
  return Object.values(foreignKeys).map((fkData) => {
20732
20865
  return {
20733
20866
  type: "delete_reference",
20734
20867
  tableName,
20735
- data: fkData
20868
+ data: fkData,
20869
+ schema: schema4
20736
20870
  };
20737
20871
  });
20738
20872
  };
20739
- prepareAlterReferencesJson = (tableName, foreignKeys) => {
20873
+ prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
20740
20874
  return Object.values(foreignKeys).map((fkData) => {
20741
20875
  return {
20742
20876
  type: "alter_reference",
20743
20877
  tableName,
20744
20878
  data: fkData.__new,
20745
- oldFkey: fkData.__old
20879
+ oldFkey: fkData.__old,
20880
+ schema: schema4
20746
20881
  };
20747
20882
  });
20748
20883
  };
20749
- prepareDropIndexesJson = (tableName, indexes) => {
20884
+ prepareDropIndexesJson = (tableName, schema4, indexes) => {
20750
20885
  return Object.values(indexes).map((indexData) => {
20751
20886
  return {
20752
20887
  type: "drop_index",
20753
20888
  tableName,
20754
- data: indexData
20889
+ data: indexData,
20890
+ schema: schema4
20755
20891
  };
20756
20892
  });
20757
20893
  };
@@ -20787,13 +20923,14 @@ var init_jsonStatements = __esm({
20787
20923
  });
20788
20924
 
20789
20925
  // src/snapshotsDiffer.ts
20790
- var makeChanged, makeSelfOrChanged, makePatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20926
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, valueFromSelfOrPatchedNew, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, applySnapshotsDiff;
20791
20927
  var init_snapshotsDiffer = __esm({
20792
20928
  "src/snapshotsDiffer.ts"() {
20793
20929
  init_sqlgenerator();
20794
20930
  init_lib();
20795
20931
  init_jsonDiffer();
20796
20932
  init_jsonStatements();
20933
+ init_utils();
20797
20934
  makeChanged = (schema4) => {
20798
20935
  return objectType({
20799
20936
  type: enumType(["changed"]),
@@ -20814,20 +20951,53 @@ var init_snapshotsDiffer = __esm({
20814
20951
  makePatched = (schema4) => {
20815
20952
  return unionType([
20816
20953
  objectType({
20817
- type: enumType(["added"]),
20954
+ type: literalType("added"),
20818
20955
  value: schema4
20819
20956
  }),
20820
20957
  objectType({
20821
- type: enumType(["deleted"]),
20958
+ type: literalType("deleted"),
20822
20959
  value: schema4
20823
20960
  }),
20824
20961
  objectType({
20825
- type: enumType(["changed"]),
20962
+ type: literalType("changed"),
20963
+ old: schema4,
20964
+ new: schema4
20965
+ })
20966
+ ]);
20967
+ };
20968
+ makeSelfOrPatched = (schema4) => {
20969
+ return unionType([
20970
+ objectType({
20971
+ type: literalType("none"),
20972
+ value: schema4
20973
+ }),
20974
+ objectType({
20975
+ type: literalType("added"),
20976
+ value: schema4
20977
+ }),
20978
+ objectType({
20979
+ type: literalType("deleted"),
20980
+ value: schema4
20981
+ }),
20982
+ objectType({
20983
+ type: literalType("changed"),
20826
20984
  old: schema4,
20827
20985
  new: schema4
20828
20986
  })
20829
20987
  ]);
20830
20988
  };
20989
+ valueFromSelfOrPatchedNew = (it) => {
20990
+ switch (it.type) {
20991
+ case "none":
20992
+ return it.value;
20993
+ case "added":
20994
+ return it.value;
20995
+ case "deleted":
20996
+ return it.value;
20997
+ case "changed":
20998
+ return it.new;
20999
+ }
21000
+ };
20831
21001
  columnSchema = objectType({
20832
21002
  name: stringType(),
20833
21003
  type: stringType(),
@@ -20840,7 +21010,7 @@ var init_snapshotsDiffer = __esm({
20840
21010
  alteredColumnSchema = objectType({
20841
21011
  name: makeSelfOrChanged(stringType()),
20842
21012
  type: makeChanged(stringType()).optional(),
20843
- default: makePatched(stringType()).optional(),
21013
+ default: makePatched(anyType()).optional(),
20844
21014
  notNull: makePatched(booleanType()).optional()
20845
21015
  }).strict();
20846
21016
  enumSchema2 = objectType({
@@ -20862,7 +21032,7 @@ var init_snapshotsDiffer = __esm({
20862
21032
  }).strict();
20863
21033
  alteredTableScheme = objectType({
20864
21034
  name: stringType(),
20865
- schema: makePatched(stringType()).optional(),
21035
+ schema: makeSelfOrPatched(stringType()),
20866
21036
  deleted: columnSchema.array(),
20867
21037
  added: columnSchema.array(),
20868
21038
  altered: alteredColumnSchema.array(),
@@ -20897,25 +21067,32 @@ var init_snapshotsDiffer = __esm({
20897
21067
  addedSchemas: stringType().array(),
20898
21068
  deletedSchemas: stringType().array()
20899
21069
  }).strict();
20900
- applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver) => {
21070
+ applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver2, tablesResolver2, columnsResolver2) => {
20901
21071
  var _a, _b, _c, _d;
20902
21072
  const diffResult = applyJsonDiff(json1, json2);
20903
21073
  if (Object.keys(diffResult).length === 0) {
20904
- return "";
21074
+ return { statements: [], sql: "" };
20905
21075
  }
20906
21076
  const typedResult = diffResultScheme.parse(diffResult);
20907
21077
  const {
20908
21078
  created: createdSchemas,
20909
21079
  deleted: deletedSchemas,
20910
21080
  renamed: renamedSchemas
20911
- } = await schemasResolver({
21081
+ } = await schemasResolver2({
20912
21082
  created: typedResult.addedSchemas.map((it) => ({ name: it })),
20913
21083
  deleted: typedResult.deletedSchemas.map((it) => ({ name: it }))
20914
21084
  });
20915
- const { created, deleted, renamed } = await tablesResolver({
21085
+ const { created, deleted, renamed } = await tablesResolver2({
20916
21086
  created: typedResult.addedTables,
20917
21087
  deleted: typedResult.deletedTables
20918
21088
  });
21089
+ const rSchemas = renamedSchemas.map((it) => ({
21090
+ from: it.from.name,
21091
+ to: it.to.name
21092
+ }));
21093
+ const rTables = renamed.map((it) => {
21094
+ return { from: it.from, to: it.to };
21095
+ });
20919
21096
  const jsonStatements = [];
20920
21097
  const jsonSQLiteCreateTables = created.map((it) => {
20921
21098
  return prepareSQLiteCreateTable(it);
@@ -20924,7 +21101,7 @@ var init_snapshotsDiffer = __esm({
20924
21101
  return prepareCreateTableJson(it);
20925
21102
  });
20926
21103
  const jsonCreateIndexesForCreatedTables = created.map((it) => {
20927
- return prepareCreateIndexesJson(it.name, it.indexes);
21104
+ return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
20928
21105
  }).flat();
20929
21106
  const jsonDropTables = deleted.map((it) => {
20930
21107
  return prepareDropTableJson(it);
@@ -20941,13 +21118,14 @@ var init_snapshotsDiffer = __esm({
20941
21118
  const jsonRenameColumnsStatements = [];
20942
21119
  const allAlteredResolved = [];
20943
21120
  for (const table4 of allAltered) {
20944
- const result = await columnsResolver({
21121
+ const result = await columnsResolver2({
20945
21122
  tableName: table4.name,
20946
21123
  created: table4.added,
20947
21124
  deleted: table4.deleted
20948
21125
  });
21126
+ const schema4 = valueFromSelfOrPatchedNew(table4.schema);
20949
21127
  jsonRenameColumnsStatements.push(
20950
- ...prepareRenameColumns(table4.name, result.renamed)
21128
+ ...prepareRenameColumns(table4.name, schema4, result.renamed)
20951
21129
  );
20952
21130
  const renamedColumnsAltered = result.renamed.map(
20953
21131
  (it) => alteredColumnSchema.parse(diffForRenamedColumn(it.from, it.to))
@@ -20989,7 +21167,7 @@ var init_snapshotsDiffer = __esm({
20989
21167
  it.name,
20990
21168
  it.alteredCompositePKs
20991
21169
  );
20992
- if (it.schema) {
21170
+ if (it.schema && typeof it.schema !== "string") {
20993
21171
  switch (it.schema.type) {
20994
21172
  case "added": {
20995
21173
  jsonSetTableSchemas.push({
@@ -21022,38 +21200,56 @@ var init_snapshotsDiffer = __esm({
21022
21200
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
21023
21201
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
21024
21202
  });
21203
+ const rColumns = jsonRenameColumnsStatements.map((it) => {
21204
+ const tableName = it.tableName;
21205
+ const schema4 = it.schema;
21206
+ return {
21207
+ from: { schema: schema4, table: tableName, column: it.oldColumnName },
21208
+ to: { schema: schema4, table: tableName, column: it.newColumnName }
21209
+ };
21210
+ });
21025
21211
  const jsonTableAlternations = allAlteredResolved.map((it) => {
21212
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21026
21213
  return prepareAlterTableColumnsJson(
21027
21214
  it.name,
21215
+ schema4,
21028
21216
  it.deleted,
21029
21217
  it.added,
21030
21218
  it.altered,
21031
21219
  it.addedForeignKeys,
21032
21220
  dialect6
21033
21221
  );
21034
- }).flat().reduce((res, it) => {
21035
- res.createColumns.push(...it.addColumns);
21036
- res.dropColumns.push(...it.dropColumns);
21037
- res.alterColumns.push(...it.alterColumns);
21038
- return res;
21039
- }, { createColumns: [], dropColumns: [], alterColumns: [] });
21222
+ }).flat().reduce(
21223
+ (res, it) => {
21224
+ res.createColumns.push(...it.addColumns);
21225
+ res.dropColumns.push(...it.dropColumns);
21226
+ res.alterColumns.push(...it.alterColumns);
21227
+ return res;
21228
+ },
21229
+ { createColumns: [], dropColumns: [], alterColumns: [] }
21230
+ );
21040
21231
  const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
21041
- return prepareCreateIndexesJson(it.name, it.addedIndexes || {});
21232
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21233
+ return prepareCreateIndexesJson(it.name, schema4, it.addedIndexes || {});
21042
21234
  }).flat();
21043
21235
  const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
21044
- return prepareDropIndexesJson(it.name, it.deletedIndexes || {});
21236
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21237
+ return prepareDropIndexesJson(it.name, schema4, it.deletedIndexes || {});
21045
21238
  }).flat();
21046
21239
  const jsonCreateReferencesForCreatedTables = created.map((it) => {
21047
- return prepareCreateReferencesJson(it.name, it.foreignKeys);
21240
+ return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
21048
21241
  }).flat();
21049
21242
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
21050
- const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, it.addedForeignKeys) : [];
21243
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21244
+ const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, schema4, it.addedForeignKeys) : [];
21051
21245
  const forAltered = prepareDropReferencesJson(
21052
21246
  it.name,
21247
+ schema4,
21053
21248
  it.deletedForeignKeys
21054
21249
  );
21055
21250
  const alteredFKs = prepareAlterReferencesJson(
21056
21251
  it.name,
21252
+ schema4,
21057
21253
  it.alteredForeignKeys
21058
21254
  );
21059
21255
  return [...forAdded, ...forAltered, ...alteredFKs];
@@ -21115,11 +21311,1334 @@ var init_snapshotsDiffer = __esm({
21115
21311
  jsonStatements.push(...jsonRemoveTableFromSchemas);
21116
21312
  jsonStatements.push(...dropSchemas);
21117
21313
  const sqlStatements = fromJson(jsonStatements, dialect6);
21118
- return sqlStatements.join("\n");
21314
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
21315
+ return { statements: jsonStatements, sql: sqlStatements.join("\n"), _meta };
21119
21316
  };
21120
21317
  }
21121
21318
  });
21122
21319
 
21320
+ // src/utils/words.ts
21321
+ var prepareMigrationMetadata, adjectives, heroes;
21322
+ var init_words = __esm({
21323
+ "src/utils/words.ts"() {
21324
+ prepareMigrationMetadata = (idx) => {
21325
+ const prefix = idx.toFixed(0).padStart(4, "0");
21326
+ const suffix = `${adjectives.random()}_${heroes.random()}`;
21327
+ const tag = `${prefix}_${suffix}`;
21328
+ return { prefix, suffix, tag };
21329
+ };
21330
+ adjectives = [
21331
+ "abandoned",
21332
+ "aberrant",
21333
+ "abnormal",
21334
+ "absent",
21335
+ "absurd",
21336
+ "acoustic",
21337
+ "adorable",
21338
+ "amazing",
21339
+ "ambiguous",
21340
+ "ambitious",
21341
+ "amused",
21342
+ "amusing",
21343
+ "ancient",
21344
+ "aromatic",
21345
+ "aspiring",
21346
+ "awesome",
21347
+ "bent",
21348
+ "big",
21349
+ "bitter",
21350
+ "bizarre",
21351
+ "black",
21352
+ "blue",
21353
+ "blushing",
21354
+ "bored",
21355
+ "boring",
21356
+ "bouncy",
21357
+ "brainy",
21358
+ "brave",
21359
+ "breezy",
21360
+ "brief",
21361
+ "bright",
21362
+ "broad",
21363
+ "broken",
21364
+ "brown",
21365
+ "bumpy",
21366
+ "burly",
21367
+ "busy",
21368
+ "calm",
21369
+ "careful",
21370
+ "careless",
21371
+ "certain",
21372
+ "charming",
21373
+ "cheerful",
21374
+ "chemical",
21375
+ "chief",
21376
+ "chilly",
21377
+ "chubby",
21378
+ "chunky",
21379
+ "clammy",
21380
+ "classy",
21381
+ "clean",
21382
+ "clear",
21383
+ "clever",
21384
+ "cloudy",
21385
+ "closed",
21386
+ "clumsy",
21387
+ "cold",
21388
+ "colorful",
21389
+ "colossal",
21390
+ "common",
21391
+ "complete",
21392
+ "complex",
21393
+ "concerned",
21394
+ "condemned",
21395
+ "confused",
21396
+ "conscious",
21397
+ "cooing",
21398
+ "cool",
21399
+ "crazy",
21400
+ "cuddly",
21401
+ "cultured",
21402
+ "curious",
21403
+ "curly",
21404
+ "curved",
21405
+ "curvy",
21406
+ "cute",
21407
+ "cynical",
21408
+ "daffy",
21409
+ "daily",
21410
+ "damp",
21411
+ "dapper",
21412
+ "dark",
21413
+ "dashing",
21414
+ "dazzling",
21415
+ "dear",
21416
+ "deep",
21417
+ "demonic",
21418
+ "dizzy",
21419
+ "dry",
21420
+ "dusty",
21421
+ "eager",
21422
+ "early",
21423
+ "easy",
21424
+ "elite",
21425
+ "eminent",
21426
+ "empty",
21427
+ "equal",
21428
+ "even",
21429
+ "exotic",
21430
+ "fair",
21431
+ "faithful",
21432
+ "familiar",
21433
+ "famous",
21434
+ "fancy",
21435
+ "fantastic",
21436
+ "far",
21437
+ "fast",
21438
+ "fat",
21439
+ "faulty",
21440
+ "fearless",
21441
+ "fine",
21442
+ "first",
21443
+ "fixed",
21444
+ "flaky",
21445
+ "flashy",
21446
+ "flat",
21447
+ "flawless",
21448
+ "flimsy",
21449
+ "flippant",
21450
+ "flowery",
21451
+ "fluffy",
21452
+ "foamy",
21453
+ "free",
21454
+ "freezing",
21455
+ "fresh",
21456
+ "friendly",
21457
+ "funny",
21458
+ "furry",
21459
+ "futuristic",
21460
+ "fuzzy",
21461
+ "giant",
21462
+ "gifted",
21463
+ "gigantic",
21464
+ "glamorous",
21465
+ "glorious",
21466
+ "glossy",
21467
+ "good",
21468
+ "goofy",
21469
+ "gorgeous",
21470
+ "graceful",
21471
+ "gray",
21472
+ "great",
21473
+ "greedy",
21474
+ "green",
21475
+ "grey",
21476
+ "groovy",
21477
+ "handy",
21478
+ "happy",
21479
+ "hard",
21480
+ "harsh",
21481
+ "heavy",
21482
+ "hesitant",
21483
+ "high",
21484
+ "hot",
21485
+ "huge",
21486
+ "icy",
21487
+ "illegal",
21488
+ "jazzy",
21489
+ "jittery",
21490
+ "keen",
21491
+ "kind",
21492
+ "known",
21493
+ "lame",
21494
+ "large",
21495
+ "last",
21496
+ "late",
21497
+ "lazy",
21498
+ "lean",
21499
+ "left",
21500
+ "legal",
21501
+ "lethal",
21502
+ "light",
21503
+ "little",
21504
+ "lively",
21505
+ "living",
21506
+ "lonely",
21507
+ "long",
21508
+ "loose",
21509
+ "loud",
21510
+ "lovely",
21511
+ "loving",
21512
+ "low",
21513
+ "lowly",
21514
+ "lucky",
21515
+ "lumpy",
21516
+ "lush",
21517
+ "luxuriant",
21518
+ "lying",
21519
+ "lyrical",
21520
+ "magenta",
21521
+ "magical",
21522
+ "majestic",
21523
+ "many",
21524
+ "massive",
21525
+ "married",
21526
+ "marvelous",
21527
+ "material",
21528
+ "mature",
21529
+ "mean",
21530
+ "medical",
21531
+ "melodic",
21532
+ "melted",
21533
+ "messy",
21534
+ "mighty",
21535
+ "military",
21536
+ "milky",
21537
+ "minor",
21538
+ "misty",
21539
+ "mixed",
21540
+ "moaning",
21541
+ "modern",
21542
+ "motionless",
21543
+ "mushy",
21544
+ "mute",
21545
+ "mysterious",
21546
+ "naive",
21547
+ "nappy",
21548
+ "narrow",
21549
+ "nasty",
21550
+ "natural",
21551
+ "neat",
21552
+ "nebulous",
21553
+ "needy",
21554
+ "nervous",
21555
+ "new",
21556
+ "next",
21557
+ "nice",
21558
+ "nifty",
21559
+ "noisy",
21560
+ "normal",
21561
+ "nostalgic",
21562
+ "nosy",
21563
+ "numerous",
21564
+ "odd",
21565
+ "old",
21566
+ "omniscient",
21567
+ "open",
21568
+ "opposite",
21569
+ "optimal",
21570
+ "orange",
21571
+ "ordinary",
21572
+ "organic",
21573
+ "outgoing",
21574
+ "outstanding",
21575
+ "oval",
21576
+ "overconfident",
21577
+ "overjoyed",
21578
+ "overrated",
21579
+ "pale",
21580
+ "panoramic",
21581
+ "parallel",
21582
+ "parched",
21583
+ "past",
21584
+ "peaceful",
21585
+ "perfect",
21586
+ "perpetual",
21587
+ "petite",
21588
+ "pink",
21589
+ "plain",
21590
+ "polite",
21591
+ "powerful",
21592
+ "premium",
21593
+ "pretty",
21594
+ "previous",
21595
+ "productive",
21596
+ "public",
21597
+ "purple",
21598
+ "puzzling",
21599
+ "quick",
21600
+ "quiet",
21601
+ "rainy",
21602
+ "rapid",
21603
+ "rare",
21604
+ "real",
21605
+ "red",
21606
+ "redundant",
21607
+ "reflective",
21608
+ "regular",
21609
+ "remarkable",
21610
+ "rich",
21611
+ "right",
21612
+ "robust",
21613
+ "romantic",
21614
+ "round",
21615
+ "sad",
21616
+ "safe",
21617
+ "salty",
21618
+ "same",
21619
+ "secret",
21620
+ "serious",
21621
+ "shallow",
21622
+ "sharp",
21623
+ "shiny",
21624
+ "shocking",
21625
+ "short",
21626
+ "silent",
21627
+ "silky",
21628
+ "silly",
21629
+ "simple",
21630
+ "skinny",
21631
+ "sleepy",
21632
+ "slim",
21633
+ "slimy",
21634
+ "slippery",
21635
+ "sloppy",
21636
+ "slow",
21637
+ "small",
21638
+ "smart",
21639
+ "smiling",
21640
+ "smooth",
21641
+ "soft",
21642
+ "solid",
21643
+ "sour",
21644
+ "sparkling",
21645
+ "special",
21646
+ "spicy",
21647
+ "spooky",
21648
+ "spotty",
21649
+ "square",
21650
+ "stale",
21651
+ "steady",
21652
+ "steep",
21653
+ "sticky",
21654
+ "stiff",
21655
+ "stormy",
21656
+ "strange",
21657
+ "striped",
21658
+ "strong",
21659
+ "sturdy",
21660
+ "sudden",
21661
+ "superb",
21662
+ "supreme",
21663
+ "sweet",
21664
+ "swift",
21665
+ "talented",
21666
+ "tan",
21667
+ "tearful",
21668
+ "tense",
21669
+ "thankful",
21670
+ "thick",
21671
+ "thin",
21672
+ "third",
21673
+ "tidy",
21674
+ "tiny",
21675
+ "tired",
21676
+ "tiresome",
21677
+ "tough",
21678
+ "tranquil",
21679
+ "tricky",
21680
+ "true",
21681
+ "typical",
21682
+ "uneven",
21683
+ "unique",
21684
+ "unknown",
21685
+ "unusual",
21686
+ "useful",
21687
+ "vengeful",
21688
+ "violet",
21689
+ "volatile",
21690
+ "wakeful",
21691
+ "wandering",
21692
+ "warm",
21693
+ "watery",
21694
+ "wealthy",
21695
+ "wet",
21696
+ "white",
21697
+ "whole",
21698
+ "wide",
21699
+ "wild",
21700
+ "windy",
21701
+ "wise",
21702
+ "wonderful",
21703
+ "wooden",
21704
+ "woozy",
21705
+ "workable",
21706
+ "worried",
21707
+ "worthless",
21708
+ "yellow",
21709
+ "yielding",
21710
+ "young",
21711
+ "youthful",
21712
+ "yummy",
21713
+ "zippy"
21714
+ ];
21715
+ heroes = [
21716
+ "aaron_stack",
21717
+ "abomination",
21718
+ "absorbing_man",
21719
+ "adam_destine",
21720
+ "adam_warlock",
21721
+ "agent_brand",
21722
+ "agent_zero",
21723
+ "albert_cleary",
21724
+ "alex_power",
21725
+ "alex_wilder",
21726
+ "alice",
21727
+ "amazoness",
21728
+ "amphibian",
21729
+ "angel",
21730
+ "anita_blake",
21731
+ "annihilus",
21732
+ "anthem",
21733
+ "apocalypse",
21734
+ "aqueduct",
21735
+ "arachne",
21736
+ "archangel",
21737
+ "arclight",
21738
+ "ares",
21739
+ "argent",
21740
+ "avengers",
21741
+ "azazel",
21742
+ "banshee",
21743
+ "baron_strucker",
21744
+ "baron_zemo",
21745
+ "barracuda",
21746
+ "bastion",
21747
+ "beast",
21748
+ "bedlam",
21749
+ "ben_grimm",
21750
+ "ben_parker",
21751
+ "ben_urich",
21752
+ "betty_brant",
21753
+ "betty_ross",
21754
+ "beyonder",
21755
+ "big_bertha",
21756
+ "bill_hollister",
21757
+ "bishop",
21758
+ "black_bird",
21759
+ "black_bolt",
21760
+ "black_cat",
21761
+ "black_crow",
21762
+ "black_knight",
21763
+ "black_panther",
21764
+ "black_queen",
21765
+ "black_tarantula",
21766
+ "black_tom",
21767
+ "black_widow",
21768
+ "blackheart",
21769
+ "blacklash",
21770
+ "blade",
21771
+ "blazing_skull",
21772
+ "blindfold",
21773
+ "blink",
21774
+ "blizzard",
21775
+ "blob",
21776
+ "blockbuster",
21777
+ "blonde_phantom",
21778
+ "bloodaxe",
21779
+ "bloodscream",
21780
+ "bloodstorm",
21781
+ "bloodstrike",
21782
+ "blue_blade",
21783
+ "blue_marvel",
21784
+ "blue_shield",
21785
+ "blur",
21786
+ "boom_boom",
21787
+ "boomer",
21788
+ "boomerang",
21789
+ "bromley",
21790
+ "brood",
21791
+ "brother_voodoo",
21792
+ "bruce_banner",
21793
+ "bucky",
21794
+ "bug",
21795
+ "bulldozer",
21796
+ "bullseye",
21797
+ "bushwacker",
21798
+ "butterfly",
21799
+ "cable",
21800
+ "callisto",
21801
+ "calypso",
21802
+ "cammi",
21803
+ "cannonball",
21804
+ "captain_america",
21805
+ "captain_britain",
21806
+ "captain_cross",
21807
+ "captain_flint",
21808
+ "captain_marvel",
21809
+ "captain_midlands",
21810
+ "captain_stacy",
21811
+ "captain_universe",
21812
+ "cardiac",
21813
+ "caretaker",
21814
+ "cargill",
21815
+ "carlie_cooper",
21816
+ "carmella_unuscione",
21817
+ "carnage",
21818
+ "cassandra_nova",
21819
+ "catseye",
21820
+ "celestials",
21821
+ "centennial",
21822
+ "cerebro",
21823
+ "cerise",
21824
+ "chamber",
21825
+ "chameleon",
21826
+ "champions",
21827
+ "changeling",
21828
+ "charles_xavier",
21829
+ "chat",
21830
+ "chimera",
21831
+ "christian_walker",
21832
+ "chronomancer",
21833
+ "clea",
21834
+ "clint_barton",
21835
+ "cloak",
21836
+ "cobalt_man",
21837
+ "colleen_wing",
21838
+ "colonel_america",
21839
+ "colossus",
21840
+ "corsair",
21841
+ "crusher_hogan",
21842
+ "crystal",
21843
+ "cyclops",
21844
+ "dagger",
21845
+ "daimon_hellstrom",
21846
+ "dakota_north",
21847
+ "daredevil",
21848
+ "dark_beast",
21849
+ "dark_phoenix",
21850
+ "darkhawk",
21851
+ "darkstar",
21852
+ "darwin",
21853
+ "dazzler",
21854
+ "deadpool",
21855
+ "deathbird",
21856
+ "deathstrike",
21857
+ "demogoblin",
21858
+ "devos",
21859
+ "dexter_bennett",
21860
+ "diamondback",
21861
+ "doctor_doom",
21862
+ "doctor_faustus",
21863
+ "doctor_octopus",
21864
+ "doctor_spectrum",
21865
+ "doctor_strange",
21866
+ "domino",
21867
+ "donald_blake",
21868
+ "doomsday",
21869
+ "doorman",
21870
+ "dorian_gray",
21871
+ "dormammu",
21872
+ "dracula",
21873
+ "dragon_lord",
21874
+ "dragon_man",
21875
+ "drax",
21876
+ "dreadnoughts",
21877
+ "dreaming_celestial",
21878
+ "dust",
21879
+ "earthquake",
21880
+ "echo",
21881
+ "eddie_brock",
21882
+ "edwin_jarvis",
21883
+ "ego",
21884
+ "electro",
21885
+ "elektra",
21886
+ "emma_frost",
21887
+ "enchantress",
21888
+ "ender_wiggin",
21889
+ "energizer",
21890
+ "epoch",
21891
+ "eternals",
21892
+ "eternity",
21893
+ "excalibur",
21894
+ "exiles",
21895
+ "exodus",
21896
+ "expediter",
21897
+ "ezekiel",
21898
+ "ezekiel_stane",
21899
+ "fabian_cortez",
21900
+ "falcon",
21901
+ "fallen_one",
21902
+ "famine",
21903
+ "fantastic_four",
21904
+ "fat_cobra",
21905
+ "felicia_hardy",
21906
+ "fenris",
21907
+ "firebird",
21908
+ "firebrand",
21909
+ "firedrake",
21910
+ "firelord",
21911
+ "firestar",
21912
+ "fixer",
21913
+ "flatman",
21914
+ "forge",
21915
+ "forgotten_one",
21916
+ "frank_castle",
21917
+ "franklin_richards",
21918
+ "franklin_storm",
21919
+ "freak",
21920
+ "frightful_four",
21921
+ "frog_thor",
21922
+ "gabe_jones",
21923
+ "galactus",
21924
+ "gambit",
21925
+ "gamma_corps",
21926
+ "gamora",
21927
+ "gargoyle",
21928
+ "garia",
21929
+ "gateway",
21930
+ "gauntlet",
21931
+ "genesis",
21932
+ "george_stacy",
21933
+ "gertrude_yorkes",
21934
+ "ghost_rider",
21935
+ "giant_girl",
21936
+ "giant_man",
21937
+ "gideon",
21938
+ "gladiator",
21939
+ "glorian",
21940
+ "goblin_queen",
21941
+ "golden_guardian",
21942
+ "goliath",
21943
+ "gorgon",
21944
+ "gorilla_man",
21945
+ "grandmaster",
21946
+ "gravity",
21947
+ "green_goblin",
21948
+ "gressill",
21949
+ "grey_gargoyle",
21950
+ "greymalkin",
21951
+ "grim_reaper",
21952
+ "groot",
21953
+ "guardian",
21954
+ "guardsmen",
21955
+ "gunslinger",
21956
+ "gwen_stacy",
21957
+ "hairball",
21958
+ "hammerhead",
21959
+ "hannibal_king",
21960
+ "hardball",
21961
+ "harpoon",
21962
+ "harrier",
21963
+ "harry_osborn",
21964
+ "havok",
21965
+ "hawkeye",
21966
+ "hedge_knight",
21967
+ "hellcat",
21968
+ "hellfire_club",
21969
+ "hellion",
21970
+ "hemingway",
21971
+ "hercules",
21972
+ "hex",
21973
+ "hiroim",
21974
+ "hitman",
21975
+ "hobgoblin",
21976
+ "holocaust",
21977
+ "hulk",
21978
+ "human_cannonball",
21979
+ "human_fly",
21980
+ "human_robot",
21981
+ "human_torch",
21982
+ "husk",
21983
+ "hydra",
21984
+ "iceman",
21985
+ "ikaris",
21986
+ "imperial_guard",
21987
+ "impossible_man",
21988
+ "inertia",
21989
+ "infant_terrible",
21990
+ "inhumans",
21991
+ "ink",
21992
+ "invaders",
21993
+ "invisible_woman",
21994
+ "iron_fist",
21995
+ "iron_lad",
21996
+ "iron_man",
21997
+ "iron_monger",
21998
+ "iron_patriot",
21999
+ "ironclad",
22000
+ "jack_flag",
22001
+ "jack_murdock",
22002
+ "jack_power",
22003
+ "jackal",
22004
+ "jackpot",
22005
+ "james_howlett",
22006
+ "jamie_braddock",
22007
+ "jane_foster",
22008
+ "jasper_sitwell",
22009
+ "jazinda",
22010
+ "jean_grey",
22011
+ "jetstream",
22012
+ "jigsaw",
22013
+ "jimmy_woo",
22014
+ "jocasta",
22015
+ "johnny_blaze",
22016
+ "johnny_storm",
22017
+ "joseph",
22018
+ "joshua_kane",
22019
+ "joystick",
22020
+ "jubilee",
22021
+ "juggernaut",
22022
+ "junta",
22023
+ "justice",
22024
+ "justin_hammer",
22025
+ "kabuki",
22026
+ "kang",
22027
+ "karen_page",
22028
+ "karma",
22029
+ "karnak",
22030
+ "kat_farrell",
22031
+ "kate_bishop",
22032
+ "katie_power",
22033
+ "ken_ellis",
22034
+ "khan",
22035
+ "kid_colt",
22036
+ "killer_shrike",
22037
+ "killmonger",
22038
+ "killraven",
22039
+ "king_bedlam",
22040
+ "king_cobra",
22041
+ "kingpin",
22042
+ "kinsey_walden",
22043
+ "kitty_pryde",
22044
+ "klaw",
22045
+ "komodo",
22046
+ "korath",
22047
+ "korg",
22048
+ "korvac",
22049
+ "kree",
22050
+ "krista_starr",
22051
+ "kronos",
22052
+ "kulan_gath",
22053
+ "kylun",
22054
+ "la_nuit",
22055
+ "lady_bullseye",
22056
+ "lady_deathstrike",
22057
+ "lady_mastermind",
22058
+ "lady_ursula",
22059
+ "lady_vermin",
22060
+ "lake",
22061
+ "landau",
22062
+ "layla_miller",
22063
+ "leader",
22064
+ "leech",
22065
+ "legion",
22066
+ "lenny_balinger",
22067
+ "leo",
22068
+ "leopardon",
22069
+ "leper_queen",
22070
+ "lester",
22071
+ "lethal_legion",
22072
+ "lifeguard",
22073
+ "lightspeed",
22074
+ "lila_cheney",
22075
+ "lilandra",
22076
+ "lilith",
22077
+ "lily_hollister",
22078
+ "lionheart",
22079
+ "living_lightning",
22080
+ "living_mummy",
22081
+ "living_tribunal",
22082
+ "liz_osborn",
22083
+ "lizard",
22084
+ "loa",
22085
+ "lockheed",
22086
+ "lockjaw",
22087
+ "logan",
22088
+ "loki",
22089
+ "loners",
22090
+ "longshot",
22091
+ "lord_hawal",
22092
+ "lord_tyger",
22093
+ "lorna_dane",
22094
+ "luckman",
22095
+ "lucky_pierre",
22096
+ "luke_cage",
22097
+ "luminals",
22098
+ "lyja",
22099
+ "ma_gnuci",
22100
+ "mac_gargan",
22101
+ "mach_iv",
22102
+ "machine_man",
22103
+ "mad_thinker",
22104
+ "madame_hydra",
22105
+ "madame_masque",
22106
+ "madame_web",
22107
+ "maddog",
22108
+ "madelyne_pryor",
22109
+ "madripoor",
22110
+ "madrox",
22111
+ "maelstrom",
22112
+ "maestro",
22113
+ "magdalene",
22114
+ "maggott",
22115
+ "magik",
22116
+ "maginty",
22117
+ "magma",
22118
+ "magneto",
22119
+ "magus",
22120
+ "major_mapleleaf",
22121
+ "makkari",
22122
+ "malcolm_colcord",
22123
+ "malice",
22124
+ "mandarin",
22125
+ "mandrill",
22126
+ "mandroid",
22127
+ "manta",
22128
+ "mantis",
22129
+ "marauders",
22130
+ "maria_hill",
22131
+ "mariko_yashida",
22132
+ "marrow",
22133
+ "marten_broadcloak",
22134
+ "martin_li",
22135
+ "marvel_apes",
22136
+ "marvel_boy",
22137
+ "marvel_zombies",
22138
+ "marvex",
22139
+ "masked_marvel",
22140
+ "masque",
22141
+ "master_chief",
22142
+ "master_mold",
22143
+ "mastermind",
22144
+ "mathemanic",
22145
+ "matthew_murdock",
22146
+ "mattie_franklin",
22147
+ "mauler",
22148
+ "maverick",
22149
+ "maximus",
22150
+ "may_parker",
22151
+ "medusa",
22152
+ "meggan",
22153
+ "meltdown",
22154
+ "menace",
22155
+ "mentallo",
22156
+ "mentor",
22157
+ "mephisto",
22158
+ "mephistopheles",
22159
+ "mercury",
22160
+ "mesmero",
22161
+ "metal_master",
22162
+ "meteorite",
22163
+ "micro/macro",
22164
+ "microbe",
22165
+ "microchip",
22166
+ "micromax",
22167
+ "midnight",
22168
+ "miek",
22169
+ "mikhail_rasputin",
22170
+ "millenium_guard",
22171
+ "mimic",
22172
+ "mindworm",
22173
+ "miracleman",
22174
+ "miss_america",
22175
+ "mister_fear",
22176
+ "mister_sinister",
22177
+ "misty_knight",
22178
+ "mockingbird",
22179
+ "moira_mactaggert",
22180
+ "mojo",
22181
+ "mole_man",
22182
+ "molecule_man",
22183
+ "molly_hayes",
22184
+ "molten_man",
22185
+ "mongoose",
22186
+ "mongu",
22187
+ "monster_badoon",
22188
+ "moon_knight",
22189
+ "moondragon",
22190
+ "moonstone",
22191
+ "morbius",
22192
+ "mordo",
22193
+ "morg",
22194
+ "morgan_stark",
22195
+ "morlocks",
22196
+ "morlun",
22197
+ "morph",
22198
+ "mother_askani",
22199
+ "mulholland_black",
22200
+ "multiple_man",
22201
+ "mysterio",
22202
+ "mystique",
22203
+ "namor",
22204
+ "namora",
22205
+ "namorita",
22206
+ "naoko",
22207
+ "natasha_romanoff",
22208
+ "nebula",
22209
+ "nehzno",
22210
+ "nekra",
22211
+ "nemesis",
22212
+ "network",
22213
+ "newton_destine",
22214
+ "next_avengers",
22215
+ "nextwave",
22216
+ "nick_fury",
22217
+ "nico_minoru",
22218
+ "nicolaos",
22219
+ "night_nurse",
22220
+ "night_thrasher",
22221
+ "nightcrawler",
22222
+ "nighthawk",
22223
+ "nightmare",
22224
+ "nightshade",
22225
+ "nitro",
22226
+ "nocturne",
22227
+ "nomad",
22228
+ "norman_osborn",
22229
+ "norrin_radd",
22230
+ "northstar",
22231
+ "nova",
22232
+ "nuke",
22233
+ "obadiah_stane",
22234
+ "odin",
22235
+ "ogun",
22236
+ "old_lace",
22237
+ "omega_flight",
22238
+ "omega_red",
22239
+ "omega_sentinel",
22240
+ "onslaught",
22241
+ "oracle",
22242
+ "orphan",
22243
+ "otto_octavius",
22244
+ "outlaw_kid",
22245
+ "overlord",
22246
+ "owl",
22247
+ "ozymandias",
22248
+ "paibok",
22249
+ "paladin",
22250
+ "pandemic",
22251
+ "paper_doll",
22252
+ "patch",
22253
+ "patriot",
22254
+ "payback",
22255
+ "penance",
22256
+ "pepper_potts",
22257
+ "pestilence",
22258
+ "pet_avengers",
22259
+ "pete_wisdom",
22260
+ "peter_parker",
22261
+ "peter_quill",
22262
+ "phalanx",
22263
+ "phantom_reporter",
22264
+ "phil_sheldon",
22265
+ "photon",
22266
+ "piledriver",
22267
+ "pixie",
22268
+ "plazm",
22269
+ "polaris",
22270
+ "post",
22271
+ "power_man",
22272
+ "power_pack",
22273
+ "praxagora",
22274
+ "preak",
22275
+ "pretty_boy",
22276
+ "pride",
22277
+ "prima",
22278
+ "princess_powerful",
22279
+ "prism",
22280
+ "prodigy",
22281
+ "proemial_gods",
22282
+ "professor_monster",
22283
+ "proteus",
22284
+ "proudstar",
22285
+ "prowler",
22286
+ "psylocke",
22287
+ "psynapse",
22288
+ "puck",
22289
+ "puff_adder",
22290
+ "puma",
22291
+ "punisher",
22292
+ "puppet_master",
22293
+ "purifiers",
22294
+ "purple_man",
22295
+ "pyro",
22296
+ "quasar",
22297
+ "quasimodo",
22298
+ "queen_noir",
22299
+ "quentin_quire",
22300
+ "quicksilver",
22301
+ "rachel_grey",
22302
+ "radioactive_man",
22303
+ "rafael_vega",
22304
+ "rage",
22305
+ "raider",
22306
+ "randall",
22307
+ "randall_flagg",
22308
+ "random",
22309
+ "rattler",
22310
+ "ravenous",
22311
+ "rawhide_kid",
22312
+ "raza",
22313
+ "reaper",
22314
+ "reavers",
22315
+ "red_ghost",
22316
+ "red_hulk",
22317
+ "red_shift",
22318
+ "red_skull",
22319
+ "red_wolf",
22320
+ "redwing",
22321
+ "reptil",
22322
+ "retro_girl",
22323
+ "revanche",
22324
+ "rhino",
22325
+ "rhodey",
22326
+ "richard_fisk",
22327
+ "rick_jones",
22328
+ "ricochet",
22329
+ "rictor",
22330
+ "riptide",
22331
+ "risque",
22332
+ "robbie_robertson",
22333
+ "robin_chapel",
22334
+ "rocket_raccoon",
22335
+ "rocket_racer",
22336
+ "rockslide",
22337
+ "rogue",
22338
+ "roland_deschain",
22339
+ "romulus",
22340
+ "ronan",
22341
+ "roughhouse",
22342
+ "roulette",
22343
+ "roxanne_simpson",
22344
+ "rumiko_fujikawa",
22345
+ "runaways",
22346
+ "russian",
22347
+ "sabra",
22348
+ "sabretooth",
22349
+ "sage",
22350
+ "sally_floyd",
22351
+ "salo",
22352
+ "sandman",
22353
+ "santa_claus",
22354
+ "saracen",
22355
+ "sasquatch",
22356
+ "satana",
22357
+ "sauron",
22358
+ "scalphunter",
22359
+ "scarecrow",
22360
+ "scarlet_spider",
22361
+ "scarlet_witch",
22362
+ "scorpion",
22363
+ "scourge",
22364
+ "scrambler",
22365
+ "scream",
22366
+ "screwball",
22367
+ "sebastian_shaw",
22368
+ "secret_warriors",
22369
+ "selene",
22370
+ "senator_kelly",
22371
+ "sentinel",
22372
+ "sentinels",
22373
+ "sentry",
22374
+ "ser_duncan",
22375
+ "serpent_society",
22376
+ "sersi",
22377
+ "shadow_king",
22378
+ "shadowcat",
22379
+ "shaman",
22380
+ "shape",
22381
+ "shard",
22382
+ "sharon_carter",
22383
+ "sharon_ventura",
22384
+ "shatterstar",
22385
+ "shen",
22386
+ "sheva_callister",
22387
+ "shinko_yamashiro",
22388
+ "shinobi_shaw",
22389
+ "shiva",
22390
+ "shiver_man",
22391
+ "shocker",
22392
+ "shockwave",
22393
+ "shooting_star",
22394
+ "shotgun",
22395
+ "shriek",
22396
+ "silhouette",
22397
+ "silk_fever",
22398
+ "silver_centurion",
22399
+ "silver_fox",
22400
+ "silver_sable",
22401
+ "silver_samurai",
22402
+ "silver_surfer",
22403
+ "silverclaw",
22404
+ "silvermane",
22405
+ "sinister_six",
22406
+ "sir_ram",
22407
+ "siren",
22408
+ "sister_grimm",
22409
+ "skaar",
22410
+ "skin",
22411
+ "skreet",
22412
+ "skrulls",
22413
+ "skullbuster",
22414
+ "slapstick",
22415
+ "slayback",
22416
+ "sleeper",
22417
+ "sleepwalker",
22418
+ "slipstream",
22419
+ "slyde",
22420
+ "smasher",
22421
+ "smiling_tiger",
22422
+ "snowbird",
22423
+ "solo",
22424
+ "songbird",
22425
+ "spacker_dave",
22426
+ "spectrum",
22427
+ "speed",
22428
+ "speed_demon",
22429
+ "speedball",
22430
+ "spencer_smythe",
22431
+ "sphinx",
22432
+ "spiral",
22433
+ "spirit",
22434
+ "spitfire",
22435
+ "spot",
22436
+ "sprite",
22437
+ "spyke",
22438
+ "squadron_sinister",
22439
+ "squadron_supreme",
22440
+ "squirrel_girl",
22441
+ "star_brand",
22442
+ "starbolt",
22443
+ "stardust",
22444
+ "starfox",
22445
+ "starhawk",
22446
+ "starjammers",
22447
+ "stark_industries",
22448
+ "stature",
22449
+ "steel_serpent",
22450
+ "stellaris",
22451
+ "stepford_cuckoos",
22452
+ "stephen_strange",
22453
+ "steve_rogers",
22454
+ "stick",
22455
+ "stingray",
22456
+ "stone_men",
22457
+ "storm",
22458
+ "stranger",
22459
+ "strong_guy",
22460
+ "stryfe",
22461
+ "sue_storm",
22462
+ "sugar_man",
22463
+ "sumo",
22464
+ "sunfire",
22465
+ "sunset_bain",
22466
+ "sunspot",
22467
+ "supernaut",
22468
+ "supreme_intelligence",
22469
+ "surge",
22470
+ "susan_delgado",
22471
+ "swarm",
22472
+ "sway",
22473
+ "switch",
22474
+ "swordsman",
22475
+ "synch",
22476
+ "tag",
22477
+ "talisman",
22478
+ "talkback",
22479
+ "talon",
22480
+ "talos",
22481
+ "tana_nile",
22482
+ "tarantula",
22483
+ "tarot",
22484
+ "taskmaster",
22485
+ "tattoo",
22486
+ "ted_forrester",
22487
+ "tempest",
22488
+ "tenebrous",
22489
+ "terrax",
22490
+ "terror",
22491
+ "texas_twister",
22492
+ "thaddeus_ross",
22493
+ "thanos",
22494
+ "the_anarchist",
22495
+ "the_call",
22496
+ "the_captain",
22497
+ "the_enforcers",
22498
+ "the_executioner",
22499
+ "the_fallen",
22500
+ "the_fury",
22501
+ "the_hand",
22502
+ "the_hood",
22503
+ "the_hunter",
22504
+ "the_initiative",
22505
+ "the_leader",
22506
+ "the_liberteens",
22507
+ "the_order",
22508
+ "the_phantom",
22509
+ "the_professor",
22510
+ "the_renegades",
22511
+ "the_santerians",
22512
+ "the_spike",
22513
+ "the_stranger",
22514
+ "the_twelve",
22515
+ "the_watchers",
22516
+ "thena",
22517
+ "thing",
22518
+ "thor",
22519
+ "thor_girl",
22520
+ "thunderball",
22521
+ "thunderbird",
22522
+ "thunderbolt",
22523
+ "thunderbolt_ross",
22524
+ "thunderbolts",
22525
+ "thundra",
22526
+ "tiger_shark",
22527
+ "tigra",
22528
+ "timeslip",
22529
+ "tinkerer",
22530
+ "titania",
22531
+ "titanium_man",
22532
+ "toad",
22533
+ "toad_men",
22534
+ "tomas",
22535
+ "tombstone",
22536
+ "tomorrow_man",
22537
+ "tony_stark",
22538
+ "toro",
22539
+ "toxin",
22540
+ "trauma",
22541
+ "triathlon",
22542
+ "trish_tilby",
22543
+ "triton",
22544
+ "true_believers",
22545
+ "turbo",
22546
+ "tusk",
22547
+ "tyger_tiger",
22548
+ "typhoid_mary",
22549
+ "tyrannus",
22550
+ "ulik",
22551
+ "ultimates",
22552
+ "ultimatum",
22553
+ "ultimo",
22554
+ "ultragirl",
22555
+ "ultron",
22556
+ "umar",
22557
+ "unicorn",
22558
+ "union_jack",
22559
+ "unus",
22560
+ "valeria_richards",
22561
+ "valkyrie",
22562
+ "vampiro",
22563
+ "vance_astro",
22564
+ "vanisher",
22565
+ "vapor",
22566
+ "vargas",
22567
+ "vector",
22568
+ "veda",
22569
+ "vengeance",
22570
+ "venom",
22571
+ "venus",
22572
+ "vermin",
22573
+ "vertigo",
22574
+ "victor_mancha",
22575
+ "vin_gonzales",
22576
+ "vindicator",
22577
+ "violations",
22578
+ "viper",
22579
+ "virginia_dare",
22580
+ "vision",
22581
+ "vivisector",
22582
+ "vulcan",
22583
+ "vulture",
22584
+ "wallflower",
22585
+ "wallop",
22586
+ "wallow",
22587
+ "war_machine",
22588
+ "warbird",
22589
+ "warbound",
22590
+ "warhawk",
22591
+ "warlock",
22592
+ "warpath",
22593
+ "warstar",
22594
+ "wasp",
22595
+ "weapon_omega",
22596
+ "wendell_rand",
22597
+ "wendell_vaughn",
22598
+ "wendigo",
22599
+ "whiplash",
22600
+ "whirlwind",
22601
+ "whistler",
22602
+ "white_queen",
22603
+ "white_tiger",
22604
+ "whizzer",
22605
+ "wiccan",
22606
+ "wild_child",
22607
+ "wild_pack",
22608
+ "wildside",
22609
+ "william_stryker",
22610
+ "wilson_fisk",
22611
+ "wind_dancer",
22612
+ "winter_soldier",
22613
+ "wither",
22614
+ "wolf_cub",
22615
+ "wolfpack",
22616
+ "wolfsbane",
22617
+ "wolverine",
22618
+ "wonder_man",
22619
+ "wong",
22620
+ "wraith",
22621
+ "wrecker",
22622
+ "wrecking_crew",
22623
+ "xavin",
22624
+ "xorn",
22625
+ "yellow_claw",
22626
+ "yellowjacket",
22627
+ "young_avengers",
22628
+ "zaladane",
22629
+ "zaran",
22630
+ "zarda",
22631
+ "zarek",
22632
+ "zeigeist",
22633
+ "zemo",
22634
+ "zodiak",
22635
+ "zombie",
22636
+ "zuras",
22637
+ "zzzax"
22638
+ ];
22639
+ }
22640
+ });
22641
+
21123
22642
  // src/cli/commands/migrate.ts
21124
22643
  var migrate_exports = {};
21125
22644
  __export(migrate_exports, {
@@ -21127,15 +22646,16 @@ __export(migrate_exports, {
21127
22646
  prepareAndMigratePg: () => prepareAndMigratePg,
21128
22647
  prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
21129
22648
  prepareSQL: () => prepareSQL,
21130
- prepareSnapshotFolderName: () => prepareSnapshotFolderName
22649
+ prepareSnapshotFolderName: () => prepareSnapshotFolderName,
22650
+ writeResult: () => writeResult
21131
22651
  });
21132
- var import_fs4, import_path2, import_hanji2, prepareAndMigratePg, prepareAndMigrateSqlite, prepareAndMigrateMySql, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
22652
+ var import_fs4, import_path3, import_hanji2, prepareAndMigratePg, prepareAndMigrateMySql, prepareAndMigrateSqlite, prepareSQL, promptColumnsConflicts, promptTablesConflict, promptSchemasConflict, writeResult, prepareSnapshotFolderName, two;
21133
22653
  var init_migrate = __esm({
21134
22654
  "src/cli/commands/migrate.ts"() {
21135
22655
  import_fs4 = __toESM(require("fs"));
21136
22656
  init_migrationPreparator();
21137
22657
  init_snapshotsDiffer();
21138
- import_path2 = __toESM(require("path"));
22658
+ import_path3 = __toESM(require("path"));
21139
22659
  import_hanji2 = __toESM(require_hanji());
21140
22660
  init_views();
21141
22661
  init_source();
@@ -21143,68 +22663,68 @@ var init_migrate = __esm({
21143
22663
  init_sqliteSchema();
21144
22664
  init_mysqlSchema();
21145
22665
  init_utils();
22666
+ init_words();
21146
22667
  prepareAndMigratePg = async (config) => {
21147
22668
  const outFolder = config.out;
21148
22669
  const schemaPath = config.schema;
21149
22670
  try {
21150
- const { migrationFolders } = prepareMigrationFolder(outFolder, "pg");
21151
- const { prev, cur } = preparePgMigrationSnapshot(
21152
- migrationFolders,
21153
- outFolder,
21154
- schemaPath
21155
- );
22671
+ assertV1OutFolder(outFolder, "pg");
22672
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
22673
+ const { prev, cur } = preparePgMigrationSnapshot(snapshots, schemaPath);
21156
22674
  const validatedPrev = pgSchema.parse(prev);
21157
22675
  const validatedCur = pgSchema.parse(cur);
21158
22676
  const squashedPrev = squashPgScheme(validatedPrev);
21159
22677
  const squashedCur = squashPgScheme(validatedCur);
21160
- const sql = await prepareSQL(squashedPrev, squashedCur, "pg");
21161
- writeResult(cur, sql, outFolder);
22678
+ const { statements, sql, _meta } = await prepareSQL(
22679
+ squashedPrev,
22680
+ squashedCur,
22681
+ "pg"
22682
+ );
22683
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21162
22684
  } catch (e) {
21163
22685
  console.error(e);
21164
22686
  }
21165
22687
  };
21166
- prepareAndMigrateSqlite = async (config) => {
22688
+ prepareAndMigrateMySql = async (config) => {
21167
22689
  const outFolder = config.out;
21168
22690
  const schemaPath = config.schema;
21169
22691
  try {
21170
- const { migrationFolders } = prepareMigrationFolder(outFolder, "sqlite");
21171
- const { prev, cur } = prepareSqliteMigrationSnapshot(
21172
- migrationFolders,
21173
- outFolder,
21174
- schemaPath
22692
+ assertV1OutFolder(outFolder, "mysql");
22693
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "mysql");
22694
+ const { prev, cur } = prepareMySqlMigrationSnapshot(snapshots, schemaPath);
22695
+ const validatedPrev = mysqlSchema.parse(prev);
22696
+ const validatedCur = mysqlSchema.parse(cur);
22697
+ const squashedPrev = squashMysqlScheme(validatedPrev);
22698
+ const squashedCur = squashMysqlScheme(validatedCur);
22699
+ const { sql, _meta } = await prepareSQL(
22700
+ squashedPrev,
22701
+ squashedCur,
22702
+ "sqlite"
21175
22703
  );
21176
- const validatedPrev = sqliteSchema.parse(prev);
21177
- const validatedCur = sqliteSchema.parse(cur);
21178
- const squashedPrev = squashSqliteScheme(validatedPrev);
21179
- const squashedCur = squashSqliteScheme(validatedCur);
21180
- const sql = await prepareSQL(squashedPrev, squashedCur, "sqlite");
21181
- writeResult(cur, sql, outFolder);
22704
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21182
22705
  } catch (e) {
21183
22706
  console.error(e);
21184
22707
  }
21185
22708
  };
21186
- prepareAndMigrateMySql = async (config) => {
22709
+ prepareAndMigrateSqlite = async (config) => {
21187
22710
  const outFolder = config.out;
21188
22711
  const schemaPath = config.schema;
21189
22712
  try {
21190
- const { migrationFolders } = prepareMigrationFolder(outFolder, "mysql");
21191
- const { prev, cur } = prepareMySqlMigrationSnapshot(
21192
- migrationFolders,
21193
- outFolder,
21194
- schemaPath
21195
- );
21196
- const validatedPrev = mysqlSchema.parse(prev);
21197
- const validatedCur = mysqlSchema.parse(cur);
21198
- const squashedPrev = squashMysqlScheme(validatedPrev);
21199
- const squashedCur = squashMysqlScheme(validatedCur);
21200
- const sql = await prepareSQL(squashedPrev, squashedCur, "mysql");
21201
- writeResult(cur, sql, outFolder);
22713
+ assertV1OutFolder(outFolder, "sqlite");
22714
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "sqlite");
22715
+ const { prev, cur } = prepareSqliteMigrationSnapshot(snapshots, schemaPath);
22716
+ const validatedPrev = sqliteSchema.parse(prev);
22717
+ const validatedCur = sqliteSchema.parse(cur);
22718
+ const squashedPrev = squashSqliteScheme(validatedPrev);
22719
+ const squashedCur = squashSqliteScheme(validatedCur);
22720
+ const { sql, _meta } = await prepareSQL(squashedPrev, squashedCur, "mysql");
22721
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21202
22722
  } catch (e) {
21203
22723
  console.error(e);
21204
22724
  }
21205
22725
  };
21206
22726
  prepareSQL = async (prev, cur, dialect6) => {
21207
- const schemasResolver = async (input) => {
22727
+ const schemasResolver2 = async (input) => {
21208
22728
  try {
21209
22729
  const { created, deleted, renamed } = await promptSchemasConflict(
21210
22730
  input.created,
@@ -21216,7 +22736,7 @@ var init_migrate = __esm({
21216
22736
  throw e;
21217
22737
  }
21218
22738
  };
21219
- const tablesResolver = async (input) => {
22739
+ const tablesResolver2 = async (input) => {
21220
22740
  try {
21221
22741
  const { created, deleted, renamed } = await promptTablesConflict(
21222
22742
  input.created,
@@ -21228,7 +22748,7 @@ var init_migrate = __esm({
21228
22748
  throw e;
21229
22749
  }
21230
22750
  };
21231
- const columnsResolver = async (input) => {
22751
+ const columnsResolver2 = async (input) => {
21232
22752
  const result = await promptColumnsConflicts(
21233
22753
  input.tableName,
21234
22754
  input.created,
@@ -21245,9 +22765,9 @@ var init_migrate = __esm({
21245
22765
  prev,
21246
22766
  cur,
21247
22767
  dialect6,
21248
- schemasResolver,
21249
- tablesResolver,
21250
- columnsResolver
22768
+ schemasResolver2,
22769
+ tablesResolver2,
22770
+ columnsResolver2
21251
22771
  );
21252
22772
  };
21253
22773
  promptColumnsConflicts = async (tableName, newColumns, missingColumns) => {
@@ -21382,24 +22902,34 @@ var init_migrate = __esm({
21382
22902
  result.deleted.push(...leftMissing);
21383
22903
  return result;
21384
22904
  };
21385
- writeResult = (cur, sql, outFolder) => {
22905
+ writeResult = (cur, sql, idx, journal, _meta, outFolder) => {
21386
22906
  console.log(schema(cur));
21387
22907
  if (sql.length === 0) {
21388
22908
  console.log("No schema changes, nothing to migrate \u{1F634}");
21389
22909
  return;
21390
22910
  }
22911
+ const { prefix, tag } = prepareMigrationMetadata(idx);
21391
22912
  const toSave = JSON.parse(JSON.stringify(cur));
21392
- const folderName = prepareSnapshotFolderName();
21393
- const migrationFolderPath = `./${outFolder}/${folderName}`;
21394
- import_fs4.default.mkdirSync(migrationFolderPath);
22913
+ toSave["_meta"] = _meta;
22914
+ const metaFolderPath = (0, import_path3.join)(outFolder, "meta");
22915
+ const metaJournal = (0, import_path3.join)(metaFolderPath, "_journal.json");
21395
22916
  import_fs4.default.writeFileSync(
21396
- `${migrationFolderPath}/snapshot.json`,
22917
+ (0, import_path3.join)(metaFolderPath, `${prefix}_snapshot.json`),
21397
22918
  JSON.stringify(toSave, null, 2)
21398
22919
  );
21399
- import_fs4.default.writeFileSync(`${migrationFolderPath}/migration.sql`, sql);
21400
- console.log(
21401
- source_default.bold.green("Done:"),
21402
- import_path2.default.join(`${migrationFolderPath}/migration.sql`)
22920
+ journal.entries.push({
22921
+ idx,
22922
+ when: +new Date(),
22923
+ tag
22924
+ });
22925
+ import_fs4.default.writeFileSync(metaJournal, JSON.stringify(journal, null, 2));
22926
+ import_fs4.default.writeFileSync(`${outFolder}/${tag}.sql`, sql);
22927
+ (0, import_hanji2.render)(
22928
+ `[${source_default.green(
22929
+ "\u2713"
22930
+ )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(
22931
+ import_path3.default.join(`${outFolder}/${tag}.sql`)
22932
+ )} \u{1F680}`
21403
22933
  );
21404
22934
  };
21405
22935
  prepareSnapshotFolderName = () => {
@@ -21436,6 +22966,9 @@ var init_utils2 = __esm({
21436
22966
  return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
21437
22967
  });
21438
22968
  };
22969
+ Array.prototype.random = function() {
22970
+ return this[~~(Math.random() * this.length)];
22971
+ };
21439
22972
  }
21440
22973
  });
21441
22974
 
@@ -26298,14 +27831,14 @@ var {
26298
27831
  } = import_index.default;
26299
27832
 
26300
27833
  // src/cli/index.ts
26301
- var import_fs8 = __toESM(require("fs"));
27834
+ var import_fs9 = __toESM(require("fs"));
26302
27835
  init_lib();
26303
27836
 
26304
27837
  // src/cli/commands/check.ts
26305
27838
  init_utils();
26306
27839
  var checkHandler = (out, dialect6) => {
26307
- const migrationFolders = prepareOutFolders(out);
26308
- const report = validateWithReport(out, migrationFolders, dialect6);
27840
+ const { snapshots } = prepareOutFolder(out, dialect6);
27841
+ const report = validateWithReport(snapshots, dialect6);
26309
27842
  if (report.nonLatest.length > 0) {
26310
27843
  console.log(
26311
27844
  report.nonLatest.map((it) => {
@@ -26341,7 +27874,7 @@ var checkHandler = (out, dialect6) => {
26341
27874
  // src/cli/index.ts
26342
27875
  var import_hanji4 = __toESM(require_hanji());
26343
27876
  init_views();
26344
- var import_path6 = __toESM(require("path"));
27877
+ var import_path8 = __toESM(require("path"));
26345
27878
 
26346
27879
  // src/cli/utils.ts
26347
27880
  init_views();
@@ -26388,7 +27921,7 @@ init_source();
26388
27921
  // package.json
26389
27922
  var package_default = {
26390
27923
  name: "drizzle-kit",
26391
- version: "0.16.8",
27924
+ version: "0.16.9",
26392
27925
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
26393
27926
  author: "Alex Blokh <aleksandrblokh@gmail.com>",
26394
27927
  license: "MIT",
@@ -26466,13 +27999,15 @@ init_utils();
26466
27999
  init_source();
26467
28000
  var import_crypto2 = require("crypto");
26468
28001
  var import_fs5 = require("fs");
26469
- var import_path3 = __toESM(require("path"));
28002
+ var import_path4 = __toESM(require("path"));
26470
28003
  init_global();
26471
28004
  init_pgSchema();
26472
28005
  init_utils();
26473
28006
  var upPgHandler = (out) => {
26474
- const migrationFolders = prepareOutFolders(out);
26475
- const report = validateWithReport(out, migrationFolders, "pg");
28007
+ };
28008
+ var upPgHandlerV4 = (out) => {
28009
+ const { snapshots } = prepareOutFolder(out, "pg");
28010
+ const report = validateWithReport(snapshots, "pg");
26476
28011
  let prevId = originUUID;
26477
28012
  report.nonLatest.map((it) => ({
26478
28013
  folder: it,
@@ -26482,10 +28017,10 @@ var upPgHandler = (out) => {
26482
28017
  const result = updateToLatest(it.raw, prevId);
26483
28018
  prevId = result.id;
26484
28019
  console.log(
26485
- `[${source_default.green("\u2713")}] ${import_path3.default.join(out, folder, "snapshot.json")}`
28020
+ `[${source_default.green("\u2713")}] ${import_path4.default.join(out, folder, "snapshot.json")}`
26486
28021
  );
26487
28022
  (0, import_fs5.writeFileSync)(
26488
- import_path3.default.join(out, folder, "snapshot.json"),
28023
+ import_path4.default.join(out, folder, "snapshot.json"),
26489
28024
  JSON.stringify(result, null, 2)
26490
28025
  );
26491
28026
  });
@@ -26655,12 +28190,12 @@ var update3to4 = (json) => {
26655
28190
  // src/cli/commands/sqliteUp.ts
26656
28191
  init_source();
26657
28192
  var import_fs6 = __toESM(require("fs"));
26658
- var import_path4 = __toESM(require("path"));
28193
+ var import_path5 = __toESM(require("path"));
26659
28194
  init_sqliteSchema();
26660
28195
  init_utils();
26661
28196
  var upSqliteHandler = (out) => {
26662
- const migrationFolders = prepareOutFolders(out);
26663
- const report = validateWithReport(out, migrationFolders, "sqlite");
28197
+ const { snapshots } = prepareOutFolder(out, "sqlite");
28198
+ const report = validateWithReport(snapshots, "sqlite");
26664
28199
  report.nonLatest.map((it) => ({
26665
28200
  folder: it,
26666
28201
  raw: report.rawMap[it]
@@ -26668,10 +28203,10 @@ var upSqliteHandler = (out) => {
26668
28203
  const folder = it.folder;
26669
28204
  const result = updateToLatest2(it.raw);
26670
28205
  console.log(
26671
- `[${source_default.green("\u2713")}] ${import_path4.default.join(out, folder, "snapshot.json")}`
28206
+ `[${source_default.green("\u2713")}] ${import_path5.default.join(out, folder, "snapshot.json")}`
26672
28207
  );
26673
28208
  import_fs6.default.writeFileSync(
26674
- import_path4.default.join(out, folder, "snapshot.json"),
28209
+ import_path5.default.join(out, folder, "snapshot.json"),
26675
28210
  JSON.stringify(result, null, 2)
26676
28211
  );
26677
28212
  });
@@ -26703,12 +28238,12 @@ var updateV3toV4 = (old) => {
26703
28238
  // src/cli/commands/mysqlUp.ts
26704
28239
  init_source();
26705
28240
  var import_fs7 = __toESM(require("fs"));
26706
- var import_path5 = __toESM(require("path"));
28241
+ var import_path6 = __toESM(require("path"));
26707
28242
  init_mysqlSchema();
26708
28243
  init_utils();
26709
28244
  var upMysqlHandler = (out) => {
26710
- const migrationFolders = prepareOutFolders(out);
26711
- const report = validateWithReport(out, migrationFolders, "mysql");
28245
+ const { snapshots } = prepareOutFolder(out, "mysql");
28246
+ const report = validateWithReport(snapshots, "mysql");
26712
28247
  report.nonLatest.map((it) => ({
26713
28248
  folder: it,
26714
28249
  raw: report.rawMap[it]
@@ -26716,10 +28251,10 @@ var upMysqlHandler = (out) => {
26716
28251
  const folder = it.folder;
26717
28252
  const result = updateToLatest3(it.raw);
26718
28253
  console.log(
26719
- `[${source_default.green("\u2713")}] ${import_path5.default.join(out, folder, "snapshot.json")}`
28254
+ `[${source_default.green("\u2713")}] ${import_path6.default.join(out, folder, "snapshot.json")}`
26720
28255
  );
26721
28256
  import_fs7.default.writeFileSync(
26722
- import_path5.default.join(out, folder, "snapshot.json"),
28257
+ import_path6.default.join(out, folder, "snapshot.json"),
26723
28258
  JSON.stringify(result, null, 2)
26724
28259
  );
26725
28260
  });
@@ -26742,6 +28277,273 @@ var updateV3toV42 = (old) => {
26742
28277
  };
26743
28278
  };
26744
28279
 
28280
+ // src/cli/commands/upFolders.ts
28281
+ var import_fs8 = require("fs");
28282
+ var import_path7 = require("path");
28283
+ init_jsonDiffer();
28284
+ init_snapshotsDiffer();
28285
+ init_utils();
28286
+ init_words();
28287
+ init_pgSchema();
28288
+ var schemasResolver = (missingSchemas, newSchemas, sql) => {
28289
+ try {
28290
+ if (missingSchemas.length === 0 || newSchemas.length === 0) {
28291
+ return { created: newSchemas, renamed: [], deleted: missingSchemas };
28292
+ }
28293
+ const result = { created: [], renamed: [], deleted: [] };
28294
+ let index4 = 0;
28295
+ let leftMissing = [...missingSchemas];
28296
+ do {
28297
+ const created = newSchemas[index4];
28298
+ index4 += 1;
28299
+ const possibleRenames = leftMissing.map((it) => {
28300
+ return {
28301
+ value: it,
28302
+ sql: `ALTER SCHEMA "${it.name}" RENAME TO "${created.name}"`
28303
+ };
28304
+ });
28305
+ const renames = possibleRenames.filter((it) => {
28306
+ return sql.includes(it.sql);
28307
+ });
28308
+ if (renames.length > 1)
28309
+ throw new Error("wtf");
28310
+ if (renames.length === 0) {
28311
+ result.created.push(created);
28312
+ } else {
28313
+ const it = renames[0];
28314
+ result.renamed.push({ from: it.value, to: created });
28315
+ delete leftMissing[leftMissing.indexOf(it.value)];
28316
+ leftMissing = leftMissing.filter(Boolean);
28317
+ }
28318
+ } while (index4 < newSchemas.length);
28319
+ result.deleted.push(...leftMissing);
28320
+ return result;
28321
+ } catch (e) {
28322
+ console.error(e);
28323
+ throw e;
28324
+ }
28325
+ };
28326
+ var tablesResolver = (missingTables, newTables, sql) => {
28327
+ try {
28328
+ if (missingTables.length === 0 || newTables.length === 0) {
28329
+ return { created: newTables, renamed: [], deleted: missingTables };
28330
+ }
28331
+ const result = { created: [], renamed: [], deleted: [] };
28332
+ let index4 = 0;
28333
+ let leftMissing = [...missingTables];
28334
+ do {
28335
+ const created = newTables[index4];
28336
+ index4 += 1;
28337
+ const possibleRenames = leftMissing.map((it) => {
28338
+ const schemaPrefix = created.schema ? `"${created.schema}".` : "";
28339
+ return {
28340
+ value: it,
28341
+ sql: `ALTER TABLE ${schemaPrefix}"${it.name}" RENAME TO ${schemaPrefix}"${created.name}"`
28342
+ };
28343
+ });
28344
+ const renames = possibleRenames.filter((it) => {
28345
+ return sql.includes(it.sql);
28346
+ });
28347
+ if (renames.length > 1)
28348
+ throw new Error("wtf");
28349
+ if (renames.length === 0) {
28350
+ result.created.push(created);
28351
+ } else {
28352
+ const it = renames[0];
28353
+ result.renamed.push({ from: it.value, to: created });
28354
+ delete leftMissing[leftMissing.indexOf(it.value)];
28355
+ leftMissing = leftMissing.filter(Boolean);
28356
+ }
28357
+ } while (index4 < newTables.length);
28358
+ result.deleted.push(...leftMissing);
28359
+ return result;
28360
+ } catch (e) {
28361
+ console.error(e);
28362
+ throw e;
28363
+ }
28364
+ };
28365
+ var columnsResolver = (tableName, missingColumns, newColumns, sql) => {
28366
+ try {
28367
+ if (missingColumns.length === 0 || newColumns.length === 0) {
28368
+ return { created: newColumns, renamed: [], deleted: missingColumns };
28369
+ }
28370
+ const result = { created: [], renamed: [], deleted: [] };
28371
+ let index4 = 0;
28372
+ let leftMissing = [...missingColumns];
28373
+ do {
28374
+ const created = newColumns[index4];
28375
+ index4 += 1;
28376
+ const possibleRenames = leftMissing.map((it) => {
28377
+ return {
28378
+ value: it,
28379
+ sql: `ALTER TABLE ${tableName} RENAME COLUMN "${it.name}" TO "${created.name}"`
28380
+ };
28381
+ });
28382
+ const renames = possibleRenames.filter((it) => {
28383
+ return sql.includes(it.sql);
28384
+ });
28385
+ if (renames.length > 1)
28386
+ throw new Error("wtf");
28387
+ if (renames.length === 0) {
28388
+ result.created.push(created);
28389
+ } else {
28390
+ const it = renames[0];
28391
+ result.renamed.push({ from: it.value, to: created });
28392
+ delete leftMissing[leftMissing.indexOf(it.value)];
28393
+ leftMissing = leftMissing.filter(Boolean);
28394
+ }
28395
+ } while (index4 < newColumns.length);
28396
+ result.deleted.push(...leftMissing);
28397
+ return result;
28398
+ } catch (e) {
28399
+ console.error(e);
28400
+ throw e;
28401
+ }
28402
+ };
28403
+ var fullfill = (prev, cur, sql) => {
28404
+ const b = pgSchemaV4.parse(cur);
28405
+ if (!prev) {
28406
+ return {
28407
+ version: "5",
28408
+ dialect: b.dialect,
28409
+ id: b.id,
28410
+ prevId: b.prevId,
28411
+ tables: b.tables,
28412
+ enums: b.enums,
28413
+ schemas: b.schemas,
28414
+ _meta: {
28415
+ schemas: {},
28416
+ tables: {},
28417
+ columns: {}
28418
+ }
28419
+ };
28420
+ }
28421
+ const a = pgSchemaV4.parse(prev);
28422
+ const json1 = squashPgScheme(a);
28423
+ const json2 = squashPgScheme(b);
28424
+ const diffResult = applyJsonDiff(json1, json2);
28425
+ const parseResult = diffResultScheme.safeParse(diffResult);
28426
+ if (!parseResult.success) {
28427
+ parseResult.error.errors.forEach((it) => {
28428
+ console.error(it);
28429
+ });
28430
+ throw new Error();
28431
+ }
28432
+ const typedResult = parseResult.data;
28433
+ const { renamed: renamedSchemas } = schemasResolver(
28434
+ typedResult.deletedSchemas.map((it) => ({ name: it })),
28435
+ typedResult.addedSchemas.map((it) => ({ name: it })),
28436
+ sql
28437
+ );
28438
+ const { renamed } = tablesResolver(
28439
+ typedResult.deletedTables,
28440
+ typedResult.addedTables,
28441
+ sql
28442
+ );
28443
+ const renamedWithAlternations = Object.values(
28444
+ alteredTableScheme.array().parse(diffForRenamedTables(renamed))
28445
+ );
28446
+ const allAltered = typedResult.alteredTablesWithColumns.concat(
28447
+ renamedWithAlternations
28448
+ );
28449
+ const rSchemas = renamedSchemas.map((it) => ({ from: it.from.name, to: it.to.name }));
28450
+ const rTables = renamed.map((it) => {
28451
+ return { from: it.from, to: it.to };
28452
+ });
28453
+ const rColumns = allAltered.map((table4) => {
28454
+ const name = table4.name;
28455
+ const result = columnsResolver(name, table4.deleted, table4.added, sql);
28456
+ const tableName = table4.name;
28457
+ const schema4 = typeof table4.schema === "string" ? table4.schema : "";
28458
+ return result.renamed.map((it) => {
28459
+ return {
28460
+ from: { schema: schema4, table: tableName, column: it.from.name },
28461
+ to: { schema: schema4, table: tableName, column: it.to.name }
28462
+ };
28463
+ });
28464
+ }).flat();
28465
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
28466
+ const bpatched = {
28467
+ version: "5",
28468
+ dialect: b.dialect,
28469
+ id: b.id,
28470
+ prevId: b.prevId,
28471
+ tables: b.tables,
28472
+ enums: b.enums,
28473
+ schemas: b.schemas,
28474
+ _meta
28475
+ };
28476
+ pgSchema.parse(bpatched);
28477
+ return {
28478
+ version: "5",
28479
+ dialect: b.dialect,
28480
+ id: b.id,
28481
+ prevId: b.prevId,
28482
+ tables: b.tables,
28483
+ enums: b.enums,
28484
+ schemas: b.schemas,
28485
+ _meta
28486
+ };
28487
+ };
28488
+ var upgradeFolders = (dialect6, out) => {
28489
+ const oldMigrationFolders = (0, import_fs8.readdirSync)(out).filter(
28490
+ (it) => it.length === 14 && /^\d+$/.test(it)
28491
+ );
28492
+ oldMigrationFolders.sort();
28493
+ const res = oldMigrationFolders.reduce(
28494
+ (res2, it) => {
28495
+ const date = new Date();
28496
+ date.setUTCFullYear(Number(it.substring(0, 4)));
28497
+ date.setUTCMonth(Number(it.substring(4, 6)));
28498
+ date.setUTCDate(Number(it.substring(6, 8)));
28499
+ date.setUTCHours(Number(it.substring(8, 10)));
28500
+ date.setUTCMinutes(Number(it.substring(10, 12)));
28501
+ date.setUTCSeconds(Number(it.substring(12, 14)));
28502
+ const path5 = (0, import_path7.join)(out, it);
28503
+ const pathJson = (0, import_path7.join)(out, it, "snapshot.json");
28504
+ const pathSQL = (0, import_path7.join)(out, it, "migration.sql");
28505
+ const snapshot = JSON.parse((0, import_fs8.readFileSync)(pathJson).toString());
28506
+ const sql = (0, import_fs8.readFileSync)(pathSQL).toString();
28507
+ res2.entries.push({
28508
+ idx: res2.idx,
28509
+ json: snapshot,
28510
+ date,
28511
+ sql,
28512
+ path: path5
28513
+ });
28514
+ res2.idx += 1;
28515
+ return res2;
28516
+ },
28517
+ {
28518
+ entries: [],
28519
+ idx: 0
28520
+ }
28521
+ );
28522
+ const metaFolder = (0, import_path7.join)(`${out}`, "meta");
28523
+ if (!(0, import_fs8.existsSync)(metaFolder)) {
28524
+ (0, import_fs8.mkdirSync)(metaFolder, { recursive: true });
28525
+ }
28526
+ const journal = dryJournal(dialect6);
28527
+ let prev = void 0;
28528
+ res.entries.forEach((it) => {
28529
+ const { prefix, suffix, tag } = prepareMigrationMetadata(it.idx);
28530
+ journal.entries.push({
28531
+ idx: it.idx,
28532
+ when: +it.date,
28533
+ tag
28534
+ });
28535
+ const patchedJSON = fullfill(prev, it.json, it.sql);
28536
+ (0, import_fs8.writeFileSync)(
28537
+ (0, import_path7.join)(`${out}`, "meta", `${prefix}_snapshot.json`),
28538
+ JSON.stringify(patchedJSON)
28539
+ );
28540
+ (0, import_fs8.writeFileSync)((0, import_path7.join)(`${out}`, `${tag}.sql`), it.sql);
28541
+ (0, import_fs8.rmSync)(it.path, { recursive: true });
28542
+ prev = it.json;
28543
+ });
28544
+ (0, import_fs8.writeFileSync)((0, import_path7.join)(metaFolder, "_journal.json"), JSON.stringify(journal));
28545
+ };
28546
+
26745
28547
  // src/cli/index.ts
26746
28548
  var printVersions = () => {
26747
28549
  console.log(`${source_default.gray(versions())}
@@ -26750,13 +28552,13 @@ var printVersions = () => {
26750
28552
  var assertEitherConfigOrOut = (config, out) => {
26751
28553
  if (out)
26752
28554
  return out;
26753
- if (!(0, import_fs8.existsSync)(import_path6.default.join(import_path6.default.resolve(config)))) {
28555
+ if (!(0, import_fs9.existsSync)(import_path8.default.join(import_path8.default.resolve(config)))) {
26754
28556
  console.log(`${config} file does not exist`);
26755
28557
  process.exit(1);
26756
28558
  }
26757
28559
  console.log(`Reading ${config}`);
26758
28560
  const drizzleConfig = JSON.parse(
26759
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(config))).toString()
28561
+ import_fs9.default.readFileSync(import_path8.default.join(import_path8.default.resolve(config))).toString()
26760
28562
  );
26761
28563
  return drizzleConfig.out;
26762
28564
  };
@@ -26826,7 +28628,7 @@ var prepareGenerateConfig = (options) => {
26826
28628
  if (!(schema4 || out)) {
26827
28629
  const path5 = config != null ? config : "drizzle.config.json";
26828
28630
  const drizzleConfig = JSON.parse(
26829
- import_fs8.default.readFileSync(import_path6.default.join(import_path6.default.resolve(path5))).toString()
28631
+ import_fs9.default.readFileSync(import_path8.default.join(import_path8.default.resolve(path5))).toString()
26830
28632
  );
26831
28633
  return drizzleConfig;
26832
28634
  }
@@ -26874,6 +28676,8 @@ var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).op
26874
28676
  process.exit(0);
26875
28677
  }
26876
28678
  assertPackages("drizzle-orm");
28679
+ upPgHandlerV4(out);
28680
+ upgradeFolders("pg", out);
26877
28681
  upPgHandler(out);
26878
28682
  });
26879
28683
  var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
@@ -26921,29 +28725,18 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
26921
28725
  console.log("Missing required params");
26922
28726
  return;
26923
28727
  }
26924
- const migrationFolders = prepareOutFolders(res.data.out);
26925
- const folderName = prepareSnapshotFolderName();
26926
- const migrationFolderPath = `./${res.data.out}/${folderName}`;
28728
+ const { snapshots, journal } = prepareOutFolder(res.data.out, "pg");
26927
28729
  const { schema: schema4, ts } = await pgIntrospect2(res.data);
26928
- const schemaFile = import_path6.default.join(res.data.out, "schema.ts");
26929
- (0, import_fs8.writeFileSync)(schemaFile, ts);
28730
+ const schemaFile = import_path8.default.join(res.data.out, "schema.ts");
28731
+ (0, import_fs9.writeFileSync)(schemaFile, ts);
26930
28732
  console.log();
26931
- if (migrationFolders.length === 0) {
26932
- import_fs8.default.mkdirSync(migrationFolderPath);
26933
- const snapshotFile = import_path6.default.join(migrationFolderPath, "snapshot.json");
26934
- (0, import_fs8.writeFileSync)(snapshotFile, JSON.stringify(schema4));
26935
- const sql = await prepareSQL(
28733
+ if (snapshots.length === 0) {
28734
+ const { sql, _meta } = await prepareSQL(
26936
28735
  squashPgScheme(dryPg),
26937
28736
  squashPgScheme(schema4),
26938
28737
  "pg"
26939
28738
  );
26940
- const sqlFile = import_path6.default.join(migrationFolderPath, "migration.sql");
26941
- (0, import_fs8.writeFileSync)(sqlFile, sql);
26942
- (0, import_hanji4.render)(
26943
- `[${source_default.green(
26944
- "\u2713"
26945
- )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(sqlFile)} \u{1F680}`
26946
- );
28739
+ writeResult(schema4, sql, 0, journal, _meta, res.data.out);
26947
28740
  } else {
26948
28741
  (0, import_hanji4.render)(
26949
28742
  `[${source_default.blue(