drizzle-kit 0.16.7 → 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 +2056 -258
  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
  };
@@ -13291,7 +13403,7 @@ var init_migrationPreparator = __esm({
13291
13403
  });
13292
13404
 
13293
13405
  // src/sqlgenerator.ts
13294
- var pgNativeTypes, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, convertors, fromJson;
13406
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, DropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableAlterColumnDropDefaultConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MysqlCreateSchemaConvertor, MysqlDropSchemaConvertor, MysqlAlterTableSetSchemaConvertor, MysqlAlterTableSetNewSchemaConvertor, MysqlAlterTableRemoveFromSchemaConvertor, convertors, fromJson;
13295
13407
  var init_sqlgenerator = __esm({
13296
13408
  "src/sqlgenerator.ts"() {
13297
13409
  init_mysqlSchema();
@@ -13325,6 +13437,11 @@ var init_sqlgenerator = __esm({
13325
13437
  "bigserial",
13326
13438
  "double precision"
13327
13439
  ]);
13440
+ isPgNativeType = (it) => {
13441
+ if (pgNativeTypes.has(it))
13442
+ return true;
13443
+ return it.startsWith("varchar(") || it.startsWith("numeric(");
13444
+ };
13328
13445
  Convertor = class {
13329
13446
  };
13330
13447
  PgCreateTableConvertor = class extends Convertor {
@@ -13342,7 +13459,7 @@ var init_sqlgenerator = __esm({
13342
13459
  const primaryKeyStatement = column5.primaryKey ? "PRIMARY KEY" : "";
13343
13460
  const notNullStatement = column5.notNull ? "NOT NULL" : "";
13344
13461
  const defaultStatement = column5.default !== void 0 ? `DEFAULT ${column5.default}` : "";
13345
- const type = pgNativeTypes.has(column5.type) ? column5.type : `"${column5.type}"`;
13462
+ const type = isPgNativeType(column5.type) ? column5.type : `"${column5.type}"`;
13346
13463
  statement += " " + `"${column5.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
13347
13464
  statement += (i === columns.length - 1 ? "" : ",") + "\n";
13348
13465
  }
@@ -13472,7 +13589,7 @@ var init_sqlgenerator = __esm({
13472
13589
  return statement.type === "rename_table" && dialect6 === "pg";
13473
13590
  }
13474
13591
  convert(statement) {
13475
- const { tableNameFrom, tableNameTo, fromSchema: schema4 } = statement;
13592
+ const { tableNameFrom, tableNameTo, toSchema: schema4 } = statement;
13476
13593
  const from = schema4 ? `"${schema4}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
13477
13594
  const to = schema4 ? `"${schema4}"."${tableNameTo}"` : `"${tableNameTo}"`;
13478
13595
  return `ALTER TABLE ${from} RENAME TO ${to};`;
@@ -13561,7 +13678,7 @@ var init_sqlgenerator = __esm({
13561
13678
  const { tableName, column: column5 } = statement;
13562
13679
  const { name, type, notNull } = column5;
13563
13680
  const defaultStatement = `${column5.default !== void 0 ? `DEFAULT ${column5.default}` : ""}`;
13564
- const fixedType = pgNativeTypes.has(column5.type) ? column5.type : `"${column5.type}"`;
13681
+ const fixedType = isPgNativeType(column5.type) ? column5.type : `"${column5.type}"`;
13565
13682
  const notNullStatement = `${notNull ? "NOT NULL" : ""}`;
13566
13683
  return `ALTER TABLE ${tableName} ADD COLUMN "${name}" ${fixedType} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim() + ";";
13567
13684
  }
@@ -18836,7 +18953,7 @@ var require_bare = __commonJS({
18836
18953
  var sgr = require_sgr();
18837
18954
  var supportsColor2 = require_supports_color2();
18838
18955
  var mods = sgr.mods;
18839
- var join = Array.prototype.join;
18956
+ var join4 = Array.prototype.join;
18840
18957
  var defineProperty = Object.defineProperty;
18841
18958
  var max = Math.max;
18842
18959
  var min = Math.min;
@@ -18890,7 +19007,7 @@ var require_bare = __commonJS({
18890
19007
  getFn = function() {
18891
19008
  return setPrototypeOf(
18892
19009
  function self2() {
18893
- 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);
18894
19011
  forEach(
18895
19012
  conf,
18896
19013
  function(mod, key) {
@@ -20321,7 +20438,7 @@ function diffForRenamedTable(t1, t2) {
20321
20438
  t1.name = t2.name;
20322
20439
  const diffed = (0, import_json_diff.diff)(t1, t2) || {};
20323
20440
  diffed.name = t2.name;
20324
- return findAlternationsInTable(diffed);
20441
+ return findAlternationsInTable(diffed, t2.schema);
20325
20442
  }
20326
20443
  function diffForRenamedColumn(t1, t2) {
20327
20444
  const renamed = { ...t1, name: t2.name };
@@ -20335,6 +20452,10 @@ function applyJsonDiff(json1, json2) {
20335
20452
  json2 = JSON.parse(JSON.stringify(json2));
20336
20453
  const rawDiff = (0, import_json_diff.diff)(json1, json2);
20337
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
+ }, {});
20338
20459
  if (!difference)
20339
20460
  return {};
20340
20461
  difference.tables = (_a = difference.tables) != null ? _a : {};
@@ -20364,7 +20485,7 @@ function applyJsonDiff(json1, json2) {
20364
20485
  const schemasEntries = Object.entries(difference.schemas);
20365
20486
  const addedSchemas = schemasEntries.filter((it) => it[0].endsWith("__added")).map((it) => it[1]);
20366
20487
  const deletedSchemas = schemasEntries.filter((it) => it[0].endsWith("__deleted")).map((it) => it[1]);
20367
- const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4));
20488
+ const alteredTablesWithColumns = alteredTables.map((table4) => findAlternationsInTable(table4, tableToSchema[table4.name]));
20368
20489
  return {
20369
20490
  addedTables,
20370
20491
  deletedTables,
@@ -20381,10 +20502,13 @@ var init_jsonDiffer = __esm({
20381
20502
  "src/jsonDiffer.js"() {
20382
20503
  import_json_diff = __toESM(require_lib());
20383
20504
  "use-strict";
20384
- findAlternationsInTable = (table4) => {
20505
+ findAlternationsInTable = (table4, tableSchema) => {
20385
20506
  var _a;
20386
20507
  const columns = (_a = table4.columns) != null ? _a : {};
20387
- let schema4;
20508
+ let schema4 = {
20509
+ type: "none",
20510
+ value: tableSchema
20511
+ };
20388
20512
  if ("schema" in table4) {
20389
20513
  if (table4.schema.__new) {
20390
20514
  schema4 = { type: "changed", old: table4.schema.__old, new: table4.schema.__new };
@@ -20521,7 +20645,8 @@ var init_jsonStatements = __esm({
20521
20645
  prepareDropTableJson = (table4) => {
20522
20646
  return {
20523
20647
  type: "drop_table",
20524
- tableName: table4.name
20648
+ tableName: table4.name,
20649
+ schema: table4.schema
20525
20650
  };
20526
20651
  };
20527
20652
  prepareRenameTableJson = (tableFrom, tableTo) => {
@@ -20574,20 +20699,21 @@ var init_jsonStatements = __esm({
20574
20699
  };
20575
20700
  });
20576
20701
  };
20577
- prepareRenameColumns = (tableName, pairs) => {
20702
+ prepareRenameColumns = (tableName, schema4, pairs) => {
20578
20703
  return pairs.map((it) => {
20579
20704
  return {
20580
20705
  type: "alter_table_rename_column",
20581
20706
  tableName,
20582
20707
  oldColumnName: it.from.name,
20583
- newColumnName: it.to.name
20708
+ newColumnName: it.to.name,
20709
+ schema: schema4
20584
20710
  };
20585
20711
  });
20586
20712
  };
20587
- prepareAlterTableColumnsJson = (tableName, deleted, added, altered, addedFk, dialect6) => {
20713
+ prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, dialect6) => {
20588
20714
  const addColumns = [];
20589
- const dropColumns = _prepareDropColumns(tableName, deleted);
20590
- const alterColumns = _prepareAlterColumns(tableName, altered);
20715
+ const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
20716
+ const alterColumns = _prepareAlterColumns(tableName, schema4, altered);
20591
20717
  if (dialect6 === "sqlite") {
20592
20718
  let jsonCreateFKStatements = Object.values(addedFk);
20593
20719
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -20597,25 +20723,27 @@ var init_jsonStatements = __esm({
20597
20723
  );
20598
20724
  addColumns.push(...sqliteAddColumns);
20599
20725
  } else {
20600
- addColumns.push(..._prepareAddColumns(tableName, added));
20726
+ addColumns.push(..._prepareAddColumns(tableName, schema4, added));
20601
20727
  }
20602
20728
  return { addColumns, dropColumns, alterColumns };
20603
20729
  };
20604
- _prepareDropColumns = (taleName, columns) => {
20730
+ _prepareDropColumns = (taleName, schema4, columns) => {
20605
20731
  return columns.map((it) => {
20606
20732
  return {
20607
20733
  type: "alter_table_drop_column",
20608
20734
  tableName: taleName,
20609
- columnName: it.name
20735
+ columnName: it.name,
20736
+ schema: schema4
20610
20737
  };
20611
20738
  });
20612
20739
  };
20613
- _prepareAddColumns = (tableName, columns) => {
20740
+ _prepareAddColumns = (tableName, schema4, columns) => {
20614
20741
  return columns.map((it) => {
20615
20742
  return {
20616
20743
  type: "alter_table_add_column",
20617
20744
  tableName,
20618
- column: it
20745
+ column: it,
20746
+ schema: schema4
20619
20747
  };
20620
20748
  });
20621
20749
  };
@@ -20635,7 +20763,7 @@ var init_jsonStatements = __esm({
20635
20763
  };
20636
20764
  });
20637
20765
  };
20638
- _prepareAlterColumns = (tableName, columns) => {
20766
+ _prepareAlterColumns = (tableName, schema4, columns) => {
20639
20767
  var _a, _b, _c, _d, _e, _f, _g;
20640
20768
  let statements = [];
20641
20769
  for (const column5 of columns) {
@@ -20645,7 +20773,8 @@ var init_jsonStatements = __esm({
20645
20773
  type: "alter_table_rename_column",
20646
20774
  tableName,
20647
20775
  oldColumnName: column5.name.old,
20648
- newColumnName: column5.name.new
20776
+ newColumnName: column5.name.new,
20777
+ schema: schema4
20649
20778
  });
20650
20779
  }
20651
20780
  if (((_a = column5.type) == null ? void 0 : _a.type) === "changed") {
@@ -20653,7 +20782,8 @@ var init_jsonStatements = __esm({
20653
20782
  type: "alter_table_alter_column_set_type",
20654
20783
  tableName,
20655
20784
  columnName,
20656
- newDataType: column5.type.new
20785
+ newDataType: column5.type.new,
20786
+ schema: schema4
20657
20787
  });
20658
20788
  }
20659
20789
  if (((_b = column5.default) == null ? void 0 : _b.type) === "added") {
@@ -20661,7 +20791,8 @@ var init_jsonStatements = __esm({
20661
20791
  type: "alter_table_alter_column_set_default",
20662
20792
  tableName,
20663
20793
  columnName,
20664
- newDefaultValue: column5.default.value
20794
+ newDefaultValue: column5.default.value,
20795
+ schema: schema4
20665
20796
  });
20666
20797
  }
20667
20798
  if (((_c = column5.default) == null ? void 0 : _c.type) === "changed") {
@@ -20669,21 +20800,24 @@ var init_jsonStatements = __esm({
20669
20800
  type: "alter_table_alter_column_set_default",
20670
20801
  tableName,
20671
20802
  columnName,
20672
- newDefaultValue: column5.default.new
20803
+ newDefaultValue: column5.default.new,
20804
+ schema: schema4
20673
20805
  });
20674
20806
  }
20675
20807
  if (((_d = column5.default) == null ? void 0 : _d.type) === "deleted") {
20676
20808
  statements.push({
20677
20809
  type: "alter_table_alter_column_drop_default",
20678
20810
  tableName,
20679
- columnName
20811
+ columnName,
20812
+ schema: schema4
20680
20813
  });
20681
20814
  }
20682
20815
  if (((_e = column5.notNull) == null ? void 0 : _e.type) === "added") {
20683
20816
  statements.push({
20684
20817
  type: "alter_table_alter_column_set_notnull",
20685
20818
  tableName,
20686
- columnName
20819
+ columnName,
20820
+ schema: schema4
20687
20821
  });
20688
20822
  }
20689
20823
  if (((_f = column5.notNull) == null ? void 0 : _f.type) === "changed") {
@@ -20691,62 +20825,69 @@ var init_jsonStatements = __esm({
20691
20825
  statements.push({
20692
20826
  type,
20693
20827
  tableName,
20694
- columnName
20828
+ columnName,
20829
+ schema: schema4
20695
20830
  });
20696
20831
  }
20697
20832
  if (((_g = column5.notNull) == null ? void 0 : _g.type) === "deleted") {
20698
20833
  statements.push({
20699
20834
  type: "alter_table_alter_column_drop_notnull",
20700
20835
  tableName,
20701
- columnName
20836
+ columnName,
20837
+ schema: schema4
20702
20838
  });
20703
20839
  }
20704
20840
  }
20705
20841
  return statements;
20706
20842
  };
20707
- prepareCreateIndexesJson = (tableName, indexes) => {
20843
+ prepareCreateIndexesJson = (tableName, schema4, indexes) => {
20708
20844
  return Object.values(indexes).map((indexData) => {
20709
20845
  return {
20710
20846
  type: "create_index",
20711
20847
  tableName,
20712
- data: indexData
20848
+ data: indexData,
20849
+ schema: schema4
20713
20850
  };
20714
20851
  });
20715
20852
  };
20716
- prepareCreateReferencesJson = (tableName, foreignKeys) => {
20853
+ prepareCreateReferencesJson = (tableName, schema4, foreignKeys) => {
20717
20854
  return Object.values(foreignKeys).map((fkData) => {
20718
20855
  return {
20719
20856
  type: "create_reference",
20720
20857
  tableName,
20721
- data: fkData
20858
+ data: fkData,
20859
+ schema: schema4
20722
20860
  };
20723
20861
  });
20724
20862
  };
20725
- prepareDropReferencesJson = (tableName, foreignKeys) => {
20863
+ prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
20726
20864
  return Object.values(foreignKeys).map((fkData) => {
20727
20865
  return {
20728
20866
  type: "delete_reference",
20729
20867
  tableName,
20730
- data: fkData
20868
+ data: fkData,
20869
+ schema: schema4
20731
20870
  };
20732
20871
  });
20733
20872
  };
20734
- prepareAlterReferencesJson = (tableName, foreignKeys) => {
20873
+ prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
20735
20874
  return Object.values(foreignKeys).map((fkData) => {
20736
20875
  return {
20737
20876
  type: "alter_reference",
20738
20877
  tableName,
20739
20878
  data: fkData.__new,
20740
- oldFkey: fkData.__old
20879
+ oldFkey: fkData.__old,
20880
+ schema: schema4
20741
20881
  };
20742
20882
  });
20743
20883
  };
20744
- prepareDropIndexesJson = (tableName, indexes) => {
20884
+ prepareDropIndexesJson = (tableName, schema4, indexes) => {
20745
20885
  return Object.values(indexes).map((indexData) => {
20746
20886
  return {
20747
20887
  type: "drop_index",
20748
20888
  tableName,
20749
- data: indexData
20889
+ data: indexData,
20890
+ schema: schema4
20750
20891
  };
20751
20892
  });
20752
20893
  };
@@ -20782,13 +20923,14 @@ var init_jsonStatements = __esm({
20782
20923
  });
20783
20924
 
20784
20925
  // src/snapshotsDiffer.ts
20785
- 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;
20786
20927
  var init_snapshotsDiffer = __esm({
20787
20928
  "src/snapshotsDiffer.ts"() {
20788
20929
  init_sqlgenerator();
20789
20930
  init_lib();
20790
20931
  init_jsonDiffer();
20791
20932
  init_jsonStatements();
20933
+ init_utils();
20792
20934
  makeChanged = (schema4) => {
20793
20935
  return objectType({
20794
20936
  type: enumType(["changed"]),
@@ -20809,20 +20951,53 @@ var init_snapshotsDiffer = __esm({
20809
20951
  makePatched = (schema4) => {
20810
20952
  return unionType([
20811
20953
  objectType({
20812
- type: enumType(["added"]),
20954
+ type: literalType("added"),
20813
20955
  value: schema4
20814
20956
  }),
20815
20957
  objectType({
20816
- type: enumType(["deleted"]),
20958
+ type: literalType("deleted"),
20817
20959
  value: schema4
20818
20960
  }),
20819
20961
  objectType({
20820
- 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"),
20821
20984
  old: schema4,
20822
20985
  new: schema4
20823
20986
  })
20824
20987
  ]);
20825
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
+ };
20826
21001
  columnSchema = objectType({
20827
21002
  name: stringType(),
20828
21003
  type: stringType(),
@@ -20835,7 +21010,7 @@ var init_snapshotsDiffer = __esm({
20835
21010
  alteredColumnSchema = objectType({
20836
21011
  name: makeSelfOrChanged(stringType()),
20837
21012
  type: makeChanged(stringType()).optional(),
20838
- default: makePatched(stringType()).optional(),
21013
+ default: makePatched(anyType()).optional(),
20839
21014
  notNull: makePatched(booleanType()).optional()
20840
21015
  }).strict();
20841
21016
  enumSchema2 = objectType({
@@ -20857,7 +21032,7 @@ var init_snapshotsDiffer = __esm({
20857
21032
  }).strict();
20858
21033
  alteredTableScheme = objectType({
20859
21034
  name: stringType(),
20860
- schema: makePatched(stringType()).optional(),
21035
+ schema: makeSelfOrPatched(stringType()),
20861
21036
  deleted: columnSchema.array(),
20862
21037
  added: columnSchema.array(),
20863
21038
  altered: alteredColumnSchema.array(),
@@ -20892,25 +21067,32 @@ var init_snapshotsDiffer = __esm({
20892
21067
  addedSchemas: stringType().array(),
20893
21068
  deletedSchemas: stringType().array()
20894
21069
  }).strict();
20895
- applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver, tablesResolver, columnsResolver) => {
21070
+ applySnapshotsDiff = async (json1, json2, dialect6, schemasResolver2, tablesResolver2, columnsResolver2) => {
20896
21071
  var _a, _b, _c, _d;
20897
21072
  const diffResult = applyJsonDiff(json1, json2);
20898
21073
  if (Object.keys(diffResult).length === 0) {
20899
- return "";
21074
+ return { statements: [], sql: "" };
20900
21075
  }
20901
21076
  const typedResult = diffResultScheme.parse(diffResult);
20902
21077
  const {
20903
21078
  created: createdSchemas,
20904
21079
  deleted: deletedSchemas,
20905
21080
  renamed: renamedSchemas
20906
- } = await schemasResolver({
21081
+ } = await schemasResolver2({
20907
21082
  created: typedResult.addedSchemas.map((it) => ({ name: it })),
20908
21083
  deleted: typedResult.deletedSchemas.map((it) => ({ name: it }))
20909
21084
  });
20910
- const { created, deleted, renamed } = await tablesResolver({
21085
+ const { created, deleted, renamed } = await tablesResolver2({
20911
21086
  created: typedResult.addedTables,
20912
21087
  deleted: typedResult.deletedTables
20913
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
+ });
20914
21096
  const jsonStatements = [];
20915
21097
  const jsonSQLiteCreateTables = created.map((it) => {
20916
21098
  return prepareSQLiteCreateTable(it);
@@ -20919,7 +21101,7 @@ var init_snapshotsDiffer = __esm({
20919
21101
  return prepareCreateTableJson(it);
20920
21102
  });
20921
21103
  const jsonCreateIndexesForCreatedTables = created.map((it) => {
20922
- return prepareCreateIndexesJson(it.name, it.indexes);
21104
+ return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
20923
21105
  }).flat();
20924
21106
  const jsonDropTables = deleted.map((it) => {
20925
21107
  return prepareDropTableJson(it);
@@ -20936,13 +21118,14 @@ var init_snapshotsDiffer = __esm({
20936
21118
  const jsonRenameColumnsStatements = [];
20937
21119
  const allAlteredResolved = [];
20938
21120
  for (const table4 of allAltered) {
20939
- const result = await columnsResolver({
21121
+ const result = await columnsResolver2({
20940
21122
  tableName: table4.name,
20941
21123
  created: table4.added,
20942
21124
  deleted: table4.deleted
20943
21125
  });
21126
+ const schema4 = valueFromSelfOrPatchedNew(table4.schema);
20944
21127
  jsonRenameColumnsStatements.push(
20945
- ...prepareRenameColumns(table4.name, result.renamed)
21128
+ ...prepareRenameColumns(table4.name, schema4, result.renamed)
20946
21129
  );
20947
21130
  const renamedColumnsAltered = result.renamed.map(
20948
21131
  (it) => alteredColumnSchema.parse(diffForRenamedColumn(it.from, it.to))
@@ -20984,7 +21167,7 @@ var init_snapshotsDiffer = __esm({
20984
21167
  it.name,
20985
21168
  it.alteredCompositePKs
20986
21169
  );
20987
- if (it.schema) {
21170
+ if (it.schema && typeof it.schema !== "string") {
20988
21171
  switch (it.schema.type) {
20989
21172
  case "added": {
20990
21173
  jsonSetTableSchemas.push({
@@ -21017,38 +21200,56 @@ var init_snapshotsDiffer = __esm({
21017
21200
  jsonDeletedCompositePKs.push(...deletedCompositePKs);
21018
21201
  jsonAlteredCompositePKs.push(...alteredCompositePKs);
21019
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
+ });
21020
21211
  const jsonTableAlternations = allAlteredResolved.map((it) => {
21212
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21021
21213
  return prepareAlterTableColumnsJson(
21022
21214
  it.name,
21215
+ schema4,
21023
21216
  it.deleted,
21024
21217
  it.added,
21025
21218
  it.altered,
21026
21219
  it.addedForeignKeys,
21027
21220
  dialect6
21028
21221
  );
21029
- }).flat().reduce((res, it) => {
21030
- res.createColumns.push(...it.addColumns);
21031
- res.dropColumns.push(...it.dropColumns);
21032
- res.alterColumns.push(...it.alterColumns);
21033
- return res;
21034
- }, { createColumns: [], dropColumns: [], alterColumns: [] });
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
+ );
21035
21231
  const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
21036
- return prepareCreateIndexesJson(it.name, it.addedIndexes || {});
21232
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21233
+ return prepareCreateIndexesJson(it.name, schema4, it.addedIndexes || {});
21037
21234
  }).flat();
21038
21235
  const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
21039
- return prepareDropIndexesJson(it.name, it.deletedIndexes || {});
21236
+ const schema4 = valueFromSelfOrPatchedNew(it.schema);
21237
+ return prepareDropIndexesJson(it.name, schema4, it.deletedIndexes || {});
21040
21238
  }).flat();
21041
21239
  const jsonCreateReferencesForCreatedTables = created.map((it) => {
21042
- return prepareCreateReferencesJson(it.name, it.foreignKeys);
21240
+ return prepareCreateReferencesJson(it.name, it.schema, it.foreignKeys);
21043
21241
  }).flat();
21044
21242
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
21045
- 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) : [];
21046
21245
  const forAltered = prepareDropReferencesJson(
21047
21246
  it.name,
21247
+ schema4,
21048
21248
  it.deletedForeignKeys
21049
21249
  );
21050
21250
  const alteredFKs = prepareAlterReferencesJson(
21051
21251
  it.name,
21252
+ schema4,
21052
21253
  it.alteredForeignKeys
21053
21254
  );
21054
21255
  return [...forAdded, ...forAltered, ...alteredFKs];
@@ -21110,11 +21311,1334 @@ var init_snapshotsDiffer = __esm({
21110
21311
  jsonStatements.push(...jsonRemoveTableFromSchemas);
21111
21312
  jsonStatements.push(...dropSchemas);
21112
21313
  const sqlStatements = fromJson(jsonStatements, dialect6);
21113
- return sqlStatements.join("\n");
21314
+ const _meta = prepareMigrationMeta(rSchemas, rTables, rColumns);
21315
+ return { statements: jsonStatements, sql: sqlStatements.join("\n"), _meta };
21114
21316
  };
21115
21317
  }
21116
21318
  });
21117
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
+
21118
22642
  // src/cli/commands/migrate.ts
21119
22643
  var migrate_exports = {};
21120
22644
  __export(migrate_exports, {
@@ -21122,15 +22646,16 @@ __export(migrate_exports, {
21122
22646
  prepareAndMigratePg: () => prepareAndMigratePg,
21123
22647
  prepareAndMigrateSqlite: () => prepareAndMigrateSqlite,
21124
22648
  prepareSQL: () => prepareSQL,
21125
- prepareSnapshotFolderName: () => prepareSnapshotFolderName
22649
+ prepareSnapshotFolderName: () => prepareSnapshotFolderName,
22650
+ writeResult: () => writeResult
21126
22651
  });
21127
- 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;
21128
22653
  var init_migrate = __esm({
21129
22654
  "src/cli/commands/migrate.ts"() {
21130
22655
  import_fs4 = __toESM(require("fs"));
21131
22656
  init_migrationPreparator();
21132
22657
  init_snapshotsDiffer();
21133
- import_path2 = __toESM(require("path"));
22658
+ import_path3 = __toESM(require("path"));
21134
22659
  import_hanji2 = __toESM(require_hanji());
21135
22660
  init_views();
21136
22661
  init_source();
@@ -21138,68 +22663,68 @@ var init_migrate = __esm({
21138
22663
  init_sqliteSchema();
21139
22664
  init_mysqlSchema();
21140
22665
  init_utils();
22666
+ init_words();
21141
22667
  prepareAndMigratePg = async (config) => {
21142
22668
  const outFolder = config.out;
21143
22669
  const schemaPath = config.schema;
21144
22670
  try {
21145
- const { migrationFolders } = prepareMigrationFolder(outFolder, "pg");
21146
- const { prev, cur } = preparePgMigrationSnapshot(
21147
- migrationFolders,
21148
- outFolder,
21149
- schemaPath
21150
- );
22671
+ assertV1OutFolder(outFolder, "pg");
22672
+ const { snapshots, journal } = prepareMigrationFolder(outFolder, "pg");
22673
+ const { prev, cur } = preparePgMigrationSnapshot(snapshots, schemaPath);
21151
22674
  const validatedPrev = pgSchema.parse(prev);
21152
22675
  const validatedCur = pgSchema.parse(cur);
21153
22676
  const squashedPrev = squashPgScheme(validatedPrev);
21154
22677
  const squashedCur = squashPgScheme(validatedCur);
21155
- const sql = await prepareSQL(squashedPrev, squashedCur, "pg");
21156
- 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);
21157
22684
  } catch (e) {
21158
22685
  console.error(e);
21159
22686
  }
21160
22687
  };
21161
- prepareAndMigrateSqlite = async (config) => {
22688
+ prepareAndMigrateMySql = async (config) => {
21162
22689
  const outFolder = config.out;
21163
22690
  const schemaPath = config.schema;
21164
22691
  try {
21165
- const { migrationFolders } = prepareMigrationFolder(outFolder, "sqlite");
21166
- const { prev, cur } = prepareSqliteMigrationSnapshot(
21167
- migrationFolders,
21168
- outFolder,
21169
- 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"
21170
22703
  );
21171
- const validatedPrev = sqliteSchema.parse(prev);
21172
- const validatedCur = sqliteSchema.parse(cur);
21173
- const squashedPrev = squashSqliteScheme(validatedPrev);
21174
- const squashedCur = squashSqliteScheme(validatedCur);
21175
- const sql = await prepareSQL(squashedPrev, squashedCur, "sqlite");
21176
- writeResult(cur, sql, outFolder);
22704
+ writeResult(cur, sql, snapshots.length, journal, _meta, outFolder);
21177
22705
  } catch (e) {
21178
22706
  console.error(e);
21179
22707
  }
21180
22708
  };
21181
- prepareAndMigrateMySql = async (config) => {
22709
+ prepareAndMigrateSqlite = async (config) => {
21182
22710
  const outFolder = config.out;
21183
22711
  const schemaPath = config.schema;
21184
22712
  try {
21185
- const { migrationFolders } = prepareMigrationFolder(outFolder, "mysql");
21186
- const { prev, cur } = prepareMySqlMigrationSnapshot(
21187
- migrationFolders,
21188
- outFolder,
21189
- schemaPath
21190
- );
21191
- const validatedPrev = mysqlSchema.parse(prev);
21192
- const validatedCur = mysqlSchema.parse(cur);
21193
- const squashedPrev = squashMysqlScheme(validatedPrev);
21194
- const squashedCur = squashMysqlScheme(validatedCur);
21195
- const sql = await prepareSQL(squashedPrev, squashedCur, "mysql");
21196
- writeResult(cur, sql, outFolder);
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);
21197
22722
  } catch (e) {
21198
22723
  console.error(e);
21199
22724
  }
21200
22725
  };
21201
22726
  prepareSQL = async (prev, cur, dialect6) => {
21202
- const schemasResolver = async (input) => {
22727
+ const schemasResolver2 = async (input) => {
21203
22728
  try {
21204
22729
  const { created, deleted, renamed } = await promptSchemasConflict(
21205
22730
  input.created,
@@ -21211,7 +22736,7 @@ var init_migrate = __esm({
21211
22736
  throw e;
21212
22737
  }
21213
22738
  };
21214
- const tablesResolver = async (input) => {
22739
+ const tablesResolver2 = async (input) => {
21215
22740
  try {
21216
22741
  const { created, deleted, renamed } = await promptTablesConflict(
21217
22742
  input.created,
@@ -21223,7 +22748,7 @@ var init_migrate = __esm({
21223
22748
  throw e;
21224
22749
  }
21225
22750
  };
21226
- const columnsResolver = async (input) => {
22751
+ const columnsResolver2 = async (input) => {
21227
22752
  const result = await promptColumnsConflicts(
21228
22753
  input.tableName,
21229
22754
  input.created,
@@ -21240,9 +22765,9 @@ var init_migrate = __esm({
21240
22765
  prev,
21241
22766
  cur,
21242
22767
  dialect6,
21243
- schemasResolver,
21244
- tablesResolver,
21245
- columnsResolver
22768
+ schemasResolver2,
22769
+ tablesResolver2,
22770
+ columnsResolver2
21246
22771
  );
21247
22772
  };
21248
22773
  promptColumnsConflicts = async (tableName, newColumns, missingColumns) => {
@@ -21377,24 +22902,34 @@ var init_migrate = __esm({
21377
22902
  result.deleted.push(...leftMissing);
21378
22903
  return result;
21379
22904
  };
21380
- writeResult = (cur, sql, outFolder) => {
22905
+ writeResult = (cur, sql, idx, journal, _meta, outFolder) => {
21381
22906
  console.log(schema(cur));
21382
22907
  if (sql.length === 0) {
21383
22908
  console.log("No schema changes, nothing to migrate \u{1F634}");
21384
22909
  return;
21385
22910
  }
22911
+ const { prefix, tag } = prepareMigrationMetadata(idx);
21386
22912
  const toSave = JSON.parse(JSON.stringify(cur));
21387
- const folderName = prepareSnapshotFolderName();
21388
- const migrationFolderPath = `./${outFolder}/${folderName}`;
21389
- 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");
21390
22916
  import_fs4.default.writeFileSync(
21391
- `${migrationFolderPath}/snapshot.json`,
22917
+ (0, import_path3.join)(metaFolderPath, `${prefix}_snapshot.json`),
21392
22918
  JSON.stringify(toSave, null, 2)
21393
22919
  );
21394
- import_fs4.default.writeFileSync(`${migrationFolderPath}/migration.sql`, sql);
21395
- console.log(
21396
- source_default.bold.green("Done:"),
21397
- import_path2.default.join(`${migrationFolderPath}/migration.sql`)
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}`
21398
22933
  );
21399
22934
  };
21400
22935
  prepareSnapshotFolderName = () => {
@@ -21431,6 +22966,9 @@ var init_utils2 = __esm({
21431
22966
  return group.toUpperCase().replace("-", "").replace("_", "").replace(" ", "");
21432
22967
  });
21433
22968
  };
22969
+ Array.prototype.random = function() {
22970
+ return this[~~(Math.random() * this.length)];
22971
+ };
21434
22972
  }
21435
22973
  });
21436
22974
 
@@ -26293,14 +27831,14 @@ var {
26293
27831
  } = import_index.default;
26294
27832
 
26295
27833
  // src/cli/index.ts
26296
- var import_fs8 = __toESM(require("fs"));
27834
+ var import_fs9 = __toESM(require("fs"));
26297
27835
  init_lib();
26298
27836
 
26299
27837
  // src/cli/commands/check.ts
26300
27838
  init_utils();
26301
27839
  var checkHandler = (out, dialect6) => {
26302
- const migrationFolders = prepareOutFolders(out);
26303
- const report = validateWithReport(out, migrationFolders, dialect6);
27840
+ const { snapshots } = prepareOutFolder(out, dialect6);
27841
+ const report = validateWithReport(snapshots, dialect6);
26304
27842
  if (report.nonLatest.length > 0) {
26305
27843
  console.log(
26306
27844
  report.nonLatest.map((it) => {
@@ -26336,7 +27874,7 @@ var checkHandler = (out, dialect6) => {
26336
27874
  // src/cli/index.ts
26337
27875
  var import_hanji4 = __toESM(require_hanji());
26338
27876
  init_views();
26339
- var import_path6 = __toESM(require("path"));
27877
+ var import_path8 = __toESM(require("path"));
26340
27878
 
26341
27879
  // src/cli/utils.ts
26342
27880
  init_views();
@@ -26383,7 +27921,7 @@ init_source();
26383
27921
  // package.json
26384
27922
  var package_default = {
26385
27923
  name: "drizzle-kit",
26386
- version: "0.16.7",
27924
+ version: "0.16.9",
26387
27925
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
26388
27926
  author: "Alex Blokh <aleksandrblokh@gmail.com>",
26389
27927
  license: "MIT",
@@ -26461,13 +27999,15 @@ init_utils();
26461
27999
  init_source();
26462
28000
  var import_crypto2 = require("crypto");
26463
28001
  var import_fs5 = require("fs");
26464
- var import_path3 = __toESM(require("path"));
28002
+ var import_path4 = __toESM(require("path"));
26465
28003
  init_global();
26466
28004
  init_pgSchema();
26467
28005
  init_utils();
26468
28006
  var upPgHandler = (out) => {
26469
- const migrationFolders = prepareOutFolders(out);
26470
- const report = validateWithReport(out, migrationFolders, "pg");
28007
+ };
28008
+ var upPgHandlerV4 = (out) => {
28009
+ const { snapshots } = prepareOutFolder(out, "pg");
28010
+ const report = validateWithReport(snapshots, "pg");
26471
28011
  let prevId = originUUID;
26472
28012
  report.nonLatest.map((it) => ({
26473
28013
  folder: it,
@@ -26477,10 +28017,10 @@ var upPgHandler = (out) => {
26477
28017
  const result = updateToLatest(it.raw, prevId);
26478
28018
  prevId = result.id;
26479
28019
  console.log(
26480
- `[${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")}`
26481
28021
  );
26482
28022
  (0, import_fs5.writeFileSync)(
26483
- import_path3.default.join(out, folder, "snapshot.json"),
28023
+ import_path4.default.join(out, folder, "snapshot.json"),
26484
28024
  JSON.stringify(result, null, 2)
26485
28025
  );
26486
28026
  });
@@ -26650,12 +28190,12 @@ var update3to4 = (json) => {
26650
28190
  // src/cli/commands/sqliteUp.ts
26651
28191
  init_source();
26652
28192
  var import_fs6 = __toESM(require("fs"));
26653
- var import_path4 = __toESM(require("path"));
28193
+ var import_path5 = __toESM(require("path"));
26654
28194
  init_sqliteSchema();
26655
28195
  init_utils();
26656
28196
  var upSqliteHandler = (out) => {
26657
- const migrationFolders = prepareOutFolders(out);
26658
- const report = validateWithReport(out, migrationFolders, "sqlite");
28197
+ const { snapshots } = prepareOutFolder(out, "sqlite");
28198
+ const report = validateWithReport(snapshots, "sqlite");
26659
28199
  report.nonLatest.map((it) => ({
26660
28200
  folder: it,
26661
28201
  raw: report.rawMap[it]
@@ -26663,10 +28203,10 @@ var upSqliteHandler = (out) => {
26663
28203
  const folder = it.folder;
26664
28204
  const result = updateToLatest2(it.raw);
26665
28205
  console.log(
26666
- `[${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")}`
26667
28207
  );
26668
28208
  import_fs6.default.writeFileSync(
26669
- import_path4.default.join(out, folder, "snapshot.json"),
28209
+ import_path5.default.join(out, folder, "snapshot.json"),
26670
28210
  JSON.stringify(result, null, 2)
26671
28211
  );
26672
28212
  });
@@ -26698,12 +28238,12 @@ var updateV3toV4 = (old) => {
26698
28238
  // src/cli/commands/mysqlUp.ts
26699
28239
  init_source();
26700
28240
  var import_fs7 = __toESM(require("fs"));
26701
- var import_path5 = __toESM(require("path"));
28241
+ var import_path6 = __toESM(require("path"));
26702
28242
  init_mysqlSchema();
26703
28243
  init_utils();
26704
28244
  var upMysqlHandler = (out) => {
26705
- const migrationFolders = prepareOutFolders(out);
26706
- const report = validateWithReport(out, migrationFolders, "mysql");
28245
+ const { snapshots } = prepareOutFolder(out, "mysql");
28246
+ const report = validateWithReport(snapshots, "mysql");
26707
28247
  report.nonLatest.map((it) => ({
26708
28248
  folder: it,
26709
28249
  raw: report.rawMap[it]
@@ -26711,10 +28251,10 @@ var upMysqlHandler = (out) => {
26711
28251
  const folder = it.folder;
26712
28252
  const result = updateToLatest3(it.raw);
26713
28253
  console.log(
26714
- `[${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")}`
26715
28255
  );
26716
28256
  import_fs7.default.writeFileSync(
26717
- import_path5.default.join(out, folder, "snapshot.json"),
28257
+ import_path6.default.join(out, folder, "snapshot.json"),
26718
28258
  JSON.stringify(result, null, 2)
26719
28259
  );
26720
28260
  });
@@ -26737,6 +28277,273 @@ var updateV3toV42 = (old) => {
26737
28277
  };
26738
28278
  };
26739
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
+
26740
28547
  // src/cli/index.ts
26741
28548
  var printVersions = () => {
26742
28549
  console.log(`${source_default.gray(versions())}
@@ -26745,13 +28552,13 @@ var printVersions = () => {
26745
28552
  var assertEitherConfigOrOut = (config, out) => {
26746
28553
  if (out)
26747
28554
  return out;
26748
- 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)))) {
26749
28556
  console.log(`${config} file does not exist`);
26750
28557
  process.exit(1);
26751
28558
  }
26752
28559
  console.log(`Reading ${config}`);
26753
28560
  const drizzleConfig = JSON.parse(
26754
- 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()
26755
28562
  );
26756
28563
  return drizzleConfig.out;
26757
28564
  };
@@ -26821,7 +28628,7 @@ var prepareGenerateConfig = (options) => {
26821
28628
  if (!(schema4 || out)) {
26822
28629
  const path5 = config != null ? config : "drizzle.config.json";
26823
28630
  const drizzleConfig = JSON.parse(
26824
- 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()
26825
28632
  );
26826
28633
  return drizzleConfig;
26827
28634
  }
@@ -26869,6 +28676,8 @@ var upPgCommand = new Command("up:pg").option("--out <out>", `Output folder`).op
26869
28676
  process.exit(0);
26870
28677
  }
26871
28678
  assertPackages("drizzle-orm");
28679
+ upPgHandlerV4(out);
28680
+ upgradeFolders("pg", out);
26872
28681
  upPgHandler(out);
26873
28682
  });
26874
28683
  var upMysqlCommand = new Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action((options) => {
@@ -26916,29 +28725,18 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
26916
28725
  console.log("Missing required params");
26917
28726
  return;
26918
28727
  }
26919
- const migrationFolders = prepareOutFolders(res.data.out);
26920
- const folderName = prepareSnapshotFolderName();
26921
- const migrationFolderPath = `./${res.data.out}/${folderName}`;
28728
+ const { snapshots, journal } = prepareOutFolder(res.data.out, "pg");
26922
28729
  const { schema: schema4, ts } = await pgIntrospect2(res.data);
26923
- const schemaFile = import_path6.default.join(res.data.out, "schema.ts");
26924
- (0, import_fs8.writeFileSync)(schemaFile, ts);
28730
+ const schemaFile = import_path8.default.join(res.data.out, "schema.ts");
28731
+ (0, import_fs9.writeFileSync)(schemaFile, ts);
26925
28732
  console.log();
26926
- if (migrationFolders.length === 0) {
26927
- import_fs8.default.mkdirSync(migrationFolderPath);
26928
- const snapshotFile = import_path6.default.join(migrationFolderPath, "snapshot.json");
26929
- (0, import_fs8.writeFileSync)(snapshotFile, JSON.stringify(schema4));
26930
- const sql = await prepareSQL(
28733
+ if (snapshots.length === 0) {
28734
+ const { sql, _meta } = await prepareSQL(
26931
28735
  squashPgScheme(dryPg),
26932
28736
  squashPgScheme(schema4),
26933
28737
  "pg"
26934
28738
  );
26935
- const sqlFile = import_path6.default.join(migrationFolderPath, "migration.sql");
26936
- (0, import_fs8.writeFileSync)(sqlFile, sql);
26937
- (0, import_hanji4.render)(
26938
- `[${source_default.green(
26939
- "\u2713"
26940
- )}] Your SQL migration file \u279C ${source_default.bold.underline.blue(sqlFile)} \u{1F680}`
26941
- );
28739
+ writeResult(schema4, sql, 0, journal, _meta, res.data.out);
26942
28740
  } else {
26943
28741
  (0, import_hanji4.render)(
26944
28742
  `[${source_default.blue(