drizzle-kit 0.24.2-5ccb794 → 0.24.2-807aa5b

Sign up to get free protection for your applications and to get access to all the features.
package/api.js CHANGED
@@ -229,8 +229,8 @@ var init_ansi_styles = __esm({
229
229
 
230
230
  // ../node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js
231
231
  function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
232
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
233
- const position = argv.indexOf(prefix + flag);
232
+ const prefix2 = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
233
+ const position = argv.indexOf(prefix2 + flag);
234
234
  const terminatorPosition = argv.indexOf("--");
235
235
  return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
236
236
  }
@@ -375,12 +375,12 @@ function stringReplaceAll(string, substring, replacer) {
375
375
  returnValue += string.slice(endIndex);
376
376
  return returnValue;
377
377
  }
378
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index4) {
378
+ function stringEncaseCRLFWithFirstIndex(string, prefix2, postfix, index4) {
379
379
  let endIndex = 0;
380
380
  let returnValue = "";
381
381
  do {
382
382
  const gotCR = string[index4 - 1] === "\r";
383
- returnValue += string.slice(endIndex, gotCR ? index4 - 1 : index4) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
383
+ returnValue += string.slice(endIndex, gotCR ? index4 - 1 : index4) + prefix2 + (gotCR ? "\r\n" : "\n") + postfix;
384
384
  endIndex = index4 + 1;
385
385
  index4 = string.indexOf("\n", endIndex);
386
386
  } while (index4 !== -1);
@@ -1897,40 +1897,40 @@ var require_sync = __commonJS({
1897
1897
  while (typeof pattern[n] === "string") {
1898
1898
  n++;
1899
1899
  }
1900
- var prefix;
1900
+ var prefix2;
1901
1901
  switch (n) {
1902
1902
  case pattern.length:
1903
1903
  this._processSimple(pattern.join("/"), index4);
1904
1904
  return;
1905
1905
  case 0:
1906
- prefix = null;
1906
+ prefix2 = null;
1907
1907
  break;
1908
1908
  default:
1909
- prefix = pattern.slice(0, n).join("/");
1909
+ prefix2 = pattern.slice(0, n).join("/");
1910
1910
  break;
1911
1911
  }
1912
1912
  var remain = pattern.slice(n);
1913
1913
  var read;
1914
- if (prefix === null)
1914
+ if (prefix2 === null)
1915
1915
  read = ".";
1916
- else if (isAbsolute(prefix) || isAbsolute(pattern.map(function(p) {
1916
+ else if (isAbsolute(prefix2) || isAbsolute(pattern.map(function(p) {
1917
1917
  return typeof p === "string" ? p : "[*]";
1918
1918
  }).join("/"))) {
1919
- if (!prefix || !isAbsolute(prefix))
1920
- prefix = "/" + prefix;
1921
- read = prefix;
1919
+ if (!prefix2 || !isAbsolute(prefix2))
1920
+ prefix2 = "/" + prefix2;
1921
+ read = prefix2;
1922
1922
  } else
1923
- read = prefix;
1923
+ read = prefix2;
1924
1924
  var abs = this._makeAbs(read);
1925
1925
  if (childrenIgnored(this, read))
1926
1926
  return;
1927
1927
  var isGlobStar = remain[0] === minimatch2.GLOBSTAR;
1928
1928
  if (isGlobStar)
1929
- this._processGlobStar(prefix, read, abs, remain, index4, inGlobStar);
1929
+ this._processGlobStar(prefix2, read, abs, remain, index4, inGlobStar);
1930
1930
  else
1931
- this._processReaddir(prefix, read, abs, remain, index4, inGlobStar);
1931
+ this._processReaddir(prefix2, read, abs, remain, index4, inGlobStar);
1932
1932
  };
1933
- GlobSync.prototype._processReaddir = function(prefix, read, abs, remain, index4, inGlobStar) {
1933
+ GlobSync.prototype._processReaddir = function(prefix2, read, abs, remain, index4, inGlobStar) {
1934
1934
  var entries = this._readdir(abs, inGlobStar);
1935
1935
  if (!entries)
1936
1936
  return;
@@ -1943,7 +1943,7 @@ var require_sync = __commonJS({
1943
1943
  var e = entries[i];
1944
1944
  if (e.charAt(0) !== "." || dotOk) {
1945
1945
  var m;
1946
- if (negate && !prefix) {
1946
+ if (negate && !prefix2) {
1947
1947
  m = !e.match(pn);
1948
1948
  } else {
1949
1949
  m = e.match(pn);
@@ -1960,11 +1960,11 @@ var require_sync = __commonJS({
1960
1960
  this.matches[index4] = /* @__PURE__ */ Object.create(null);
1961
1961
  for (var i = 0; i < len; i++) {
1962
1962
  var e = matchedEntries[i];
1963
- if (prefix) {
1964
- if (prefix.slice(-1) !== "/")
1965
- e = prefix + "/" + e;
1963
+ if (prefix2) {
1964
+ if (prefix2.slice(-1) !== "/")
1965
+ e = prefix2 + "/" + e;
1966
1966
  else
1967
- e = prefix + e;
1967
+ e = prefix2 + e;
1968
1968
  }
1969
1969
  if (e.charAt(0) === "/" && !this.nomount) {
1970
1970
  e = path2.join(this.root, e);
@@ -1977,8 +1977,8 @@ var require_sync = __commonJS({
1977
1977
  for (var i = 0; i < len; i++) {
1978
1978
  var e = matchedEntries[i];
1979
1979
  var newPattern;
1980
- if (prefix)
1981
- newPattern = [prefix, e];
1980
+ if (prefix2)
1981
+ newPattern = [prefix2, e];
1982
1982
  else
1983
1983
  newPattern = [e];
1984
1984
  this._process(newPattern.concat(remain), index4, inGlobStar);
@@ -2085,12 +2085,12 @@ var require_sync = __commonJS({
2085
2085
  break;
2086
2086
  }
2087
2087
  };
2088
- GlobSync.prototype._processGlobStar = function(prefix, read, abs, remain, index4, inGlobStar) {
2088
+ GlobSync.prototype._processGlobStar = function(prefix2, read, abs, remain, index4, inGlobStar) {
2089
2089
  var entries = this._readdir(abs, inGlobStar);
2090
2090
  if (!entries)
2091
2091
  return;
2092
2092
  var remainWithoutGlobStar = remain.slice(1);
2093
- var gspref = prefix ? [prefix] : [];
2093
+ var gspref = prefix2 ? [prefix2] : [];
2094
2094
  var noGlobStar = gspref.concat(remainWithoutGlobStar);
2095
2095
  this._process(noGlobStar, index4, false);
2096
2096
  var len = entries.length;
@@ -2107,25 +2107,25 @@ var require_sync = __commonJS({
2107
2107
  this._process(below, index4, true);
2108
2108
  }
2109
2109
  };
2110
- GlobSync.prototype._processSimple = function(prefix, index4) {
2111
- var exists2 = this._stat(prefix);
2110
+ GlobSync.prototype._processSimple = function(prefix2, index4) {
2111
+ var exists2 = this._stat(prefix2);
2112
2112
  if (!this.matches[index4])
2113
2113
  this.matches[index4] = /* @__PURE__ */ Object.create(null);
2114
2114
  if (!exists2)
2115
2115
  return;
2116
- if (prefix && isAbsolute(prefix) && !this.nomount) {
2117
- var trail = /[\/\\]$/.test(prefix);
2118
- if (prefix.charAt(0) === "/") {
2119
- prefix = path2.join(this.root, prefix);
2116
+ if (prefix2 && isAbsolute(prefix2) && !this.nomount) {
2117
+ var trail = /[\/\\]$/.test(prefix2);
2118
+ if (prefix2.charAt(0) === "/") {
2119
+ prefix2 = path2.join(this.root, prefix2);
2120
2120
  } else {
2121
- prefix = path2.resolve(this.root, prefix);
2121
+ prefix2 = path2.resolve(this.root, prefix2);
2122
2122
  if (trail)
2123
- prefix += "/";
2123
+ prefix2 += "/";
2124
2124
  }
2125
2125
  }
2126
2126
  if (process.platform === "win32")
2127
- prefix = prefix.replace(/\\/g, "/");
2128
- this._emitMatch(index4, prefix);
2127
+ prefix2 = prefix2.replace(/\\/g, "/");
2128
+ this._emitMatch(index4, prefix2);
2129
2129
  };
2130
2130
  GlobSync.prototype._stat = function(f) {
2131
2131
  var abs = this._makeAbs(f);
@@ -2520,46 +2520,46 @@ var require_glob = __commonJS({
2520
2520
  while (typeof pattern[n] === "string") {
2521
2521
  n++;
2522
2522
  }
2523
- var prefix;
2523
+ var prefix2;
2524
2524
  switch (n) {
2525
2525
  case pattern.length:
2526
2526
  this._processSimple(pattern.join("/"), index4, cb);
2527
2527
  return;
2528
2528
  case 0:
2529
- prefix = null;
2529
+ prefix2 = null;
2530
2530
  break;
2531
2531
  default:
2532
- prefix = pattern.slice(0, n).join("/");
2532
+ prefix2 = pattern.slice(0, n).join("/");
2533
2533
  break;
2534
2534
  }
2535
2535
  var remain = pattern.slice(n);
2536
2536
  var read;
2537
- if (prefix === null)
2537
+ if (prefix2 === null)
2538
2538
  read = ".";
2539
- else if (isAbsolute(prefix) || isAbsolute(pattern.map(function(p) {
2539
+ else if (isAbsolute(prefix2) || isAbsolute(pattern.map(function(p) {
2540
2540
  return typeof p === "string" ? p : "[*]";
2541
2541
  }).join("/"))) {
2542
- if (!prefix || !isAbsolute(prefix))
2543
- prefix = "/" + prefix;
2544
- read = prefix;
2542
+ if (!prefix2 || !isAbsolute(prefix2))
2543
+ prefix2 = "/" + prefix2;
2544
+ read = prefix2;
2545
2545
  } else
2546
- read = prefix;
2546
+ read = prefix2;
2547
2547
  var abs = this._makeAbs(read);
2548
2548
  if (childrenIgnored(this, read))
2549
2549
  return cb();
2550
2550
  var isGlobStar = remain[0] === minimatch2.GLOBSTAR;
2551
2551
  if (isGlobStar)
2552
- this._processGlobStar(prefix, read, abs, remain, index4, inGlobStar, cb);
2552
+ this._processGlobStar(prefix2, read, abs, remain, index4, inGlobStar, cb);
2553
2553
  else
2554
- this._processReaddir(prefix, read, abs, remain, index4, inGlobStar, cb);
2554
+ this._processReaddir(prefix2, read, abs, remain, index4, inGlobStar, cb);
2555
2555
  };
2556
- Glob.prototype._processReaddir = function(prefix, read, abs, remain, index4, inGlobStar, cb) {
2556
+ Glob.prototype._processReaddir = function(prefix2, read, abs, remain, index4, inGlobStar, cb) {
2557
2557
  var self2 = this;
2558
2558
  this._readdir(abs, inGlobStar, function(er, entries) {
2559
- return self2._processReaddir2(prefix, read, abs, remain, index4, inGlobStar, entries, cb);
2559
+ return self2._processReaddir2(prefix2, read, abs, remain, index4, inGlobStar, entries, cb);
2560
2560
  });
2561
2561
  };
2562
- Glob.prototype._processReaddir2 = function(prefix, read, abs, remain, index4, inGlobStar, entries, cb) {
2562
+ Glob.prototype._processReaddir2 = function(prefix2, read, abs, remain, index4, inGlobStar, entries, cb) {
2563
2563
  if (!entries)
2564
2564
  return cb();
2565
2565
  var pn = remain[0];
@@ -2571,7 +2571,7 @@ var require_glob = __commonJS({
2571
2571
  var e = entries[i];
2572
2572
  if (e.charAt(0) !== "." || dotOk) {
2573
2573
  var m;
2574
- if (negate && !prefix) {
2574
+ if (negate && !prefix2) {
2575
2575
  m = !e.match(pn);
2576
2576
  } else {
2577
2577
  m = e.match(pn);
@@ -2588,11 +2588,11 @@ var require_glob = __commonJS({
2588
2588
  this.matches[index4] = /* @__PURE__ */ Object.create(null);
2589
2589
  for (var i = 0; i < len; i++) {
2590
2590
  var e = matchedEntries[i];
2591
- if (prefix) {
2592
- if (prefix !== "/")
2593
- e = prefix + "/" + e;
2591
+ if (prefix2) {
2592
+ if (prefix2 !== "/")
2593
+ e = prefix2 + "/" + e;
2594
2594
  else
2595
- e = prefix + e;
2595
+ e = prefix2 + e;
2596
2596
  }
2597
2597
  if (e.charAt(0) === "/" && !this.nomount) {
2598
2598
  e = path2.join(this.root, e);
@@ -2605,11 +2605,11 @@ var require_glob = __commonJS({
2605
2605
  for (var i = 0; i < len; i++) {
2606
2606
  var e = matchedEntries[i];
2607
2607
  var newPattern;
2608
- if (prefix) {
2609
- if (prefix !== "/")
2610
- e = prefix + "/" + e;
2608
+ if (prefix2) {
2609
+ if (prefix2 !== "/")
2610
+ e = prefix2 + "/" + e;
2611
2611
  else
2612
- e = prefix + e;
2612
+ e = prefix2 + e;
2613
2613
  }
2614
2614
  this._process([e].concat(remain), index4, inGlobStar, cb);
2615
2615
  }
@@ -2740,17 +2740,17 @@ var require_glob = __commonJS({
2740
2740
  }
2741
2741
  return cb();
2742
2742
  };
2743
- Glob.prototype._processGlobStar = function(prefix, read, abs, remain, index4, inGlobStar, cb) {
2743
+ Glob.prototype._processGlobStar = function(prefix2, read, abs, remain, index4, inGlobStar, cb) {
2744
2744
  var self2 = this;
2745
2745
  this._readdir(abs, inGlobStar, function(er, entries) {
2746
- self2._processGlobStar2(prefix, read, abs, remain, index4, inGlobStar, entries, cb);
2746
+ self2._processGlobStar2(prefix2, read, abs, remain, index4, inGlobStar, entries, cb);
2747
2747
  });
2748
2748
  };
2749
- Glob.prototype._processGlobStar2 = function(prefix, read, abs, remain, index4, inGlobStar, entries, cb) {
2749
+ Glob.prototype._processGlobStar2 = function(prefix2, read, abs, remain, index4, inGlobStar, entries, cb) {
2750
2750
  if (!entries)
2751
2751
  return cb();
2752
2752
  var remainWithoutGlobStar = remain.slice(1);
2753
- var gspref = prefix ? [prefix] : [];
2753
+ var gspref = prefix2 ? [prefix2] : [];
2754
2754
  var noGlobStar = gspref.concat(remainWithoutGlobStar);
2755
2755
  this._process(noGlobStar, index4, false, cb);
2756
2756
  var isSym = this.symlinks[abs];
@@ -2768,30 +2768,30 @@ var require_glob = __commonJS({
2768
2768
  }
2769
2769
  cb();
2770
2770
  };
2771
- Glob.prototype._processSimple = function(prefix, index4, cb) {
2771
+ Glob.prototype._processSimple = function(prefix2, index4, cb) {
2772
2772
  var self2 = this;
2773
- this._stat(prefix, function(er, exists2) {
2774
- self2._processSimple2(prefix, index4, er, exists2, cb);
2773
+ this._stat(prefix2, function(er, exists2) {
2774
+ self2._processSimple2(prefix2, index4, er, exists2, cb);
2775
2775
  });
2776
2776
  };
2777
- Glob.prototype._processSimple2 = function(prefix, index4, er, exists2, cb) {
2777
+ Glob.prototype._processSimple2 = function(prefix2, index4, er, exists2, cb) {
2778
2778
  if (!this.matches[index4])
2779
2779
  this.matches[index4] = /* @__PURE__ */ Object.create(null);
2780
2780
  if (!exists2)
2781
2781
  return cb();
2782
- if (prefix && isAbsolute(prefix) && !this.nomount) {
2783
- var trail = /[\/\\]$/.test(prefix);
2784
- if (prefix.charAt(0) === "/") {
2785
- prefix = path2.join(this.root, prefix);
2782
+ if (prefix2 && isAbsolute(prefix2) && !this.nomount) {
2783
+ var trail = /[\/\\]$/.test(prefix2);
2784
+ if (prefix2.charAt(0) === "/") {
2785
+ prefix2 = path2.join(this.root, prefix2);
2786
2786
  } else {
2787
- prefix = path2.resolve(this.root, prefix);
2787
+ prefix2 = path2.resolve(this.root, prefix2);
2788
2788
  if (trail)
2789
- prefix += "/";
2789
+ prefix2 += "/";
2790
2790
  }
2791
2791
  }
2792
2792
  if (process.platform === "win32")
2793
- prefix = prefix.replace(/\\/g, "/");
2794
- this._emitMatch(index4, prefix);
2793
+ prefix2 = prefix2.replace(/\\/g, "/");
2794
+ this._emitMatch(index4, prefix2);
2795
2795
  cb();
2796
2796
  };
2797
2797
  Glob.prototype._stat = function(f, cb) {
@@ -8361,6 +8361,13 @@ var init_sqliteSchema = __esm({
8361
8361
  function isPgArrayType(sqlType) {
8362
8362
  return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
8363
8363
  }
8364
+ function findAddedAndRemoved(columnNames1, columnNames2) {
8365
+ const set1 = new Set(columnNames1);
8366
+ const set2 = new Set(columnNames2);
8367
+ const addedColumns = columnNames2.filter((it) => !set1.has(it));
8368
+ const removedColumns = columnNames1.filter((it) => !set2.has(it));
8369
+ return { addedColumns, removedColumns };
8370
+ }
8364
8371
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8365
8372
  var init_utils = __esm({
8366
8373
  "src/utils.ts"() {
@@ -8419,7 +8426,7 @@ var init_views = __esm({
8419
8426
  import_hanji = __toESM(require_hanji());
8420
8427
  init_utils();
8421
8428
  warning = (msg) => {
8422
- (0, import_hanji.render)(`${source_default.bgYellow.bold(" Warning ")} ${msg}`);
8429
+ (0, import_hanji.render)(`[${source_default.yellow("Warning")}] ${msg}`);
8423
8430
  };
8424
8431
  error = (error2, greyMsg = "") => {
8425
8432
  return `${source_default.bgRed.bold(" Error ")} ${error2} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim();
@@ -9743,7 +9750,7 @@ var require_difflib = __commonJS({
9743
9750
  return `${beginning},${beginning + length - 1}`;
9744
9751
  };
9745
9752
  contextDiff = function(a, b, { fromfile, tofile, fromfiledate, tofiledate, n, lineterm } = {}) {
9746
- var _2, file1Range, file2Range, first, fromdate, group, i1, i2, j1, j2, l, last, len, len1, len2, len3, len4, line, lines, m, o, p, prefix, q, ref, ref1, ref2, started, tag, todate;
9753
+ var _2, file1Range, file2Range, first, fromdate, group, i1, i2, j1, j2, l, last, len, len1, len2, len3, len4, line, lines, m, o, p, prefix2, q, ref, ref1, ref2, started, tag, todate;
9747
9754
  if (fromfile == null) {
9748
9755
  fromfile = "";
9749
9756
  }
@@ -9762,7 +9769,7 @@ var require_difflib = __commonJS({
9762
9769
  if (lineterm == null) {
9763
9770
  lineterm = "\n";
9764
9771
  }
9765
- prefix = {
9772
+ prefix2 = {
9766
9773
  insert: "+ ",
9767
9774
  delete: "- ",
9768
9775
  replace: "! ",
@@ -9798,7 +9805,7 @@ var require_difflib = __commonJS({
9798
9805
  ref1 = a.slice(i1, i2);
9799
9806
  for (o = 0, len2 = ref1.length; o < len2; o++) {
9800
9807
  line = ref1[o];
9801
- lines.push(prefix[tag] + line);
9808
+ lines.push(prefix2[tag] + line);
9802
9809
  }
9803
9810
  }
9804
9811
  }
@@ -9820,7 +9827,7 @@ var require_difflib = __commonJS({
9820
9827
  ref2 = b.slice(j1, j2);
9821
9828
  for (q = 0, len4 = ref2.length; q < len4; q++) {
9822
9829
  line = ref2[q];
9823
- lines.push(prefix[tag] + line);
9830
+ lines.push(prefix2[tag] + line);
9824
9831
  }
9825
9832
  }
9826
9833
  }
@@ -9833,7 +9840,7 @@ var require_difflib = __commonJS({
9833
9840
  return new Differ(linejunk, charjunk).compare(a, b);
9834
9841
  };
9835
9842
  restore = function(delta, which) {
9836
- var l, len, line, lines, prefixes, ref, tag;
9843
+ var l, len, line, lines, prefixes2, ref, tag;
9837
9844
  tag = {
9838
9845
  1: "- ",
9839
9846
  2: "+ "
@@ -9841,11 +9848,11 @@ var require_difflib = __commonJS({
9841
9848
  if (!tag) {
9842
9849
  throw new Error(`unknow delta choice (must be 1 or 2): ${which}`);
9843
9850
  }
9844
- prefixes = [" ", tag];
9851
+ prefixes2 = [" ", tag];
9845
9852
  lines = [];
9846
9853
  for (l = 0, len = delta.length; l < len; l++) {
9847
9854
  line = delta[l];
9848
- if (ref = line.slice(0, 2), indexOf.call(prefixes, ref) >= 0) {
9855
+ if (ref = line.slice(0, 2), indexOf.call(prefixes2, ref) >= 0) {
9849
9856
  lines.push(line.slice(2));
9850
9857
  }
9851
9858
  }
@@ -9986,8 +9993,8 @@ var require_has_flag = __commonJS({
9986
9993
  module2.exports = function(flag, argv) {
9987
9994
  argv = argv || process.argv;
9988
9995
  var terminatorPos = argv.indexOf("--");
9989
- var prefix = /^-{1,2}/.test(flag) ? "" : "--";
9990
- var pos = argv.indexOf(prefix + flag);
9996
+ var prefix2 = /^-{1,2}/.test(flag) ? "" : "--";
9997
+ var pos = argv.indexOf(prefix2 + flag);
9991
9998
  return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
9992
9999
  };
9993
10000
  }
@@ -10596,7 +10603,7 @@ var require_colorize = __commonJS({
10596
10603
  };
10597
10604
  var subcolorizeToCallback = function(options, key, diff2, output, color2, indent) {
10598
10605
  let subvalue;
10599
- const prefix = key ? `${key}: ` : "";
10606
+ const prefix2 = key ? `${key}: ` : "";
10600
10607
  const subindent = indent + " ";
10601
10608
  const outputElisions = (n) => {
10602
10609
  const maxElisions = options.maxElisions === void 0 ? Infinity : options.maxElisions;
@@ -10614,7 +10621,7 @@ var require_colorize = __commonJS({
10614
10621
  subcolorizeToCallback(options, key, diff2.__old, output, "-", indent);
10615
10622
  return subcolorizeToCallback(options, key, diff2.__new, output, "+", indent);
10616
10623
  } else {
10617
- output(color2, `${indent}${prefix}{`);
10624
+ output(color2, `${indent}${prefix2}{`);
10618
10625
  for (const subkey of Object.keys(diff2)) {
10619
10626
  let m;
10620
10627
  subvalue = diff2[subkey];
@@ -10629,7 +10636,7 @@ var require_colorize = __commonJS({
10629
10636
  return output(color2, `${indent}}`);
10630
10637
  }
10631
10638
  case "array": {
10632
- output(color2, `${indent}${prefix}[`);
10639
+ output(color2, `${indent}${prefix2}[`);
10633
10640
  let looksLikeDiff = true;
10634
10641
  for (const item of diff2) {
10635
10642
  if (extendedTypeOf(item) !== "array" || !(item.length === 2 || item.length === 1 && item[0] === " ") || !(typeof item[0] === "string") || item[0].length !== 1 || ![" ", "-", "+", "~"].includes(item[0])) {
@@ -10668,7 +10675,7 @@ var require_colorize = __commonJS({
10668
10675
  }
10669
10676
  default:
10670
10677
  if (diff2 === 0 || diff2 === null || diff2 === false || diff2 === "" || diff2) {
10671
- return output(color2, indent + prefix + JSON.stringify(diff2));
10678
+ return output(color2, indent + prefix2 + JSON.stringify(diff2));
10672
10679
  }
10673
10680
  }
10674
10681
  };
@@ -11470,7 +11477,20 @@ var init_jsonDiffer = __esm({
11470
11477
  });
11471
11478
 
11472
11479
  // src/sqlgenerator.ts
11473
- var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, SQLiteAlterTableAddUniqueConstraintConvertor, SQLiteAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, SQLiteAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, SqliteAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, MySqlModifyColumn, SqliteAlterTableAlterColumnDropDefaultConvertor, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, SqliteAlterTableCreateCompositePrimaryKeyConvertor, SqliteAlterTableDeleteCompositePrimaryKeyConvertor, SqliteAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetNotNullConvertor, SqliteAlterTableAlterColumnSetAutoincrementConvertor, SqliteAlterTableAlterColumnDropAutoincrementConvertor, PgAlterTableAlterColumnDropNotNullConvertor, SqliteAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, SqliteCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, SqliteAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, SqliteDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, convertors, fromJson;
11480
+ function fromJson(statements, dialect7, action, json2) {
11481
+ const result = statements.flatMap((statement) => {
11482
+ const filtered = convertors.filter((it) => {
11483
+ return it.can(statement, dialect7);
11484
+ });
11485
+ const convertor = filtered.length === 1 ? filtered[0] : void 0;
11486
+ if (!convertor) {
11487
+ return "";
11488
+ }
11489
+ return convertor.convert(statement, json2, action);
11490
+ }).filter((it) => it !== "");
11491
+ return result;
11492
+ }
11493
+ var pgNativeTypes, isPgNativeType, Convertor, PgCreateTableConvertor, MySqlCreateTableConvertor, SQLiteCreateTableConvertor, PgAlterTableAlterColumnSetGenerated, PgAlterTableAlterColumnDropGenerated, PgAlterTableAlterColumnAlterGenerated, PgAlterTableAddUniqueConstraintConvertor, PgAlterTableDropUniqueConstraintConvertor, MySQLAlterTableAddUniqueConstraintConvertor, MySQLAlterTableDropUniqueConstraintConvertor, CreatePgSequenceConvertor, DropPgSequenceConvertor, RenamePgSequenceConvertor, MovePgSequenceConvertor, AlterPgSequenceConvertor, CreateTypeEnumConvertor, AlterTypeAddValueConvertor, PgDropTableConvertor, MySQLDropTableConvertor, SQLiteDropTableConvertor, PgRenameTableConvertor, SqliteRenameTableConvertor, MySqlRenameTableConvertor, PgAlterTableRenameColumnConvertor, MySqlAlterTableRenameColumnConvertor, SQLiteAlterTableRenameColumnConvertor, PgAlterTableDropColumnConvertor, MySqlAlterTableDropColumnConvertor, SQLiteAlterTableDropColumnConvertor, PgAlterTableAddColumnConvertor, MySqlAlterTableAddColumnConvertor, SQLiteAlterTableAddColumnConvertor, PgAlterTableAlterColumnSetTypeConvertor, PgAlterTableAlterColumnSetDefaultConvertor, PgAlterTableAlterColumnDropDefaultConvertor, PgAlterTableAlterColumnDropGeneratedConvertor, PgAlterTableAlterColumnSetExpressionConvertor, PgAlterTableAlterColumnAlterrGeneratedConvertor, SqliteAlterTableAlterColumnDropGeneratedConvertor, SqliteAlterTableAlterColumnSetExpressionConvertor, SqliteAlterTableAlterColumnAlterGeneratedConvertor, MySqlAlterTableAlterColumnAlterrGeneratedConvertor, MySqlAlterTableAddPk, MySqlAlterTableDropPk, LibSQLModifyColumn, MySqlModifyColumn, PgAlterTableCreateCompositePrimaryKeyConvertor, PgAlterTableDeleteCompositePrimaryKeyConvertor, PgAlterTableAlterCompositePrimaryKeyConvertor, MySqlAlterTableCreateCompositePrimaryKeyConvertor, MySqlAlterTableDeleteCompositePrimaryKeyConvertor, MySqlAlterTableAlterCompositePrimaryKeyConvertor, PgAlterTableAlterColumnSetPrimaryKeyConvertor, PgAlterTableAlterColumnDropPrimaryKeyConvertor, PgAlterTableAlterColumnSetNotNullConvertor, PgAlterTableAlterColumnDropNotNullConvertor, PgCreateForeignKeyConvertor, LibSQLCreateForeignKeyConvertor, MySqlCreateForeignKeyConvertor, PgAlterForeignKeyConvertor, PgDeleteForeignKeyConvertor, MySqlDeleteForeignKeyConvertor, CreatePgIndexConvertor, CreateMySqlIndexConvertor, CreateSqliteIndexConvertor, PgDropIndexConvertor, PgCreateSchemaConvertor, PgRenameSchemaConvertor, PgDropSchemaConvertor, PgAlterTableSetSchemaConvertor, PgAlterTableSetNewSchemaConvertor, PgAlterTableRemoveFromSchemaConvertor, SqliteDropIndexConvertor, MySqlDropIndexConvertor, SQLiteRecreateTableConvertor, LibSQLRecreateTableConvertor, convertors;
11474
11494
  var init_sqlgenerator = __esm({
11475
11495
  "src/sqlgenerator.ts"() {
11476
11496
  "use strict";
@@ -11622,7 +11642,7 @@ var init_sqlgenerator = __esm({
11622
11642
  };
11623
11643
  SQLiteCreateTableConvertor = class extends Convertor {
11624
11644
  can(statement, dialect7) {
11625
- return statement.type === "sqlite_create_table" && dialect7 === "sqlite";
11645
+ return statement.type === "sqlite_create_table" && (dialect7 === "sqlite" || dialect7 === "turso");
11626
11646
  }
11627
11647
  convert(st) {
11628
11648
  const {
@@ -11792,32 +11812,6 @@ var init_sqlgenerator = __esm({
11792
11812
  return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
11793
11813
  }
11794
11814
  };
11795
- SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
11796
- can(statement, dialect7) {
11797
- return statement.type === "create_unique_constraint" && dialect7 === "sqlite";
11798
- }
11799
- convert(statement) {
11800
- return `/*
11801
- SQLite does not support "Adding unique constraint to an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
11802
- Please refer to: https://www.techonthenet.com/sqlite/unique.php
11803
-
11804
- Due to that we don't generate migration automatically and it has to be done manually
11805
- */`;
11806
- }
11807
- };
11808
- SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
11809
- can(statement, dialect7) {
11810
- return statement.type === "delete_unique_constraint" && dialect7 === "sqlite";
11811
- }
11812
- convert(statement) {
11813
- return `/*
11814
- SQLite does not support "Dropping unique constraint from an existing table" out of the box, we do not generate automatic migration for that, so it has to be done manually
11815
- Please refer to: https://www.techonthenet.com/sqlite/unique.php
11816
-
11817
- Due to that we don't generate migration automatically and it has to be done manually
11818
- */`;
11819
- }
11820
- };
11821
11815
  CreatePgSequenceConvertor = class extends Convertor {
11822
11816
  can(statement, dialect7) {
11823
11817
  return statement.type === "create_sequence" && dialect7 === "postgresql";
@@ -11925,7 +11919,7 @@ var init_sqlgenerator = __esm({
11925
11919
  };
11926
11920
  SQLiteDropTableConvertor = class extends Convertor {
11927
11921
  can(statement, dialect7) {
11928
- return statement.type === "drop_table" && dialect7 === "sqlite";
11922
+ return statement.type === "drop_table" && (dialect7 === "sqlite" || dialect7 === "turso");
11929
11923
  }
11930
11924
  convert(statement) {
11931
11925
  const { tableName } = statement;
@@ -11945,7 +11939,7 @@ var init_sqlgenerator = __esm({
11945
11939
  };
11946
11940
  SqliteRenameTableConvertor = class extends Convertor {
11947
11941
  can(statement, dialect7) {
11948
- return statement.type === "rename_table" && dialect7 === "sqlite";
11942
+ return statement.type === "rename_table" && (dialect7 === "sqlite" || dialect7 === "turso");
11949
11943
  }
11950
11944
  convert(statement) {
11951
11945
  const { tableNameFrom, tableNameTo } = statement;
@@ -11982,11 +11976,11 @@ var init_sqlgenerator = __esm({
11982
11976
  };
11983
11977
  SQLiteAlterTableRenameColumnConvertor = class extends Convertor {
11984
11978
  can(statement, dialect7) {
11985
- return statement.type === "alter_table_rename_column" && dialect7 === "sqlite";
11979
+ return statement.type === "alter_table_rename_column" && (dialect7 === "sqlite" || dialect7 === "turso");
11986
11980
  }
11987
11981
  convert(statement) {
11988
11982
  const { tableName, oldColumnName, newColumnName } = statement;
11989
- return `ALTER TABLE \`${tableName}\` RENAME COLUMN \`${oldColumnName}\` TO \`${newColumnName}\`;`;
11983
+ return `ALTER TABLE \`${tableName}\` RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
11990
11984
  }
11991
11985
  };
11992
11986
  PgAlterTableDropColumnConvertor = class extends Convertor {
@@ -12010,7 +12004,7 @@ var init_sqlgenerator = __esm({
12010
12004
  };
12011
12005
  SQLiteAlterTableDropColumnConvertor = class extends Convertor {
12012
12006
  can(statement, dialect7) {
12013
- return statement.type === "alter_table_drop_column" && dialect7 === "sqlite";
12007
+ return statement.type === "alter_table_drop_column" && (dialect7 === "sqlite" || dialect7 === "turso");
12014
12008
  }
12015
12009
  convert(statement) {
12016
12010
  const { tableName, columnName } = statement;
@@ -12063,7 +12057,7 @@ var init_sqlgenerator = __esm({
12063
12057
  };
12064
12058
  SQLiteAlterTableAddColumnConvertor = class extends Convertor {
12065
12059
  can(statement, dialect7) {
12066
- return statement.type === "sqlite_alter_table_add_column" && dialect7 === "sqlite";
12060
+ return statement.type === "sqlite_alter_table_add_column" && (dialect7 === "sqlite" || dialect7 === "turso");
12067
12061
  }
12068
12062
  convert(statement) {
12069
12063
  const { tableName, column: column4, referenceData } = statement;
@@ -12087,21 +12081,6 @@ var init_sqlgenerator = __esm({
12087
12081
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DATA TYPE ${newDataType};`;
12088
12082
  }
12089
12083
  };
12090
- SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
12091
- can(statement, dialect7) {
12092
- return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
12093
- }
12094
- convert(statement) {
12095
- return `/*
12096
- SQLite does not support "Changing existing column type" out of the box, we do not generate automatic migration for that, so it has to be done manually
12097
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12098
- https://www.sqlite.org/lang_altertable.html
12099
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12100
-
12101
- Due to that we don't generate migration automatically and it has to be done manually
12102
- */`;
12103
- }
12104
- };
12105
12084
  PgAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
12106
12085
  can(statement, dialect7) {
12107
12086
  return statement.type === "alter_table_alter_column_set_default" && dialect7 === "postgresql";
@@ -12112,21 +12091,6 @@ var init_sqlgenerator = __esm({
12112
12091
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DEFAULT ${statement.newDefaultValue};`;
12113
12092
  }
12114
12093
  };
12115
- SqliteAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
12116
- can(statement, dialect7) {
12117
- return statement.type === "alter_table_alter_column_set_default" && dialect7 === "sqlite";
12118
- }
12119
- convert(statement) {
12120
- return `/*
12121
- SQLite does not support "Set default to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12122
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12123
- https://www.sqlite.org/lang_altertable.html
12124
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12125
-
12126
- Due to that we don't generate migration automatically and it has to be done manually
12127
- */`;
12128
- }
12129
- };
12130
12094
  PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
12131
12095
  can(statement, dialect7) {
12132
12096
  return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "postgresql";
@@ -12225,7 +12189,7 @@ var init_sqlgenerator = __esm({
12225
12189
  };
12226
12190
  SqliteAlterTableAlterColumnDropGeneratedConvertor = class extends Convertor {
12227
12191
  can(statement, dialect7) {
12228
- return statement.type === "alter_table_alter_column_drop_generated" && dialect7 === "sqlite";
12192
+ return statement.type === "alter_table_alter_column_drop_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
12229
12193
  }
12230
12194
  convert(statement) {
12231
12195
  const {
@@ -12266,7 +12230,7 @@ var init_sqlgenerator = __esm({
12266
12230
  };
12267
12231
  SqliteAlterTableAlterColumnSetExpressionConvertor = class extends Convertor {
12268
12232
  can(statement, dialect7) {
12269
- return statement.type === "alter_table_alter_column_set_generated" && dialect7 === "sqlite";
12233
+ return statement.type === "alter_table_alter_column_set_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
12270
12234
  }
12271
12235
  convert(statement) {
12272
12236
  const {
@@ -12307,7 +12271,7 @@ var init_sqlgenerator = __esm({
12307
12271
  };
12308
12272
  SqliteAlterTableAlterColumnAlterGeneratedConvertor = class extends Convertor {
12309
12273
  can(statement, dialect7) {
12310
- return statement.type === "alter_table_alter_column_alter_generated" && dialect7 === "sqlite";
12274
+ return statement.type === "alter_table_alter_column_alter_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
12311
12275
  }
12312
12276
  convert(statement) {
12313
12277
  const {
@@ -12400,6 +12364,67 @@ var init_sqlgenerator = __esm({
12400
12364
  return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
12401
12365
  }
12402
12366
  };
12367
+ LibSQLModifyColumn = class extends Convertor {
12368
+ can(statement, dialect7) {
12369
+ return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") && dialect7 === "turso";
12370
+ }
12371
+ convert(statement, json2) {
12372
+ const { tableName, columnName } = statement;
12373
+ let columnType = ``;
12374
+ let columnDefault = "";
12375
+ let columnNotNull = "";
12376
+ const sqlStatements = [];
12377
+ const indexes = [];
12378
+ for (const table4 of Object.values(json2.tables)) {
12379
+ for (const index4 of Object.values(table4.indexes)) {
12380
+ const unsquashed = SQLiteSquasher.unsquashIdx(index4);
12381
+ sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
12382
+ indexes.push({ ...unsquashed, tableName: table4.name });
12383
+ }
12384
+ }
12385
+ switch (statement.type) {
12386
+ case "alter_table_alter_column_set_type":
12387
+ columnType = ` ${statement.newDataType}`;
12388
+ columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12389
+ columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12390
+ break;
12391
+ case "alter_table_alter_column_drop_notnull":
12392
+ columnType = ` ${statement.newDataType}`;
12393
+ columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12394
+ columnNotNull = "";
12395
+ break;
12396
+ case "alter_table_alter_column_set_notnull":
12397
+ columnType = ` ${statement.newDataType}`;
12398
+ columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
12399
+ columnNotNull = ` NOT NULL`;
12400
+ break;
12401
+ case "alter_table_alter_column_set_default":
12402
+ columnType = ` ${statement.newDataType}`;
12403
+ columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
12404
+ columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12405
+ break;
12406
+ case "alter_table_alter_column_drop_default":
12407
+ columnType = ` ${statement.newDataType}`;
12408
+ columnDefault = "";
12409
+ columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
12410
+ break;
12411
+ }
12412
+ columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
12413
+ sqlStatements.push(
12414
+ `ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`
12415
+ );
12416
+ for (const index4 of indexes) {
12417
+ const indexPart = index4.isUnique ? "UNIQUE INDEX" : "INDEX";
12418
+ const whereStatement = index4.where ? ` WHERE ${index4.where}` : "";
12419
+ const uniqueString = index4.columns.map((it) => `\`${it}\``).join(",");
12420
+ const tableName2 = index4.tableName;
12421
+ sqlStatements.push(
12422
+ `CREATE ${indexPart} \`${index4.name}\` ON \`${tableName2}\` (${uniqueString})${whereStatement};`
12423
+ );
12424
+ }
12425
+ return sqlStatements;
12426
+ }
12427
+ };
12403
12428
  MySqlModifyColumn = class extends Convertor {
12404
12429
  can(statement, dialect7) {
12405
12430
  return (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_on_update" || statement.type === "alter_table_alter_column_set_on_update" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_generated" || statement.type === "alter_table_alter_column_drop_generated") && dialect7 === "mysql";
@@ -12537,21 +12562,6 @@ var init_sqlgenerator = __esm({
12537
12562
  return `ALTER TABLE \`${tableName}\` MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnGenerated}${columnNotNull}${columnDefault}${columnOnUpdate};`;
12538
12563
  }
12539
12564
  };
12540
- SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
12541
- can(statement, dialect7) {
12542
- return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "sqlite";
12543
- }
12544
- convert(statement) {
12545
- return `/*
12546
- SQLite does not support "Drop default from column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12547
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12548
- https://www.sqlite.org/lang_altertable.html
12549
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12550
-
12551
- Due to that we don't generate migration automatically and it has to be done manually
12552
- */`;
12553
- }
12554
- };
12555
12565
  PgAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
12556
12566
  can(statement, dialect7) {
12557
12567
  return statement.type === "create_composite_pk" && dialect7 === "postgresql";
@@ -12616,85 +12626,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12616
12626
  return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY, ADD PRIMARY KEY(\`${newColumns.join("`,`")}\`);`;
12617
12627
  }
12618
12628
  };
12619
- SqliteAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
12620
- can(statement, dialect7) {
12621
- return statement.type === "create_composite_pk" && dialect7 === "sqlite";
12622
- }
12623
- convert(statement) {
12624
- let msg = "/*\n";
12625
- msg += `You're trying to add PRIMARY KEY(${statement.data}) to '${statement.tableName}' table
12626
- `;
12627
- msg += "SQLite does not support adding primary key to an already created table\n";
12628
- msg += "You can do it in 3 steps with drizzle orm:\n";
12629
- msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
12630
- msg += " - migrate old data from one table to another\n";
12631
- msg += " - delete old_table in schema, generate sql\n\n";
12632
- msg += "or create manual migration like below:\n\n";
12633
- msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12634
- msg += "CREATE TABLE table_name (\n";
12635
- msg += " column1 datatype [ NULL | NOT NULL ],\n";
12636
- msg += " column2 datatype [ NULL | NOT NULL ],\n";
12637
- msg += " ...\n";
12638
- msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12639
- msg += " );\n";
12640
- msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12641
- msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12642
- msg += "*/\n";
12643
- return msg;
12644
- }
12645
- };
12646
- SqliteAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
12647
- can(statement, dialect7) {
12648
- return statement.type === "delete_composite_pk" && dialect7 === "sqlite";
12649
- }
12650
- convert(statement) {
12651
- let msg = "/*\n";
12652
- msg += `You're trying to delete PRIMARY KEY(${statement.data}) from '${statement.tableName}' table
12653
- `;
12654
- msg += "SQLite does not supportprimary key deletion from existing table\n";
12655
- msg += "You can do it in 3 steps with drizzle orm:\n";
12656
- msg += " - create new mirror table table without pk, rename current table to old_table, generate SQL\n";
12657
- msg += " - migrate old data from one table to another\n";
12658
- msg += " - delete old_table in schema, generate sql\n\n";
12659
- msg += "or create manual migration like below:\n\n";
12660
- msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12661
- msg += "CREATE TABLE table_name (\n";
12662
- msg += " column1 datatype [ NULL | NOT NULL ],\n";
12663
- msg += " column2 datatype [ NULL | NOT NULL ],\n";
12664
- msg += " ...\n";
12665
- msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12666
- msg += " );\n";
12667
- msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12668
- msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12669
- msg += "*/\n";
12670
- return msg;
12671
- }
12672
- };
12673
- SqliteAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
12674
- can(statement, dialect7) {
12675
- return statement.type === "alter_composite_pk" && dialect7 === "sqlite";
12676
- }
12677
- convert(statement) {
12678
- let msg = "/*\n";
12679
- msg += "SQLite does not support altering primary key\n";
12680
- msg += "You can do it in 3 steps with drizzle orm:\n";
12681
- msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
12682
- msg += " - migrate old data from one table to another\n";
12683
- msg += " - delete old_table in schema, generate sql\n\n";
12684
- msg += "or create manual migration like below:\n\n";
12685
- msg += "ALTER TABLE table_name RENAME TO old_table;\n";
12686
- msg += "CREATE TABLE table_name (\n";
12687
- msg += " column1 datatype [ NULL | NOT NULL ],\n";
12688
- msg += " column2 datatype [ NULL | NOT NULL ],\n";
12689
- msg += " ...\n";
12690
- msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
12691
- msg += " );\n";
12692
- msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
12693
- msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
12694
- msg += "*/\n";
12695
- return msg;
12696
- }
12697
- };
12698
12629
  PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
12699
12630
  can(statement, dialect7) {
12700
12631
  return statement.type === "alter_table_alter_column_set_pk" && dialect7 === "postgresql";
@@ -12739,51 +12670,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12739
12670
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET NOT NULL;`;
12740
12671
  }
12741
12672
  };
12742
- SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
12743
- can(statement, dialect7) {
12744
- return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
12745
- }
12746
- convert(statement) {
12747
- return `/*
12748
- SQLite does not support "Set not null to column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12749
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12750
- https://www.sqlite.org/lang_altertable.html
12751
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12752
-
12753
- Due to that we don't generate migration automatically and it has to be done manually
12754
- */`;
12755
- }
12756
- };
12757
- SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
12758
- can(statement, dialect7) {
12759
- return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
12760
- }
12761
- convert(statement) {
12762
- return `/*
12763
- SQLite does not support "Set autoincrement to a column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12764
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12765
- https://www.sqlite.org/lang_altertable.html
12766
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12767
-
12768
- Due to that we don't generate migration automatically and it has to be done manually
12769
- */`;
12770
- }
12771
- };
12772
- SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
12773
- can(statement, dialect7) {
12774
- return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
12775
- }
12776
- convert(statement) {
12777
- return `/*
12778
- SQLite does not support "Drop autoincrement from a column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12779
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12780
- https://www.sqlite.org/lang_altertable.html
12781
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12782
-
12783
- Due to that we don't generate migration automatically and it has to be done manually
12784
- */`;
12785
- }
12786
- };
12787
12673
  PgAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
12788
12674
  can(statement, dialect7) {
12789
12675
  return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "postgresql";
@@ -12794,21 +12680,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12794
12680
  return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP NOT NULL;`;
12795
12681
  }
12796
12682
  };
12797
- SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
12798
- can(statement, dialect7) {
12799
- return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
12800
- }
12801
- convert(statement) {
12802
- return `/*
12803
- SQLite does not support "Drop not null from column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12804
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12805
- https://www.sqlite.org/lang_altertable.html
12806
- https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
12807
-
12808
- Due to that we don't generate migration automatically and it has to be done manually
12809
- */`;
12810
- }
12811
- };
12812
12683
  PgCreateForeignKeyConvertor = class extends Convertor {
12813
12684
  can(statement, dialect7) {
12814
12685
  return statement.type === "create_reference" && dialect7 === "postgresql";
@@ -12839,18 +12710,21 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12839
12710
  return sql2;
12840
12711
  }
12841
12712
  };
12842
- SqliteCreateForeignKeyConvertor = class extends Convertor {
12713
+ LibSQLCreateForeignKeyConvertor = class extends Convertor {
12843
12714
  can(statement, dialect7) {
12844
- return statement.type === "create_reference" && dialect7 === "sqlite";
12715
+ return statement.type === "create_reference" && dialect7 === "turso";
12845
12716
  }
12846
- convert(statement) {
12847
- return `/*
12848
- SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually
12849
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12850
- https://www.sqlite.org/lang_altertable.html
12851
-
12852
- Due to that we don't generate migration automatically and it has to be done manually
12853
- */`;
12717
+ convert(statement, json2, action) {
12718
+ const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
12719
+ const { columnDefault, columnNotNull, columnType } = statement;
12720
+ const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
12721
+ const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
12722
+ const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
12723
+ const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
12724
+ const columnTypeValue = columnType ? ` ${columnType}` : "";
12725
+ const columnFrom = columnsFrom[0];
12726
+ const columnTo = columnsTo[0];
12727
+ return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
12854
12728
  }
12855
12729
  };
12856
12730
  MySqlCreateForeignKeyConvertor = class extends Convertor {
@@ -12899,20 +12773,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12899
12773
  return sql2;
12900
12774
  }
12901
12775
  };
12902
- SqliteAlterForeignKeyConvertor = class extends Convertor {
12903
- can(statement, dialect7) {
12904
- return statement.type === "alter_reference" && dialect7 === "sqlite";
12905
- }
12906
- convert(statement) {
12907
- return `/*
12908
- SQLite does not support "Changing existing foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually
12909
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12910
- https://www.sqlite.org/lang_altertable.html
12911
-
12912
- Due to that we don't generate migration automatically and it has to be done manually
12913
- */`;
12914
- }
12915
- };
12916
12776
  PgDeleteForeignKeyConvertor = class extends Convertor {
12917
12777
  can(statement, dialect7) {
12918
12778
  return statement.type === "delete_reference" && dialect7 === "postgresql";
@@ -12925,20 +12785,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12925
12785
  `;
12926
12786
  }
12927
12787
  };
12928
- SqliteDeleteForeignKeyConvertor = class extends Convertor {
12929
- can(statement, dialect7) {
12930
- return statement.type === "delete_reference" && dialect7 === "sqlite";
12931
- }
12932
- convert(statement) {
12933
- return `/*
12934
- SQLite does not support "Dropping foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually
12935
- Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
12936
- https://www.sqlite.org/lang_altertable.html
12937
-
12938
- Due to that we don't generate migration automatically and it has to be done manually
12939
- */`;
12940
- }
12941
- };
12942
12788
  MySqlDeleteForeignKeyConvertor = class extends Convertor {
12943
12789
  can(statement, dialect7) {
12944
12790
  return statement.type === "delete_reference" && dialect7 === "mysql";
@@ -12999,7 +12845,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
12999
12845
  };
13000
12846
  CreateSqliteIndexConvertor = class extends Convertor {
13001
12847
  can(statement, dialect7) {
13002
- return statement.type === "create_index" && dialect7 === "sqlite";
12848
+ return statement.type === "create_index" && (dialect7 === "sqlite" || dialect7 === "turso");
13003
12849
  }
13004
12850
  convert(statement) {
13005
12851
  const { name: name2, columns, isUnique, where } = SQLiteSquasher.unsquashIdx(
@@ -13086,7 +12932,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13086
12932
  };
13087
12933
  SqliteDropIndexConvertor = class extends Convertor {
13088
12934
  can(statement, dialect7) {
13089
- return statement.type === "drop_index" && dialect7 === "sqlite";
12935
+ return statement.type === "drop_index" && (dialect7 === "sqlite" || dialect7 === "turso");
13090
12936
  }
13091
12937
  convert(statement) {
13092
12938
  const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
@@ -13102,10 +12948,96 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13102
12948
  return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
13103
12949
  }
13104
12950
  };
12951
+ SQLiteRecreateTableConvertor = class extends Convertor {
12952
+ can(statement, dialect7) {
12953
+ return statement.type === "recreate_table" && dialect7 === "sqlite";
12954
+ }
12955
+ convert(statement) {
12956
+ const { tableName, columns, compositePKs, referenceData } = statement;
12957
+ const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
12958
+ const newTableName = `__new_${tableName}`;
12959
+ const sqlStatements = [];
12960
+ sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
12961
+ sqlStatements.push(
12962
+ new SQLiteCreateTableConvertor().convert({
12963
+ type: "sqlite_create_table",
12964
+ tableName: newTableName,
12965
+ columns,
12966
+ referenceData,
12967
+ compositePKs
12968
+ })
12969
+ );
12970
+ sqlStatements.push(
12971
+ `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
12972
+ );
12973
+ sqlStatements.push(
12974
+ new SQLiteDropTableConvertor().convert({
12975
+ type: "drop_table",
12976
+ tableName,
12977
+ schema: ""
12978
+ })
12979
+ );
12980
+ sqlStatements.push(
12981
+ new SqliteRenameTableConvertor().convert({
12982
+ fromSchema: "",
12983
+ tableNameFrom: newTableName,
12984
+ tableNameTo: tableName,
12985
+ toSchema: "",
12986
+ type: "rename_table"
12987
+ })
12988
+ );
12989
+ sqlStatements.push(`PRAGMA foreign_keys=ON;`);
12990
+ return sqlStatements;
12991
+ }
12992
+ };
12993
+ LibSQLRecreateTableConvertor = class extends Convertor {
12994
+ can(statement, dialect7) {
12995
+ return statement.type === "recreate_table" && dialect7 === "turso";
12996
+ }
12997
+ convert(statement) {
12998
+ const { tableName, columns, compositePKs, referenceData } = statement;
12999
+ const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
13000
+ const newTableName = `__new_${tableName}`;
13001
+ const sqlStatements = [];
13002
+ sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
13003
+ sqlStatements.push(
13004
+ new SQLiteCreateTableConvertor().convert({
13005
+ type: "sqlite_create_table",
13006
+ tableName: newTableName,
13007
+ columns,
13008
+ referenceData,
13009
+ compositePKs
13010
+ })
13011
+ );
13012
+ sqlStatements.push(
13013
+ `INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
13014
+ );
13015
+ sqlStatements.push(
13016
+ new SQLiteDropTableConvertor().convert({
13017
+ type: "drop_table",
13018
+ tableName,
13019
+ schema: ""
13020
+ })
13021
+ );
13022
+ sqlStatements.push(
13023
+ new SqliteRenameTableConvertor().convert({
13024
+ fromSchema: "",
13025
+ tableNameFrom: newTableName,
13026
+ tableNameTo: tableName,
13027
+ toSchema: "",
13028
+ type: "rename_table"
13029
+ })
13030
+ );
13031
+ sqlStatements.push(`PRAGMA foreign_keys=ON;`);
13032
+ return sqlStatements;
13033
+ }
13034
+ };
13105
13035
  convertors = [];
13106
13036
  convertors.push(new PgCreateTableConvertor());
13107
13037
  convertors.push(new MySqlCreateTableConvertor());
13108
13038
  convertors.push(new SQLiteCreateTableConvertor());
13039
+ convertors.push(new SQLiteRecreateTableConvertor());
13040
+ convertors.push(new LibSQLRecreateTableConvertor());
13109
13041
  convertors.push(new CreateTypeEnumConvertor());
13110
13042
  convertors.push(new CreatePgSequenceConvertor());
13111
13043
  convertors.push(new DropPgSequenceConvertor());
@@ -13153,6 +13085,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13153
13085
  convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
13154
13086
  convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
13155
13087
  convertors.push(new MySqlModifyColumn());
13088
+ convertors.push(new LibSQLModifyColumn());
13156
13089
  convertors.push(new PgCreateForeignKeyConvertor());
13157
13090
  convertors.push(new MySqlCreateForeignKeyConvertor());
13158
13091
  convertors.push(new PgAlterForeignKeyConvertor());
@@ -13164,24 +13097,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13164
13097
  convertors.push(new PgAlterTableSetSchemaConvertor());
13165
13098
  convertors.push(new PgAlterTableSetNewSchemaConvertor());
13166
13099
  convertors.push(new PgAlterTableRemoveFromSchemaConvertor());
13167
- convertors.push(new SQLiteAlterTableAlterColumnSetTypeConvertor());
13168
- convertors.push(new SqliteAlterForeignKeyConvertor());
13169
- convertors.push(new SqliteDeleteForeignKeyConvertor());
13170
- convertors.push(new SqliteCreateForeignKeyConvertor());
13171
- convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
13172
- convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
13100
+ convertors.push(new LibSQLCreateForeignKeyConvertor());
13173
13101
  convertors.push(new PgAlterTableAlterColumnDropGenerated());
13174
13102
  convertors.push(new PgAlterTableAlterColumnSetGenerated());
13175
13103
  convertors.push(new PgAlterTableAlterColumnAlterGenerated());
13176
- convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
13177
- convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
13178
- convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
13179
- convertors.push(new SqliteAlterTableAlterColumnDropDefaultConvertor());
13180
- convertors.push(new SqliteAlterTableAlterColumnSetAutoincrementConvertor());
13181
- convertors.push(new SqliteAlterTableAlterColumnDropAutoincrementConvertor());
13182
- convertors.push(new SqliteAlterTableCreateCompositePrimaryKeyConvertor());
13183
- convertors.push(new SqliteAlterTableDeleteCompositePrimaryKeyConvertor());
13184
- convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
13185
13104
  convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
13186
13105
  convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
13187
13106
  convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
@@ -13190,19 +13109,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
13190
13109
  convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
13191
13110
  convertors.push(new MySqlAlterTableAddPk());
13192
13111
  convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
13193
- fromJson = (statements, dialect7) => {
13194
- const result = statements.flatMap((statement) => {
13195
- const filtered = convertors.filter((it) => {
13196
- return it.can(statement, dialect7);
13197
- });
13198
- const convertor = filtered.length === 1 ? filtered[0] : void 0;
13199
- if (!convertor) {
13200
- return "";
13201
- }
13202
- return convertor.convert(statement);
13203
- }).filter((it) => it !== "");
13204
- return result;
13205
- };
13206
13112
  https: `
13207
13113
  create table users (
13208
13114
  id int,
@@ -13229,12 +13135,248 @@ drop type __venum;
13229
13135
  }
13230
13136
  });
13231
13137
 
13138
+ // src/cli/commands/sqlitePushUtils.ts
13139
+ var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
13140
+ var init_sqlitePushUtils = __esm({
13141
+ "src/cli/commands/sqlitePushUtils.ts"() {
13142
+ "use strict";
13143
+ init_source();
13144
+ init_sqliteSchema();
13145
+ init_sqlgenerator();
13146
+ init_utils();
13147
+ _moveDataStatements = (tableName, json, dataLoss = false) => {
13148
+ const statements = [];
13149
+ const newTableName = `__new_${tableName}`;
13150
+ const tableColumns = Object.values(json.tables[tableName].columns);
13151
+ const referenceData = Object.values(json.tables[tableName].foreignKeys);
13152
+ const compositePKs = Object.values(
13153
+ json.tables[tableName].compositePrimaryKeys
13154
+ ).map((it) => SQLiteSquasher.unsquashPK(it));
13155
+ const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
13156
+ statements.push(
13157
+ new SQLiteCreateTableConvertor().convert({
13158
+ type: "sqlite_create_table",
13159
+ tableName: newTableName,
13160
+ columns: tableColumns,
13161
+ referenceData: fks,
13162
+ compositePKs
13163
+ })
13164
+ );
13165
+ if (!dataLoss) {
13166
+ const columns = Object.keys(json.tables[tableName].columns).map(
13167
+ (c) => `"${c}"`
13168
+ );
13169
+ statements.push(
13170
+ `INSERT INTO \`${newTableName}\`(${columns.join(
13171
+ ", "
13172
+ )}) SELECT ${columns.join(", ")} FROM \`${tableName}\`;`
13173
+ );
13174
+ }
13175
+ statements.push(
13176
+ new SQLiteDropTableConvertor().convert({
13177
+ type: "drop_table",
13178
+ tableName,
13179
+ schema: ""
13180
+ })
13181
+ );
13182
+ statements.push(
13183
+ new SqliteRenameTableConvertor().convert({
13184
+ fromSchema: "",
13185
+ tableNameFrom: newTableName,
13186
+ tableNameTo: tableName,
13187
+ toSchema: "",
13188
+ type: "rename_table"
13189
+ })
13190
+ );
13191
+ for (const idx of Object.values(json.tables[tableName].indexes)) {
13192
+ statements.push(
13193
+ new CreateSqliteIndexConvertor().convert({
13194
+ type: "create_index",
13195
+ tableName,
13196
+ schema: "",
13197
+ data: idx
13198
+ })
13199
+ );
13200
+ }
13201
+ return statements;
13202
+ };
13203
+ getOldTableName = (tableName, meta) => {
13204
+ for (const key of Object.keys(meta.tables)) {
13205
+ const value = meta.tables[key];
13206
+ if (`"${tableName}"` === value) {
13207
+ return key.substring(1, key.length - 1);
13208
+ }
13209
+ }
13210
+ return tableName;
13211
+ };
13212
+ getNewTableName = (tableName, meta) => {
13213
+ if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
13214
+ return meta.tables[`"${tableName}"`].substring(
13215
+ 1,
13216
+ meta.tables[`"${tableName}"`].length - 1
13217
+ );
13218
+ }
13219
+ return tableName;
13220
+ };
13221
+ logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
13222
+ let shouldAskForApprove = false;
13223
+ const statementsToExecute = [];
13224
+ const infoToPrint = [];
13225
+ const tablesToRemove = [];
13226
+ const columnsToRemove = [];
13227
+ const schemasToRemove = [];
13228
+ const tablesToTruncate = [];
13229
+ for (const statement of statements) {
13230
+ if (statement.type === "drop_table") {
13231
+ const res = await connection.query(
13232
+ `select count(*) as count from \`${statement.tableName}\``
13233
+ );
13234
+ const count2 = Number(res[0].count);
13235
+ if (count2 > 0) {
13236
+ infoToPrint.push(
13237
+ `\xB7 You're about to delete ${source_default.underline(
13238
+ statement.tableName
13239
+ )} table with ${count2} items`
13240
+ );
13241
+ tablesToRemove.push(statement.tableName);
13242
+ shouldAskForApprove = true;
13243
+ }
13244
+ const fromJsonStatement = fromJson([statement], "sqlite", "push");
13245
+ statementsToExecute.push(
13246
+ ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13247
+ );
13248
+ } else if (statement.type === "alter_table_drop_column") {
13249
+ const tableName = statement.tableName;
13250
+ const columnName = statement.columnName;
13251
+ const res = await connection.query(
13252
+ `select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
13253
+ );
13254
+ const count2 = Number(res[0].count);
13255
+ if (count2 > 0) {
13256
+ infoToPrint.push(
13257
+ `\xB7 You're about to delete ${source_default.underline(
13258
+ columnName
13259
+ )} column in ${tableName} table with ${count2} items`
13260
+ );
13261
+ columnsToRemove.push(`${tableName}_${statement.columnName}`);
13262
+ shouldAskForApprove = true;
13263
+ }
13264
+ const fromJsonStatement = fromJson([statement], "sqlite", "push");
13265
+ statementsToExecute.push(
13266
+ ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13267
+ );
13268
+ } else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
13269
+ const tableName = statement.tableName;
13270
+ const columnName = statement.column.name;
13271
+ const res = await connection.query(
13272
+ `select count(*) as count from \`${tableName}\``
13273
+ );
13274
+ const count2 = Number(res[0].count);
13275
+ if (count2 > 0) {
13276
+ infoToPrint.push(
13277
+ `\xB7 You're about to add not-null ${source_default.underline(
13278
+ columnName
13279
+ )} column without default value, which contains ${count2} items`
13280
+ );
13281
+ tablesToTruncate.push(tableName);
13282
+ statementsToExecute.push(`delete from ${tableName};`);
13283
+ shouldAskForApprove = true;
13284
+ }
13285
+ const fromJsonStatement = fromJson([statement], "sqlite", "push");
13286
+ statementsToExecute.push(
13287
+ ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13288
+ );
13289
+ } else if (statement.type === "recreate_table") {
13290
+ const tableName = statement.tableName;
13291
+ const oldTableName = getOldTableName(tableName, meta);
13292
+ let dataLoss = false;
13293
+ const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
13294
+ const currentColumnNames = Object.keys(json2.tables[tableName].columns);
13295
+ const { removedColumns, addedColumns } = findAddedAndRemoved(
13296
+ prevColumnNames,
13297
+ currentColumnNames
13298
+ );
13299
+ if (removedColumns.length) {
13300
+ for (const removedColumn of removedColumns) {
13301
+ const res = await connection.query(
13302
+ `select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
13303
+ );
13304
+ const count2 = Number(res[0].count);
13305
+ if (count2 > 0) {
13306
+ infoToPrint.push(
13307
+ `\xB7 You're about to delete ${source_default.underline(
13308
+ removedColumn
13309
+ )} column in ${tableName} table with ${count2} items`
13310
+ );
13311
+ columnsToRemove.push(removedColumn);
13312
+ shouldAskForApprove = true;
13313
+ }
13314
+ }
13315
+ }
13316
+ if (addedColumns.length) {
13317
+ for (const addedColumn of addedColumns) {
13318
+ const [res] = await connection.query(
13319
+ `select count(*) as count from \`${tableName}\``
13320
+ );
13321
+ const columnConf = json2.tables[tableName].columns[addedColumn];
13322
+ const count2 = Number(res.count);
13323
+ if (count2 > 0 && columnConf.notNull && !columnConf.default) {
13324
+ dataLoss = true;
13325
+ infoToPrint.push(
13326
+ `\xB7 You're about to add not-null ${source_default.underline(
13327
+ addedColumn
13328
+ )} column without default value to table, which contains ${count2} items`
13329
+ );
13330
+ shouldAskForApprove = true;
13331
+ tablesToTruncate.push(tableName);
13332
+ statementsToExecute.push(`DELETE FROM \`${tableName}\`;`);
13333
+ }
13334
+ }
13335
+ }
13336
+ const tablesReferencingCurrent = [];
13337
+ for (const table4 of Object.values(json2.tables)) {
13338
+ const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
13339
+ tablesReferencingCurrent.push(...tablesRefs);
13340
+ }
13341
+ if (!tablesReferencingCurrent.length) {
13342
+ statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
13343
+ continue;
13344
+ }
13345
+ const [{ foreign_keys: pragmaState }] = await connection.query(`PRAGMA foreign_keys;`);
13346
+ if (pragmaState) {
13347
+ statementsToExecute.push(`PRAGMA foreign_keys=OFF;`);
13348
+ }
13349
+ statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
13350
+ if (pragmaState) {
13351
+ statementsToExecute.push(`PRAGMA foreign_keys=ON;`);
13352
+ }
13353
+ } else {
13354
+ const fromJsonStatement = fromJson([statement], "sqlite", "push");
13355
+ statementsToExecute.push(
13356
+ ...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
13357
+ );
13358
+ }
13359
+ }
13360
+ return {
13361
+ statementsToExecute,
13362
+ shouldAskForApprove,
13363
+ infoToPrint,
13364
+ columnsToRemove: [...new Set(columnsToRemove)],
13365
+ schemasToRemove: [...new Set(schemasToRemove)],
13366
+ tablesToTruncate: [...new Set(tablesToTruncate)],
13367
+ tablesToRemove: [...new Set(tablesToRemove)]
13368
+ };
13369
+ };
13370
+ }
13371
+ });
13372
+
13232
13373
  // src/jsonStatements.ts
13233
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13374
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSequenceJson, prepareAlterSequenceJson, prepareDropSequenceJson, prepareMoveSequenceJson, prepareRenameSequenceJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareLibSQLCreateReferencesJson, prepareDropReferencesJson, prepareLibSQLDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
13234
13375
  var init_jsonStatements = __esm({
13235
13376
  "src/jsonStatements.ts"() {
13236
13377
  "use strict";
13237
13378
  init_source();
13379
+ init_sqlitePushUtils();
13238
13380
  init_views();
13239
13381
  init_mysqlSchema();
13240
13382
  init_pgSchema();
@@ -14018,6 +14160,49 @@ var init_jsonStatements = __esm({
14018
14160
  const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
14019
14161
  const columnGenerated = json2.tables[tableName].columns[columnName].generated;
14020
14162
  const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
14163
+ if (column4.autoincrement?.type === "added") {
14164
+ statements.push({
14165
+ type: "alter_table_alter_column_set_autoincrement",
14166
+ tableName,
14167
+ columnName,
14168
+ schema: schema4,
14169
+ newDataType: columnType,
14170
+ columnDefault,
14171
+ columnOnUpdate,
14172
+ columnNotNull,
14173
+ columnAutoIncrement,
14174
+ columnPk
14175
+ });
14176
+ }
14177
+ if (column4.autoincrement?.type === "changed") {
14178
+ const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
14179
+ statements.push({
14180
+ type,
14181
+ tableName,
14182
+ columnName,
14183
+ schema: schema4,
14184
+ newDataType: columnType,
14185
+ columnDefault,
14186
+ columnOnUpdate,
14187
+ columnNotNull,
14188
+ columnAutoIncrement,
14189
+ columnPk
14190
+ });
14191
+ }
14192
+ if (column4.autoincrement?.type === "deleted") {
14193
+ statements.push({
14194
+ type: "alter_table_alter_column_drop_autoincrement",
14195
+ tableName,
14196
+ columnName,
14197
+ schema: schema4,
14198
+ newDataType: columnType,
14199
+ columnDefault,
14200
+ columnOnUpdate,
14201
+ columnNotNull,
14202
+ columnAutoIncrement,
14203
+ columnPk
14204
+ });
14205
+ }
14021
14206
  if (typeof column4.name !== "string") {
14022
14207
  statements.push({
14023
14208
  type: "alter_table_rename_column",
@@ -14281,6 +14466,37 @@ var init_jsonStatements = __esm({
14281
14466
  };
14282
14467
  });
14283
14468
  };
14469
+ prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
14470
+ return Object.values(foreignKeys).map((fkData) => {
14471
+ const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14472
+ let isMulticolumn = false;
14473
+ if (columnsFrom.length > 1 || columnsTo.length > 1) {
14474
+ isMulticolumn = true;
14475
+ return {
14476
+ type: "create_reference",
14477
+ tableName,
14478
+ data: fkData,
14479
+ schema: schema4,
14480
+ isMulticolumn
14481
+ };
14482
+ }
14483
+ const columnFrom = columnsFrom[0];
14484
+ const {
14485
+ notNull: columnNotNull,
14486
+ default: columnDefault,
14487
+ type: columnType
14488
+ } = json2.tables[tableFrom].columns[columnFrom];
14489
+ return {
14490
+ type: "create_reference",
14491
+ tableName,
14492
+ data: fkData,
14493
+ schema: schema4,
14494
+ columnNotNull,
14495
+ columnDefault,
14496
+ columnType
14497
+ };
14498
+ });
14499
+ };
14284
14500
  prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
14285
14501
  return Object.values(foreignKeys).map((fkData) => {
14286
14502
  return {
@@ -14291,6 +14507,53 @@ var init_jsonStatements = __esm({
14291
14507
  };
14292
14508
  });
14293
14509
  };
14510
+ prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
14511
+ const statements = Object.values(foreignKeys).map((fkData) => {
14512
+ const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
14513
+ const keys = Object.keys(json2.tables[tableName].columns);
14514
+ const filtered = columnsFrom.filter((it) => keys.includes(it));
14515
+ const fullDrop = filtered.length === 0;
14516
+ if (fullDrop) return;
14517
+ let isMulticolumn = false;
14518
+ if (columnsFrom.length > 1 || columnsTo.length > 1) {
14519
+ isMulticolumn = true;
14520
+ return {
14521
+ type: "delete_reference",
14522
+ tableName,
14523
+ data: fkData,
14524
+ schema: schema4,
14525
+ isMulticolumn
14526
+ };
14527
+ }
14528
+ const columnFrom = columnsFrom[0];
14529
+ const newTableName = getNewTableName(tableFrom, meta);
14530
+ const {
14531
+ notNull: columnNotNull,
14532
+ default: columnDefault,
14533
+ type: columnType
14534
+ } = json2.tables[newTableName].columns[columnFrom];
14535
+ const fkToSquash = {
14536
+ columnsFrom,
14537
+ columnsTo,
14538
+ name: name2,
14539
+ tableFrom: newTableName,
14540
+ tableTo,
14541
+ onDelete,
14542
+ onUpdate
14543
+ };
14544
+ const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
14545
+ return {
14546
+ type: "delete_reference",
14547
+ tableName,
14548
+ data: foreignKey,
14549
+ schema: schema4,
14550
+ columnNotNull,
14551
+ columnDefault,
14552
+ columnType
14553
+ };
14554
+ });
14555
+ return statements.filter((it) => it);
14556
+ };
14294
14557
  prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
14295
14558
  const stmts = [];
14296
14559
  Object.values(foreignKeys).map((val) => {
@@ -14444,10 +14707,292 @@ var init_jsonStatements = __esm({
14444
14707
  }
14445
14708
  });
14446
14709
 
14710
+ // src/statementCombiner.ts
14711
+ var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
14712
+ var init_statementCombiner = __esm({
14713
+ "src/statementCombiner.ts"() {
14714
+ "use strict";
14715
+ init_jsonStatements();
14716
+ init_sqliteSchema();
14717
+ prepareLibSQLRecreateTable = (table4, action) => {
14718
+ const { name: name2, columns, uniqueConstraints, indexes } = table4;
14719
+ const composites = Object.values(table4.compositePrimaryKeys).map(
14720
+ (it) => SQLiteSquasher.unsquashPK(it)
14721
+ );
14722
+ const references2 = Object.values(table4.foreignKeys);
14723
+ const fks = references2.map(
14724
+ (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14725
+ );
14726
+ const statements = [
14727
+ {
14728
+ type: "recreate_table",
14729
+ tableName: name2,
14730
+ columns: Object.values(columns),
14731
+ compositePKs: composites,
14732
+ referenceData: fks,
14733
+ uniqueConstraints: Object.values(uniqueConstraints)
14734
+ }
14735
+ ];
14736
+ if (Object.keys(indexes).length) {
14737
+ statements.push(...prepareCreateIndexesJson(name2, "", indexes));
14738
+ }
14739
+ return statements;
14740
+ };
14741
+ prepareSQLiteRecreateTable = (table4, action) => {
14742
+ const { name: name2, columns, uniqueConstraints, indexes } = table4;
14743
+ const composites = Object.values(table4.compositePrimaryKeys).map(
14744
+ (it) => SQLiteSquasher.unsquashPK(it)
14745
+ );
14746
+ const references2 = Object.values(table4.foreignKeys);
14747
+ const fks = references2.map(
14748
+ (it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
14749
+ );
14750
+ const statements = [
14751
+ {
14752
+ type: "recreate_table",
14753
+ tableName: name2,
14754
+ columns: Object.values(columns),
14755
+ compositePKs: composites,
14756
+ referenceData: fks,
14757
+ uniqueConstraints: Object.values(uniqueConstraints)
14758
+ }
14759
+ ];
14760
+ if (Object.keys(indexes).length) {
14761
+ statements.push(...prepareCreateIndexesJson(name2, "", indexes));
14762
+ }
14763
+ return statements;
14764
+ };
14765
+ libSQLCombineStatements = (statements, json2, action) => {
14766
+ const newStatements = {};
14767
+ for (const statement of statements) {
14768
+ if (statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk") {
14769
+ const tableName2 = statement.tableName;
14770
+ const statementsForTable2 = newStatements[tableName2];
14771
+ if (!statementsForTable2) {
14772
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14773
+ continue;
14774
+ }
14775
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14776
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14777
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14778
+ if (wasRename) {
14779
+ newStatements[tableName2].push(...preparedStatements);
14780
+ } else {
14781
+ newStatements[tableName2] = preparedStatements;
14782
+ }
14783
+ continue;
14784
+ }
14785
+ continue;
14786
+ }
14787
+ if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default") {
14788
+ const { tableName: tableName2, columnName, columnPk } = statement;
14789
+ const columnIsPartOfForeignKey = Object.values(
14790
+ json2.tables[tableName2].foreignKeys
14791
+ ).some((it) => {
14792
+ const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
14793
+ return unsquashFk.columnsFrom.includes(columnName);
14794
+ });
14795
+ const statementsForTable2 = newStatements[tableName2];
14796
+ if (!statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
14797
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14798
+ continue;
14799
+ }
14800
+ if (statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
14801
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14802
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14803
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14804
+ if (wasRename) {
14805
+ newStatements[tableName2].push(...preparedStatements);
14806
+ } else {
14807
+ newStatements[tableName2] = preparedStatements;
14808
+ }
14809
+ }
14810
+ continue;
14811
+ }
14812
+ if (statementsForTable2 && !(columnIsPartOfForeignKey || columnPk)) {
14813
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14814
+ newStatements[tableName2].push(statement);
14815
+ }
14816
+ continue;
14817
+ }
14818
+ newStatements[tableName2] = [statement];
14819
+ continue;
14820
+ }
14821
+ if (statement.type === "create_reference") {
14822
+ const tableName2 = statement.tableName;
14823
+ const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
14824
+ const statementsForTable2 = newStatements[tableName2];
14825
+ if (!statementsForTable2) {
14826
+ newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : [statement];
14827
+ continue;
14828
+ }
14829
+ if (!statement.isMulticolumn && statementsForTable2.some(
14830
+ (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
14831
+ )) {
14832
+ continue;
14833
+ }
14834
+ if (statement.isMulticolumn) {
14835
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14836
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14837
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14838
+ if (wasRename) {
14839
+ newStatements[tableName2].push(...preparedStatements);
14840
+ } else {
14841
+ newStatements[tableName2] = preparedStatements;
14842
+ }
14843
+ continue;
14844
+ }
14845
+ continue;
14846
+ }
14847
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14848
+ newStatements[tableName2].push(statement);
14849
+ }
14850
+ continue;
14851
+ }
14852
+ if (statement.type === "delete_reference") {
14853
+ const tableName2 = statement.tableName;
14854
+ const statementsForTable2 = newStatements[tableName2];
14855
+ if (!statementsForTable2) {
14856
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14857
+ continue;
14858
+ }
14859
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14860
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14861
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14862
+ if (wasRename) {
14863
+ newStatements[tableName2].push(...preparedStatements);
14864
+ } else {
14865
+ newStatements[tableName2] = preparedStatements;
14866
+ }
14867
+ continue;
14868
+ }
14869
+ continue;
14870
+ }
14871
+ if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
14872
+ const tableName2 = statement.tableName;
14873
+ const statementsForTable2 = newStatements[tableName2];
14874
+ if (!statementsForTable2) {
14875
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14876
+ continue;
14877
+ }
14878
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14879
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14880
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14881
+ if (wasRename) {
14882
+ newStatements[tableName2].push(...preparedStatements);
14883
+ } else {
14884
+ newStatements[tableName2] = preparedStatements;
14885
+ }
14886
+ continue;
14887
+ }
14888
+ continue;
14889
+ }
14890
+ const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
14891
+ const statementsForTable = newStatements[tableName];
14892
+ if (!statementsForTable) {
14893
+ newStatements[tableName] = [statement];
14894
+ continue;
14895
+ }
14896
+ if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
14897
+ newStatements[tableName].push(statement);
14898
+ }
14899
+ }
14900
+ const combinedStatements = Object.values(newStatements).flat();
14901
+ const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
14902
+ const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
14903
+ const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
14904
+ return [...renamedTables, ...renamedColumns, ...rest];
14905
+ };
14906
+ sqliteCombineStatements = (statements, json2, action) => {
14907
+ const newStatements = {};
14908
+ for (const statement of statements) {
14909
+ if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk" || statement.type === "delete_reference" || statement.type === "alter_reference" || statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
14910
+ const tableName2 = statement.tableName;
14911
+ const statementsForTable2 = newStatements[tableName2];
14912
+ if (!statementsForTable2) {
14913
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14914
+ continue;
14915
+ }
14916
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14917
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14918
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14919
+ if (wasRename) {
14920
+ newStatements[tableName2].push(...preparedStatements);
14921
+ } else {
14922
+ newStatements[tableName2] = preparedStatements;
14923
+ }
14924
+ continue;
14925
+ }
14926
+ continue;
14927
+ }
14928
+ if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
14929
+ const tableName2 = statement.tableName;
14930
+ const statementsForTable2 = newStatements[tableName2];
14931
+ if (!statementsForTable2) {
14932
+ newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14933
+ continue;
14934
+ }
14935
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14936
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14937
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14938
+ if (wasRename) {
14939
+ newStatements[tableName2].push(...preparedStatements);
14940
+ } else {
14941
+ newStatements[tableName2] = preparedStatements;
14942
+ }
14943
+ continue;
14944
+ }
14945
+ continue;
14946
+ }
14947
+ if (statement.type === "create_reference") {
14948
+ const tableName2 = statement.tableName;
14949
+ const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
14950
+ const statementsForTable2 = newStatements[tableName2];
14951
+ if (!statementsForTable2) {
14952
+ newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
14953
+ continue;
14954
+ }
14955
+ if (data.columnsFrom.length === 1 && statementsForTable2.some(
14956
+ (st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
14957
+ )) {
14958
+ continue;
14959
+ }
14960
+ if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
14961
+ const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
14962
+ const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
14963
+ if (wasRename) {
14964
+ newStatements[tableName2].push(...preparedStatements);
14965
+ } else {
14966
+ newStatements[tableName2] = preparedStatements;
14967
+ }
14968
+ continue;
14969
+ }
14970
+ continue;
14971
+ }
14972
+ const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
14973
+ const statementsForTable = newStatements[tableName];
14974
+ if (!statementsForTable) {
14975
+ newStatements[tableName] = [statement];
14976
+ continue;
14977
+ }
14978
+ if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
14979
+ newStatements[tableName].push(statement);
14980
+ }
14981
+ }
14982
+ const combinedStatements = Object.values(newStatements).flat();
14983
+ const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
14984
+ const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
14985
+ const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
14986
+ return [...renamedTables, ...renamedColumns, ...rest];
14987
+ };
14988
+ }
14989
+ });
14990
+
14447
14991
  // src/snapshotsDiffer.ts
14448
14992
  var snapshotsDiffer_exports = {};
14449
14993
  __export(snapshotsDiffer_exports, {
14450
14994
  alteredTableScheme: () => alteredTableScheme,
14995
+ applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
14451
14996
  applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
14452
14997
  applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
14453
14998
  applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
@@ -14457,7 +15002,7 @@ __export(snapshotsDiffer_exports, {
14457
15002
  makePatched: () => makePatched,
14458
15003
  makeSelfOrPatched: () => makeSelfOrPatched
14459
15004
  });
14460
- var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
15005
+ var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
14461
15006
  var init_snapshotsDiffer = __esm({
14462
15007
  "src/snapshotsDiffer.ts"() {
14463
15008
  "use strict";
@@ -14469,6 +15014,7 @@ var init_snapshotsDiffer = __esm({
14469
15014
  init_mysqlSchema();
14470
15015
  init_pgSchema();
14471
15016
  init_sqliteSchema();
15017
+ init_statementCombiner();
14472
15018
  init_utils();
14473
15019
  makeChanged = (schema4) => {
14474
15020
  return objectType({
@@ -15817,7 +16363,8 @@ var init_snapshotsDiffer = __esm({
15817
16363
  jsonStatements.push(...jsonDropColumnsStatemets);
15818
16364
  jsonStatements.push(...jsonAlteredCompositePKs);
15819
16365
  jsonStatements.push(...jsonAlteredUniqueConstraints);
15820
- const sqlStatements = fromJson(jsonStatements, "sqlite");
16366
+ const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json2, action);
16367
+ const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
15821
16368
  const uniqueSqlStatements = [];
15822
16369
  sqlStatements.forEach((ss) => {
15823
16370
  if (!uniqueSqlStatements.includes(ss)) {
@@ -15829,7 +16376,297 @@ var init_snapshotsDiffer = __esm({
15829
16376
  });
15830
16377
  const _meta = prepareMigrationMeta([], rTables, rColumns);
15831
16378
  return {
15832
- statements: jsonStatements,
16379
+ statements: combinedJsonStatements,
16380
+ sqlStatements: uniqueSqlStatements,
16381
+ _meta
16382
+ };
16383
+ };
16384
+ applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
16385
+ const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
16386
+ const {
16387
+ created: createdTables,
16388
+ deleted: deletedTables,
16389
+ renamed: renamedTables
16390
+ } = await tablesResolver2({
16391
+ created: tablesDiff.added,
16392
+ deleted: tablesDiff.deleted
16393
+ });
16394
+ const tablesPatchedSnap1 = copy(json1);
16395
+ tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
16396
+ const { name: name2 } = nameChangeFor(it, renamedTables);
16397
+ it.name = name2;
16398
+ return [name2, it];
16399
+ });
16400
+ const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
16401
+ const columnRenames = [];
16402
+ const columnCreates = [];
16403
+ const columnDeletes = [];
16404
+ for (let entry of Object.values(res)) {
16405
+ const { renamed, created, deleted } = await columnsResolver2({
16406
+ tableName: entry.name,
16407
+ schema: entry.schema,
16408
+ deleted: entry.columns.deleted,
16409
+ created: entry.columns.added
16410
+ });
16411
+ if (created.length > 0) {
16412
+ columnCreates.push({
16413
+ table: entry.name,
16414
+ columns: created
16415
+ });
16416
+ }
16417
+ if (deleted.length > 0) {
16418
+ columnDeletes.push({
16419
+ table: entry.name,
16420
+ columns: deleted
16421
+ });
16422
+ }
16423
+ if (renamed.length > 0) {
16424
+ columnRenames.push({
16425
+ table: entry.name,
16426
+ renames: renamed
16427
+ });
16428
+ }
16429
+ }
16430
+ const columnRenamesDict = columnRenames.reduce(
16431
+ (acc, it) => {
16432
+ acc[it.table] = it.renames;
16433
+ return acc;
16434
+ },
16435
+ {}
16436
+ );
16437
+ const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
16438
+ columnsPatchedSnap1.tables = mapEntries(
16439
+ columnsPatchedSnap1.tables,
16440
+ (tableKey2, tableValue) => {
16441
+ const patchedColumns = mapKeys(
16442
+ tableValue.columns,
16443
+ (columnKey, column4) => {
16444
+ const rens = columnRenamesDict[tableValue.name] || [];
16445
+ const newName = columnChangeFor(columnKey, rens);
16446
+ column4.name = newName;
16447
+ return newName;
16448
+ }
16449
+ );
16450
+ tableValue.columns = patchedColumns;
16451
+ return [tableKey2, tableValue];
16452
+ }
16453
+ );
16454
+ const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
16455
+ const typedResult = diffResultSchemeSQLite.parse(diffResult);
16456
+ const tablesMap = {};
16457
+ typedResult.alteredTablesWithColumns.forEach((obj) => {
16458
+ tablesMap[obj.name] = obj;
16459
+ });
16460
+ const jsonCreateTables = createdTables.map((it) => {
16461
+ return prepareSQLiteCreateTable(it, action);
16462
+ });
16463
+ const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
16464
+ return prepareCreateIndexesJson(
16465
+ it.name,
16466
+ it.schema,
16467
+ it.indexes,
16468
+ curFull.internal
16469
+ );
16470
+ }).flat();
16471
+ const jsonDropTables = deletedTables.map((it) => {
16472
+ return prepareDropTableJson(it);
16473
+ });
16474
+ const jsonRenameTables = renamedTables.map((it) => {
16475
+ return prepareRenameTableJson(it.from, it.to);
16476
+ });
16477
+ const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
16478
+ const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
16479
+ const jsonAddColumnsStatemets = columnCreates.map((it) => {
16480
+ return _prepareSqliteAddColumns(
16481
+ it.table,
16482
+ it.columns,
16483
+ tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
16484
+ );
16485
+ }).flat();
16486
+ const rColumns = jsonRenameColumnsStatements.map((it) => {
16487
+ const tableName = it.tableName;
16488
+ const schema4 = it.schema;
16489
+ return {
16490
+ from: { schema: schema4, table: tableName, column: it.oldColumnName },
16491
+ to: { schema: schema4, table: tableName, column: it.newColumnName }
16492
+ };
16493
+ });
16494
+ const rTables = renamedTables.map((it) => {
16495
+ return { from: it.from, to: it.to };
16496
+ });
16497
+ const _meta = prepareMigrationMeta([], rTables, rColumns);
16498
+ const allAltered = typedResult.alteredTablesWithColumns;
16499
+ const jsonAddedCompositePKs = [];
16500
+ const jsonDeletedCompositePKs = [];
16501
+ const jsonAlteredCompositePKs = [];
16502
+ const jsonAddedUniqueConstraints = [];
16503
+ const jsonDeletedUniqueConstraints = [];
16504
+ const jsonAlteredUniqueConstraints = [];
16505
+ allAltered.forEach((it) => {
16506
+ let addedColumns = [];
16507
+ for (const addedPkName of Object.keys(it.addedCompositePKs)) {
16508
+ const addedPkColumns = it.addedCompositePKs[addedPkName];
16509
+ addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
16510
+ }
16511
+ let deletedColumns = [];
16512
+ for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
16513
+ const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
16514
+ deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
16515
+ }
16516
+ const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
16517
+ let addedCompositePKs = [];
16518
+ let deletedCompositePKs = [];
16519
+ let alteredCompositePKs = [];
16520
+ if (doPerformDeleteAndCreate) {
16521
+ addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
16522
+ it.name,
16523
+ it.addedCompositePKs
16524
+ );
16525
+ deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
16526
+ it.name,
16527
+ it.deletedCompositePKs
16528
+ );
16529
+ }
16530
+ alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
16531
+ it.name,
16532
+ it.alteredCompositePKs
16533
+ );
16534
+ let addedUniqueConstraints = [];
16535
+ let deletedUniqueConstraints = [];
16536
+ let alteredUniqueConstraints = [];
16537
+ addedUniqueConstraints = prepareAddUniqueConstraintPg(
16538
+ it.name,
16539
+ it.schema,
16540
+ it.addedUniqueConstraints
16541
+ );
16542
+ deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
16543
+ it.name,
16544
+ it.schema,
16545
+ it.deletedUniqueConstraints
16546
+ );
16547
+ if (it.alteredUniqueConstraints) {
16548
+ const added = {};
16549
+ const deleted = {};
16550
+ for (const k of Object.keys(it.alteredUniqueConstraints)) {
16551
+ added[k] = it.alteredUniqueConstraints[k].__new;
16552
+ deleted[k] = it.alteredUniqueConstraints[k].__old;
16553
+ }
16554
+ addedUniqueConstraints.push(
16555
+ ...prepareAddUniqueConstraintPg(it.name, it.schema, added)
16556
+ );
16557
+ deletedUniqueConstraints.push(
16558
+ ...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
16559
+ );
16560
+ }
16561
+ jsonAddedCompositePKs.push(...addedCompositePKs);
16562
+ jsonDeletedCompositePKs.push(...deletedCompositePKs);
16563
+ jsonAlteredCompositePKs.push(...alteredCompositePKs);
16564
+ jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
16565
+ jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
16566
+ jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
16567
+ });
16568
+ const jsonTableAlternations = allAltered.map((it) => {
16569
+ return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
16570
+ }).flat();
16571
+ const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
16572
+ return prepareCreateIndexesJson(
16573
+ it.name,
16574
+ it.schema,
16575
+ it.addedIndexes || {},
16576
+ curFull.internal
16577
+ );
16578
+ }).flat();
16579
+ const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
16580
+ return prepareDropIndexesJson(
16581
+ it.name,
16582
+ it.schema,
16583
+ it.deletedIndexes || {}
16584
+ );
16585
+ }).flat();
16586
+ allAltered.forEach((it) => {
16587
+ const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
16588
+ (current, item) => {
16589
+ current[item] = it.alteredIndexes[item].__old;
16590
+ return current;
16591
+ },
16592
+ {}
16593
+ );
16594
+ const createdIndexes = Object.keys(it.alteredIndexes).reduce(
16595
+ (current, item) => {
16596
+ current[item] = it.alteredIndexes[item].__new;
16597
+ return current;
16598
+ },
16599
+ {}
16600
+ );
16601
+ jsonCreateIndexesForAllAlteredTables.push(
16602
+ ...prepareCreateIndexesJson(
16603
+ it.name,
16604
+ it.schema,
16605
+ createdIndexes || {},
16606
+ curFull.internal
16607
+ )
16608
+ );
16609
+ jsonDropIndexesForAllAlteredTables.push(
16610
+ ...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
16611
+ );
16612
+ });
16613
+ const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
16614
+ const forAdded = prepareLibSQLCreateReferencesJson(
16615
+ it.name,
16616
+ it.schema,
16617
+ it.addedForeignKeys,
16618
+ json2,
16619
+ action
16620
+ );
16621
+ const forAltered = prepareLibSQLDropReferencesJson(
16622
+ it.name,
16623
+ it.schema,
16624
+ it.deletedForeignKeys,
16625
+ json2,
16626
+ _meta,
16627
+ action
16628
+ );
16629
+ const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
16630
+ return [...forAdded, ...forAltered, ...alteredFKs];
16631
+ }).flat();
16632
+ const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16633
+ (t) => t.type === "create_reference"
16634
+ );
16635
+ const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
16636
+ (t) => t.type === "delete_reference"
16637
+ );
16638
+ const jsonStatements = [];
16639
+ jsonStatements.push(...jsonCreateTables);
16640
+ jsonStatements.push(...jsonDropTables);
16641
+ jsonStatements.push(...jsonRenameTables);
16642
+ jsonStatements.push(...jsonRenameColumnsStatements);
16643
+ jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
16644
+ jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
16645
+ jsonStatements.push(...jsonDeletedCompositePKs);
16646
+ jsonStatements.push(...jsonTableAlternations);
16647
+ jsonStatements.push(...jsonAddedCompositePKs);
16648
+ jsonStatements.push(...jsonAddColumnsStatemets);
16649
+ jsonStatements.push(...jsonCreateIndexesForCreatedTables);
16650
+ jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
16651
+ jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
16652
+ jsonStatements.push(...jsonDropColumnsStatemets);
16653
+ jsonStatements.push(...jsonAlteredCompositePKs);
16654
+ jsonStatements.push(...jsonAlteredUniqueConstraints);
16655
+ const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
16656
+ const sqlStatements = fromJson(
16657
+ combinedJsonStatements,
16658
+ "turso",
16659
+ action,
16660
+ json2
16661
+ );
16662
+ const uniqueSqlStatements = [];
16663
+ sqlStatements.forEach((ss) => {
16664
+ if (!uniqueSqlStatements.includes(ss)) {
16665
+ uniqueSqlStatements.push(ss);
16666
+ }
16667
+ });
16668
+ return {
16669
+ statements: combinedJsonStatements,
15833
16670
  sqlStatements: uniqueSqlStatements,
15834
16671
  _meta
15835
16672
  };
@@ -15853,7 +16690,7 @@ var init_schemaValidator = __esm({
15853
16690
  init_mysqlSchema();
15854
16691
  init_pgSchema();
15855
16692
  init_sqliteSchema();
15856
- dialects = ["postgresql", "mysql", "sqlite"];
16693
+ dialects = ["postgresql", "mysql", "sqlite", "turso"];
15857
16694
  dialect3 = enumType(dialects);
15858
16695
  commonSquashedSchema = unionType([
15859
16696
  pgSchemaSquashed,
@@ -15865,7 +16702,7 @@ var init_schemaValidator = __esm({
15865
16702
  });
15866
16703
 
15867
16704
  // src/cli/validations/common.ts
15868
- var sqliteDriversLiterals, postgresqlDriversLiterals, sqliteDriver, postgresDriver, driver, configMigrations, configCommonSchema, casing, introspectParams, configIntrospectCliSchema, configGenerateSchema, configPushSchema;
16705
+ var sqliteDriversLiterals, postgresqlDriversLiterals, prefixes, prefix, sqliteDriver, postgresDriver, driver, configMigrations, configCommonSchema, casing, introspectParams, configIntrospectCliSchema, configGenerateSchema, configPushSchema;
15869
16706
  var init_common = __esm({
15870
16707
  "src/cli/validations/common.ts"() {
15871
16708
  "use strict";
@@ -15873,7 +16710,6 @@ var init_common = __esm({
15873
16710
  init_schemaValidator();
15874
16711
  init_outputs();
15875
16712
  sqliteDriversLiterals = [
15876
- literalType("turso"),
15877
16713
  literalType("d1-http"),
15878
16714
  literalType("expo")
15879
16715
  ];
@@ -15881,12 +16717,24 @@ var init_common = __esm({
15881
16717
  literalType("aws-data-api"),
15882
16718
  literalType("pglite")
15883
16719
  ];
16720
+ prefixes = [
16721
+ "index",
16722
+ "timestamp",
16723
+ "supabase",
16724
+ "unix",
16725
+ "none"
16726
+ ];
16727
+ prefix = enumType(prefixes);
16728
+ {
16729
+ const _2 = "";
16730
+ }
15884
16731
  sqliteDriver = unionType(sqliteDriversLiterals);
15885
16732
  postgresDriver = unionType(postgresqlDriversLiterals);
15886
16733
  driver = unionType([sqliteDriver, postgresDriver]);
15887
16734
  configMigrations = objectType({
15888
16735
  table: stringType().optional(),
15889
- schema: stringType().optional()
16736
+ schema: stringType().optional(),
16737
+ prefix: prefix.optional().default("index")
15890
16738
  }).optional();
15891
16739
  configCommonSchema = objectType({
15892
16740
  dialect: dialect3,
@@ -25638,267 +26486,6 @@ var init_selector_ui = __esm({
25638
26486
  }
25639
26487
  });
25640
26488
 
25641
- // src/cli/validations/cli.ts
25642
- var pushParams, pullParams, configCheck, cliConfigCheck;
25643
- var init_cli = __esm({
25644
- "src/cli/validations/cli.ts"() {
25645
- "use strict";
25646
- init_lib();
25647
- init_schemaValidator();
25648
- init_common();
25649
- pushParams = objectType({
25650
- dialect: dialect3,
25651
- schema: unionType([stringType(), stringType().array()]),
25652
- tablesFilter: unionType([stringType(), stringType().array()]).optional(),
25653
- schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
25654
- extensionsFilters: literalType("postgis").array().optional(),
25655
- verbose: booleanType().optional(),
25656
- strict: booleanType().optional()
25657
- }).passthrough();
25658
- pullParams = objectType({
25659
- config: stringType().optional(),
25660
- dialect: dialect3,
25661
- out: stringType().optional().default("drizzle"),
25662
- tablesFilter: unionType([stringType(), stringType().array()]).optional(),
25663
- schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
25664
- extensionsFilters: literalType("postgis").array().optional(),
25665
- casing,
25666
- breakpoints: booleanType().optional().default(true)
25667
- }).passthrough();
25668
- configCheck = objectType({
25669
- dialect: dialect3.optional(),
25670
- out: stringType().optional()
25671
- });
25672
- cliConfigCheck = intersectionType(
25673
- objectType({
25674
- config: stringType().optional()
25675
- }),
25676
- configCheck
25677
- );
25678
- }
25679
- });
25680
-
25681
- // src/cli/validations/mysql.ts
25682
- var mysqlCredentials;
25683
- var init_mysql = __esm({
25684
- "src/cli/validations/mysql.ts"() {
25685
- "use strict";
25686
- init_lib();
25687
- init_views();
25688
- init_common();
25689
- init_outputs();
25690
- mysqlCredentials = unionType([
25691
- objectType({
25692
- host: stringType().min(1),
25693
- port: coerce.number().min(1).optional(),
25694
- user: stringType().min(1).optional(),
25695
- password: stringType().min(1).optional(),
25696
- database: stringType().min(1),
25697
- ssl: unionType([
25698
- stringType(),
25699
- objectType({
25700
- pfx: stringType().optional(),
25701
- key: stringType().optional(),
25702
- passphrase: stringType().optional(),
25703
- cert: stringType().optional(),
25704
- ca: unionType([stringType(), stringType().array()]).optional(),
25705
- crl: unionType([stringType(), stringType().array()]).optional(),
25706
- ciphers: stringType().optional(),
25707
- rejectUnauthorized: booleanType().optional()
25708
- })
25709
- ]).optional()
25710
- }),
25711
- objectType({
25712
- url: stringType().min(1)
25713
- })
25714
- ]);
25715
- }
25716
- });
25717
-
25718
- // src/cli/validations/postgres.ts
25719
- var postgresCredentials;
25720
- var init_postgres = __esm({
25721
- "src/cli/validations/postgres.ts"() {
25722
- "use strict";
25723
- init_lib();
25724
- init_views();
25725
- init_common();
25726
- postgresCredentials = unionType([
25727
- objectType({
25728
- driver: undefinedType(),
25729
- host: stringType().min(1),
25730
- port: coerce.number().min(1).optional(),
25731
- user: stringType().min(1).optional(),
25732
- password: stringType().min(1).optional(),
25733
- database: stringType().min(1),
25734
- ssl: unionType([
25735
- literalType("require"),
25736
- literalType("allow"),
25737
- literalType("prefer"),
25738
- literalType("verify-full"),
25739
- booleanType(),
25740
- objectType({}).passthrough()
25741
- ]).optional()
25742
- }).transform((o) => {
25743
- delete o.driver;
25744
- return o;
25745
- }),
25746
- objectType({
25747
- driver: undefinedType(),
25748
- url: stringType().min(1)
25749
- }).transform((o) => {
25750
- delete o.driver;
25751
- return o;
25752
- }),
25753
- objectType({
25754
- driver: literalType("aws-data-api"),
25755
- database: stringType().min(1),
25756
- secretArn: stringType().min(1),
25757
- resourceArn: stringType().min(1)
25758
- }),
25759
- objectType({
25760
- driver: literalType("pglite"),
25761
- url: stringType().min(1)
25762
- })
25763
- ]);
25764
- }
25765
- });
25766
-
25767
- // src/cli/validations/sqlite.ts
25768
- var sqliteCredentials;
25769
- var init_sqlite = __esm({
25770
- "src/cli/validations/sqlite.ts"() {
25771
- "use strict";
25772
- init_global();
25773
- init_lib();
25774
- init_views();
25775
- init_common();
25776
- sqliteCredentials = unionType([
25777
- objectType({
25778
- driver: literalType("turso"),
25779
- url: stringType().min(1),
25780
- authToken: stringType().min(1).optional()
25781
- }),
25782
- objectType({
25783
- driver: literalType("d1-http"),
25784
- accountId: stringType().min(1),
25785
- databaseId: stringType().min(1),
25786
- token: stringType().min(1)
25787
- }),
25788
- objectType({
25789
- driver: undefinedType(),
25790
- url: stringType().min(1)
25791
- }).transform((o) => {
25792
- delete o.driver;
25793
- return o;
25794
- })
25795
- ]);
25796
- }
25797
- });
25798
-
25799
- // src/cli/validations/studio.ts
25800
- var credentials, studioCliParams, studioConfig;
25801
- var init_studio = __esm({
25802
- "src/cli/validations/studio.ts"() {
25803
- "use strict";
25804
- init_lib();
25805
- init_schemaValidator();
25806
- init_mysql();
25807
- init_postgres();
25808
- init_sqlite();
25809
- credentials = intersectionType(
25810
- postgresCredentials,
25811
- mysqlCredentials,
25812
- sqliteCredentials
25813
- );
25814
- studioCliParams = objectType({
25815
- port: coerce.number().optional().default(4983),
25816
- host: stringType().optional().default("127.0.0.1"),
25817
- config: stringType().optional()
25818
- });
25819
- studioConfig = objectType({
25820
- dialect: dialect3,
25821
- schema: unionType([stringType(), stringType().array()]).optional()
25822
- });
25823
- }
25824
- });
25825
-
25826
- // src/cli/commands/_es5.ts
25827
- var es5_exports = {};
25828
- __export(es5_exports, {
25829
- default: () => es5_default
25830
- });
25831
- var _, es5_default;
25832
- var init_es5 = __esm({
25833
- "src/cli/commands/_es5.ts"() {
25834
- "use strict";
25835
- _ = "";
25836
- es5_default = _;
25837
- }
25838
- });
25839
-
25840
- // src/cli/commands/utils.ts
25841
- var import_hanji6, assertES5, safeRegister, migrateConfig;
25842
- var init_utils6 = __esm({
25843
- "src/cli/commands/utils.ts"() {
25844
- "use strict";
25845
- import_hanji6 = __toESM(require_hanji());
25846
- init_lib();
25847
- init_global();
25848
- init_schemaValidator();
25849
- init_serializer();
25850
- init_cli();
25851
- init_common();
25852
- init_mysql();
25853
- init_outputs();
25854
- init_postgres();
25855
- init_sqlite();
25856
- init_studio();
25857
- init_views();
25858
- assertES5 = async (unregister) => {
25859
- try {
25860
- init_es5();
25861
- } catch (e) {
25862
- if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
25863
- const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
25864
- if (es5Error) {
25865
- console.log(
25866
- error(
25867
- `Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
25868
- )
25869
- );
25870
- process.exit(1);
25871
- }
25872
- }
25873
- console.error(e);
25874
- process.exit(1);
25875
- }
25876
- };
25877
- safeRegister = async () => {
25878
- const { register } = require("esbuild-register/dist/node");
25879
- let res;
25880
- try {
25881
- res = register({
25882
- format: "cjs",
25883
- loader: "ts"
25884
- });
25885
- } catch {
25886
- res = {
25887
- unregister: () => {
25888
- }
25889
- };
25890
- }
25891
- await assertES5(res.unregister);
25892
- return res;
25893
- };
25894
- migrateConfig = objectType({
25895
- dialect: dialect3,
25896
- out: stringType().optional().default("drizzle"),
25897
- migrations: configMigrations
25898
- });
25899
- }
25900
- });
25901
-
25902
26489
  // ../drizzle-orm/dist/sqlite-core/alias.js
25903
26490
  var init_alias3 = __esm({
25904
26491
  "../drizzle-orm/dist/sqlite-core/alias.js"() {
@@ -29005,7 +29592,7 @@ function getTableConfig2(table4) {
29005
29592
  name: name2
29006
29593
  };
29007
29594
  }
29008
- var init_utils7 = __esm({
29595
+ var init_utils6 = __esm({
29009
29596
  "../drizzle-orm/dist/sqlite-core/utils.js"() {
29010
29597
  "use strict";
29011
29598
  init_entity();
@@ -29141,7 +29728,7 @@ var init_sqlite_core = __esm({
29141
29728
  init_subquery3();
29142
29729
  init_table3();
29143
29730
  init_unique_constraint2();
29144
- init_utils7();
29731
+ init_utils6();
29145
29732
  init_view2();
29146
29733
  }
29147
29734
  });
@@ -33562,7 +34149,7 @@ function getTableConfig3(table4) {
33562
34149
  baseName
33563
34150
  };
33564
34151
  }
33565
- var init_utils8 = __esm({
34152
+ var init_utils7 = __esm({
33566
34153
  "../drizzle-orm/dist/mysql-core/utils.js"() {
33567
34154
  "use strict";
33568
34155
  init_entity();
@@ -33594,7 +34181,7 @@ var init_mysql_core = __esm({
33594
34181
  init_subquery4();
33595
34182
  init_table4();
33596
34183
  init_unique_constraint3();
33597
- init_utils8();
34184
+ init_utils7();
33598
34185
  init_view_common4();
33599
34186
  init_view3();
33600
34187
  }
@@ -34151,6 +34738,298 @@ We have encountered a collision between the index name on columns ${source_defau
34151
34738
  }
34152
34739
  });
34153
34740
 
34741
+ // src/cli/validations/cli.ts
34742
+ var cliConfigGenerate, pushParams, pullParams, configCheck, cliConfigCheck;
34743
+ var init_cli = __esm({
34744
+ "src/cli/validations/cli.ts"() {
34745
+ "use strict";
34746
+ init_lib();
34747
+ init_schemaValidator();
34748
+ init_common();
34749
+ cliConfigGenerate = objectType({
34750
+ dialect: dialect3.optional(),
34751
+ schema: unionType([stringType(), stringType().array()]).optional(),
34752
+ out: stringType().optional().default("./drizzle"),
34753
+ config: stringType().optional(),
34754
+ name: stringType().optional(),
34755
+ prefix: prefix.optional(),
34756
+ breakpoints: booleanType().optional().default(true),
34757
+ custom: booleanType().optional().default(false)
34758
+ }).strict();
34759
+ pushParams = objectType({
34760
+ dialect: dialect3,
34761
+ schema: unionType([stringType(), stringType().array()]),
34762
+ tablesFilter: unionType([stringType(), stringType().array()]).optional(),
34763
+ schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
34764
+ extensionsFilters: literalType("postgis").array().optional(),
34765
+ verbose: booleanType().optional(),
34766
+ strict: booleanType().optional(),
34767
+ driver: driver.optional()
34768
+ }).passthrough();
34769
+ pullParams = objectType({
34770
+ config: stringType().optional(),
34771
+ dialect: dialect3,
34772
+ out: stringType().optional().default("drizzle"),
34773
+ tablesFilter: unionType([stringType(), stringType().array()]).optional(),
34774
+ schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
34775
+ extensionsFilters: literalType("postgis").array().optional(),
34776
+ casing,
34777
+ breakpoints: booleanType().optional().default(true),
34778
+ migrations: objectType({
34779
+ prefix: prefix.optional().default("index")
34780
+ }).optional()
34781
+ }).passthrough();
34782
+ configCheck = objectType({
34783
+ dialect: dialect3.optional(),
34784
+ out: stringType().optional()
34785
+ });
34786
+ cliConfigCheck = intersectionType(
34787
+ objectType({
34788
+ config: stringType().optional()
34789
+ }),
34790
+ configCheck
34791
+ );
34792
+ }
34793
+ });
34794
+
34795
+ // src/cli/validations/libsql.ts
34796
+ var libSQLCredentials;
34797
+ var init_libsql = __esm({
34798
+ "src/cli/validations/libsql.ts"() {
34799
+ "use strict";
34800
+ init_lib();
34801
+ init_views();
34802
+ init_common();
34803
+ libSQLCredentials = objectType({
34804
+ url: stringType().min(1),
34805
+ authToken: stringType().min(1).optional()
34806
+ });
34807
+ }
34808
+ });
34809
+
34810
+ // src/cli/validations/mysql.ts
34811
+ var mysqlCredentials;
34812
+ var init_mysql = __esm({
34813
+ "src/cli/validations/mysql.ts"() {
34814
+ "use strict";
34815
+ init_lib();
34816
+ init_views();
34817
+ init_common();
34818
+ init_outputs();
34819
+ mysqlCredentials = unionType([
34820
+ objectType({
34821
+ host: stringType().min(1),
34822
+ port: coerce.number().min(1).optional(),
34823
+ user: stringType().min(1).optional(),
34824
+ password: stringType().min(1).optional(),
34825
+ database: stringType().min(1),
34826
+ ssl: unionType([
34827
+ stringType(),
34828
+ objectType({
34829
+ pfx: stringType().optional(),
34830
+ key: stringType().optional(),
34831
+ passphrase: stringType().optional(),
34832
+ cert: stringType().optional(),
34833
+ ca: unionType([stringType(), stringType().array()]).optional(),
34834
+ crl: unionType([stringType(), stringType().array()]).optional(),
34835
+ ciphers: stringType().optional(),
34836
+ rejectUnauthorized: booleanType().optional()
34837
+ })
34838
+ ]).optional()
34839
+ }),
34840
+ objectType({
34841
+ url: stringType().min(1)
34842
+ })
34843
+ ]);
34844
+ }
34845
+ });
34846
+
34847
+ // src/cli/validations/postgres.ts
34848
+ var postgresCredentials;
34849
+ var init_postgres = __esm({
34850
+ "src/cli/validations/postgres.ts"() {
34851
+ "use strict";
34852
+ init_lib();
34853
+ init_views();
34854
+ init_common();
34855
+ postgresCredentials = unionType([
34856
+ objectType({
34857
+ driver: undefinedType(),
34858
+ host: stringType().min(1),
34859
+ port: coerce.number().min(1).optional(),
34860
+ user: stringType().min(1).optional(),
34861
+ password: stringType().min(1).optional(),
34862
+ database: stringType().min(1),
34863
+ ssl: unionType([
34864
+ literalType("require"),
34865
+ literalType("allow"),
34866
+ literalType("prefer"),
34867
+ literalType("verify-full"),
34868
+ booleanType(),
34869
+ objectType({}).passthrough()
34870
+ ]).optional()
34871
+ }).transform((o) => {
34872
+ delete o.driver;
34873
+ return o;
34874
+ }),
34875
+ objectType({
34876
+ driver: undefinedType(),
34877
+ url: stringType().min(1)
34878
+ }).transform((o) => {
34879
+ delete o.driver;
34880
+ return o;
34881
+ }),
34882
+ objectType({
34883
+ driver: literalType("aws-data-api"),
34884
+ database: stringType().min(1),
34885
+ secretArn: stringType().min(1),
34886
+ resourceArn: stringType().min(1)
34887
+ }),
34888
+ objectType({
34889
+ driver: literalType("pglite"),
34890
+ url: stringType().min(1)
34891
+ })
34892
+ ]);
34893
+ }
34894
+ });
34895
+
34896
+ // src/cli/validations/sqlite.ts
34897
+ var sqliteCredentials;
34898
+ var init_sqlite = __esm({
34899
+ "src/cli/validations/sqlite.ts"() {
34900
+ "use strict";
34901
+ init_global();
34902
+ init_lib();
34903
+ init_views();
34904
+ init_common();
34905
+ sqliteCredentials = unionType([
34906
+ objectType({
34907
+ driver: literalType("turso"),
34908
+ url: stringType().min(1),
34909
+ authToken: stringType().min(1).optional()
34910
+ }),
34911
+ objectType({
34912
+ driver: literalType("d1-http"),
34913
+ accountId: stringType().min(1),
34914
+ databaseId: stringType().min(1),
34915
+ token: stringType().min(1)
34916
+ }),
34917
+ objectType({
34918
+ driver: undefinedType(),
34919
+ url: stringType().min(1)
34920
+ }).transform((o) => {
34921
+ delete o.driver;
34922
+ return o;
34923
+ })
34924
+ ]);
34925
+ }
34926
+ });
34927
+
34928
+ // src/cli/validations/studio.ts
34929
+ var credentials, studioCliParams, studioConfig;
34930
+ var init_studio = __esm({
34931
+ "src/cli/validations/studio.ts"() {
34932
+ "use strict";
34933
+ init_lib();
34934
+ init_schemaValidator();
34935
+ init_mysql();
34936
+ init_postgres();
34937
+ init_sqlite();
34938
+ credentials = intersectionType(
34939
+ postgresCredentials,
34940
+ mysqlCredentials,
34941
+ sqliteCredentials
34942
+ );
34943
+ studioCliParams = objectType({
34944
+ port: coerce.number().optional().default(4983),
34945
+ host: stringType().optional().default("127.0.0.1"),
34946
+ config: stringType().optional()
34947
+ });
34948
+ studioConfig = objectType({
34949
+ dialect: dialect3,
34950
+ schema: unionType([stringType(), stringType().array()]).optional()
34951
+ });
34952
+ }
34953
+ });
34954
+
34955
+ // src/cli/commands/_es5.ts
34956
+ var es5_exports = {};
34957
+ __export(es5_exports, {
34958
+ default: () => es5_default
34959
+ });
34960
+ var _, es5_default;
34961
+ var init_es5 = __esm({
34962
+ "src/cli/commands/_es5.ts"() {
34963
+ "use strict";
34964
+ _ = "";
34965
+ es5_default = _;
34966
+ }
34967
+ });
34968
+
34969
+ // src/cli/commands/utils.ts
34970
+ var import_hanji7, assertES5, safeRegister, migrateConfig;
34971
+ var init_utils8 = __esm({
34972
+ "src/cli/commands/utils.ts"() {
34973
+ "use strict";
34974
+ import_hanji7 = __toESM(require_hanji());
34975
+ init_lib();
34976
+ init_global();
34977
+ init_schemaValidator();
34978
+ init_serializer();
34979
+ init_cli();
34980
+ init_common();
34981
+ init_libsql();
34982
+ init_libsql();
34983
+ init_mysql();
34984
+ init_outputs();
34985
+ init_postgres();
34986
+ init_sqlite();
34987
+ init_studio();
34988
+ init_views();
34989
+ assertES5 = async (unregister) => {
34990
+ try {
34991
+ init_es5();
34992
+ } catch (e) {
34993
+ if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
34994
+ const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
34995
+ if (es5Error) {
34996
+ console.log(
34997
+ error(
34998
+ `Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
34999
+ )
35000
+ );
35001
+ process.exit(1);
35002
+ }
35003
+ }
35004
+ console.error(e);
35005
+ process.exit(1);
35006
+ }
35007
+ };
35008
+ safeRegister = async () => {
35009
+ const { register } = require("esbuild-register/dist/node");
35010
+ let res;
35011
+ try {
35012
+ res = register({
35013
+ format: "cjs",
35014
+ loader: "ts"
35015
+ });
35016
+ } catch {
35017
+ res = {
35018
+ unregister: () => {
35019
+ }
35020
+ };
35021
+ }
35022
+ await assertES5(res.unregister);
35023
+ return res;
35024
+ };
35025
+ migrateConfig = objectType({
35026
+ dialect: dialect3,
35027
+ out: stringType().optional().default("drizzle"),
35028
+ migrations: configMigrations
35029
+ });
35030
+ }
35031
+ });
35032
+
34154
35033
  // src/serializer/pgImports.ts
34155
35034
  var prepareFromExports;
34156
35035
  var init_pgImports = __esm({
@@ -34158,7 +35037,7 @@ var init_pgImports = __esm({
34158
35037
  "use strict";
34159
35038
  init_dist();
34160
35039
  init_pg_core();
34161
- init_utils6();
35040
+ init_utils8();
34162
35041
  prepareFromExports = (exports2) => {
34163
35042
  const tables = [];
34164
35043
  const enums = [];
@@ -34197,7 +35076,7 @@ var init_sqliteImports = __esm({
34197
35076
  "use strict";
34198
35077
  init_dist();
34199
35078
  init_sqlite_core();
34200
- init_utils6();
35079
+ init_utils8();
34201
35080
  prepareFromExports2 = (exports2) => {
34202
35081
  const tables = [];
34203
35082
  const i0values = Object.values(exports2);
@@ -34235,7 +35114,7 @@ var init_mysqlImports = __esm({
34235
35114
  "use strict";
34236
35115
  init_dist();
34237
35116
  init_mysql_core();
34238
- init_utils6();
35117
+ init_utils8();
34239
35118
  prepareFromExports3 = (exports2) => {
34240
35119
  const tables = [];
34241
35120
  const i0values = Object.values(exports2);
@@ -34865,7 +35744,6 @@ var pgSuggestions = async (db, statements) => {
34865
35744
  // src/cli/commands/pgUp.ts
34866
35745
  init_pgSchema();
34867
35746
  init_utils();
34868
- init_utils6();
34869
35747
  var updateUpToV6 = (json) => {
34870
35748
  const schema4 = pgSchemaV5.parse(json);
34871
35749
  const tables = Object.fromEntries(
@@ -34929,7 +35807,7 @@ var updateUpToV7 = (json) => {
34929
35807
  };
34930
35808
 
34931
35809
  // src/cli/commands/sqliteIntrospect.ts
34932
- var import_hanji7 = __toESM(require_hanji());
35810
+ var import_hanji6 = __toESM(require_hanji());
34933
35811
  init_mjs();
34934
35812
  init_global();
34935
35813
 
@@ -35068,289 +35946,13 @@ var sqlitePushIntrospect = async (db, filters) => {
35068
35946
  "Pulling schema from database...",
35069
35947
  "Pulling schema from database..."
35070
35948
  );
35071
- const res = await (0, import_hanji7.renderWithTask)(progress, fromDatabase2(db, filter2));
35949
+ const res = await (0, import_hanji6.renderWithTask)(progress, fromDatabase2(db, filter2));
35072
35950
  const schema4 = { id: originUUID, prevId: "", ...res };
35073
35951
  return { schema: schema4 };
35074
35952
  };
35075
35953
 
35076
- // src/cli/commands/sqlitePushUtils.ts
35077
- init_source();
35078
- init_sqliteSchema();
35079
- init_sqlgenerator();
35080
- var _moveDataStatements = (tableName, json, dataLoss = false) => {
35081
- const statements = [];
35082
- statements.push(
35083
- new SqliteRenameTableConvertor().convert({
35084
- type: "rename_table",
35085
- tableNameFrom: tableName,
35086
- tableNameTo: `__old_push_${tableName}`,
35087
- fromSchema: "",
35088
- toSchema: ""
35089
- })
35090
- );
35091
- const tableColumns = Object.values(json.tables[tableName].columns);
35092
- const referenceData = Object.values(json.tables[tableName].foreignKeys);
35093
- const compositePKs = Object.values(
35094
- json.tables[tableName].compositePrimaryKeys
35095
- ).map((it) => SQLiteSquasher.unsquashPK(it));
35096
- const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
35097
- statements.push(
35098
- new SQLiteCreateTableConvertor().convert({
35099
- type: "sqlite_create_table",
35100
- tableName,
35101
- columns: tableColumns,
35102
- referenceData: fks,
35103
- compositePKs
35104
- })
35105
- );
35106
- if (!dataLoss) {
35107
- statements.push(
35108
- `INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
35109
- );
35110
- }
35111
- statements.push(
35112
- new SQLiteDropTableConvertor().convert({
35113
- type: "drop_table",
35114
- tableName: `__old_push_${tableName}`,
35115
- schema: ""
35116
- })
35117
- );
35118
- for (const idx of Object.values(json.tables[tableName].indexes)) {
35119
- statements.push(
35120
- new CreateSqliteIndexConvertor().convert({
35121
- type: "create_index",
35122
- tableName,
35123
- schema: "",
35124
- data: idx
35125
- })
35126
- );
35127
- }
35128
- return statements;
35129
- };
35130
- var getOldTableName = (tableName, meta) => {
35131
- for (const key of Object.keys(meta.tables)) {
35132
- const value = meta.tables[key];
35133
- if (`"${tableName}"` === value) {
35134
- return key.substring(1, key.length - 1);
35135
- }
35136
- }
35137
- return tableName;
35138
- };
35139
- var getNewTableName = (tableName, meta) => {
35140
- if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
35141
- return meta.tables[`"${tableName}"`].substring(
35142
- 1,
35143
- meta.tables[`"${tableName}"`].length - 1
35144
- );
35145
- }
35146
- return tableName;
35147
- };
35148
- var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
35149
- let shouldAskForApprove = false;
35150
- const statementsToExecute = [];
35151
- const infoToPrint = [];
35152
- const tablesToRemove = [];
35153
- const columnsToRemove = [];
35154
- const schemasToRemove = [];
35155
- const tablesToTruncate = [];
35156
- const tablesContext = {};
35157
- for (const statement of statements) {
35158
- if (statement.type === "drop_table") {
35159
- const res = await connection.query(
35160
- `select count(*) as count from \`${statement.tableName}\``
35161
- );
35162
- const count2 = Number(res[0].count);
35163
- if (count2 > 0) {
35164
- infoToPrint.push(
35165
- `\xB7 You're about to delete ${source_default.underline(
35166
- statement.tableName
35167
- )} table with ${count2} items`
35168
- );
35169
- tablesToRemove.push(statement.tableName);
35170
- shouldAskForApprove = true;
35171
- }
35172
- const stmnt = fromJson([statement], "sqlite")[0];
35173
- statementsToExecute.push(stmnt);
35174
- } else if (statement.type === "alter_table_drop_column") {
35175
- const newTableName = getOldTableName(statement.tableName, meta);
35176
- const columnIsPartOfPk = Object.values(
35177
- json1.tables[newTableName].compositePrimaryKeys
35178
- ).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
35179
- const columnIsPartOfIndex = Object.values(
35180
- json1.tables[newTableName].indexes
35181
- ).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
35182
- const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
35183
- const columnIsPartOfFk = Object.values(
35184
- json1.tables[newTableName].foreignKeys
35185
- ).find(
35186
- (t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
35187
- statement.columnName
35188
- )
35189
- );
35190
- const res = await connection.query(
35191
- `select count(*) as count from \`${newTableName}\``
35192
- );
35193
- const count2 = Number(res[0].count);
35194
- if (count2 > 0) {
35195
- infoToPrint.push(
35196
- `\xB7 You're about to delete ${source_default.underline(
35197
- statement.columnName
35198
- )} column in ${newTableName} table with ${count2} items`
35199
- );
35200
- columnsToRemove.push(`${newTableName}_${statement.columnName}`);
35201
- shouldAskForApprove = true;
35202
- }
35203
- if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
35204
- tablesContext[newTableName] = [
35205
- ..._moveDataStatements(statement.tableName, json2, true)
35206
- ];
35207
- const tablesReferncingCurrent = [];
35208
- for (const table4 of Object.values(json1.tables)) {
35209
- const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35210
- (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35211
- ).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
35212
- tablesReferncingCurrent.push(...tablesRefs);
35213
- }
35214
- const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35215
- for (const table4 of uniqueTableRefs) {
35216
- if (typeof tablesContext[table4] === "undefined") {
35217
- tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35218
- }
35219
- }
35220
- } else {
35221
- if (typeof tablesContext[newTableName] === "undefined") {
35222
- const stmnt = fromJson([statement], "sqlite")[0];
35223
- statementsToExecute.push(stmnt);
35224
- }
35225
- }
35226
- } else if (statement.type === "sqlite_alter_table_add_column") {
35227
- const newTableName = getOldTableName(statement.tableName, meta);
35228
- if (statement.column.notNull && !statement.column.default) {
35229
- const res = await connection.query(
35230
- `select count(*) as count from \`${newTableName}\``
35231
- );
35232
- const count2 = Number(res[0].count);
35233
- if (count2 > 0) {
35234
- infoToPrint.push(
35235
- `\xB7 You're about to add not-null ${source_default.underline(
35236
- statement.column.name
35237
- )} column without default value, which contains ${count2} items`
35238
- );
35239
- tablesToTruncate.push(newTableName);
35240
- statementsToExecute.push(`delete from ${newTableName};`);
35241
- shouldAskForApprove = true;
35242
- }
35243
- }
35244
- if (statement.column.primaryKey) {
35245
- tablesContext[newTableName] = [
35246
- ..._moveDataStatements(statement.tableName, json2, true)
35247
- ];
35248
- const tablesReferncingCurrent = [];
35249
- for (const table4 of Object.values(json1.tables)) {
35250
- const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35251
- (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35252
- ).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
35253
- tablesReferncingCurrent.push(...tablesRefs);
35254
- }
35255
- const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35256
- for (const table4 of uniqueTableRefs) {
35257
- if (typeof tablesContext[table4] === "undefined") {
35258
- tablesContext[table4] = [..._moveDataStatements(table4, json2)];
35259
- }
35260
- }
35261
- } else {
35262
- if (typeof tablesContext[newTableName] === "undefined") {
35263
- const stmnt = fromJson([statement], "sqlite")[0];
35264
- statementsToExecute.push(stmnt);
35265
- }
35266
- }
35267
- } else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
35268
- if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
35269
- const newTableName = getOldTableName(statement.tableName, meta);
35270
- if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
35271
- const res = await connection.query(
35272
- `select count(*) as count from \`${newTableName}\``
35273
- );
35274
- const count2 = Number(res[0].count);
35275
- if (count2 > 0) {
35276
- infoToPrint.push(
35277
- `\xB7 You're about to add not-null constraint to ${source_default.underline(
35278
- statement.columnName
35279
- )} column without default value, which contains ${count2} items`
35280
- );
35281
- tablesToTruncate.push(newTableName);
35282
- shouldAskForApprove = true;
35283
- }
35284
- tablesContext[newTableName] = _moveDataStatements(
35285
- statement.tableName,
35286
- json1,
35287
- true
35288
- );
35289
- } else {
35290
- if (typeof tablesContext[newTableName] === "undefined") {
35291
- tablesContext[newTableName] = _moveDataStatements(
35292
- statement.tableName,
35293
- json1
35294
- );
35295
- }
35296
- }
35297
- const tablesReferncingCurrent = [];
35298
- for (const table4 of Object.values(json1.tables)) {
35299
- const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
35300
- (t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
35301
- ).map((t) => {
35302
- return getNewTableName(
35303
- SQLiteSquasher.unsquashPushFK(t).tableFrom,
35304
- meta
35305
- );
35306
- });
35307
- tablesReferncingCurrent.push(...tablesRefs);
35308
- }
35309
- const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
35310
- for (const table4 of uniqueTableRefs) {
35311
- if (typeof tablesContext[table4] === "undefined") {
35312
- tablesContext[table4] = [..._moveDataStatements(table4, json1)];
35313
- }
35314
- }
35315
- }
35316
- } else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
35317
- const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
35318
- if (typeof tablesContext[statement.tableName] === "undefined") {
35319
- tablesContext[statement.tableName] = _moveDataStatements(
35320
- statement.tableName,
35321
- json2
35322
- );
35323
- }
35324
- } else if (statement.type === "create_composite_pk" || statement.type === "alter_composite_pk" || statement.type === "delete_composite_pk" || statement.type === "create_unique_constraint" || statement.type === "delete_unique_constraint") {
35325
- const newTableName = getOldTableName(statement.tableName, meta);
35326
- if (typeof tablesContext[newTableName] === "undefined") {
35327
- tablesContext[newTableName] = _moveDataStatements(
35328
- statement.tableName,
35329
- json2
35330
- );
35331
- }
35332
- } else {
35333
- const stmnt = fromJson([statement], "sqlite");
35334
- if (typeof stmnt !== "undefined") {
35335
- statementsToExecute.push(...stmnt);
35336
- }
35337
- }
35338
- }
35339
- for (const context of Object.values(tablesContext)) {
35340
- statementsToExecute.push(...context);
35341
- }
35342
- return {
35343
- statementsToExecute,
35344
- shouldAskForApprove,
35345
- infoToPrint,
35346
- columnsToRemove: [...new Set(columnsToRemove)],
35347
- schemasToRemove: [...new Set(schemasToRemove)],
35348
- tablesToTruncate: [...new Set(tablesToTruncate)],
35349
- tablesToRemove: [...new Set(tablesToRemove)]
35350
- };
35351
- };
35352
-
35353
35954
  // src/api.ts
35955
+ init_sqlitePushUtils();
35354
35956
  init_global();
35355
35957
  init_migrationPreparator();
35356
35958
  init_mysqlSchema();