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.d.mts +6 -6
- package/api.d.ts +6 -6
- package/api.js +1535 -933
- package/api.mjs +1535 -933
- package/bin.cjs +67963 -64533
- package/index.d.mts +6 -4
- package/index.d.ts +6 -4
- package/package.json +2 -3
- package/utils.js +44 -17
- package/utils.mjs +42 -17
package/api.mjs
CHANGED
@@ -237,8 +237,8 @@ import process2 from "process";
|
|
237
237
|
import os from "os";
|
238
238
|
import tty from "tty";
|
239
239
|
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
240
|
-
const
|
241
|
-
const position = argv.indexOf(
|
240
|
+
const prefix2 = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
241
|
+
const position = argv.indexOf(prefix2 + flag);
|
242
242
|
const terminatorPosition = argv.indexOf("--");
|
243
243
|
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
244
244
|
}
|
@@ -380,12 +380,12 @@ function stringReplaceAll(string, substring, replacer) {
|
|
380
380
|
returnValue += string.slice(endIndex);
|
381
381
|
return returnValue;
|
382
382
|
}
|
383
|
-
function stringEncaseCRLFWithFirstIndex(string,
|
383
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix2, postfix, index4) {
|
384
384
|
let endIndex = 0;
|
385
385
|
let returnValue = "";
|
386
386
|
do {
|
387
387
|
const gotCR = string[index4 - 1] === "\r";
|
388
|
-
returnValue += string.slice(endIndex, gotCR ? index4 - 1 : index4) +
|
388
|
+
returnValue += string.slice(endIndex, gotCR ? index4 - 1 : index4) + prefix2 + (gotCR ? "\r\n" : "\n") + postfix;
|
389
389
|
endIndex = index4 + 1;
|
390
390
|
index4 = string.indexOf("\n", endIndex);
|
391
391
|
} while (index4 !== -1);
|
@@ -1902,40 +1902,40 @@ var require_sync = __commonJS({
|
|
1902
1902
|
while (typeof pattern[n] === "string") {
|
1903
1903
|
n++;
|
1904
1904
|
}
|
1905
|
-
var
|
1905
|
+
var prefix2;
|
1906
1906
|
switch (n) {
|
1907
1907
|
case pattern.length:
|
1908
1908
|
this._processSimple(pattern.join("/"), index4);
|
1909
1909
|
return;
|
1910
1910
|
case 0:
|
1911
|
-
|
1911
|
+
prefix2 = null;
|
1912
1912
|
break;
|
1913
1913
|
default:
|
1914
|
-
|
1914
|
+
prefix2 = pattern.slice(0, n).join("/");
|
1915
1915
|
break;
|
1916
1916
|
}
|
1917
1917
|
var remain = pattern.slice(n);
|
1918
1918
|
var read;
|
1919
|
-
if (
|
1919
|
+
if (prefix2 === null)
|
1920
1920
|
read = ".";
|
1921
|
-
else if (isAbsolute(
|
1921
|
+
else if (isAbsolute(prefix2) || isAbsolute(pattern.map(function(p) {
|
1922
1922
|
return typeof p === "string" ? p : "[*]";
|
1923
1923
|
}).join("/"))) {
|
1924
|
-
if (!
|
1925
|
-
|
1926
|
-
read =
|
1924
|
+
if (!prefix2 || !isAbsolute(prefix2))
|
1925
|
+
prefix2 = "/" + prefix2;
|
1926
|
+
read = prefix2;
|
1927
1927
|
} else
|
1928
|
-
read =
|
1928
|
+
read = prefix2;
|
1929
1929
|
var abs = this._makeAbs(read);
|
1930
1930
|
if (childrenIgnored(this, read))
|
1931
1931
|
return;
|
1932
1932
|
var isGlobStar = remain[0] === minimatch2.GLOBSTAR;
|
1933
1933
|
if (isGlobStar)
|
1934
|
-
this._processGlobStar(
|
1934
|
+
this._processGlobStar(prefix2, read, abs, remain, index4, inGlobStar);
|
1935
1935
|
else
|
1936
|
-
this._processReaddir(
|
1936
|
+
this._processReaddir(prefix2, read, abs, remain, index4, inGlobStar);
|
1937
1937
|
};
|
1938
|
-
GlobSync.prototype._processReaddir = function(
|
1938
|
+
GlobSync.prototype._processReaddir = function(prefix2, read, abs, remain, index4, inGlobStar) {
|
1939
1939
|
var entries = this._readdir(abs, inGlobStar);
|
1940
1940
|
if (!entries)
|
1941
1941
|
return;
|
@@ -1948,7 +1948,7 @@ var require_sync = __commonJS({
|
|
1948
1948
|
var e = entries[i];
|
1949
1949
|
if (e.charAt(0) !== "." || dotOk) {
|
1950
1950
|
var m;
|
1951
|
-
if (negate && !
|
1951
|
+
if (negate && !prefix2) {
|
1952
1952
|
m = !e.match(pn);
|
1953
1953
|
} else {
|
1954
1954
|
m = e.match(pn);
|
@@ -1965,11 +1965,11 @@ var require_sync = __commonJS({
|
|
1965
1965
|
this.matches[index4] = /* @__PURE__ */ Object.create(null);
|
1966
1966
|
for (var i = 0; i < len; i++) {
|
1967
1967
|
var e = matchedEntries[i];
|
1968
|
-
if (
|
1969
|
-
if (
|
1970
|
-
e =
|
1968
|
+
if (prefix2) {
|
1969
|
+
if (prefix2.slice(-1) !== "/")
|
1970
|
+
e = prefix2 + "/" + e;
|
1971
1971
|
else
|
1972
|
-
e =
|
1972
|
+
e = prefix2 + e;
|
1973
1973
|
}
|
1974
1974
|
if (e.charAt(0) === "/" && !this.nomount) {
|
1975
1975
|
e = path2.join(this.root, e);
|
@@ -1982,8 +1982,8 @@ var require_sync = __commonJS({
|
|
1982
1982
|
for (var i = 0; i < len; i++) {
|
1983
1983
|
var e = matchedEntries[i];
|
1984
1984
|
var newPattern;
|
1985
|
-
if (
|
1986
|
-
newPattern = [
|
1985
|
+
if (prefix2)
|
1986
|
+
newPattern = [prefix2, e];
|
1987
1987
|
else
|
1988
1988
|
newPattern = [e];
|
1989
1989
|
this._process(newPattern.concat(remain), index4, inGlobStar);
|
@@ -2090,12 +2090,12 @@ var require_sync = __commonJS({
|
|
2090
2090
|
break;
|
2091
2091
|
}
|
2092
2092
|
};
|
2093
|
-
GlobSync.prototype._processGlobStar = function(
|
2093
|
+
GlobSync.prototype._processGlobStar = function(prefix2, read, abs, remain, index4, inGlobStar) {
|
2094
2094
|
var entries = this._readdir(abs, inGlobStar);
|
2095
2095
|
if (!entries)
|
2096
2096
|
return;
|
2097
2097
|
var remainWithoutGlobStar = remain.slice(1);
|
2098
|
-
var gspref =
|
2098
|
+
var gspref = prefix2 ? [prefix2] : [];
|
2099
2099
|
var noGlobStar = gspref.concat(remainWithoutGlobStar);
|
2100
2100
|
this._process(noGlobStar, index4, false);
|
2101
2101
|
var len = entries.length;
|
@@ -2112,25 +2112,25 @@ var require_sync = __commonJS({
|
|
2112
2112
|
this._process(below, index4, true);
|
2113
2113
|
}
|
2114
2114
|
};
|
2115
|
-
GlobSync.prototype._processSimple = function(
|
2116
|
-
var exists2 = this._stat(
|
2115
|
+
GlobSync.prototype._processSimple = function(prefix2, index4) {
|
2116
|
+
var exists2 = this._stat(prefix2);
|
2117
2117
|
if (!this.matches[index4])
|
2118
2118
|
this.matches[index4] = /* @__PURE__ */ Object.create(null);
|
2119
2119
|
if (!exists2)
|
2120
2120
|
return;
|
2121
|
-
if (
|
2122
|
-
var trail = /[\/\\]$/.test(
|
2123
|
-
if (
|
2124
|
-
|
2121
|
+
if (prefix2 && isAbsolute(prefix2) && !this.nomount) {
|
2122
|
+
var trail = /[\/\\]$/.test(prefix2);
|
2123
|
+
if (prefix2.charAt(0) === "/") {
|
2124
|
+
prefix2 = path2.join(this.root, prefix2);
|
2125
2125
|
} else {
|
2126
|
-
|
2126
|
+
prefix2 = path2.resolve(this.root, prefix2);
|
2127
2127
|
if (trail)
|
2128
|
-
|
2128
|
+
prefix2 += "/";
|
2129
2129
|
}
|
2130
2130
|
}
|
2131
2131
|
if (process.platform === "win32")
|
2132
|
-
|
2133
|
-
this._emitMatch(index4,
|
2132
|
+
prefix2 = prefix2.replace(/\\/g, "/");
|
2133
|
+
this._emitMatch(index4, prefix2);
|
2134
2134
|
};
|
2135
2135
|
GlobSync.prototype._stat = function(f) {
|
2136
2136
|
var abs = this._makeAbs(f);
|
@@ -2525,46 +2525,46 @@ var require_glob = __commonJS({
|
|
2525
2525
|
while (typeof pattern[n] === "string") {
|
2526
2526
|
n++;
|
2527
2527
|
}
|
2528
|
-
var
|
2528
|
+
var prefix2;
|
2529
2529
|
switch (n) {
|
2530
2530
|
case pattern.length:
|
2531
2531
|
this._processSimple(pattern.join("/"), index4, cb);
|
2532
2532
|
return;
|
2533
2533
|
case 0:
|
2534
|
-
|
2534
|
+
prefix2 = null;
|
2535
2535
|
break;
|
2536
2536
|
default:
|
2537
|
-
|
2537
|
+
prefix2 = pattern.slice(0, n).join("/");
|
2538
2538
|
break;
|
2539
2539
|
}
|
2540
2540
|
var remain = pattern.slice(n);
|
2541
2541
|
var read;
|
2542
|
-
if (
|
2542
|
+
if (prefix2 === null)
|
2543
2543
|
read = ".";
|
2544
|
-
else if (isAbsolute(
|
2544
|
+
else if (isAbsolute(prefix2) || isAbsolute(pattern.map(function(p) {
|
2545
2545
|
return typeof p === "string" ? p : "[*]";
|
2546
2546
|
}).join("/"))) {
|
2547
|
-
if (!
|
2548
|
-
|
2549
|
-
read =
|
2547
|
+
if (!prefix2 || !isAbsolute(prefix2))
|
2548
|
+
prefix2 = "/" + prefix2;
|
2549
|
+
read = prefix2;
|
2550
2550
|
} else
|
2551
|
-
read =
|
2551
|
+
read = prefix2;
|
2552
2552
|
var abs = this._makeAbs(read);
|
2553
2553
|
if (childrenIgnored(this, read))
|
2554
2554
|
return cb();
|
2555
2555
|
var isGlobStar = remain[0] === minimatch2.GLOBSTAR;
|
2556
2556
|
if (isGlobStar)
|
2557
|
-
this._processGlobStar(
|
2557
|
+
this._processGlobStar(prefix2, read, abs, remain, index4, inGlobStar, cb);
|
2558
2558
|
else
|
2559
|
-
this._processReaddir(
|
2559
|
+
this._processReaddir(prefix2, read, abs, remain, index4, inGlobStar, cb);
|
2560
2560
|
};
|
2561
|
-
Glob.prototype._processReaddir = function(
|
2561
|
+
Glob.prototype._processReaddir = function(prefix2, read, abs, remain, index4, inGlobStar, cb) {
|
2562
2562
|
var self2 = this;
|
2563
2563
|
this._readdir(abs, inGlobStar, function(er, entries) {
|
2564
|
-
return self2._processReaddir2(
|
2564
|
+
return self2._processReaddir2(prefix2, read, abs, remain, index4, inGlobStar, entries, cb);
|
2565
2565
|
});
|
2566
2566
|
};
|
2567
|
-
Glob.prototype._processReaddir2 = function(
|
2567
|
+
Glob.prototype._processReaddir2 = function(prefix2, read, abs, remain, index4, inGlobStar, entries, cb) {
|
2568
2568
|
if (!entries)
|
2569
2569
|
return cb();
|
2570
2570
|
var pn = remain[0];
|
@@ -2576,7 +2576,7 @@ var require_glob = __commonJS({
|
|
2576
2576
|
var e = entries[i];
|
2577
2577
|
if (e.charAt(0) !== "." || dotOk) {
|
2578
2578
|
var m;
|
2579
|
-
if (negate && !
|
2579
|
+
if (negate && !prefix2) {
|
2580
2580
|
m = !e.match(pn);
|
2581
2581
|
} else {
|
2582
2582
|
m = e.match(pn);
|
@@ -2593,11 +2593,11 @@ var require_glob = __commonJS({
|
|
2593
2593
|
this.matches[index4] = /* @__PURE__ */ Object.create(null);
|
2594
2594
|
for (var i = 0; i < len; i++) {
|
2595
2595
|
var e = matchedEntries[i];
|
2596
|
-
if (
|
2597
|
-
if (
|
2598
|
-
e =
|
2596
|
+
if (prefix2) {
|
2597
|
+
if (prefix2 !== "/")
|
2598
|
+
e = prefix2 + "/" + e;
|
2599
2599
|
else
|
2600
|
-
e =
|
2600
|
+
e = prefix2 + e;
|
2601
2601
|
}
|
2602
2602
|
if (e.charAt(0) === "/" && !this.nomount) {
|
2603
2603
|
e = path2.join(this.root, e);
|
@@ -2610,11 +2610,11 @@ var require_glob = __commonJS({
|
|
2610
2610
|
for (var i = 0; i < len; i++) {
|
2611
2611
|
var e = matchedEntries[i];
|
2612
2612
|
var newPattern;
|
2613
|
-
if (
|
2614
|
-
if (
|
2615
|
-
e =
|
2613
|
+
if (prefix2) {
|
2614
|
+
if (prefix2 !== "/")
|
2615
|
+
e = prefix2 + "/" + e;
|
2616
2616
|
else
|
2617
|
-
e =
|
2617
|
+
e = prefix2 + e;
|
2618
2618
|
}
|
2619
2619
|
this._process([e].concat(remain), index4, inGlobStar, cb);
|
2620
2620
|
}
|
@@ -2745,17 +2745,17 @@ var require_glob = __commonJS({
|
|
2745
2745
|
}
|
2746
2746
|
return cb();
|
2747
2747
|
};
|
2748
|
-
Glob.prototype._processGlobStar = function(
|
2748
|
+
Glob.prototype._processGlobStar = function(prefix2, read, abs, remain, index4, inGlobStar, cb) {
|
2749
2749
|
var self2 = this;
|
2750
2750
|
this._readdir(abs, inGlobStar, function(er, entries) {
|
2751
|
-
self2._processGlobStar2(
|
2751
|
+
self2._processGlobStar2(prefix2, read, abs, remain, index4, inGlobStar, entries, cb);
|
2752
2752
|
});
|
2753
2753
|
};
|
2754
|
-
Glob.prototype._processGlobStar2 = function(
|
2754
|
+
Glob.prototype._processGlobStar2 = function(prefix2, read, abs, remain, index4, inGlobStar, entries, cb) {
|
2755
2755
|
if (!entries)
|
2756
2756
|
return cb();
|
2757
2757
|
var remainWithoutGlobStar = remain.slice(1);
|
2758
|
-
var gspref =
|
2758
|
+
var gspref = prefix2 ? [prefix2] : [];
|
2759
2759
|
var noGlobStar = gspref.concat(remainWithoutGlobStar);
|
2760
2760
|
this._process(noGlobStar, index4, false, cb);
|
2761
2761
|
var isSym = this.symlinks[abs];
|
@@ -2773,30 +2773,30 @@ var require_glob = __commonJS({
|
|
2773
2773
|
}
|
2774
2774
|
cb();
|
2775
2775
|
};
|
2776
|
-
Glob.prototype._processSimple = function(
|
2776
|
+
Glob.prototype._processSimple = function(prefix2, index4, cb) {
|
2777
2777
|
var self2 = this;
|
2778
|
-
this._stat(
|
2779
|
-
self2._processSimple2(
|
2778
|
+
this._stat(prefix2, function(er, exists2) {
|
2779
|
+
self2._processSimple2(prefix2, index4, er, exists2, cb);
|
2780
2780
|
});
|
2781
2781
|
};
|
2782
|
-
Glob.prototype._processSimple2 = function(
|
2782
|
+
Glob.prototype._processSimple2 = function(prefix2, index4, er, exists2, cb) {
|
2783
2783
|
if (!this.matches[index4])
|
2784
2784
|
this.matches[index4] = /* @__PURE__ */ Object.create(null);
|
2785
2785
|
if (!exists2)
|
2786
2786
|
return cb();
|
2787
|
-
if (
|
2788
|
-
var trail = /[\/\\]$/.test(
|
2789
|
-
if (
|
2790
|
-
|
2787
|
+
if (prefix2 && isAbsolute(prefix2) && !this.nomount) {
|
2788
|
+
var trail = /[\/\\]$/.test(prefix2);
|
2789
|
+
if (prefix2.charAt(0) === "/") {
|
2790
|
+
prefix2 = path2.join(this.root, prefix2);
|
2791
2791
|
} else {
|
2792
|
-
|
2792
|
+
prefix2 = path2.resolve(this.root, prefix2);
|
2793
2793
|
if (trail)
|
2794
|
-
|
2794
|
+
prefix2 += "/";
|
2795
2795
|
}
|
2796
2796
|
}
|
2797
2797
|
if (process.platform === "win32")
|
2798
|
-
|
2799
|
-
this._emitMatch(index4,
|
2798
|
+
prefix2 = prefix2.replace(/\\/g, "/");
|
2799
|
+
this._emitMatch(index4, prefix2);
|
2800
2800
|
cb();
|
2801
2801
|
};
|
2802
2802
|
Glob.prototype._stat = function(f, cb) {
|
@@ -8366,6 +8366,13 @@ var init_sqliteSchema = __esm({
|
|
8366
8366
|
function isPgArrayType(sqlType) {
|
8367
8367
|
return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
|
8368
8368
|
}
|
8369
|
+
function findAddedAndRemoved(columnNames1, columnNames2) {
|
8370
|
+
const set1 = new Set(columnNames1);
|
8371
|
+
const set2 = new Set(columnNames2);
|
8372
|
+
const addedColumns = columnNames2.filter((it) => !set1.has(it));
|
8373
|
+
const removedColumns = columnNames1.filter((it) => !set2.has(it));
|
8374
|
+
return { addedColumns, removedColumns };
|
8375
|
+
}
|
8369
8376
|
var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
|
8370
8377
|
var init_utils = __esm({
|
8371
8378
|
"src/utils.ts"() {
|
@@ -8424,7 +8431,7 @@ var init_views = __esm({
|
|
8424
8431
|
import_hanji = __toESM(require_hanji());
|
8425
8432
|
init_utils();
|
8426
8433
|
warning = (msg) => {
|
8427
|
-
(0, import_hanji.render)(
|
8434
|
+
(0, import_hanji.render)(`[${source_default.yellow("Warning")}] ${msg}`);
|
8428
8435
|
};
|
8429
8436
|
error = (error2, greyMsg = "") => {
|
8430
8437
|
return `${source_default.bgRed.bold(" Error ")} ${error2} ${greyMsg ? source_default.grey(greyMsg) : ""}`.trim();
|
@@ -9748,7 +9755,7 @@ var require_difflib = __commonJS({
|
|
9748
9755
|
return `${beginning},${beginning + length - 1}`;
|
9749
9756
|
};
|
9750
9757
|
contextDiff = function(a, b, { fromfile, tofile, fromfiledate, tofiledate, n, lineterm } = {}) {
|
9751
|
-
var _2, file1Range, file2Range, first, fromdate, group, i1, i2, j1, j2, l, last, len, len1, len2, len3, len4, line, lines, m, o, p,
|
9758
|
+
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;
|
9752
9759
|
if (fromfile == null) {
|
9753
9760
|
fromfile = "";
|
9754
9761
|
}
|
@@ -9767,7 +9774,7 @@ var require_difflib = __commonJS({
|
|
9767
9774
|
if (lineterm == null) {
|
9768
9775
|
lineterm = "\n";
|
9769
9776
|
}
|
9770
|
-
|
9777
|
+
prefix2 = {
|
9771
9778
|
insert: "+ ",
|
9772
9779
|
delete: "- ",
|
9773
9780
|
replace: "! ",
|
@@ -9803,7 +9810,7 @@ var require_difflib = __commonJS({
|
|
9803
9810
|
ref1 = a.slice(i1, i2);
|
9804
9811
|
for (o = 0, len2 = ref1.length; o < len2; o++) {
|
9805
9812
|
line = ref1[o];
|
9806
|
-
lines.push(
|
9813
|
+
lines.push(prefix2[tag] + line);
|
9807
9814
|
}
|
9808
9815
|
}
|
9809
9816
|
}
|
@@ -9825,7 +9832,7 @@ var require_difflib = __commonJS({
|
|
9825
9832
|
ref2 = b.slice(j1, j2);
|
9826
9833
|
for (q = 0, len4 = ref2.length; q < len4; q++) {
|
9827
9834
|
line = ref2[q];
|
9828
|
-
lines.push(
|
9835
|
+
lines.push(prefix2[tag] + line);
|
9829
9836
|
}
|
9830
9837
|
}
|
9831
9838
|
}
|
@@ -9838,7 +9845,7 @@ var require_difflib = __commonJS({
|
|
9838
9845
|
return new Differ(linejunk, charjunk).compare(a, b);
|
9839
9846
|
};
|
9840
9847
|
restore = function(delta, which) {
|
9841
|
-
var l, len, line, lines,
|
9848
|
+
var l, len, line, lines, prefixes2, ref, tag;
|
9842
9849
|
tag = {
|
9843
9850
|
1: "- ",
|
9844
9851
|
2: "+ "
|
@@ -9846,11 +9853,11 @@ var require_difflib = __commonJS({
|
|
9846
9853
|
if (!tag) {
|
9847
9854
|
throw new Error(`unknow delta choice (must be 1 or 2): ${which}`);
|
9848
9855
|
}
|
9849
|
-
|
9856
|
+
prefixes2 = [" ", tag];
|
9850
9857
|
lines = [];
|
9851
9858
|
for (l = 0, len = delta.length; l < len; l++) {
|
9852
9859
|
line = delta[l];
|
9853
|
-
if (ref = line.slice(0, 2), indexOf.call(
|
9860
|
+
if (ref = line.slice(0, 2), indexOf.call(prefixes2, ref) >= 0) {
|
9854
9861
|
lines.push(line.slice(2));
|
9855
9862
|
}
|
9856
9863
|
}
|
@@ -9991,8 +9998,8 @@ var require_has_flag = __commonJS({
|
|
9991
9998
|
module.exports = function(flag, argv) {
|
9992
9999
|
argv = argv || process.argv;
|
9993
10000
|
var terminatorPos = argv.indexOf("--");
|
9994
|
-
var
|
9995
|
-
var pos = argv.indexOf(
|
10001
|
+
var prefix2 = /^-{1,2}/.test(flag) ? "" : "--";
|
10002
|
+
var pos = argv.indexOf(prefix2 + flag);
|
9996
10003
|
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
9997
10004
|
};
|
9998
10005
|
}
|
@@ -10601,7 +10608,7 @@ var require_colorize = __commonJS({
|
|
10601
10608
|
};
|
10602
10609
|
var subcolorizeToCallback = function(options, key, diff2, output, color2, indent) {
|
10603
10610
|
let subvalue;
|
10604
|
-
const
|
10611
|
+
const prefix2 = key ? `${key}: ` : "";
|
10605
10612
|
const subindent = indent + " ";
|
10606
10613
|
const outputElisions = (n) => {
|
10607
10614
|
const maxElisions = options.maxElisions === void 0 ? Infinity : options.maxElisions;
|
@@ -10619,7 +10626,7 @@ var require_colorize = __commonJS({
|
|
10619
10626
|
subcolorizeToCallback(options, key, diff2.__old, output, "-", indent);
|
10620
10627
|
return subcolorizeToCallback(options, key, diff2.__new, output, "+", indent);
|
10621
10628
|
} else {
|
10622
|
-
output(color2, `${indent}${
|
10629
|
+
output(color2, `${indent}${prefix2}{`);
|
10623
10630
|
for (const subkey of Object.keys(diff2)) {
|
10624
10631
|
let m;
|
10625
10632
|
subvalue = diff2[subkey];
|
@@ -10634,7 +10641,7 @@ var require_colorize = __commonJS({
|
|
10634
10641
|
return output(color2, `${indent}}`);
|
10635
10642
|
}
|
10636
10643
|
case "array": {
|
10637
|
-
output(color2, `${indent}${
|
10644
|
+
output(color2, `${indent}${prefix2}[`);
|
10638
10645
|
let looksLikeDiff = true;
|
10639
10646
|
for (const item of diff2) {
|
10640
10647
|
if (extendedTypeOf(item) !== "array" || !(item.length === 2 || item.length === 1 && item[0] === " ") || !(typeof item[0] === "string") || item[0].length !== 1 || ![" ", "-", "+", "~"].includes(item[0])) {
|
@@ -10673,7 +10680,7 @@ var require_colorize = __commonJS({
|
|
10673
10680
|
}
|
10674
10681
|
default:
|
10675
10682
|
if (diff2 === 0 || diff2 === null || diff2 === false || diff2 === "" || diff2) {
|
10676
|
-
return output(color2, indent +
|
10683
|
+
return output(color2, indent + prefix2 + JSON.stringify(diff2));
|
10677
10684
|
}
|
10678
10685
|
}
|
10679
10686
|
};
|
@@ -11475,7 +11482,20 @@ var init_jsonDiffer = __esm({
|
|
11475
11482
|
});
|
11476
11483
|
|
11477
11484
|
// src/sqlgenerator.ts
|
11478
|
-
|
11485
|
+
function fromJson(statements, dialect7, action, json2) {
|
11486
|
+
const result = statements.flatMap((statement) => {
|
11487
|
+
const filtered = convertors.filter((it) => {
|
11488
|
+
return it.can(statement, dialect7);
|
11489
|
+
});
|
11490
|
+
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
11491
|
+
if (!convertor) {
|
11492
|
+
return "";
|
11493
|
+
}
|
11494
|
+
return convertor.convert(statement, json2, action);
|
11495
|
+
}).filter((it) => it !== "");
|
11496
|
+
return result;
|
11497
|
+
}
|
11498
|
+
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;
|
11479
11499
|
var init_sqlgenerator = __esm({
|
11480
11500
|
"src/sqlgenerator.ts"() {
|
11481
11501
|
"use strict";
|
@@ -11627,7 +11647,7 @@ var init_sqlgenerator = __esm({
|
|
11627
11647
|
};
|
11628
11648
|
SQLiteCreateTableConvertor = class extends Convertor {
|
11629
11649
|
can(statement, dialect7) {
|
11630
|
-
return statement.type === "sqlite_create_table" && dialect7 === "sqlite";
|
11650
|
+
return statement.type === "sqlite_create_table" && (dialect7 === "sqlite" || dialect7 === "turso");
|
11631
11651
|
}
|
11632
11652
|
convert(st) {
|
11633
11653
|
const {
|
@@ -11797,32 +11817,6 @@ var init_sqlgenerator = __esm({
|
|
11797
11817
|
return `ALTER TABLE \`${statement.tableName}\` DROP INDEX \`${unsquashed.name}\`;`;
|
11798
11818
|
}
|
11799
11819
|
};
|
11800
|
-
SQLiteAlterTableAddUniqueConstraintConvertor = class extends Convertor {
|
11801
|
-
can(statement, dialect7) {
|
11802
|
-
return statement.type === "create_unique_constraint" && dialect7 === "sqlite";
|
11803
|
-
}
|
11804
|
-
convert(statement) {
|
11805
|
-
return `/*
|
11806
|
-
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
|
11807
|
-
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
11808
|
-
|
11809
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
11810
|
-
*/`;
|
11811
|
-
}
|
11812
|
-
};
|
11813
|
-
SQLiteAlterTableDropUniqueConstraintConvertor = class extends Convertor {
|
11814
|
-
can(statement, dialect7) {
|
11815
|
-
return statement.type === "delete_unique_constraint" && dialect7 === "sqlite";
|
11816
|
-
}
|
11817
|
-
convert(statement) {
|
11818
|
-
return `/*
|
11819
|
-
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
|
11820
|
-
Please refer to: https://www.techonthenet.com/sqlite/unique.php
|
11821
|
-
|
11822
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
11823
|
-
*/`;
|
11824
|
-
}
|
11825
|
-
};
|
11826
11820
|
CreatePgSequenceConvertor = class extends Convertor {
|
11827
11821
|
can(statement, dialect7) {
|
11828
11822
|
return statement.type === "create_sequence" && dialect7 === "postgresql";
|
@@ -11930,7 +11924,7 @@ var init_sqlgenerator = __esm({
|
|
11930
11924
|
};
|
11931
11925
|
SQLiteDropTableConvertor = class extends Convertor {
|
11932
11926
|
can(statement, dialect7) {
|
11933
|
-
return statement.type === "drop_table" && dialect7 === "sqlite";
|
11927
|
+
return statement.type === "drop_table" && (dialect7 === "sqlite" || dialect7 === "turso");
|
11934
11928
|
}
|
11935
11929
|
convert(statement) {
|
11936
11930
|
const { tableName } = statement;
|
@@ -11950,7 +11944,7 @@ var init_sqlgenerator = __esm({
|
|
11950
11944
|
};
|
11951
11945
|
SqliteRenameTableConvertor = class extends Convertor {
|
11952
11946
|
can(statement, dialect7) {
|
11953
|
-
return statement.type === "rename_table" && dialect7 === "sqlite";
|
11947
|
+
return statement.type === "rename_table" && (dialect7 === "sqlite" || dialect7 === "turso");
|
11954
11948
|
}
|
11955
11949
|
convert(statement) {
|
11956
11950
|
const { tableNameFrom, tableNameTo } = statement;
|
@@ -11987,11 +11981,11 @@ var init_sqlgenerator = __esm({
|
|
11987
11981
|
};
|
11988
11982
|
SQLiteAlterTableRenameColumnConvertor = class extends Convertor {
|
11989
11983
|
can(statement, dialect7) {
|
11990
|
-
return statement.type === "alter_table_rename_column" && dialect7 === "sqlite";
|
11984
|
+
return statement.type === "alter_table_rename_column" && (dialect7 === "sqlite" || dialect7 === "turso");
|
11991
11985
|
}
|
11992
11986
|
convert(statement) {
|
11993
11987
|
const { tableName, oldColumnName, newColumnName } = statement;
|
11994
|
-
return `ALTER TABLE \`${tableName}\` RENAME COLUMN
|
11988
|
+
return `ALTER TABLE \`${tableName}\` RENAME COLUMN "${oldColumnName}" TO "${newColumnName}";`;
|
11995
11989
|
}
|
11996
11990
|
};
|
11997
11991
|
PgAlterTableDropColumnConvertor = class extends Convertor {
|
@@ -12015,7 +12009,7 @@ var init_sqlgenerator = __esm({
|
|
12015
12009
|
};
|
12016
12010
|
SQLiteAlterTableDropColumnConvertor = class extends Convertor {
|
12017
12011
|
can(statement, dialect7) {
|
12018
|
-
return statement.type === "alter_table_drop_column" && dialect7 === "sqlite";
|
12012
|
+
return statement.type === "alter_table_drop_column" && (dialect7 === "sqlite" || dialect7 === "turso");
|
12019
12013
|
}
|
12020
12014
|
convert(statement) {
|
12021
12015
|
const { tableName, columnName } = statement;
|
@@ -12068,7 +12062,7 @@ var init_sqlgenerator = __esm({
|
|
12068
12062
|
};
|
12069
12063
|
SQLiteAlterTableAddColumnConvertor = class extends Convertor {
|
12070
12064
|
can(statement, dialect7) {
|
12071
|
-
return statement.type === "sqlite_alter_table_add_column" && dialect7 === "sqlite";
|
12065
|
+
return statement.type === "sqlite_alter_table_add_column" && (dialect7 === "sqlite" || dialect7 === "turso");
|
12072
12066
|
}
|
12073
12067
|
convert(statement) {
|
12074
12068
|
const { tableName, column: column4, referenceData } = statement;
|
@@ -12092,21 +12086,6 @@ var init_sqlgenerator = __esm({
|
|
12092
12086
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DATA TYPE ${newDataType};`;
|
12093
12087
|
}
|
12094
12088
|
};
|
12095
|
-
SQLiteAlterTableAlterColumnSetTypeConvertor = class extends Convertor {
|
12096
|
-
can(statement, dialect7) {
|
12097
|
-
return statement.type === "alter_table_alter_column_set_type" && dialect7 === "sqlite";
|
12098
|
-
}
|
12099
|
-
convert(statement) {
|
12100
|
-
return `/*
|
12101
|
-
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
|
12102
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12103
|
-
https://www.sqlite.org/lang_altertable.html
|
12104
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12105
|
-
|
12106
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12107
|
-
*/`;
|
12108
|
-
}
|
12109
|
-
};
|
12110
12089
|
PgAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
12111
12090
|
can(statement, dialect7) {
|
12112
12091
|
return statement.type === "alter_table_alter_column_set_default" && dialect7 === "postgresql";
|
@@ -12117,21 +12096,6 @@ var init_sqlgenerator = __esm({
|
|
12117
12096
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET DEFAULT ${statement.newDefaultValue};`;
|
12118
12097
|
}
|
12119
12098
|
};
|
12120
|
-
SqliteAlterTableAlterColumnSetDefaultConvertor = class extends Convertor {
|
12121
|
-
can(statement, dialect7) {
|
12122
|
-
return statement.type === "alter_table_alter_column_set_default" && dialect7 === "sqlite";
|
12123
|
-
}
|
12124
|
-
convert(statement) {
|
12125
|
-
return `/*
|
12126
|
-
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
|
12127
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12128
|
-
https://www.sqlite.org/lang_altertable.html
|
12129
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12130
|
-
|
12131
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12132
|
-
*/`;
|
12133
|
-
}
|
12134
|
-
};
|
12135
12099
|
PgAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
12136
12100
|
can(statement, dialect7) {
|
12137
12101
|
return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "postgresql";
|
@@ -12230,7 +12194,7 @@ var init_sqlgenerator = __esm({
|
|
12230
12194
|
};
|
12231
12195
|
SqliteAlterTableAlterColumnDropGeneratedConvertor = class extends Convertor {
|
12232
12196
|
can(statement, dialect7) {
|
12233
|
-
return statement.type === "alter_table_alter_column_drop_generated" && dialect7 === "sqlite";
|
12197
|
+
return statement.type === "alter_table_alter_column_drop_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
|
12234
12198
|
}
|
12235
12199
|
convert(statement) {
|
12236
12200
|
const {
|
@@ -12271,7 +12235,7 @@ var init_sqlgenerator = __esm({
|
|
12271
12235
|
};
|
12272
12236
|
SqliteAlterTableAlterColumnSetExpressionConvertor = class extends Convertor {
|
12273
12237
|
can(statement, dialect7) {
|
12274
|
-
return statement.type === "alter_table_alter_column_set_generated" && dialect7 === "sqlite";
|
12238
|
+
return statement.type === "alter_table_alter_column_set_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
|
12275
12239
|
}
|
12276
12240
|
convert(statement) {
|
12277
12241
|
const {
|
@@ -12312,7 +12276,7 @@ var init_sqlgenerator = __esm({
|
|
12312
12276
|
};
|
12313
12277
|
SqliteAlterTableAlterColumnAlterGeneratedConvertor = class extends Convertor {
|
12314
12278
|
can(statement, dialect7) {
|
12315
|
-
return statement.type === "alter_table_alter_column_alter_generated" && dialect7 === "sqlite";
|
12279
|
+
return statement.type === "alter_table_alter_column_alter_generated" && (dialect7 === "sqlite" || dialect7 === "turso");
|
12316
12280
|
}
|
12317
12281
|
convert(statement) {
|
12318
12282
|
const {
|
@@ -12405,6 +12369,67 @@ var init_sqlgenerator = __esm({
|
|
12405
12369
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY`;
|
12406
12370
|
}
|
12407
12371
|
};
|
12372
|
+
LibSQLModifyColumn = class extends Convertor {
|
12373
|
+
can(statement, dialect7) {
|
12374
|
+
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";
|
12375
|
+
}
|
12376
|
+
convert(statement, json2) {
|
12377
|
+
const { tableName, columnName } = statement;
|
12378
|
+
let columnType = ``;
|
12379
|
+
let columnDefault = "";
|
12380
|
+
let columnNotNull = "";
|
12381
|
+
const sqlStatements = [];
|
12382
|
+
const indexes = [];
|
12383
|
+
for (const table4 of Object.values(json2.tables)) {
|
12384
|
+
for (const index4 of Object.values(table4.indexes)) {
|
12385
|
+
const unsquashed = SQLiteSquasher.unsquashIdx(index4);
|
12386
|
+
sqlStatements.push(`DROP INDEX IF EXISTS "${unsquashed.name}";`);
|
12387
|
+
indexes.push({ ...unsquashed, tableName: table4.name });
|
12388
|
+
}
|
12389
|
+
}
|
12390
|
+
switch (statement.type) {
|
12391
|
+
case "alter_table_alter_column_set_type":
|
12392
|
+
columnType = ` ${statement.newDataType}`;
|
12393
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12394
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12395
|
+
break;
|
12396
|
+
case "alter_table_alter_column_drop_notnull":
|
12397
|
+
columnType = ` ${statement.newDataType}`;
|
12398
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12399
|
+
columnNotNull = "";
|
12400
|
+
break;
|
12401
|
+
case "alter_table_alter_column_set_notnull":
|
12402
|
+
columnType = ` ${statement.newDataType}`;
|
12403
|
+
columnDefault = statement.columnDefault ? ` DEFAULT ${statement.columnDefault}` : "";
|
12404
|
+
columnNotNull = ` NOT NULL`;
|
12405
|
+
break;
|
12406
|
+
case "alter_table_alter_column_set_default":
|
12407
|
+
columnType = ` ${statement.newDataType}`;
|
12408
|
+
columnDefault = ` DEFAULT ${statement.newDefaultValue}`;
|
12409
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12410
|
+
break;
|
12411
|
+
case "alter_table_alter_column_drop_default":
|
12412
|
+
columnType = ` ${statement.newDataType}`;
|
12413
|
+
columnDefault = "";
|
12414
|
+
columnNotNull = statement.columnNotNull ? ` NOT NULL` : "";
|
12415
|
+
break;
|
12416
|
+
}
|
12417
|
+
columnDefault = columnDefault instanceof Date ? columnDefault.toISOString() : columnDefault;
|
12418
|
+
sqlStatements.push(
|
12419
|
+
`ALTER TABLE \`${tableName}\` ALTER COLUMN "${columnName}" TO "${columnName}"${columnType}${columnNotNull}${columnDefault};`
|
12420
|
+
);
|
12421
|
+
for (const index4 of indexes) {
|
12422
|
+
const indexPart = index4.isUnique ? "UNIQUE INDEX" : "INDEX";
|
12423
|
+
const whereStatement = index4.where ? ` WHERE ${index4.where}` : "";
|
12424
|
+
const uniqueString = index4.columns.map((it) => `\`${it}\``).join(",");
|
12425
|
+
const tableName2 = index4.tableName;
|
12426
|
+
sqlStatements.push(
|
12427
|
+
`CREATE ${indexPart} \`${index4.name}\` ON \`${tableName2}\` (${uniqueString})${whereStatement};`
|
12428
|
+
);
|
12429
|
+
}
|
12430
|
+
return sqlStatements;
|
12431
|
+
}
|
12432
|
+
};
|
12408
12433
|
MySqlModifyColumn = class extends Convertor {
|
12409
12434
|
can(statement, dialect7) {
|
12410
12435
|
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";
|
@@ -12542,21 +12567,6 @@ var init_sqlgenerator = __esm({
|
|
12542
12567
|
return `ALTER TABLE \`${tableName}\` MODIFY COLUMN \`${columnName}\`${columnType}${columnAutoincrement}${columnGenerated}${columnNotNull}${columnDefault}${columnOnUpdate};`;
|
12543
12568
|
}
|
12544
12569
|
};
|
12545
|
-
SqliteAlterTableAlterColumnDropDefaultConvertor = class extends Convertor {
|
12546
|
-
can(statement, dialect7) {
|
12547
|
-
return statement.type === "alter_table_alter_column_drop_default" && dialect7 === "sqlite";
|
12548
|
-
}
|
12549
|
-
convert(statement) {
|
12550
|
-
return `/*
|
12551
|
-
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
|
12552
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12553
|
-
https://www.sqlite.org/lang_altertable.html
|
12554
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12555
|
-
|
12556
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12557
|
-
*/`;
|
12558
|
-
}
|
12559
|
-
};
|
12560
12570
|
PgAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
12561
12571
|
can(statement, dialect7) {
|
12562
12572
|
return statement.type === "create_composite_pk" && dialect7 === "postgresql";
|
@@ -12621,85 +12631,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12621
12631
|
return `ALTER TABLE \`${statement.tableName}\` DROP PRIMARY KEY, ADD PRIMARY KEY(\`${newColumns.join("`,`")}\`);`;
|
12622
12632
|
}
|
12623
12633
|
};
|
12624
|
-
SqliteAlterTableCreateCompositePrimaryKeyConvertor = class extends Convertor {
|
12625
|
-
can(statement, dialect7) {
|
12626
|
-
return statement.type === "create_composite_pk" && dialect7 === "sqlite";
|
12627
|
-
}
|
12628
|
-
convert(statement) {
|
12629
|
-
let msg = "/*\n";
|
12630
|
-
msg += `You're trying to add PRIMARY KEY(${statement.data}) to '${statement.tableName}' table
|
12631
|
-
`;
|
12632
|
-
msg += "SQLite does not support adding primary key to an already created table\n";
|
12633
|
-
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12634
|
-
msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
|
12635
|
-
msg += " - migrate old data from one table to another\n";
|
12636
|
-
msg += " - delete old_table in schema, generate sql\n\n";
|
12637
|
-
msg += "or create manual migration like below:\n\n";
|
12638
|
-
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12639
|
-
msg += "CREATE TABLE table_name (\n";
|
12640
|
-
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12641
|
-
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12642
|
-
msg += " ...\n";
|
12643
|
-
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12644
|
-
msg += " );\n";
|
12645
|
-
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12646
|
-
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12647
|
-
msg += "*/\n";
|
12648
|
-
return msg;
|
12649
|
-
}
|
12650
|
-
};
|
12651
|
-
SqliteAlterTableDeleteCompositePrimaryKeyConvertor = class extends Convertor {
|
12652
|
-
can(statement, dialect7) {
|
12653
|
-
return statement.type === "delete_composite_pk" && dialect7 === "sqlite";
|
12654
|
-
}
|
12655
|
-
convert(statement) {
|
12656
|
-
let msg = "/*\n";
|
12657
|
-
msg += `You're trying to delete PRIMARY KEY(${statement.data}) from '${statement.tableName}' table
|
12658
|
-
`;
|
12659
|
-
msg += "SQLite does not supportprimary key deletion from existing table\n";
|
12660
|
-
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12661
|
-
msg += " - create new mirror table table without pk, rename current table to old_table, generate SQL\n";
|
12662
|
-
msg += " - migrate old data from one table to another\n";
|
12663
|
-
msg += " - delete old_table in schema, generate sql\n\n";
|
12664
|
-
msg += "or create manual migration like below:\n\n";
|
12665
|
-
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12666
|
-
msg += "CREATE TABLE table_name (\n";
|
12667
|
-
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12668
|
-
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12669
|
-
msg += " ...\n";
|
12670
|
-
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12671
|
-
msg += " );\n";
|
12672
|
-
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12673
|
-
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12674
|
-
msg += "*/\n";
|
12675
|
-
return msg;
|
12676
|
-
}
|
12677
|
-
};
|
12678
|
-
SqliteAlterTableAlterCompositePrimaryKeyConvertor = class extends Convertor {
|
12679
|
-
can(statement, dialect7) {
|
12680
|
-
return statement.type === "alter_composite_pk" && dialect7 === "sqlite";
|
12681
|
-
}
|
12682
|
-
convert(statement) {
|
12683
|
-
let msg = "/*\n";
|
12684
|
-
msg += "SQLite does not support altering primary key\n";
|
12685
|
-
msg += "You can do it in 3 steps with drizzle orm:\n";
|
12686
|
-
msg += " - create new mirror table with needed pk, rename current table to old_table, generate SQL\n";
|
12687
|
-
msg += " - migrate old data from one table to another\n";
|
12688
|
-
msg += " - delete old_table in schema, generate sql\n\n";
|
12689
|
-
msg += "or create manual migration like below:\n\n";
|
12690
|
-
msg += "ALTER TABLE table_name RENAME TO old_table;\n";
|
12691
|
-
msg += "CREATE TABLE table_name (\n";
|
12692
|
-
msg += " column1 datatype [ NULL | NOT NULL ],\n";
|
12693
|
-
msg += " column2 datatype [ NULL | NOT NULL ],\n";
|
12694
|
-
msg += " ...\n";
|
12695
|
-
msg += " PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)\n";
|
12696
|
-
msg += " );\n";
|
12697
|
-
msg += "INSERT INTO table_name SELECT * FROM old_table;\n\n";
|
12698
|
-
msg += "Due to that we don't generate migration automatically and it has to be done manually\n";
|
12699
|
-
msg += "*/\n";
|
12700
|
-
return msg;
|
12701
|
-
}
|
12702
|
-
};
|
12703
12634
|
PgAlterTableAlterColumnSetPrimaryKeyConvertor = class extends Convertor {
|
12704
12635
|
can(statement, dialect7) {
|
12705
12636
|
return statement.type === "alter_table_alter_column_set_pk" && dialect7 === "postgresql";
|
@@ -12744,51 +12675,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12744
12675
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" SET NOT NULL;`;
|
12745
12676
|
}
|
12746
12677
|
};
|
12747
|
-
SqliteAlterTableAlterColumnSetNotNullConvertor = class extends Convertor {
|
12748
|
-
can(statement, dialect7) {
|
12749
|
-
return statement.type === "alter_table_alter_column_set_notnull" && dialect7 === "sqlite";
|
12750
|
-
}
|
12751
|
-
convert(statement) {
|
12752
|
-
return `/*
|
12753
|
-
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
|
12754
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12755
|
-
https://www.sqlite.org/lang_altertable.html
|
12756
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12757
|
-
|
12758
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12759
|
-
*/`;
|
12760
|
-
}
|
12761
|
-
};
|
12762
|
-
SqliteAlterTableAlterColumnSetAutoincrementConvertor = class extends Convertor {
|
12763
|
-
can(statement, dialect7) {
|
12764
|
-
return statement.type === "alter_table_alter_column_set_autoincrement" && dialect7 === "sqlite";
|
12765
|
-
}
|
12766
|
-
convert(statement) {
|
12767
|
-
return `/*
|
12768
|
-
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
|
12769
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12770
|
-
https://www.sqlite.org/lang_altertable.html
|
12771
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12772
|
-
|
12773
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12774
|
-
*/`;
|
12775
|
-
}
|
12776
|
-
};
|
12777
|
-
SqliteAlterTableAlterColumnDropAutoincrementConvertor = class extends Convertor {
|
12778
|
-
can(statement, dialect7) {
|
12779
|
-
return statement.type === "alter_table_alter_column_drop_autoincrement" && dialect7 === "sqlite";
|
12780
|
-
}
|
12781
|
-
convert(statement) {
|
12782
|
-
return `/*
|
12783
|
-
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
|
12784
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12785
|
-
https://www.sqlite.org/lang_altertable.html
|
12786
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12787
|
-
|
12788
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12789
|
-
*/`;
|
12790
|
-
}
|
12791
|
-
};
|
12792
12678
|
PgAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12793
12679
|
can(statement, dialect7) {
|
12794
12680
|
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "postgresql";
|
@@ -12799,21 +12685,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12799
12685
|
return `ALTER TABLE ${tableNameWithSchema} ALTER COLUMN "${columnName}" DROP NOT NULL;`;
|
12800
12686
|
}
|
12801
12687
|
};
|
12802
|
-
SqliteAlterTableAlterColumnDropNotNullConvertor = class extends Convertor {
|
12803
|
-
can(statement, dialect7) {
|
12804
|
-
return statement.type === "alter_table_alter_column_drop_notnull" && dialect7 === "sqlite";
|
12805
|
-
}
|
12806
|
-
convert(statement) {
|
12807
|
-
return `/*
|
12808
|
-
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
|
12809
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12810
|
-
https://www.sqlite.org/lang_altertable.html
|
12811
|
-
https://stackoverflow.com/questions/2083543/modify-a-columns-type-in-sqlite3
|
12812
|
-
|
12813
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12814
|
-
*/`;
|
12815
|
-
}
|
12816
|
-
};
|
12817
12688
|
PgCreateForeignKeyConvertor = class extends Convertor {
|
12818
12689
|
can(statement, dialect7) {
|
12819
12690
|
return statement.type === "create_reference" && dialect7 === "postgresql";
|
@@ -12844,18 +12715,21 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12844
12715
|
return sql2;
|
12845
12716
|
}
|
12846
12717
|
};
|
12847
|
-
|
12718
|
+
LibSQLCreateForeignKeyConvertor = class extends Convertor {
|
12848
12719
|
can(statement, dialect7) {
|
12849
|
-
return statement.type === "create_reference" && dialect7 === "
|
12720
|
+
return statement.type === "create_reference" && dialect7 === "turso";
|
12850
12721
|
}
|
12851
|
-
convert(statement) {
|
12852
|
-
|
12853
|
-
|
12854
|
-
|
12855
|
-
|
12856
|
-
|
12857
|
-
|
12858
|
-
|
12722
|
+
convert(statement, json2, action) {
|
12723
|
+
const { columnsFrom, columnsTo, tableFrom, onDelete, onUpdate, tableTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
12724
|
+
const { columnDefault, columnNotNull, columnType } = statement;
|
12725
|
+
const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
|
12726
|
+
const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
|
12727
|
+
const columnsDefaultValue = columnDefault ? ` DEFAULT ${columnDefault}` : "";
|
12728
|
+
const columnNotNullValue = columnNotNull ? ` NOT NULL` : "";
|
12729
|
+
const columnTypeValue = columnType ? ` ${columnType}` : "";
|
12730
|
+
const columnFrom = columnsFrom[0];
|
12731
|
+
const columnTo = columnsTo[0];
|
12732
|
+
return `ALTER TABLE \`${tableFrom}\` ALTER COLUMN "${columnFrom}" TO "${columnFrom}"${columnTypeValue}${columnNotNullValue}${columnsDefaultValue} REFERENCES ${tableTo}(${columnTo})${onDeleteStatement}${onUpdateStatement};`;
|
12859
12733
|
}
|
12860
12734
|
};
|
12861
12735
|
MySqlCreateForeignKeyConvertor = class extends Convertor {
|
@@ -12904,20 +12778,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12904
12778
|
return sql2;
|
12905
12779
|
}
|
12906
12780
|
};
|
12907
|
-
SqliteAlterForeignKeyConvertor = class extends Convertor {
|
12908
|
-
can(statement, dialect7) {
|
12909
|
-
return statement.type === "alter_reference" && dialect7 === "sqlite";
|
12910
|
-
}
|
12911
|
-
convert(statement) {
|
12912
|
-
return `/*
|
12913
|
-
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
|
12914
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12915
|
-
https://www.sqlite.org/lang_altertable.html
|
12916
|
-
|
12917
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12918
|
-
*/`;
|
12919
|
-
}
|
12920
|
-
};
|
12921
12781
|
PgDeleteForeignKeyConvertor = class extends Convertor {
|
12922
12782
|
can(statement, dialect7) {
|
12923
12783
|
return statement.type === "delete_reference" && dialect7 === "postgresql";
|
@@ -12930,20 +12790,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
12930
12790
|
`;
|
12931
12791
|
}
|
12932
12792
|
};
|
12933
|
-
SqliteDeleteForeignKeyConvertor = class extends Convertor {
|
12934
|
-
can(statement, dialect7) {
|
12935
|
-
return statement.type === "delete_reference" && dialect7 === "sqlite";
|
12936
|
-
}
|
12937
|
-
convert(statement) {
|
12938
|
-
return `/*
|
12939
|
-
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
|
12940
|
-
Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php
|
12941
|
-
https://www.sqlite.org/lang_altertable.html
|
12942
|
-
|
12943
|
-
Due to that we don't generate migration automatically and it has to be done manually
|
12944
|
-
*/`;
|
12945
|
-
}
|
12946
|
-
};
|
12947
12793
|
MySqlDeleteForeignKeyConvertor = class extends Convertor {
|
12948
12794
|
can(statement, dialect7) {
|
12949
12795
|
return statement.type === "delete_reference" && dialect7 === "mysql";
|
@@ -13004,7 +12850,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13004
12850
|
};
|
13005
12851
|
CreateSqliteIndexConvertor = class extends Convertor {
|
13006
12852
|
can(statement, dialect7) {
|
13007
|
-
return statement.type === "create_index" && dialect7 === "sqlite";
|
12853
|
+
return statement.type === "create_index" && (dialect7 === "sqlite" || dialect7 === "turso");
|
13008
12854
|
}
|
13009
12855
|
convert(statement) {
|
13010
12856
|
const { name: name2, columns, isUnique, where } = SQLiteSquasher.unsquashIdx(
|
@@ -13091,7 +12937,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13091
12937
|
};
|
13092
12938
|
SqliteDropIndexConvertor = class extends Convertor {
|
13093
12939
|
can(statement, dialect7) {
|
13094
|
-
return statement.type === "drop_index" && dialect7 === "sqlite";
|
12940
|
+
return statement.type === "drop_index" && (dialect7 === "sqlite" || dialect7 === "turso");
|
13095
12941
|
}
|
13096
12942
|
convert(statement) {
|
13097
12943
|
const { name: name2 } = PgSquasher.unsquashIdx(statement.data);
|
@@ -13107,10 +12953,96 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13107
12953
|
return `DROP INDEX \`${name2}\` ON \`${statement.tableName}\`;`;
|
13108
12954
|
}
|
13109
12955
|
};
|
12956
|
+
SQLiteRecreateTableConvertor = class extends Convertor {
|
12957
|
+
can(statement, dialect7) {
|
12958
|
+
return statement.type === "recreate_table" && dialect7 === "sqlite";
|
12959
|
+
}
|
12960
|
+
convert(statement) {
|
12961
|
+
const { tableName, columns, compositePKs, referenceData } = statement;
|
12962
|
+
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
12963
|
+
const newTableName = `__new_${tableName}`;
|
12964
|
+
const sqlStatements = [];
|
12965
|
+
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
12966
|
+
sqlStatements.push(
|
12967
|
+
new SQLiteCreateTableConvertor().convert({
|
12968
|
+
type: "sqlite_create_table",
|
12969
|
+
tableName: newTableName,
|
12970
|
+
columns,
|
12971
|
+
referenceData,
|
12972
|
+
compositePKs
|
12973
|
+
})
|
12974
|
+
);
|
12975
|
+
sqlStatements.push(
|
12976
|
+
`INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
|
12977
|
+
);
|
12978
|
+
sqlStatements.push(
|
12979
|
+
new SQLiteDropTableConvertor().convert({
|
12980
|
+
type: "drop_table",
|
12981
|
+
tableName,
|
12982
|
+
schema: ""
|
12983
|
+
})
|
12984
|
+
);
|
12985
|
+
sqlStatements.push(
|
12986
|
+
new SqliteRenameTableConvertor().convert({
|
12987
|
+
fromSchema: "",
|
12988
|
+
tableNameFrom: newTableName,
|
12989
|
+
tableNameTo: tableName,
|
12990
|
+
toSchema: "",
|
12991
|
+
type: "rename_table"
|
12992
|
+
})
|
12993
|
+
);
|
12994
|
+
sqlStatements.push(`PRAGMA foreign_keys=ON;`);
|
12995
|
+
return sqlStatements;
|
12996
|
+
}
|
12997
|
+
};
|
12998
|
+
LibSQLRecreateTableConvertor = class extends Convertor {
|
12999
|
+
can(statement, dialect7) {
|
13000
|
+
return statement.type === "recreate_table" && dialect7 === "turso";
|
13001
|
+
}
|
13002
|
+
convert(statement) {
|
13003
|
+
const { tableName, columns, compositePKs, referenceData } = statement;
|
13004
|
+
const columnNames = columns.map((it) => `"${it.name}"`).join(", ");
|
13005
|
+
const newTableName = `__new_${tableName}`;
|
13006
|
+
const sqlStatements = [];
|
13007
|
+
sqlStatements.push(`PRAGMA foreign_keys=OFF;`);
|
13008
|
+
sqlStatements.push(
|
13009
|
+
new SQLiteCreateTableConvertor().convert({
|
13010
|
+
type: "sqlite_create_table",
|
13011
|
+
tableName: newTableName,
|
13012
|
+
columns,
|
13013
|
+
referenceData,
|
13014
|
+
compositePKs
|
13015
|
+
})
|
13016
|
+
);
|
13017
|
+
sqlStatements.push(
|
13018
|
+
`INSERT INTO \`${newTableName}\`(${columnNames}) SELECT ${columnNames} FROM \`${tableName}\`;`
|
13019
|
+
);
|
13020
|
+
sqlStatements.push(
|
13021
|
+
new SQLiteDropTableConvertor().convert({
|
13022
|
+
type: "drop_table",
|
13023
|
+
tableName,
|
13024
|
+
schema: ""
|
13025
|
+
})
|
13026
|
+
);
|
13027
|
+
sqlStatements.push(
|
13028
|
+
new SqliteRenameTableConvertor().convert({
|
13029
|
+
fromSchema: "",
|
13030
|
+
tableNameFrom: newTableName,
|
13031
|
+
tableNameTo: tableName,
|
13032
|
+
toSchema: "",
|
13033
|
+
type: "rename_table"
|
13034
|
+
})
|
13035
|
+
);
|
13036
|
+
sqlStatements.push(`PRAGMA foreign_keys=ON;`);
|
13037
|
+
return sqlStatements;
|
13038
|
+
}
|
13039
|
+
};
|
13110
13040
|
convertors = [];
|
13111
13041
|
convertors.push(new PgCreateTableConvertor());
|
13112
13042
|
convertors.push(new MySqlCreateTableConvertor());
|
13113
13043
|
convertors.push(new SQLiteCreateTableConvertor());
|
13044
|
+
convertors.push(new SQLiteRecreateTableConvertor());
|
13045
|
+
convertors.push(new LibSQLRecreateTableConvertor());
|
13114
13046
|
convertors.push(new CreateTypeEnumConvertor());
|
13115
13047
|
convertors.push(new CreatePgSequenceConvertor());
|
13116
13048
|
convertors.push(new DropPgSequenceConvertor());
|
@@ -13158,6 +13090,7 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13158
13090
|
convertors.push(new SqliteAlterTableAlterColumnAlterGeneratedConvertor());
|
13159
13091
|
convertors.push(new SqliteAlterTableAlterColumnSetExpressionConvertor());
|
13160
13092
|
convertors.push(new MySqlModifyColumn());
|
13093
|
+
convertors.push(new LibSQLModifyColumn());
|
13161
13094
|
convertors.push(new PgCreateForeignKeyConvertor());
|
13162
13095
|
convertors.push(new MySqlCreateForeignKeyConvertor());
|
13163
13096
|
convertors.push(new PgAlterForeignKeyConvertor());
|
@@ -13169,24 +13102,10 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13169
13102
|
convertors.push(new PgAlterTableSetSchemaConvertor());
|
13170
13103
|
convertors.push(new PgAlterTableSetNewSchemaConvertor());
|
13171
13104
|
convertors.push(new PgAlterTableRemoveFromSchemaConvertor());
|
13172
|
-
convertors.push(new
|
13173
|
-
convertors.push(new SqliteAlterForeignKeyConvertor());
|
13174
|
-
convertors.push(new SqliteDeleteForeignKeyConvertor());
|
13175
|
-
convertors.push(new SqliteCreateForeignKeyConvertor());
|
13176
|
-
convertors.push(new SQLiteAlterTableAddUniqueConstraintConvertor());
|
13177
|
-
convertors.push(new SQLiteAlterTableDropUniqueConstraintConvertor());
|
13105
|
+
convertors.push(new LibSQLCreateForeignKeyConvertor());
|
13178
13106
|
convertors.push(new PgAlterTableAlterColumnDropGenerated());
|
13179
13107
|
convertors.push(new PgAlterTableAlterColumnSetGenerated());
|
13180
13108
|
convertors.push(new PgAlterTableAlterColumnAlterGenerated());
|
13181
|
-
convertors.push(new SqliteAlterTableAlterColumnSetNotNullConvertor());
|
13182
|
-
convertors.push(new SqliteAlterTableAlterColumnDropNotNullConvertor());
|
13183
|
-
convertors.push(new SqliteAlterTableAlterColumnSetDefaultConvertor());
|
13184
|
-
convertors.push(new SqliteAlterTableAlterColumnDropDefaultConvertor());
|
13185
|
-
convertors.push(new SqliteAlterTableAlterColumnSetAutoincrementConvertor());
|
13186
|
-
convertors.push(new SqliteAlterTableAlterColumnDropAutoincrementConvertor());
|
13187
|
-
convertors.push(new SqliteAlterTableCreateCompositePrimaryKeyConvertor());
|
13188
|
-
convertors.push(new SqliteAlterTableDeleteCompositePrimaryKeyConvertor());
|
13189
|
-
convertors.push(new SqliteAlterTableAlterCompositePrimaryKeyConvertor());
|
13190
13109
|
convertors.push(new PgAlterTableCreateCompositePrimaryKeyConvertor());
|
13191
13110
|
convertors.push(new PgAlterTableDeleteCompositePrimaryKeyConvertor());
|
13192
13111
|
convertors.push(new PgAlterTableAlterCompositePrimaryKeyConvertor());
|
@@ -13195,19 +13114,6 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
|
|
13195
13114
|
convertors.push(new MySqlAlterTableCreateCompositePrimaryKeyConvertor());
|
13196
13115
|
convertors.push(new MySqlAlterTableAddPk());
|
13197
13116
|
convertors.push(new MySqlAlterTableAlterCompositePrimaryKeyConvertor());
|
13198
|
-
fromJson = (statements, dialect7) => {
|
13199
|
-
const result = statements.flatMap((statement) => {
|
13200
|
-
const filtered = convertors.filter((it) => {
|
13201
|
-
return it.can(statement, dialect7);
|
13202
|
-
});
|
13203
|
-
const convertor = filtered.length === 1 ? filtered[0] : void 0;
|
13204
|
-
if (!convertor) {
|
13205
|
-
return "";
|
13206
|
-
}
|
13207
|
-
return convertor.convert(statement);
|
13208
|
-
}).filter((it) => it !== "");
|
13209
|
-
return result;
|
13210
|
-
};
|
13211
13117
|
https: `
|
13212
13118
|
create table users (
|
13213
13119
|
id int,
|
@@ -13234,12 +13140,248 @@ drop type __venum;
|
|
13234
13140
|
}
|
13235
13141
|
});
|
13236
13142
|
|
13143
|
+
// src/cli/commands/sqlitePushUtils.ts
|
13144
|
+
var _moveDataStatements, getOldTableName, getNewTableName, logSuggestionsAndReturn;
|
13145
|
+
var init_sqlitePushUtils = __esm({
|
13146
|
+
"src/cli/commands/sqlitePushUtils.ts"() {
|
13147
|
+
"use strict";
|
13148
|
+
init_source();
|
13149
|
+
init_sqliteSchema();
|
13150
|
+
init_sqlgenerator();
|
13151
|
+
init_utils();
|
13152
|
+
_moveDataStatements = (tableName, json, dataLoss = false) => {
|
13153
|
+
const statements = [];
|
13154
|
+
const newTableName = `__new_${tableName}`;
|
13155
|
+
const tableColumns = Object.values(json.tables[tableName].columns);
|
13156
|
+
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
13157
|
+
const compositePKs = Object.values(
|
13158
|
+
json.tables[tableName].compositePrimaryKeys
|
13159
|
+
).map((it) => SQLiteSquasher.unsquashPK(it));
|
13160
|
+
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
13161
|
+
statements.push(
|
13162
|
+
new SQLiteCreateTableConvertor().convert({
|
13163
|
+
type: "sqlite_create_table",
|
13164
|
+
tableName: newTableName,
|
13165
|
+
columns: tableColumns,
|
13166
|
+
referenceData: fks,
|
13167
|
+
compositePKs
|
13168
|
+
})
|
13169
|
+
);
|
13170
|
+
if (!dataLoss) {
|
13171
|
+
const columns = Object.keys(json.tables[tableName].columns).map(
|
13172
|
+
(c) => `"${c}"`
|
13173
|
+
);
|
13174
|
+
statements.push(
|
13175
|
+
`INSERT INTO \`${newTableName}\`(${columns.join(
|
13176
|
+
", "
|
13177
|
+
)}) SELECT ${columns.join(", ")} FROM \`${tableName}\`;`
|
13178
|
+
);
|
13179
|
+
}
|
13180
|
+
statements.push(
|
13181
|
+
new SQLiteDropTableConvertor().convert({
|
13182
|
+
type: "drop_table",
|
13183
|
+
tableName,
|
13184
|
+
schema: ""
|
13185
|
+
})
|
13186
|
+
);
|
13187
|
+
statements.push(
|
13188
|
+
new SqliteRenameTableConvertor().convert({
|
13189
|
+
fromSchema: "",
|
13190
|
+
tableNameFrom: newTableName,
|
13191
|
+
tableNameTo: tableName,
|
13192
|
+
toSchema: "",
|
13193
|
+
type: "rename_table"
|
13194
|
+
})
|
13195
|
+
);
|
13196
|
+
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
13197
|
+
statements.push(
|
13198
|
+
new CreateSqliteIndexConvertor().convert({
|
13199
|
+
type: "create_index",
|
13200
|
+
tableName,
|
13201
|
+
schema: "",
|
13202
|
+
data: idx
|
13203
|
+
})
|
13204
|
+
);
|
13205
|
+
}
|
13206
|
+
return statements;
|
13207
|
+
};
|
13208
|
+
getOldTableName = (tableName, meta) => {
|
13209
|
+
for (const key of Object.keys(meta.tables)) {
|
13210
|
+
const value = meta.tables[key];
|
13211
|
+
if (`"${tableName}"` === value) {
|
13212
|
+
return key.substring(1, key.length - 1);
|
13213
|
+
}
|
13214
|
+
}
|
13215
|
+
return tableName;
|
13216
|
+
};
|
13217
|
+
getNewTableName = (tableName, meta) => {
|
13218
|
+
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
13219
|
+
return meta.tables[`"${tableName}"`].substring(
|
13220
|
+
1,
|
13221
|
+
meta.tables[`"${tableName}"`].length - 1
|
13222
|
+
);
|
13223
|
+
}
|
13224
|
+
return tableName;
|
13225
|
+
};
|
13226
|
+
logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
13227
|
+
let shouldAskForApprove = false;
|
13228
|
+
const statementsToExecute = [];
|
13229
|
+
const infoToPrint = [];
|
13230
|
+
const tablesToRemove = [];
|
13231
|
+
const columnsToRemove = [];
|
13232
|
+
const schemasToRemove = [];
|
13233
|
+
const tablesToTruncate = [];
|
13234
|
+
for (const statement of statements) {
|
13235
|
+
if (statement.type === "drop_table") {
|
13236
|
+
const res = await connection.query(
|
13237
|
+
`select count(*) as count from \`${statement.tableName}\``
|
13238
|
+
);
|
13239
|
+
const count2 = Number(res[0].count);
|
13240
|
+
if (count2 > 0) {
|
13241
|
+
infoToPrint.push(
|
13242
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13243
|
+
statement.tableName
|
13244
|
+
)} table with ${count2} items`
|
13245
|
+
);
|
13246
|
+
tablesToRemove.push(statement.tableName);
|
13247
|
+
shouldAskForApprove = true;
|
13248
|
+
}
|
13249
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13250
|
+
statementsToExecute.push(
|
13251
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13252
|
+
);
|
13253
|
+
} else if (statement.type === "alter_table_drop_column") {
|
13254
|
+
const tableName = statement.tableName;
|
13255
|
+
const columnName = statement.columnName;
|
13256
|
+
const res = await connection.query(
|
13257
|
+
`select count(\`${tableName}\`.\`${columnName}\`) as count from \`${tableName}\``
|
13258
|
+
);
|
13259
|
+
const count2 = Number(res[0].count);
|
13260
|
+
if (count2 > 0) {
|
13261
|
+
infoToPrint.push(
|
13262
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13263
|
+
columnName
|
13264
|
+
)} column in ${tableName} table with ${count2} items`
|
13265
|
+
);
|
13266
|
+
columnsToRemove.push(`${tableName}_${statement.columnName}`);
|
13267
|
+
shouldAskForApprove = true;
|
13268
|
+
}
|
13269
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13270
|
+
statementsToExecute.push(
|
13271
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13272
|
+
);
|
13273
|
+
} else if (statement.type === "sqlite_alter_table_add_column" && (statement.column.notNull && !statement.column.default)) {
|
13274
|
+
const tableName = statement.tableName;
|
13275
|
+
const columnName = statement.column.name;
|
13276
|
+
const res = await connection.query(
|
13277
|
+
`select count(*) as count from \`${tableName}\``
|
13278
|
+
);
|
13279
|
+
const count2 = Number(res[0].count);
|
13280
|
+
if (count2 > 0) {
|
13281
|
+
infoToPrint.push(
|
13282
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
13283
|
+
columnName
|
13284
|
+
)} column without default value, which contains ${count2} items`
|
13285
|
+
);
|
13286
|
+
tablesToTruncate.push(tableName);
|
13287
|
+
statementsToExecute.push(`delete from ${tableName};`);
|
13288
|
+
shouldAskForApprove = true;
|
13289
|
+
}
|
13290
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13291
|
+
statementsToExecute.push(
|
13292
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13293
|
+
);
|
13294
|
+
} else if (statement.type === "recreate_table") {
|
13295
|
+
const tableName = statement.tableName;
|
13296
|
+
const oldTableName = getOldTableName(tableName, meta);
|
13297
|
+
let dataLoss = false;
|
13298
|
+
const prevColumnNames = Object.keys(json1.tables[oldTableName].columns);
|
13299
|
+
const currentColumnNames = Object.keys(json2.tables[tableName].columns);
|
13300
|
+
const { removedColumns, addedColumns } = findAddedAndRemoved(
|
13301
|
+
prevColumnNames,
|
13302
|
+
currentColumnNames
|
13303
|
+
);
|
13304
|
+
if (removedColumns.length) {
|
13305
|
+
for (const removedColumn of removedColumns) {
|
13306
|
+
const res = await connection.query(
|
13307
|
+
`select count(\`${tableName}\`.\`${removedColumn}\`) as count from \`${tableName}\``
|
13308
|
+
);
|
13309
|
+
const count2 = Number(res[0].count);
|
13310
|
+
if (count2 > 0) {
|
13311
|
+
infoToPrint.push(
|
13312
|
+
`\xB7 You're about to delete ${source_default.underline(
|
13313
|
+
removedColumn
|
13314
|
+
)} column in ${tableName} table with ${count2} items`
|
13315
|
+
);
|
13316
|
+
columnsToRemove.push(removedColumn);
|
13317
|
+
shouldAskForApprove = true;
|
13318
|
+
}
|
13319
|
+
}
|
13320
|
+
}
|
13321
|
+
if (addedColumns.length) {
|
13322
|
+
for (const addedColumn of addedColumns) {
|
13323
|
+
const [res] = await connection.query(
|
13324
|
+
`select count(*) as count from \`${tableName}\``
|
13325
|
+
);
|
13326
|
+
const columnConf = json2.tables[tableName].columns[addedColumn];
|
13327
|
+
const count2 = Number(res.count);
|
13328
|
+
if (count2 > 0 && columnConf.notNull && !columnConf.default) {
|
13329
|
+
dataLoss = true;
|
13330
|
+
infoToPrint.push(
|
13331
|
+
`\xB7 You're about to add not-null ${source_default.underline(
|
13332
|
+
addedColumn
|
13333
|
+
)} column without default value to table, which contains ${count2} items`
|
13334
|
+
);
|
13335
|
+
shouldAskForApprove = true;
|
13336
|
+
tablesToTruncate.push(tableName);
|
13337
|
+
statementsToExecute.push(`DELETE FROM \`${tableName}\`;`);
|
13338
|
+
}
|
13339
|
+
}
|
13340
|
+
}
|
13341
|
+
const tablesReferencingCurrent = [];
|
13342
|
+
for (const table4 of Object.values(json2.tables)) {
|
13343
|
+
const tablesRefs = Object.values(json2.tables[table4.name].foreignKeys).filter((t) => SQLiteSquasher.unsquashPushFK(t).tableTo === tableName).map((it) => SQLiteSquasher.unsquashPushFK(it).tableFrom);
|
13344
|
+
tablesReferencingCurrent.push(...tablesRefs);
|
13345
|
+
}
|
13346
|
+
if (!tablesReferencingCurrent.length) {
|
13347
|
+
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
13348
|
+
continue;
|
13349
|
+
}
|
13350
|
+
const [{ foreign_keys: pragmaState }] = await connection.query(`PRAGMA foreign_keys;`);
|
13351
|
+
if (pragmaState) {
|
13352
|
+
statementsToExecute.push(`PRAGMA foreign_keys=OFF;`);
|
13353
|
+
}
|
13354
|
+
statementsToExecute.push(..._moveDataStatements(tableName, json2, dataLoss));
|
13355
|
+
if (pragmaState) {
|
13356
|
+
statementsToExecute.push(`PRAGMA foreign_keys=ON;`);
|
13357
|
+
}
|
13358
|
+
} else {
|
13359
|
+
const fromJsonStatement = fromJson([statement], "sqlite", "push");
|
13360
|
+
statementsToExecute.push(
|
13361
|
+
...Array.isArray(fromJsonStatement) ? fromJsonStatement : [fromJsonStatement]
|
13362
|
+
);
|
13363
|
+
}
|
13364
|
+
}
|
13365
|
+
return {
|
13366
|
+
statementsToExecute,
|
13367
|
+
shouldAskForApprove,
|
13368
|
+
infoToPrint,
|
13369
|
+
columnsToRemove: [...new Set(columnsToRemove)],
|
13370
|
+
schemasToRemove: [...new Set(schemasToRemove)],
|
13371
|
+
tablesToTruncate: [...new Set(tablesToTruncate)],
|
13372
|
+
tablesToRemove: [...new Set(tablesToRemove)]
|
13373
|
+
};
|
13374
|
+
};
|
13375
|
+
}
|
13376
|
+
});
|
13377
|
+
|
13237
13378
|
// src/jsonStatements.ts
|
13238
|
-
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;
|
13379
|
+
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;
|
13239
13380
|
var init_jsonStatements = __esm({
|
13240
13381
|
"src/jsonStatements.ts"() {
|
13241
13382
|
"use strict";
|
13242
13383
|
init_source();
|
13384
|
+
init_sqlitePushUtils();
|
13243
13385
|
init_views();
|
13244
13386
|
init_mysqlSchema();
|
13245
13387
|
init_pgSchema();
|
@@ -14023,6 +14165,49 @@ var init_jsonStatements = __esm({
|
|
14023
14165
|
const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
|
14024
14166
|
const columnGenerated = json2.tables[tableName].columns[columnName].generated;
|
14025
14167
|
const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
|
14168
|
+
if (column4.autoincrement?.type === "added") {
|
14169
|
+
statements.push({
|
14170
|
+
type: "alter_table_alter_column_set_autoincrement",
|
14171
|
+
tableName,
|
14172
|
+
columnName,
|
14173
|
+
schema: schema4,
|
14174
|
+
newDataType: columnType,
|
14175
|
+
columnDefault,
|
14176
|
+
columnOnUpdate,
|
14177
|
+
columnNotNull,
|
14178
|
+
columnAutoIncrement,
|
14179
|
+
columnPk
|
14180
|
+
});
|
14181
|
+
}
|
14182
|
+
if (column4.autoincrement?.type === "changed") {
|
14183
|
+
const type = column4.autoincrement.new ? "alter_table_alter_column_set_autoincrement" : "alter_table_alter_column_drop_autoincrement";
|
14184
|
+
statements.push({
|
14185
|
+
type,
|
14186
|
+
tableName,
|
14187
|
+
columnName,
|
14188
|
+
schema: schema4,
|
14189
|
+
newDataType: columnType,
|
14190
|
+
columnDefault,
|
14191
|
+
columnOnUpdate,
|
14192
|
+
columnNotNull,
|
14193
|
+
columnAutoIncrement,
|
14194
|
+
columnPk
|
14195
|
+
});
|
14196
|
+
}
|
14197
|
+
if (column4.autoincrement?.type === "deleted") {
|
14198
|
+
statements.push({
|
14199
|
+
type: "alter_table_alter_column_drop_autoincrement",
|
14200
|
+
tableName,
|
14201
|
+
columnName,
|
14202
|
+
schema: schema4,
|
14203
|
+
newDataType: columnType,
|
14204
|
+
columnDefault,
|
14205
|
+
columnOnUpdate,
|
14206
|
+
columnNotNull,
|
14207
|
+
columnAutoIncrement,
|
14208
|
+
columnPk
|
14209
|
+
});
|
14210
|
+
}
|
14026
14211
|
if (typeof column4.name !== "string") {
|
14027
14212
|
statements.push({
|
14028
14213
|
type: "alter_table_rename_column",
|
@@ -14286,6 +14471,37 @@ var init_jsonStatements = __esm({
|
|
14286
14471
|
};
|
14287
14472
|
});
|
14288
14473
|
};
|
14474
|
+
prepareLibSQLCreateReferencesJson = (tableName, schema4, foreignKeys, json2, action) => {
|
14475
|
+
return Object.values(foreignKeys).map((fkData) => {
|
14476
|
+
const { columnsFrom, tableFrom, columnsTo } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14477
|
+
let isMulticolumn = false;
|
14478
|
+
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14479
|
+
isMulticolumn = true;
|
14480
|
+
return {
|
14481
|
+
type: "create_reference",
|
14482
|
+
tableName,
|
14483
|
+
data: fkData,
|
14484
|
+
schema: schema4,
|
14485
|
+
isMulticolumn
|
14486
|
+
};
|
14487
|
+
}
|
14488
|
+
const columnFrom = columnsFrom[0];
|
14489
|
+
const {
|
14490
|
+
notNull: columnNotNull,
|
14491
|
+
default: columnDefault,
|
14492
|
+
type: columnType
|
14493
|
+
} = json2.tables[tableFrom].columns[columnFrom];
|
14494
|
+
return {
|
14495
|
+
type: "create_reference",
|
14496
|
+
tableName,
|
14497
|
+
data: fkData,
|
14498
|
+
schema: schema4,
|
14499
|
+
columnNotNull,
|
14500
|
+
columnDefault,
|
14501
|
+
columnType
|
14502
|
+
};
|
14503
|
+
});
|
14504
|
+
};
|
14289
14505
|
prepareDropReferencesJson = (tableName, schema4, foreignKeys) => {
|
14290
14506
|
return Object.values(foreignKeys).map((fkData) => {
|
14291
14507
|
return {
|
@@ -14296,6 +14512,53 @@ var init_jsonStatements = __esm({
|
|
14296
14512
|
};
|
14297
14513
|
});
|
14298
14514
|
};
|
14515
|
+
prepareLibSQLDropReferencesJson = (tableName, schema4, foreignKeys, json2, meta, action) => {
|
14516
|
+
const statements = Object.values(foreignKeys).map((fkData) => {
|
14517
|
+
const { columnsFrom, tableFrom, columnsTo, name: name2, tableTo, onDelete, onUpdate } = action === "push" ? SQLiteSquasher.unsquashPushFK(fkData) : SQLiteSquasher.unsquashFK(fkData);
|
14518
|
+
const keys = Object.keys(json2.tables[tableName].columns);
|
14519
|
+
const filtered = columnsFrom.filter((it) => keys.includes(it));
|
14520
|
+
const fullDrop = filtered.length === 0;
|
14521
|
+
if (fullDrop) return;
|
14522
|
+
let isMulticolumn = false;
|
14523
|
+
if (columnsFrom.length > 1 || columnsTo.length > 1) {
|
14524
|
+
isMulticolumn = true;
|
14525
|
+
return {
|
14526
|
+
type: "delete_reference",
|
14527
|
+
tableName,
|
14528
|
+
data: fkData,
|
14529
|
+
schema: schema4,
|
14530
|
+
isMulticolumn
|
14531
|
+
};
|
14532
|
+
}
|
14533
|
+
const columnFrom = columnsFrom[0];
|
14534
|
+
const newTableName = getNewTableName(tableFrom, meta);
|
14535
|
+
const {
|
14536
|
+
notNull: columnNotNull,
|
14537
|
+
default: columnDefault,
|
14538
|
+
type: columnType
|
14539
|
+
} = json2.tables[newTableName].columns[columnFrom];
|
14540
|
+
const fkToSquash = {
|
14541
|
+
columnsFrom,
|
14542
|
+
columnsTo,
|
14543
|
+
name: name2,
|
14544
|
+
tableFrom: newTableName,
|
14545
|
+
tableTo,
|
14546
|
+
onDelete,
|
14547
|
+
onUpdate
|
14548
|
+
};
|
14549
|
+
const foreignKey = action === "push" ? SQLiteSquasher.squashPushFK(fkToSquash) : SQLiteSquasher.squashFK(fkToSquash);
|
14550
|
+
return {
|
14551
|
+
type: "delete_reference",
|
14552
|
+
tableName,
|
14553
|
+
data: foreignKey,
|
14554
|
+
schema: schema4,
|
14555
|
+
columnNotNull,
|
14556
|
+
columnDefault,
|
14557
|
+
columnType
|
14558
|
+
};
|
14559
|
+
});
|
14560
|
+
return statements.filter((it) => it);
|
14561
|
+
};
|
14299
14562
|
prepareAlterReferencesJson = (tableName, schema4, foreignKeys) => {
|
14300
14563
|
const stmts = [];
|
14301
14564
|
Object.values(foreignKeys).map((val) => {
|
@@ -14449,10 +14712,292 @@ var init_jsonStatements = __esm({
|
|
14449
14712
|
}
|
14450
14713
|
});
|
14451
14714
|
|
14715
|
+
// src/statementCombiner.ts
|
14716
|
+
var prepareLibSQLRecreateTable, prepareSQLiteRecreateTable, libSQLCombineStatements, sqliteCombineStatements;
|
14717
|
+
var init_statementCombiner = __esm({
|
14718
|
+
"src/statementCombiner.ts"() {
|
14719
|
+
"use strict";
|
14720
|
+
init_jsonStatements();
|
14721
|
+
init_sqliteSchema();
|
14722
|
+
prepareLibSQLRecreateTable = (table4, action) => {
|
14723
|
+
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14724
|
+
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14725
|
+
(it) => SQLiteSquasher.unsquashPK(it)
|
14726
|
+
);
|
14727
|
+
const references2 = Object.values(table4.foreignKeys);
|
14728
|
+
const fks = references2.map(
|
14729
|
+
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14730
|
+
);
|
14731
|
+
const statements = [
|
14732
|
+
{
|
14733
|
+
type: "recreate_table",
|
14734
|
+
tableName: name2,
|
14735
|
+
columns: Object.values(columns),
|
14736
|
+
compositePKs: composites,
|
14737
|
+
referenceData: fks,
|
14738
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
14739
|
+
}
|
14740
|
+
];
|
14741
|
+
if (Object.keys(indexes).length) {
|
14742
|
+
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14743
|
+
}
|
14744
|
+
return statements;
|
14745
|
+
};
|
14746
|
+
prepareSQLiteRecreateTable = (table4, action) => {
|
14747
|
+
const { name: name2, columns, uniqueConstraints, indexes } = table4;
|
14748
|
+
const composites = Object.values(table4.compositePrimaryKeys).map(
|
14749
|
+
(it) => SQLiteSquasher.unsquashPK(it)
|
14750
|
+
);
|
14751
|
+
const references2 = Object.values(table4.foreignKeys);
|
14752
|
+
const fks = references2.map(
|
14753
|
+
(it) => action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
|
14754
|
+
);
|
14755
|
+
const statements = [
|
14756
|
+
{
|
14757
|
+
type: "recreate_table",
|
14758
|
+
tableName: name2,
|
14759
|
+
columns: Object.values(columns),
|
14760
|
+
compositePKs: composites,
|
14761
|
+
referenceData: fks,
|
14762
|
+
uniqueConstraints: Object.values(uniqueConstraints)
|
14763
|
+
}
|
14764
|
+
];
|
14765
|
+
if (Object.keys(indexes).length) {
|
14766
|
+
statements.push(...prepareCreateIndexesJson(name2, "", indexes));
|
14767
|
+
}
|
14768
|
+
return statements;
|
14769
|
+
};
|
14770
|
+
libSQLCombineStatements = (statements, json2, action) => {
|
14771
|
+
const newStatements = {};
|
14772
|
+
for (const statement of statements) {
|
14773
|
+
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") {
|
14774
|
+
const tableName2 = statement.tableName;
|
14775
|
+
const statementsForTable2 = newStatements[tableName2];
|
14776
|
+
if (!statementsForTable2) {
|
14777
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14778
|
+
continue;
|
14779
|
+
}
|
14780
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14781
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14782
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14783
|
+
if (wasRename) {
|
14784
|
+
newStatements[tableName2].push(...preparedStatements);
|
14785
|
+
} else {
|
14786
|
+
newStatements[tableName2] = preparedStatements;
|
14787
|
+
}
|
14788
|
+
continue;
|
14789
|
+
}
|
14790
|
+
continue;
|
14791
|
+
}
|
14792
|
+
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") {
|
14793
|
+
const { tableName: tableName2, columnName, columnPk } = statement;
|
14794
|
+
const columnIsPartOfForeignKey = Object.values(
|
14795
|
+
json2.tables[tableName2].foreignKeys
|
14796
|
+
).some((it) => {
|
14797
|
+
const unsquashFk = action === "push" ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it);
|
14798
|
+
return unsquashFk.columnsFrom.includes(columnName);
|
14799
|
+
});
|
14800
|
+
const statementsForTable2 = newStatements[tableName2];
|
14801
|
+
if (!statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
|
14802
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14803
|
+
continue;
|
14804
|
+
}
|
14805
|
+
if (statementsForTable2 && (columnIsPartOfForeignKey || columnPk)) {
|
14806
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14807
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14808
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14809
|
+
if (wasRename) {
|
14810
|
+
newStatements[tableName2].push(...preparedStatements);
|
14811
|
+
} else {
|
14812
|
+
newStatements[tableName2] = preparedStatements;
|
14813
|
+
}
|
14814
|
+
}
|
14815
|
+
continue;
|
14816
|
+
}
|
14817
|
+
if (statementsForTable2 && !(columnIsPartOfForeignKey || columnPk)) {
|
14818
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14819
|
+
newStatements[tableName2].push(statement);
|
14820
|
+
}
|
14821
|
+
continue;
|
14822
|
+
}
|
14823
|
+
newStatements[tableName2] = [statement];
|
14824
|
+
continue;
|
14825
|
+
}
|
14826
|
+
if (statement.type === "create_reference") {
|
14827
|
+
const tableName2 = statement.tableName;
|
14828
|
+
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
14829
|
+
const statementsForTable2 = newStatements[tableName2];
|
14830
|
+
if (!statementsForTable2) {
|
14831
|
+
newStatements[tableName2] = statement.isMulticolumn ? prepareLibSQLRecreateTable(json2.tables[tableName2], action) : [statement];
|
14832
|
+
continue;
|
14833
|
+
}
|
14834
|
+
if (!statement.isMulticolumn && statementsForTable2.some(
|
14835
|
+
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
14836
|
+
)) {
|
14837
|
+
continue;
|
14838
|
+
}
|
14839
|
+
if (statement.isMulticolumn) {
|
14840
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14841
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14842
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14843
|
+
if (wasRename) {
|
14844
|
+
newStatements[tableName2].push(...preparedStatements);
|
14845
|
+
} else {
|
14846
|
+
newStatements[tableName2] = preparedStatements;
|
14847
|
+
}
|
14848
|
+
continue;
|
14849
|
+
}
|
14850
|
+
continue;
|
14851
|
+
}
|
14852
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14853
|
+
newStatements[tableName2].push(statement);
|
14854
|
+
}
|
14855
|
+
continue;
|
14856
|
+
}
|
14857
|
+
if (statement.type === "delete_reference") {
|
14858
|
+
const tableName2 = statement.tableName;
|
14859
|
+
const statementsForTable2 = newStatements[tableName2];
|
14860
|
+
if (!statementsForTable2) {
|
14861
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14862
|
+
continue;
|
14863
|
+
}
|
14864
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14865
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14866
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14867
|
+
if (wasRename) {
|
14868
|
+
newStatements[tableName2].push(...preparedStatements);
|
14869
|
+
} else {
|
14870
|
+
newStatements[tableName2] = preparedStatements;
|
14871
|
+
}
|
14872
|
+
continue;
|
14873
|
+
}
|
14874
|
+
continue;
|
14875
|
+
}
|
14876
|
+
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
14877
|
+
const tableName2 = statement.tableName;
|
14878
|
+
const statementsForTable2 = newStatements[tableName2];
|
14879
|
+
if (!statementsForTable2) {
|
14880
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14881
|
+
continue;
|
14882
|
+
}
|
14883
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14884
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14885
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14886
|
+
if (wasRename) {
|
14887
|
+
newStatements[tableName2].push(...preparedStatements);
|
14888
|
+
} else {
|
14889
|
+
newStatements[tableName2] = preparedStatements;
|
14890
|
+
}
|
14891
|
+
continue;
|
14892
|
+
}
|
14893
|
+
continue;
|
14894
|
+
}
|
14895
|
+
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
14896
|
+
const statementsForTable = newStatements[tableName];
|
14897
|
+
if (!statementsForTable) {
|
14898
|
+
newStatements[tableName] = [statement];
|
14899
|
+
continue;
|
14900
|
+
}
|
14901
|
+
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
14902
|
+
newStatements[tableName].push(statement);
|
14903
|
+
}
|
14904
|
+
}
|
14905
|
+
const combinedStatements = Object.values(newStatements).flat();
|
14906
|
+
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
14907
|
+
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
14908
|
+
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
14909
|
+
return [...renamedTables, ...renamedColumns, ...rest];
|
14910
|
+
};
|
14911
|
+
sqliteCombineStatements = (statements, json2, action) => {
|
14912
|
+
const newStatements = {};
|
14913
|
+
for (const statement of statements) {
|
14914
|
+
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") {
|
14915
|
+
const tableName2 = statement.tableName;
|
14916
|
+
const statementsForTable2 = newStatements[tableName2];
|
14917
|
+
if (!statementsForTable2) {
|
14918
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14919
|
+
continue;
|
14920
|
+
}
|
14921
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14922
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14923
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14924
|
+
if (wasRename) {
|
14925
|
+
newStatements[tableName2].push(...preparedStatements);
|
14926
|
+
} else {
|
14927
|
+
newStatements[tableName2] = preparedStatements;
|
14928
|
+
}
|
14929
|
+
continue;
|
14930
|
+
}
|
14931
|
+
continue;
|
14932
|
+
}
|
14933
|
+
if (statement.type === "sqlite_alter_table_add_column" && statement.column.primaryKey) {
|
14934
|
+
const tableName2 = statement.tableName;
|
14935
|
+
const statementsForTable2 = newStatements[tableName2];
|
14936
|
+
if (!statementsForTable2) {
|
14937
|
+
newStatements[tableName2] = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14938
|
+
continue;
|
14939
|
+
}
|
14940
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14941
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14942
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14943
|
+
if (wasRename) {
|
14944
|
+
newStatements[tableName2].push(...preparedStatements);
|
14945
|
+
} else {
|
14946
|
+
newStatements[tableName2] = preparedStatements;
|
14947
|
+
}
|
14948
|
+
continue;
|
14949
|
+
}
|
14950
|
+
continue;
|
14951
|
+
}
|
14952
|
+
if (statement.type === "create_reference") {
|
14953
|
+
const tableName2 = statement.tableName;
|
14954
|
+
const data = action === "push" ? SQLiteSquasher.unsquashPushFK(statement.data) : SQLiteSquasher.unsquashFK(statement.data);
|
14955
|
+
const statementsForTable2 = newStatements[tableName2];
|
14956
|
+
if (!statementsForTable2) {
|
14957
|
+
newStatements[tableName2] = prepareSQLiteRecreateTable(json2.tables[tableName2], action);
|
14958
|
+
continue;
|
14959
|
+
}
|
14960
|
+
if (data.columnsFrom.length === 1 && statementsForTable2.some(
|
14961
|
+
(st) => st.type === "sqlite_alter_table_add_column" && st.column.name === data.columnsFrom[0]
|
14962
|
+
)) {
|
14963
|
+
continue;
|
14964
|
+
}
|
14965
|
+
if (!statementsForTable2.some(({ type }) => type === "recreate_table")) {
|
14966
|
+
const wasRename = statementsForTable2.some(({ type }) => type === "rename_table");
|
14967
|
+
const preparedStatements = prepareLibSQLRecreateTable(json2.tables[tableName2], action);
|
14968
|
+
if (wasRename) {
|
14969
|
+
newStatements[tableName2].push(...preparedStatements);
|
14970
|
+
} else {
|
14971
|
+
newStatements[tableName2] = preparedStatements;
|
14972
|
+
}
|
14973
|
+
continue;
|
14974
|
+
}
|
14975
|
+
continue;
|
14976
|
+
}
|
14977
|
+
const tableName = statement.type === "rename_table" ? statement.tableNameTo : statement.tableName;
|
14978
|
+
const statementsForTable = newStatements[tableName];
|
14979
|
+
if (!statementsForTable) {
|
14980
|
+
newStatements[tableName] = [statement];
|
14981
|
+
continue;
|
14982
|
+
}
|
14983
|
+
if (!statementsForTable.some(({ type }) => type === "recreate_table")) {
|
14984
|
+
newStatements[tableName].push(statement);
|
14985
|
+
}
|
14986
|
+
}
|
14987
|
+
const combinedStatements = Object.values(newStatements).flat();
|
14988
|
+
const renamedTables = combinedStatements.filter((it) => it.type === "rename_table");
|
14989
|
+
const renamedColumns = combinedStatements.filter((it) => it.type === "alter_table_rename_column");
|
14990
|
+
const rest = combinedStatements.filter((it) => it.type !== "rename_table" && it.type !== "alter_table_rename_column");
|
14991
|
+
return [...renamedTables, ...renamedColumns, ...rest];
|
14992
|
+
};
|
14993
|
+
}
|
14994
|
+
});
|
14995
|
+
|
14452
14996
|
// src/snapshotsDiffer.ts
|
14453
14997
|
var snapshotsDiffer_exports = {};
|
14454
14998
|
__export(snapshotsDiffer_exports, {
|
14455
14999
|
alteredTableScheme: () => alteredTableScheme,
|
15000
|
+
applyLibSQLSnapshotsDiff: () => applyLibSQLSnapshotsDiff,
|
14456
15001
|
applyMysqlSnapshotsDiff: () => applyMysqlSnapshotsDiff,
|
14457
15002
|
applyPgSnapshotsDiff: () => applyPgSnapshotsDiff,
|
14458
15003
|
applySqliteSnapshotsDiff: () => applySqliteSnapshotsDiff,
|
@@ -14462,7 +15007,7 @@ __export(snapshotsDiffer_exports, {
|
|
14462
15007
|
makePatched: () => makePatched,
|
14463
15008
|
makeSelfOrPatched: () => makeSelfOrPatched
|
14464
15009
|
});
|
14465
|
-
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff;
|
15010
|
+
var makeChanged, makeSelfOrChanged, makePatched, makeSelfOrPatched, columnSchema, alteredColumnSchema, enumSchema2, changedEnumSchema, tableScheme, alteredTableScheme, diffResultScheme, diffResultSchemeMysql, diffResultSchemeSQLite, schemaChangeFor, nameChangeFor, nameSchemaChangeFor, columnChangeFor, applyPgSnapshotsDiff, applyMysqlSnapshotsDiff, applySqliteSnapshotsDiff, applyLibSQLSnapshotsDiff;
|
14466
15011
|
var init_snapshotsDiffer = __esm({
|
14467
15012
|
"src/snapshotsDiffer.ts"() {
|
14468
15013
|
"use strict";
|
@@ -14474,6 +15019,7 @@ var init_snapshotsDiffer = __esm({
|
|
14474
15019
|
init_mysqlSchema();
|
14475
15020
|
init_pgSchema();
|
14476
15021
|
init_sqliteSchema();
|
15022
|
+
init_statementCombiner();
|
14477
15023
|
init_utils();
|
14478
15024
|
makeChanged = (schema4) => {
|
14479
15025
|
return objectType({
|
@@ -15822,7 +16368,8 @@ var init_snapshotsDiffer = __esm({
|
|
15822
16368
|
jsonStatements.push(...jsonDropColumnsStatemets);
|
15823
16369
|
jsonStatements.push(...jsonAlteredCompositePKs);
|
15824
16370
|
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
15825
|
-
const
|
16371
|
+
const combinedJsonStatements = sqliteCombineStatements(jsonStatements, json2, action);
|
16372
|
+
const sqlStatements = fromJson(combinedJsonStatements, "sqlite");
|
15826
16373
|
const uniqueSqlStatements = [];
|
15827
16374
|
sqlStatements.forEach((ss) => {
|
15828
16375
|
if (!uniqueSqlStatements.includes(ss)) {
|
@@ -15834,7 +16381,297 @@ var init_snapshotsDiffer = __esm({
|
|
15834
16381
|
});
|
15835
16382
|
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
15836
16383
|
return {
|
15837
|
-
statements:
|
16384
|
+
statements: combinedJsonStatements,
|
16385
|
+
sqlStatements: uniqueSqlStatements,
|
16386
|
+
_meta
|
16387
|
+
};
|
16388
|
+
};
|
16389
|
+
applyLibSQLSnapshotsDiff = async (json1, json2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
|
16390
|
+
const tablesDiff = diffSchemasOrTables(json1.tables, json2.tables);
|
16391
|
+
const {
|
16392
|
+
created: createdTables,
|
16393
|
+
deleted: deletedTables,
|
16394
|
+
renamed: renamedTables
|
16395
|
+
} = await tablesResolver2({
|
16396
|
+
created: tablesDiff.added,
|
16397
|
+
deleted: tablesDiff.deleted
|
16398
|
+
});
|
16399
|
+
const tablesPatchedSnap1 = copy(json1);
|
16400
|
+
tablesPatchedSnap1.tables = mapEntries(tablesPatchedSnap1.tables, (_2, it) => {
|
16401
|
+
const { name: name2 } = nameChangeFor(it, renamedTables);
|
16402
|
+
it.name = name2;
|
16403
|
+
return [name2, it];
|
16404
|
+
});
|
16405
|
+
const res = diffColumns(tablesPatchedSnap1.tables, json2.tables);
|
16406
|
+
const columnRenames = [];
|
16407
|
+
const columnCreates = [];
|
16408
|
+
const columnDeletes = [];
|
16409
|
+
for (let entry of Object.values(res)) {
|
16410
|
+
const { renamed, created, deleted } = await columnsResolver2({
|
16411
|
+
tableName: entry.name,
|
16412
|
+
schema: entry.schema,
|
16413
|
+
deleted: entry.columns.deleted,
|
16414
|
+
created: entry.columns.added
|
16415
|
+
});
|
16416
|
+
if (created.length > 0) {
|
16417
|
+
columnCreates.push({
|
16418
|
+
table: entry.name,
|
16419
|
+
columns: created
|
16420
|
+
});
|
16421
|
+
}
|
16422
|
+
if (deleted.length > 0) {
|
16423
|
+
columnDeletes.push({
|
16424
|
+
table: entry.name,
|
16425
|
+
columns: deleted
|
16426
|
+
});
|
16427
|
+
}
|
16428
|
+
if (renamed.length > 0) {
|
16429
|
+
columnRenames.push({
|
16430
|
+
table: entry.name,
|
16431
|
+
renames: renamed
|
16432
|
+
});
|
16433
|
+
}
|
16434
|
+
}
|
16435
|
+
const columnRenamesDict = columnRenames.reduce(
|
16436
|
+
(acc, it) => {
|
16437
|
+
acc[it.table] = it.renames;
|
16438
|
+
return acc;
|
16439
|
+
},
|
16440
|
+
{}
|
16441
|
+
);
|
16442
|
+
const columnsPatchedSnap1 = copy(tablesPatchedSnap1);
|
16443
|
+
columnsPatchedSnap1.tables = mapEntries(
|
16444
|
+
columnsPatchedSnap1.tables,
|
16445
|
+
(tableKey2, tableValue) => {
|
16446
|
+
const patchedColumns = mapKeys(
|
16447
|
+
tableValue.columns,
|
16448
|
+
(columnKey, column4) => {
|
16449
|
+
const rens = columnRenamesDict[tableValue.name] || [];
|
16450
|
+
const newName = columnChangeFor(columnKey, rens);
|
16451
|
+
column4.name = newName;
|
16452
|
+
return newName;
|
16453
|
+
}
|
16454
|
+
);
|
16455
|
+
tableValue.columns = patchedColumns;
|
16456
|
+
return [tableKey2, tableValue];
|
16457
|
+
}
|
16458
|
+
);
|
16459
|
+
const diffResult = applyJsonDiff(columnsPatchedSnap1, json2);
|
16460
|
+
const typedResult = diffResultSchemeSQLite.parse(diffResult);
|
16461
|
+
const tablesMap = {};
|
16462
|
+
typedResult.alteredTablesWithColumns.forEach((obj) => {
|
16463
|
+
tablesMap[obj.name] = obj;
|
16464
|
+
});
|
16465
|
+
const jsonCreateTables = createdTables.map((it) => {
|
16466
|
+
return prepareSQLiteCreateTable(it, action);
|
16467
|
+
});
|
16468
|
+
const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
|
16469
|
+
return prepareCreateIndexesJson(
|
16470
|
+
it.name,
|
16471
|
+
it.schema,
|
16472
|
+
it.indexes,
|
16473
|
+
curFull.internal
|
16474
|
+
);
|
16475
|
+
}).flat();
|
16476
|
+
const jsonDropTables = deletedTables.map((it) => {
|
16477
|
+
return prepareDropTableJson(it);
|
16478
|
+
});
|
16479
|
+
const jsonRenameTables = renamedTables.map((it) => {
|
16480
|
+
return prepareRenameTableJson(it.from, it.to);
|
16481
|
+
});
|
16482
|
+
const jsonRenameColumnsStatements = columnRenames.map((it) => prepareRenameColumns(it.table, "", it.renames)).flat();
|
16483
|
+
const jsonDropColumnsStatemets = columnDeletes.map((it) => _prepareDropColumns(it.table, "", it.columns)).flat();
|
16484
|
+
const jsonAddColumnsStatemets = columnCreates.map((it) => {
|
16485
|
+
return _prepareSqliteAddColumns(
|
16486
|
+
it.table,
|
16487
|
+
it.columns,
|
16488
|
+
tablesMap[it.table] && tablesMap[it.table].addedForeignKeys ? Object.values(tablesMap[it.table].addedForeignKeys) : []
|
16489
|
+
);
|
16490
|
+
}).flat();
|
16491
|
+
const rColumns = jsonRenameColumnsStatements.map((it) => {
|
16492
|
+
const tableName = it.tableName;
|
16493
|
+
const schema4 = it.schema;
|
16494
|
+
return {
|
16495
|
+
from: { schema: schema4, table: tableName, column: it.oldColumnName },
|
16496
|
+
to: { schema: schema4, table: tableName, column: it.newColumnName }
|
16497
|
+
};
|
16498
|
+
});
|
16499
|
+
const rTables = renamedTables.map((it) => {
|
16500
|
+
return { from: it.from, to: it.to };
|
16501
|
+
});
|
16502
|
+
const _meta = prepareMigrationMeta([], rTables, rColumns);
|
16503
|
+
const allAltered = typedResult.alteredTablesWithColumns;
|
16504
|
+
const jsonAddedCompositePKs = [];
|
16505
|
+
const jsonDeletedCompositePKs = [];
|
16506
|
+
const jsonAlteredCompositePKs = [];
|
16507
|
+
const jsonAddedUniqueConstraints = [];
|
16508
|
+
const jsonDeletedUniqueConstraints = [];
|
16509
|
+
const jsonAlteredUniqueConstraints = [];
|
16510
|
+
allAltered.forEach((it) => {
|
16511
|
+
let addedColumns = [];
|
16512
|
+
for (const addedPkName of Object.keys(it.addedCompositePKs)) {
|
16513
|
+
const addedPkColumns = it.addedCompositePKs[addedPkName];
|
16514
|
+
addedColumns = SQLiteSquasher.unsquashPK(addedPkColumns);
|
16515
|
+
}
|
16516
|
+
let deletedColumns = [];
|
16517
|
+
for (const deletedPkName of Object.keys(it.deletedCompositePKs)) {
|
16518
|
+
const deletedPkColumns = it.deletedCompositePKs[deletedPkName];
|
16519
|
+
deletedColumns = SQLiteSquasher.unsquashPK(deletedPkColumns);
|
16520
|
+
}
|
16521
|
+
const doPerformDeleteAndCreate = JSON.stringify(addedColumns) !== JSON.stringify(deletedColumns);
|
16522
|
+
let addedCompositePKs = [];
|
16523
|
+
let deletedCompositePKs = [];
|
16524
|
+
let alteredCompositePKs = [];
|
16525
|
+
if (doPerformDeleteAndCreate) {
|
16526
|
+
addedCompositePKs = prepareAddCompositePrimaryKeySqlite(
|
16527
|
+
it.name,
|
16528
|
+
it.addedCompositePKs
|
16529
|
+
);
|
16530
|
+
deletedCompositePKs = prepareDeleteCompositePrimaryKeySqlite(
|
16531
|
+
it.name,
|
16532
|
+
it.deletedCompositePKs
|
16533
|
+
);
|
16534
|
+
}
|
16535
|
+
alteredCompositePKs = prepareAlterCompositePrimaryKeySqlite(
|
16536
|
+
it.name,
|
16537
|
+
it.alteredCompositePKs
|
16538
|
+
);
|
16539
|
+
let addedUniqueConstraints = [];
|
16540
|
+
let deletedUniqueConstraints = [];
|
16541
|
+
let alteredUniqueConstraints = [];
|
16542
|
+
addedUniqueConstraints = prepareAddUniqueConstraintPg(
|
16543
|
+
it.name,
|
16544
|
+
it.schema,
|
16545
|
+
it.addedUniqueConstraints
|
16546
|
+
);
|
16547
|
+
deletedUniqueConstraints = prepareDeleteUniqueConstraintPg(
|
16548
|
+
it.name,
|
16549
|
+
it.schema,
|
16550
|
+
it.deletedUniqueConstraints
|
16551
|
+
);
|
16552
|
+
if (it.alteredUniqueConstraints) {
|
16553
|
+
const added = {};
|
16554
|
+
const deleted = {};
|
16555
|
+
for (const k of Object.keys(it.alteredUniqueConstraints)) {
|
16556
|
+
added[k] = it.alteredUniqueConstraints[k].__new;
|
16557
|
+
deleted[k] = it.alteredUniqueConstraints[k].__old;
|
16558
|
+
}
|
16559
|
+
addedUniqueConstraints.push(
|
16560
|
+
...prepareAddUniqueConstraintPg(it.name, it.schema, added)
|
16561
|
+
);
|
16562
|
+
deletedUniqueConstraints.push(
|
16563
|
+
...prepareDeleteUniqueConstraintPg(it.name, it.schema, deleted)
|
16564
|
+
);
|
16565
|
+
}
|
16566
|
+
jsonAddedCompositePKs.push(...addedCompositePKs);
|
16567
|
+
jsonDeletedCompositePKs.push(...deletedCompositePKs);
|
16568
|
+
jsonAlteredCompositePKs.push(...alteredCompositePKs);
|
16569
|
+
jsonAddedUniqueConstraints.push(...addedUniqueConstraints);
|
16570
|
+
jsonDeletedUniqueConstraints.push(...deletedUniqueConstraints);
|
16571
|
+
jsonAlteredUniqueConstraints.push(...alteredUniqueConstraints);
|
16572
|
+
});
|
16573
|
+
const jsonTableAlternations = allAltered.map((it) => {
|
16574
|
+
return prepareSqliteAlterColumns(it.name, it.schema, it.altered, json2);
|
16575
|
+
}).flat();
|
16576
|
+
const jsonCreateIndexesForAllAlteredTables = allAltered.map((it) => {
|
16577
|
+
return prepareCreateIndexesJson(
|
16578
|
+
it.name,
|
16579
|
+
it.schema,
|
16580
|
+
it.addedIndexes || {},
|
16581
|
+
curFull.internal
|
16582
|
+
);
|
16583
|
+
}).flat();
|
16584
|
+
const jsonDropIndexesForAllAlteredTables = allAltered.map((it) => {
|
16585
|
+
return prepareDropIndexesJson(
|
16586
|
+
it.name,
|
16587
|
+
it.schema,
|
16588
|
+
it.deletedIndexes || {}
|
16589
|
+
);
|
16590
|
+
}).flat();
|
16591
|
+
allAltered.forEach((it) => {
|
16592
|
+
const droppedIndexes = Object.keys(it.alteredIndexes).reduce(
|
16593
|
+
(current, item) => {
|
16594
|
+
current[item] = it.alteredIndexes[item].__old;
|
16595
|
+
return current;
|
16596
|
+
},
|
16597
|
+
{}
|
16598
|
+
);
|
16599
|
+
const createdIndexes = Object.keys(it.alteredIndexes).reduce(
|
16600
|
+
(current, item) => {
|
16601
|
+
current[item] = it.alteredIndexes[item].__new;
|
16602
|
+
return current;
|
16603
|
+
},
|
16604
|
+
{}
|
16605
|
+
);
|
16606
|
+
jsonCreateIndexesForAllAlteredTables.push(
|
16607
|
+
...prepareCreateIndexesJson(
|
16608
|
+
it.name,
|
16609
|
+
it.schema,
|
16610
|
+
createdIndexes || {},
|
16611
|
+
curFull.internal
|
16612
|
+
)
|
16613
|
+
);
|
16614
|
+
jsonDropIndexesForAllAlteredTables.push(
|
16615
|
+
...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
|
16616
|
+
);
|
16617
|
+
});
|
16618
|
+
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
16619
|
+
const forAdded = prepareLibSQLCreateReferencesJson(
|
16620
|
+
it.name,
|
16621
|
+
it.schema,
|
16622
|
+
it.addedForeignKeys,
|
16623
|
+
json2,
|
16624
|
+
action
|
16625
|
+
);
|
16626
|
+
const forAltered = prepareLibSQLDropReferencesJson(
|
16627
|
+
it.name,
|
16628
|
+
it.schema,
|
16629
|
+
it.deletedForeignKeys,
|
16630
|
+
json2,
|
16631
|
+
_meta,
|
16632
|
+
action
|
16633
|
+
);
|
16634
|
+
const alteredFKs = prepareAlterReferencesJson(it.name, it.schema, it.alteredForeignKeys);
|
16635
|
+
return [...forAdded, ...forAltered, ...alteredFKs];
|
16636
|
+
}).flat();
|
16637
|
+
const jsonCreatedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16638
|
+
(t) => t.type === "create_reference"
|
16639
|
+
);
|
16640
|
+
const jsonDroppedReferencesForAlteredTables = jsonReferencesForAllAlteredTables.filter(
|
16641
|
+
(t) => t.type === "delete_reference"
|
16642
|
+
);
|
16643
|
+
const jsonStatements = [];
|
16644
|
+
jsonStatements.push(...jsonCreateTables);
|
16645
|
+
jsonStatements.push(...jsonDropTables);
|
16646
|
+
jsonStatements.push(...jsonRenameTables);
|
16647
|
+
jsonStatements.push(...jsonRenameColumnsStatements);
|
16648
|
+
jsonStatements.push(...jsonDroppedReferencesForAlteredTables);
|
16649
|
+
jsonStatements.push(...jsonDropIndexesForAllAlteredTables);
|
16650
|
+
jsonStatements.push(...jsonDeletedCompositePKs);
|
16651
|
+
jsonStatements.push(...jsonTableAlternations);
|
16652
|
+
jsonStatements.push(...jsonAddedCompositePKs);
|
16653
|
+
jsonStatements.push(...jsonAddColumnsStatemets);
|
16654
|
+
jsonStatements.push(...jsonCreateIndexesForCreatedTables);
|
16655
|
+
jsonStatements.push(...jsonCreateIndexesForAllAlteredTables);
|
16656
|
+
jsonStatements.push(...jsonCreatedReferencesForAlteredTables);
|
16657
|
+
jsonStatements.push(...jsonDropColumnsStatemets);
|
16658
|
+
jsonStatements.push(...jsonAlteredCompositePKs);
|
16659
|
+
jsonStatements.push(...jsonAlteredUniqueConstraints);
|
16660
|
+
const combinedJsonStatements = libSQLCombineStatements(jsonStatements, json2, action);
|
16661
|
+
const sqlStatements = fromJson(
|
16662
|
+
combinedJsonStatements,
|
16663
|
+
"turso",
|
16664
|
+
action,
|
16665
|
+
json2
|
16666
|
+
);
|
16667
|
+
const uniqueSqlStatements = [];
|
16668
|
+
sqlStatements.forEach((ss) => {
|
16669
|
+
if (!uniqueSqlStatements.includes(ss)) {
|
16670
|
+
uniqueSqlStatements.push(ss);
|
16671
|
+
}
|
16672
|
+
});
|
16673
|
+
return {
|
16674
|
+
statements: combinedJsonStatements,
|
15838
16675
|
sqlStatements: uniqueSqlStatements,
|
15839
16676
|
_meta
|
15840
16677
|
};
|
@@ -15858,7 +16695,7 @@ var init_schemaValidator = __esm({
|
|
15858
16695
|
init_mysqlSchema();
|
15859
16696
|
init_pgSchema();
|
15860
16697
|
init_sqliteSchema();
|
15861
|
-
dialects = ["postgresql", "mysql", "sqlite"];
|
16698
|
+
dialects = ["postgresql", "mysql", "sqlite", "turso"];
|
15862
16699
|
dialect3 = enumType(dialects);
|
15863
16700
|
commonSquashedSchema = unionType([
|
15864
16701
|
pgSchemaSquashed,
|
@@ -15870,7 +16707,7 @@ var init_schemaValidator = __esm({
|
|
15870
16707
|
});
|
15871
16708
|
|
15872
16709
|
// src/cli/validations/common.ts
|
15873
|
-
var sqliteDriversLiterals, postgresqlDriversLiterals, sqliteDriver, postgresDriver, driver, configMigrations, configCommonSchema, casing, introspectParams, configIntrospectCliSchema, configGenerateSchema, configPushSchema;
|
16710
|
+
var sqliteDriversLiterals, postgresqlDriversLiterals, prefixes, prefix, sqliteDriver, postgresDriver, driver, configMigrations, configCommonSchema, casing, introspectParams, configIntrospectCliSchema, configGenerateSchema, configPushSchema;
|
15874
16711
|
var init_common = __esm({
|
15875
16712
|
"src/cli/validations/common.ts"() {
|
15876
16713
|
"use strict";
|
@@ -15878,7 +16715,6 @@ var init_common = __esm({
|
|
15878
16715
|
init_schemaValidator();
|
15879
16716
|
init_outputs();
|
15880
16717
|
sqliteDriversLiterals = [
|
15881
|
-
literalType("turso"),
|
15882
16718
|
literalType("d1-http"),
|
15883
16719
|
literalType("expo")
|
15884
16720
|
];
|
@@ -15886,12 +16722,24 @@ var init_common = __esm({
|
|
15886
16722
|
literalType("aws-data-api"),
|
15887
16723
|
literalType("pglite")
|
15888
16724
|
];
|
16725
|
+
prefixes = [
|
16726
|
+
"index",
|
16727
|
+
"timestamp",
|
16728
|
+
"supabase",
|
16729
|
+
"unix",
|
16730
|
+
"none"
|
16731
|
+
];
|
16732
|
+
prefix = enumType(prefixes);
|
16733
|
+
{
|
16734
|
+
const _2 = "";
|
16735
|
+
}
|
15889
16736
|
sqliteDriver = unionType(sqliteDriversLiterals);
|
15890
16737
|
postgresDriver = unionType(postgresqlDriversLiterals);
|
15891
16738
|
driver = unionType([sqliteDriver, postgresDriver]);
|
15892
16739
|
configMigrations = objectType({
|
15893
16740
|
table: stringType().optional(),
|
15894
|
-
schema: stringType().optional()
|
16741
|
+
schema: stringType().optional(),
|
16742
|
+
prefix: prefix.optional().default("index")
|
15895
16743
|
}).optional();
|
15896
16744
|
configCommonSchema = objectType({
|
15897
16745
|
dialect: dialect3,
|
@@ -25643,267 +26491,6 @@ var init_selector_ui = __esm({
|
|
25643
26491
|
}
|
25644
26492
|
});
|
25645
26493
|
|
25646
|
-
// src/cli/validations/cli.ts
|
25647
|
-
var pushParams, pullParams, configCheck, cliConfigCheck;
|
25648
|
-
var init_cli = __esm({
|
25649
|
-
"src/cli/validations/cli.ts"() {
|
25650
|
-
"use strict";
|
25651
|
-
init_lib();
|
25652
|
-
init_schemaValidator();
|
25653
|
-
init_common();
|
25654
|
-
pushParams = objectType({
|
25655
|
-
dialect: dialect3,
|
25656
|
-
schema: unionType([stringType(), stringType().array()]),
|
25657
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
25658
|
-
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
25659
|
-
extensionsFilters: literalType("postgis").array().optional(),
|
25660
|
-
verbose: booleanType().optional(),
|
25661
|
-
strict: booleanType().optional()
|
25662
|
-
}).passthrough();
|
25663
|
-
pullParams = objectType({
|
25664
|
-
config: stringType().optional(),
|
25665
|
-
dialect: dialect3,
|
25666
|
-
out: stringType().optional().default("drizzle"),
|
25667
|
-
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
25668
|
-
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
25669
|
-
extensionsFilters: literalType("postgis").array().optional(),
|
25670
|
-
casing,
|
25671
|
-
breakpoints: booleanType().optional().default(true)
|
25672
|
-
}).passthrough();
|
25673
|
-
configCheck = objectType({
|
25674
|
-
dialect: dialect3.optional(),
|
25675
|
-
out: stringType().optional()
|
25676
|
-
});
|
25677
|
-
cliConfigCheck = intersectionType(
|
25678
|
-
objectType({
|
25679
|
-
config: stringType().optional()
|
25680
|
-
}),
|
25681
|
-
configCheck
|
25682
|
-
);
|
25683
|
-
}
|
25684
|
-
});
|
25685
|
-
|
25686
|
-
// src/cli/validations/mysql.ts
|
25687
|
-
var mysqlCredentials;
|
25688
|
-
var init_mysql = __esm({
|
25689
|
-
"src/cli/validations/mysql.ts"() {
|
25690
|
-
"use strict";
|
25691
|
-
init_lib();
|
25692
|
-
init_views();
|
25693
|
-
init_common();
|
25694
|
-
init_outputs();
|
25695
|
-
mysqlCredentials = unionType([
|
25696
|
-
objectType({
|
25697
|
-
host: stringType().min(1),
|
25698
|
-
port: coerce.number().min(1).optional(),
|
25699
|
-
user: stringType().min(1).optional(),
|
25700
|
-
password: stringType().min(1).optional(),
|
25701
|
-
database: stringType().min(1),
|
25702
|
-
ssl: unionType([
|
25703
|
-
stringType(),
|
25704
|
-
objectType({
|
25705
|
-
pfx: stringType().optional(),
|
25706
|
-
key: stringType().optional(),
|
25707
|
-
passphrase: stringType().optional(),
|
25708
|
-
cert: stringType().optional(),
|
25709
|
-
ca: unionType([stringType(), stringType().array()]).optional(),
|
25710
|
-
crl: unionType([stringType(), stringType().array()]).optional(),
|
25711
|
-
ciphers: stringType().optional(),
|
25712
|
-
rejectUnauthorized: booleanType().optional()
|
25713
|
-
})
|
25714
|
-
]).optional()
|
25715
|
-
}),
|
25716
|
-
objectType({
|
25717
|
-
url: stringType().min(1)
|
25718
|
-
})
|
25719
|
-
]);
|
25720
|
-
}
|
25721
|
-
});
|
25722
|
-
|
25723
|
-
// src/cli/validations/postgres.ts
|
25724
|
-
var postgresCredentials;
|
25725
|
-
var init_postgres = __esm({
|
25726
|
-
"src/cli/validations/postgres.ts"() {
|
25727
|
-
"use strict";
|
25728
|
-
init_lib();
|
25729
|
-
init_views();
|
25730
|
-
init_common();
|
25731
|
-
postgresCredentials = unionType([
|
25732
|
-
objectType({
|
25733
|
-
driver: undefinedType(),
|
25734
|
-
host: stringType().min(1),
|
25735
|
-
port: coerce.number().min(1).optional(),
|
25736
|
-
user: stringType().min(1).optional(),
|
25737
|
-
password: stringType().min(1).optional(),
|
25738
|
-
database: stringType().min(1),
|
25739
|
-
ssl: unionType([
|
25740
|
-
literalType("require"),
|
25741
|
-
literalType("allow"),
|
25742
|
-
literalType("prefer"),
|
25743
|
-
literalType("verify-full"),
|
25744
|
-
booleanType(),
|
25745
|
-
objectType({}).passthrough()
|
25746
|
-
]).optional()
|
25747
|
-
}).transform((o) => {
|
25748
|
-
delete o.driver;
|
25749
|
-
return o;
|
25750
|
-
}),
|
25751
|
-
objectType({
|
25752
|
-
driver: undefinedType(),
|
25753
|
-
url: stringType().min(1)
|
25754
|
-
}).transform((o) => {
|
25755
|
-
delete o.driver;
|
25756
|
-
return o;
|
25757
|
-
}),
|
25758
|
-
objectType({
|
25759
|
-
driver: literalType("aws-data-api"),
|
25760
|
-
database: stringType().min(1),
|
25761
|
-
secretArn: stringType().min(1),
|
25762
|
-
resourceArn: stringType().min(1)
|
25763
|
-
}),
|
25764
|
-
objectType({
|
25765
|
-
driver: literalType("pglite"),
|
25766
|
-
url: stringType().min(1)
|
25767
|
-
})
|
25768
|
-
]);
|
25769
|
-
}
|
25770
|
-
});
|
25771
|
-
|
25772
|
-
// src/cli/validations/sqlite.ts
|
25773
|
-
var sqliteCredentials;
|
25774
|
-
var init_sqlite = __esm({
|
25775
|
-
"src/cli/validations/sqlite.ts"() {
|
25776
|
-
"use strict";
|
25777
|
-
init_global();
|
25778
|
-
init_lib();
|
25779
|
-
init_views();
|
25780
|
-
init_common();
|
25781
|
-
sqliteCredentials = unionType([
|
25782
|
-
objectType({
|
25783
|
-
driver: literalType("turso"),
|
25784
|
-
url: stringType().min(1),
|
25785
|
-
authToken: stringType().min(1).optional()
|
25786
|
-
}),
|
25787
|
-
objectType({
|
25788
|
-
driver: literalType("d1-http"),
|
25789
|
-
accountId: stringType().min(1),
|
25790
|
-
databaseId: stringType().min(1),
|
25791
|
-
token: stringType().min(1)
|
25792
|
-
}),
|
25793
|
-
objectType({
|
25794
|
-
driver: undefinedType(),
|
25795
|
-
url: stringType().min(1)
|
25796
|
-
}).transform((o) => {
|
25797
|
-
delete o.driver;
|
25798
|
-
return o;
|
25799
|
-
})
|
25800
|
-
]);
|
25801
|
-
}
|
25802
|
-
});
|
25803
|
-
|
25804
|
-
// src/cli/validations/studio.ts
|
25805
|
-
var credentials, studioCliParams, studioConfig;
|
25806
|
-
var init_studio = __esm({
|
25807
|
-
"src/cli/validations/studio.ts"() {
|
25808
|
-
"use strict";
|
25809
|
-
init_lib();
|
25810
|
-
init_schemaValidator();
|
25811
|
-
init_mysql();
|
25812
|
-
init_postgres();
|
25813
|
-
init_sqlite();
|
25814
|
-
credentials = intersectionType(
|
25815
|
-
postgresCredentials,
|
25816
|
-
mysqlCredentials,
|
25817
|
-
sqliteCredentials
|
25818
|
-
);
|
25819
|
-
studioCliParams = objectType({
|
25820
|
-
port: coerce.number().optional().default(4983),
|
25821
|
-
host: stringType().optional().default("127.0.0.1"),
|
25822
|
-
config: stringType().optional()
|
25823
|
-
});
|
25824
|
-
studioConfig = objectType({
|
25825
|
-
dialect: dialect3,
|
25826
|
-
schema: unionType([stringType(), stringType().array()]).optional()
|
25827
|
-
});
|
25828
|
-
}
|
25829
|
-
});
|
25830
|
-
|
25831
|
-
// src/cli/commands/_es5.ts
|
25832
|
-
var es5_exports = {};
|
25833
|
-
__export(es5_exports, {
|
25834
|
-
default: () => es5_default
|
25835
|
-
});
|
25836
|
-
var _, es5_default;
|
25837
|
-
var init_es5 = __esm({
|
25838
|
-
"src/cli/commands/_es5.ts"() {
|
25839
|
-
"use strict";
|
25840
|
-
_ = "";
|
25841
|
-
es5_default = _;
|
25842
|
-
}
|
25843
|
-
});
|
25844
|
-
|
25845
|
-
// src/cli/commands/utils.ts
|
25846
|
-
var import_hanji6, assertES5, safeRegister, migrateConfig;
|
25847
|
-
var init_utils6 = __esm({
|
25848
|
-
"src/cli/commands/utils.ts"() {
|
25849
|
-
"use strict";
|
25850
|
-
import_hanji6 = __toESM(require_hanji());
|
25851
|
-
init_lib();
|
25852
|
-
init_global();
|
25853
|
-
init_schemaValidator();
|
25854
|
-
init_serializer();
|
25855
|
-
init_cli();
|
25856
|
-
init_common();
|
25857
|
-
init_mysql();
|
25858
|
-
init_outputs();
|
25859
|
-
init_postgres();
|
25860
|
-
init_sqlite();
|
25861
|
-
init_studio();
|
25862
|
-
init_views();
|
25863
|
-
assertES5 = async (unregister) => {
|
25864
|
-
try {
|
25865
|
-
init_es5();
|
25866
|
-
} catch (e) {
|
25867
|
-
if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
|
25868
|
-
const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
|
25869
|
-
if (es5Error) {
|
25870
|
-
console.log(
|
25871
|
-
error(
|
25872
|
-
`Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
|
25873
|
-
)
|
25874
|
-
);
|
25875
|
-
process.exit(1);
|
25876
|
-
}
|
25877
|
-
}
|
25878
|
-
console.error(e);
|
25879
|
-
process.exit(1);
|
25880
|
-
}
|
25881
|
-
};
|
25882
|
-
safeRegister = async () => {
|
25883
|
-
const { register } = await import("esbuild-register/dist/node");
|
25884
|
-
let res;
|
25885
|
-
try {
|
25886
|
-
res = register({
|
25887
|
-
format: "cjs",
|
25888
|
-
loader: "ts"
|
25889
|
-
});
|
25890
|
-
} catch {
|
25891
|
-
res = {
|
25892
|
-
unregister: () => {
|
25893
|
-
}
|
25894
|
-
};
|
25895
|
-
}
|
25896
|
-
await assertES5(res.unregister);
|
25897
|
-
return res;
|
25898
|
-
};
|
25899
|
-
migrateConfig = objectType({
|
25900
|
-
dialect: dialect3,
|
25901
|
-
out: stringType().optional().default("drizzle"),
|
25902
|
-
migrations: configMigrations
|
25903
|
-
});
|
25904
|
-
}
|
25905
|
-
});
|
25906
|
-
|
25907
26494
|
// ../drizzle-orm/dist/sqlite-core/alias.js
|
25908
26495
|
var init_alias3 = __esm({
|
25909
26496
|
"../drizzle-orm/dist/sqlite-core/alias.js"() {
|
@@ -29010,7 +29597,7 @@ function getTableConfig2(table4) {
|
|
29010
29597
|
name: name2
|
29011
29598
|
};
|
29012
29599
|
}
|
29013
|
-
var
|
29600
|
+
var init_utils6 = __esm({
|
29014
29601
|
"../drizzle-orm/dist/sqlite-core/utils.js"() {
|
29015
29602
|
"use strict";
|
29016
29603
|
init_entity();
|
@@ -29146,7 +29733,7 @@ var init_sqlite_core = __esm({
|
|
29146
29733
|
init_subquery3();
|
29147
29734
|
init_table3();
|
29148
29735
|
init_unique_constraint2();
|
29149
|
-
|
29736
|
+
init_utils6();
|
29150
29737
|
init_view2();
|
29151
29738
|
}
|
29152
29739
|
});
|
@@ -33567,7 +34154,7 @@ function getTableConfig3(table4) {
|
|
33567
34154
|
baseName
|
33568
34155
|
};
|
33569
34156
|
}
|
33570
|
-
var
|
34157
|
+
var init_utils7 = __esm({
|
33571
34158
|
"../drizzle-orm/dist/mysql-core/utils.js"() {
|
33572
34159
|
"use strict";
|
33573
34160
|
init_entity();
|
@@ -33599,7 +34186,7 @@ var init_mysql_core = __esm({
|
|
33599
34186
|
init_subquery4();
|
33600
34187
|
init_table4();
|
33601
34188
|
init_unique_constraint3();
|
33602
|
-
|
34189
|
+
init_utils7();
|
33603
34190
|
init_view_common4();
|
33604
34191
|
init_view3();
|
33605
34192
|
}
|
@@ -34156,6 +34743,298 @@ We have encountered a collision between the index name on columns ${source_defau
|
|
34156
34743
|
}
|
34157
34744
|
});
|
34158
34745
|
|
34746
|
+
// src/cli/validations/cli.ts
|
34747
|
+
var cliConfigGenerate, pushParams, pullParams, configCheck, cliConfigCheck;
|
34748
|
+
var init_cli = __esm({
|
34749
|
+
"src/cli/validations/cli.ts"() {
|
34750
|
+
"use strict";
|
34751
|
+
init_lib();
|
34752
|
+
init_schemaValidator();
|
34753
|
+
init_common();
|
34754
|
+
cliConfigGenerate = objectType({
|
34755
|
+
dialect: dialect3.optional(),
|
34756
|
+
schema: unionType([stringType(), stringType().array()]).optional(),
|
34757
|
+
out: stringType().optional().default("./drizzle"),
|
34758
|
+
config: stringType().optional(),
|
34759
|
+
name: stringType().optional(),
|
34760
|
+
prefix: prefix.optional(),
|
34761
|
+
breakpoints: booleanType().optional().default(true),
|
34762
|
+
custom: booleanType().optional().default(false)
|
34763
|
+
}).strict();
|
34764
|
+
pushParams = objectType({
|
34765
|
+
dialect: dialect3,
|
34766
|
+
schema: unionType([stringType(), stringType().array()]),
|
34767
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
34768
|
+
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34769
|
+
extensionsFilters: literalType("postgis").array().optional(),
|
34770
|
+
verbose: booleanType().optional(),
|
34771
|
+
strict: booleanType().optional(),
|
34772
|
+
driver: driver.optional()
|
34773
|
+
}).passthrough();
|
34774
|
+
pullParams = objectType({
|
34775
|
+
config: stringType().optional(),
|
34776
|
+
dialect: dialect3,
|
34777
|
+
out: stringType().optional().default("drizzle"),
|
34778
|
+
tablesFilter: unionType([stringType(), stringType().array()]).optional(),
|
34779
|
+
schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
|
34780
|
+
extensionsFilters: literalType("postgis").array().optional(),
|
34781
|
+
casing,
|
34782
|
+
breakpoints: booleanType().optional().default(true),
|
34783
|
+
migrations: objectType({
|
34784
|
+
prefix: prefix.optional().default("index")
|
34785
|
+
}).optional()
|
34786
|
+
}).passthrough();
|
34787
|
+
configCheck = objectType({
|
34788
|
+
dialect: dialect3.optional(),
|
34789
|
+
out: stringType().optional()
|
34790
|
+
});
|
34791
|
+
cliConfigCheck = intersectionType(
|
34792
|
+
objectType({
|
34793
|
+
config: stringType().optional()
|
34794
|
+
}),
|
34795
|
+
configCheck
|
34796
|
+
);
|
34797
|
+
}
|
34798
|
+
});
|
34799
|
+
|
34800
|
+
// src/cli/validations/libsql.ts
|
34801
|
+
var libSQLCredentials;
|
34802
|
+
var init_libsql = __esm({
|
34803
|
+
"src/cli/validations/libsql.ts"() {
|
34804
|
+
"use strict";
|
34805
|
+
init_lib();
|
34806
|
+
init_views();
|
34807
|
+
init_common();
|
34808
|
+
libSQLCredentials = objectType({
|
34809
|
+
url: stringType().min(1),
|
34810
|
+
authToken: stringType().min(1).optional()
|
34811
|
+
});
|
34812
|
+
}
|
34813
|
+
});
|
34814
|
+
|
34815
|
+
// src/cli/validations/mysql.ts
|
34816
|
+
var mysqlCredentials;
|
34817
|
+
var init_mysql = __esm({
|
34818
|
+
"src/cli/validations/mysql.ts"() {
|
34819
|
+
"use strict";
|
34820
|
+
init_lib();
|
34821
|
+
init_views();
|
34822
|
+
init_common();
|
34823
|
+
init_outputs();
|
34824
|
+
mysqlCredentials = unionType([
|
34825
|
+
objectType({
|
34826
|
+
host: stringType().min(1),
|
34827
|
+
port: coerce.number().min(1).optional(),
|
34828
|
+
user: stringType().min(1).optional(),
|
34829
|
+
password: stringType().min(1).optional(),
|
34830
|
+
database: stringType().min(1),
|
34831
|
+
ssl: unionType([
|
34832
|
+
stringType(),
|
34833
|
+
objectType({
|
34834
|
+
pfx: stringType().optional(),
|
34835
|
+
key: stringType().optional(),
|
34836
|
+
passphrase: stringType().optional(),
|
34837
|
+
cert: stringType().optional(),
|
34838
|
+
ca: unionType([stringType(), stringType().array()]).optional(),
|
34839
|
+
crl: unionType([stringType(), stringType().array()]).optional(),
|
34840
|
+
ciphers: stringType().optional(),
|
34841
|
+
rejectUnauthorized: booleanType().optional()
|
34842
|
+
})
|
34843
|
+
]).optional()
|
34844
|
+
}),
|
34845
|
+
objectType({
|
34846
|
+
url: stringType().min(1)
|
34847
|
+
})
|
34848
|
+
]);
|
34849
|
+
}
|
34850
|
+
});
|
34851
|
+
|
34852
|
+
// src/cli/validations/postgres.ts
|
34853
|
+
var postgresCredentials;
|
34854
|
+
var init_postgres = __esm({
|
34855
|
+
"src/cli/validations/postgres.ts"() {
|
34856
|
+
"use strict";
|
34857
|
+
init_lib();
|
34858
|
+
init_views();
|
34859
|
+
init_common();
|
34860
|
+
postgresCredentials = unionType([
|
34861
|
+
objectType({
|
34862
|
+
driver: undefinedType(),
|
34863
|
+
host: stringType().min(1),
|
34864
|
+
port: coerce.number().min(1).optional(),
|
34865
|
+
user: stringType().min(1).optional(),
|
34866
|
+
password: stringType().min(1).optional(),
|
34867
|
+
database: stringType().min(1),
|
34868
|
+
ssl: unionType([
|
34869
|
+
literalType("require"),
|
34870
|
+
literalType("allow"),
|
34871
|
+
literalType("prefer"),
|
34872
|
+
literalType("verify-full"),
|
34873
|
+
booleanType(),
|
34874
|
+
objectType({}).passthrough()
|
34875
|
+
]).optional()
|
34876
|
+
}).transform((o) => {
|
34877
|
+
delete o.driver;
|
34878
|
+
return o;
|
34879
|
+
}),
|
34880
|
+
objectType({
|
34881
|
+
driver: undefinedType(),
|
34882
|
+
url: stringType().min(1)
|
34883
|
+
}).transform((o) => {
|
34884
|
+
delete o.driver;
|
34885
|
+
return o;
|
34886
|
+
}),
|
34887
|
+
objectType({
|
34888
|
+
driver: literalType("aws-data-api"),
|
34889
|
+
database: stringType().min(1),
|
34890
|
+
secretArn: stringType().min(1),
|
34891
|
+
resourceArn: stringType().min(1)
|
34892
|
+
}),
|
34893
|
+
objectType({
|
34894
|
+
driver: literalType("pglite"),
|
34895
|
+
url: stringType().min(1)
|
34896
|
+
})
|
34897
|
+
]);
|
34898
|
+
}
|
34899
|
+
});
|
34900
|
+
|
34901
|
+
// src/cli/validations/sqlite.ts
|
34902
|
+
var sqliteCredentials;
|
34903
|
+
var init_sqlite = __esm({
|
34904
|
+
"src/cli/validations/sqlite.ts"() {
|
34905
|
+
"use strict";
|
34906
|
+
init_global();
|
34907
|
+
init_lib();
|
34908
|
+
init_views();
|
34909
|
+
init_common();
|
34910
|
+
sqliteCredentials = unionType([
|
34911
|
+
objectType({
|
34912
|
+
driver: literalType("turso"),
|
34913
|
+
url: stringType().min(1),
|
34914
|
+
authToken: stringType().min(1).optional()
|
34915
|
+
}),
|
34916
|
+
objectType({
|
34917
|
+
driver: literalType("d1-http"),
|
34918
|
+
accountId: stringType().min(1),
|
34919
|
+
databaseId: stringType().min(1),
|
34920
|
+
token: stringType().min(1)
|
34921
|
+
}),
|
34922
|
+
objectType({
|
34923
|
+
driver: undefinedType(),
|
34924
|
+
url: stringType().min(1)
|
34925
|
+
}).transform((o) => {
|
34926
|
+
delete o.driver;
|
34927
|
+
return o;
|
34928
|
+
})
|
34929
|
+
]);
|
34930
|
+
}
|
34931
|
+
});
|
34932
|
+
|
34933
|
+
// src/cli/validations/studio.ts
|
34934
|
+
var credentials, studioCliParams, studioConfig;
|
34935
|
+
var init_studio = __esm({
|
34936
|
+
"src/cli/validations/studio.ts"() {
|
34937
|
+
"use strict";
|
34938
|
+
init_lib();
|
34939
|
+
init_schemaValidator();
|
34940
|
+
init_mysql();
|
34941
|
+
init_postgres();
|
34942
|
+
init_sqlite();
|
34943
|
+
credentials = intersectionType(
|
34944
|
+
postgresCredentials,
|
34945
|
+
mysqlCredentials,
|
34946
|
+
sqliteCredentials
|
34947
|
+
);
|
34948
|
+
studioCliParams = objectType({
|
34949
|
+
port: coerce.number().optional().default(4983),
|
34950
|
+
host: stringType().optional().default("127.0.0.1"),
|
34951
|
+
config: stringType().optional()
|
34952
|
+
});
|
34953
|
+
studioConfig = objectType({
|
34954
|
+
dialect: dialect3,
|
34955
|
+
schema: unionType([stringType(), stringType().array()]).optional()
|
34956
|
+
});
|
34957
|
+
}
|
34958
|
+
});
|
34959
|
+
|
34960
|
+
// src/cli/commands/_es5.ts
|
34961
|
+
var es5_exports = {};
|
34962
|
+
__export(es5_exports, {
|
34963
|
+
default: () => es5_default
|
34964
|
+
});
|
34965
|
+
var _, es5_default;
|
34966
|
+
var init_es5 = __esm({
|
34967
|
+
"src/cli/commands/_es5.ts"() {
|
34968
|
+
"use strict";
|
34969
|
+
_ = "";
|
34970
|
+
es5_default = _;
|
34971
|
+
}
|
34972
|
+
});
|
34973
|
+
|
34974
|
+
// src/cli/commands/utils.ts
|
34975
|
+
var import_hanji7, assertES5, safeRegister, migrateConfig;
|
34976
|
+
var init_utils8 = __esm({
|
34977
|
+
"src/cli/commands/utils.ts"() {
|
34978
|
+
"use strict";
|
34979
|
+
import_hanji7 = __toESM(require_hanji());
|
34980
|
+
init_lib();
|
34981
|
+
init_global();
|
34982
|
+
init_schemaValidator();
|
34983
|
+
init_serializer();
|
34984
|
+
init_cli();
|
34985
|
+
init_common();
|
34986
|
+
init_libsql();
|
34987
|
+
init_libsql();
|
34988
|
+
init_mysql();
|
34989
|
+
init_outputs();
|
34990
|
+
init_postgres();
|
34991
|
+
init_sqlite();
|
34992
|
+
init_studio();
|
34993
|
+
init_views();
|
34994
|
+
assertES5 = async (unregister) => {
|
34995
|
+
try {
|
34996
|
+
init_es5();
|
34997
|
+
} catch (e) {
|
34998
|
+
if ("errors" in e && Array.isArray(e.errors) && e.errors.length > 0) {
|
34999
|
+
const es5Error = e.errors.filter((it) => it.text?.includes(`("es5") is not supported yet`)).length > 0;
|
35000
|
+
if (es5Error) {
|
35001
|
+
console.log(
|
35002
|
+
error(
|
35003
|
+
`Please change compilerOptions.target from 'es5' to 'es6' or above in your tsconfig.json`
|
35004
|
+
)
|
35005
|
+
);
|
35006
|
+
process.exit(1);
|
35007
|
+
}
|
35008
|
+
}
|
35009
|
+
console.error(e);
|
35010
|
+
process.exit(1);
|
35011
|
+
}
|
35012
|
+
};
|
35013
|
+
safeRegister = async () => {
|
35014
|
+
const { register } = await import("esbuild-register/dist/node");
|
35015
|
+
let res;
|
35016
|
+
try {
|
35017
|
+
res = register({
|
35018
|
+
format: "cjs",
|
35019
|
+
loader: "ts"
|
35020
|
+
});
|
35021
|
+
} catch {
|
35022
|
+
res = {
|
35023
|
+
unregister: () => {
|
35024
|
+
}
|
35025
|
+
};
|
35026
|
+
}
|
35027
|
+
await assertES5(res.unregister);
|
35028
|
+
return res;
|
35029
|
+
};
|
35030
|
+
migrateConfig = objectType({
|
35031
|
+
dialect: dialect3,
|
35032
|
+
out: stringType().optional().default("drizzle"),
|
35033
|
+
migrations: configMigrations
|
35034
|
+
});
|
35035
|
+
}
|
35036
|
+
});
|
35037
|
+
|
34159
35038
|
// src/serializer/pgImports.ts
|
34160
35039
|
var prepareFromExports;
|
34161
35040
|
var init_pgImports = __esm({
|
@@ -34163,7 +35042,7 @@ var init_pgImports = __esm({
|
|
34163
35042
|
"use strict";
|
34164
35043
|
init_dist();
|
34165
35044
|
init_pg_core();
|
34166
|
-
|
35045
|
+
init_utils8();
|
34167
35046
|
prepareFromExports = (exports) => {
|
34168
35047
|
const tables = [];
|
34169
35048
|
const enums = [];
|
@@ -34202,7 +35081,7 @@ var init_sqliteImports = __esm({
|
|
34202
35081
|
"use strict";
|
34203
35082
|
init_dist();
|
34204
35083
|
init_sqlite_core();
|
34205
|
-
|
35084
|
+
init_utils8();
|
34206
35085
|
prepareFromExports2 = (exports) => {
|
34207
35086
|
const tables = [];
|
34208
35087
|
const i0values = Object.values(exports);
|
@@ -34240,7 +35119,7 @@ var init_mysqlImports = __esm({
|
|
34240
35119
|
"use strict";
|
34241
35120
|
init_dist();
|
34242
35121
|
init_mysql_core();
|
34243
|
-
|
35122
|
+
init_utils8();
|
34244
35123
|
prepareFromExports3 = (exports) => {
|
34245
35124
|
const tables = [];
|
34246
35125
|
const i0values = Object.values(exports);
|
@@ -34856,7 +35735,6 @@ var pgSuggestions = async (db, statements) => {
|
|
34856
35735
|
// src/cli/commands/pgUp.ts
|
34857
35736
|
init_pgSchema();
|
34858
35737
|
init_utils();
|
34859
|
-
init_utils6();
|
34860
35738
|
var updateUpToV6 = (json) => {
|
34861
35739
|
const schema4 = pgSchemaV5.parse(json);
|
34862
35740
|
const tables = Object.fromEntries(
|
@@ -34920,7 +35798,7 @@ var updateUpToV7 = (json) => {
|
|
34920
35798
|
};
|
34921
35799
|
|
34922
35800
|
// src/cli/commands/sqliteIntrospect.ts
|
34923
|
-
var
|
35801
|
+
var import_hanji6 = __toESM(require_hanji());
|
34924
35802
|
init_mjs();
|
34925
35803
|
init_global();
|
34926
35804
|
|
@@ -35059,289 +35937,13 @@ var sqlitePushIntrospect = async (db, filters) => {
|
|
35059
35937
|
"Pulling schema from database...",
|
35060
35938
|
"Pulling schema from database..."
|
35061
35939
|
);
|
35062
|
-
const res = await (0,
|
35940
|
+
const res = await (0, import_hanji6.renderWithTask)(progress, fromDatabase2(db, filter2));
|
35063
35941
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
35064
35942
|
return { schema: schema4 };
|
35065
35943
|
};
|
35066
35944
|
|
35067
|
-
// src/cli/commands/sqlitePushUtils.ts
|
35068
|
-
init_source();
|
35069
|
-
init_sqliteSchema();
|
35070
|
-
init_sqlgenerator();
|
35071
|
-
var _moveDataStatements = (tableName, json, dataLoss = false) => {
|
35072
|
-
const statements = [];
|
35073
|
-
statements.push(
|
35074
|
-
new SqliteRenameTableConvertor().convert({
|
35075
|
-
type: "rename_table",
|
35076
|
-
tableNameFrom: tableName,
|
35077
|
-
tableNameTo: `__old_push_${tableName}`,
|
35078
|
-
fromSchema: "",
|
35079
|
-
toSchema: ""
|
35080
|
-
})
|
35081
|
-
);
|
35082
|
-
const tableColumns = Object.values(json.tables[tableName].columns);
|
35083
|
-
const referenceData = Object.values(json.tables[tableName].foreignKeys);
|
35084
|
-
const compositePKs = Object.values(
|
35085
|
-
json.tables[tableName].compositePrimaryKeys
|
35086
|
-
).map((it) => SQLiteSquasher.unsquashPK(it));
|
35087
|
-
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
|
35088
|
-
statements.push(
|
35089
|
-
new SQLiteCreateTableConvertor().convert({
|
35090
|
-
type: "sqlite_create_table",
|
35091
|
-
tableName,
|
35092
|
-
columns: tableColumns,
|
35093
|
-
referenceData: fks,
|
35094
|
-
compositePKs
|
35095
|
-
})
|
35096
|
-
);
|
35097
|
-
if (!dataLoss) {
|
35098
|
-
statements.push(
|
35099
|
-
`INSERT INTO "${tableName}" SELECT * FROM "__old_push_${tableName}";`
|
35100
|
-
);
|
35101
|
-
}
|
35102
|
-
statements.push(
|
35103
|
-
new SQLiteDropTableConvertor().convert({
|
35104
|
-
type: "drop_table",
|
35105
|
-
tableName: `__old_push_${tableName}`,
|
35106
|
-
schema: ""
|
35107
|
-
})
|
35108
|
-
);
|
35109
|
-
for (const idx of Object.values(json.tables[tableName].indexes)) {
|
35110
|
-
statements.push(
|
35111
|
-
new CreateSqliteIndexConvertor().convert({
|
35112
|
-
type: "create_index",
|
35113
|
-
tableName,
|
35114
|
-
schema: "",
|
35115
|
-
data: idx
|
35116
|
-
})
|
35117
|
-
);
|
35118
|
-
}
|
35119
|
-
return statements;
|
35120
|
-
};
|
35121
|
-
var getOldTableName = (tableName, meta) => {
|
35122
|
-
for (const key of Object.keys(meta.tables)) {
|
35123
|
-
const value = meta.tables[key];
|
35124
|
-
if (`"${tableName}"` === value) {
|
35125
|
-
return key.substring(1, key.length - 1);
|
35126
|
-
}
|
35127
|
-
}
|
35128
|
-
return tableName;
|
35129
|
-
};
|
35130
|
-
var getNewTableName = (tableName, meta) => {
|
35131
|
-
if (typeof meta.tables[`"${tableName}"`] !== "undefined") {
|
35132
|
-
return meta.tables[`"${tableName}"`].substring(
|
35133
|
-
1,
|
35134
|
-
meta.tables[`"${tableName}"`].length - 1
|
35135
|
-
);
|
35136
|
-
}
|
35137
|
-
return tableName;
|
35138
|
-
};
|
35139
|
-
var logSuggestionsAndReturn = async (connection, statements, json1, json2, meta) => {
|
35140
|
-
let shouldAskForApprove = false;
|
35141
|
-
const statementsToExecute = [];
|
35142
|
-
const infoToPrint = [];
|
35143
|
-
const tablesToRemove = [];
|
35144
|
-
const columnsToRemove = [];
|
35145
|
-
const schemasToRemove = [];
|
35146
|
-
const tablesToTruncate = [];
|
35147
|
-
const tablesContext = {};
|
35148
|
-
for (const statement of statements) {
|
35149
|
-
if (statement.type === "drop_table") {
|
35150
|
-
const res = await connection.query(
|
35151
|
-
`select count(*) as count from \`${statement.tableName}\``
|
35152
|
-
);
|
35153
|
-
const count2 = Number(res[0].count);
|
35154
|
-
if (count2 > 0) {
|
35155
|
-
infoToPrint.push(
|
35156
|
-
`\xB7 You're about to delete ${source_default.underline(
|
35157
|
-
statement.tableName
|
35158
|
-
)} table with ${count2} items`
|
35159
|
-
);
|
35160
|
-
tablesToRemove.push(statement.tableName);
|
35161
|
-
shouldAskForApprove = true;
|
35162
|
-
}
|
35163
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35164
|
-
statementsToExecute.push(stmnt);
|
35165
|
-
} else if (statement.type === "alter_table_drop_column") {
|
35166
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35167
|
-
const columnIsPartOfPk = Object.values(
|
35168
|
-
json1.tables[newTableName].compositePrimaryKeys
|
35169
|
-
).find((c) => SQLiteSquasher.unsquashPK(c).includes(statement.columnName));
|
35170
|
-
const columnIsPartOfIndex = Object.values(
|
35171
|
-
json1.tables[newTableName].indexes
|
35172
|
-
).find((c) => SQLiteSquasher.unsquashIdx(c).columns.includes(statement.columnName));
|
35173
|
-
const columnIsPk = json1.tables[newTableName].columns[statement.columnName].primaryKey;
|
35174
|
-
const columnIsPartOfFk = Object.values(
|
35175
|
-
json1.tables[newTableName].foreignKeys
|
35176
|
-
).find(
|
35177
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).columnsFrom.includes(
|
35178
|
-
statement.columnName
|
35179
|
-
)
|
35180
|
-
);
|
35181
|
-
const res = await connection.query(
|
35182
|
-
`select count(*) as count from \`${newTableName}\``
|
35183
|
-
);
|
35184
|
-
const count2 = Number(res[0].count);
|
35185
|
-
if (count2 > 0) {
|
35186
|
-
infoToPrint.push(
|
35187
|
-
`\xB7 You're about to delete ${source_default.underline(
|
35188
|
-
statement.columnName
|
35189
|
-
)} column in ${newTableName} table with ${count2} items`
|
35190
|
-
);
|
35191
|
-
columnsToRemove.push(`${newTableName}_${statement.columnName}`);
|
35192
|
-
shouldAskForApprove = true;
|
35193
|
-
}
|
35194
|
-
if (columnIsPk || columnIsPartOfPk || columnIsPartOfIndex || columnIsPartOfFk) {
|
35195
|
-
tablesContext[newTableName] = [
|
35196
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
35197
|
-
];
|
35198
|
-
const tablesReferncingCurrent = [];
|
35199
|
-
for (const table4 of Object.values(json1.tables)) {
|
35200
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35201
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35202
|
-
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35203
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35204
|
-
}
|
35205
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35206
|
-
for (const table4 of uniqueTableRefs) {
|
35207
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35208
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35209
|
-
}
|
35210
|
-
}
|
35211
|
-
} else {
|
35212
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35213
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35214
|
-
statementsToExecute.push(stmnt);
|
35215
|
-
}
|
35216
|
-
}
|
35217
|
-
} else if (statement.type === "sqlite_alter_table_add_column") {
|
35218
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35219
|
-
if (statement.column.notNull && !statement.column.default) {
|
35220
|
-
const res = await connection.query(
|
35221
|
-
`select count(*) as count from \`${newTableName}\``
|
35222
|
-
);
|
35223
|
-
const count2 = Number(res[0].count);
|
35224
|
-
if (count2 > 0) {
|
35225
|
-
infoToPrint.push(
|
35226
|
-
`\xB7 You're about to add not-null ${source_default.underline(
|
35227
|
-
statement.column.name
|
35228
|
-
)} column without default value, which contains ${count2} items`
|
35229
|
-
);
|
35230
|
-
tablesToTruncate.push(newTableName);
|
35231
|
-
statementsToExecute.push(`delete from ${newTableName};`);
|
35232
|
-
shouldAskForApprove = true;
|
35233
|
-
}
|
35234
|
-
}
|
35235
|
-
if (statement.column.primaryKey) {
|
35236
|
-
tablesContext[newTableName] = [
|
35237
|
-
..._moveDataStatements(statement.tableName, json2, true)
|
35238
|
-
];
|
35239
|
-
const tablesReferncingCurrent = [];
|
35240
|
-
for (const table4 of Object.values(json1.tables)) {
|
35241
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35242
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35243
|
-
).map((t) => SQLiteSquasher.unsquashPushFK(t).tableFrom);
|
35244
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35245
|
-
}
|
35246
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35247
|
-
for (const table4 of uniqueTableRefs) {
|
35248
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35249
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json2)];
|
35250
|
-
}
|
35251
|
-
}
|
35252
|
-
} else {
|
35253
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35254
|
-
const stmnt = fromJson([statement], "sqlite")[0];
|
35255
|
-
statementsToExecute.push(stmnt);
|
35256
|
-
}
|
35257
|
-
}
|
35258
|
-
} 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") {
|
35259
|
-
if (!(statement.type === "alter_table_alter_column_set_notnull" && statement.columnPk)) {
|
35260
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35261
|
-
if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
|
35262
|
-
const res = await connection.query(
|
35263
|
-
`select count(*) as count from \`${newTableName}\``
|
35264
|
-
);
|
35265
|
-
const count2 = Number(res[0].count);
|
35266
|
-
if (count2 > 0) {
|
35267
|
-
infoToPrint.push(
|
35268
|
-
`\xB7 You're about to add not-null constraint to ${source_default.underline(
|
35269
|
-
statement.columnName
|
35270
|
-
)} column without default value, which contains ${count2} items`
|
35271
|
-
);
|
35272
|
-
tablesToTruncate.push(newTableName);
|
35273
|
-
shouldAskForApprove = true;
|
35274
|
-
}
|
35275
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35276
|
-
statement.tableName,
|
35277
|
-
json1,
|
35278
|
-
true
|
35279
|
-
);
|
35280
|
-
} else {
|
35281
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35282
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35283
|
-
statement.tableName,
|
35284
|
-
json1
|
35285
|
-
);
|
35286
|
-
}
|
35287
|
-
}
|
35288
|
-
const tablesReferncingCurrent = [];
|
35289
|
-
for (const table4 of Object.values(json1.tables)) {
|
35290
|
-
const tablesRefs = Object.values(json1.tables[table4.name].foreignKeys).filter(
|
35291
|
-
(t) => SQLiteSquasher.unsquashPushFK(t).tableTo === newTableName
|
35292
|
-
).map((t) => {
|
35293
|
-
return getNewTableName(
|
35294
|
-
SQLiteSquasher.unsquashPushFK(t).tableFrom,
|
35295
|
-
meta
|
35296
|
-
);
|
35297
|
-
});
|
35298
|
-
tablesReferncingCurrent.push(...tablesRefs);
|
35299
|
-
}
|
35300
|
-
const uniqueTableRefs = [...new Set(tablesReferncingCurrent)];
|
35301
|
-
for (const table4 of uniqueTableRefs) {
|
35302
|
-
if (typeof tablesContext[table4] === "undefined") {
|
35303
|
-
tablesContext[table4] = [..._moveDataStatements(table4, json1)];
|
35304
|
-
}
|
35305
|
-
}
|
35306
|
-
}
|
35307
|
-
} else if (statement.type === "create_reference" || statement.type === "delete_reference" || statement.type === "alter_reference") {
|
35308
|
-
const fk4 = SQLiteSquasher.unsquashPushFK(statement.data);
|
35309
|
-
if (typeof tablesContext[statement.tableName] === "undefined") {
|
35310
|
-
tablesContext[statement.tableName] = _moveDataStatements(
|
35311
|
-
statement.tableName,
|
35312
|
-
json2
|
35313
|
-
);
|
35314
|
-
}
|
35315
|
-
} 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") {
|
35316
|
-
const newTableName = getOldTableName(statement.tableName, meta);
|
35317
|
-
if (typeof tablesContext[newTableName] === "undefined") {
|
35318
|
-
tablesContext[newTableName] = _moveDataStatements(
|
35319
|
-
statement.tableName,
|
35320
|
-
json2
|
35321
|
-
);
|
35322
|
-
}
|
35323
|
-
} else {
|
35324
|
-
const stmnt = fromJson([statement], "sqlite");
|
35325
|
-
if (typeof stmnt !== "undefined") {
|
35326
|
-
statementsToExecute.push(...stmnt);
|
35327
|
-
}
|
35328
|
-
}
|
35329
|
-
}
|
35330
|
-
for (const context of Object.values(tablesContext)) {
|
35331
|
-
statementsToExecute.push(...context);
|
35332
|
-
}
|
35333
|
-
return {
|
35334
|
-
statementsToExecute,
|
35335
|
-
shouldAskForApprove,
|
35336
|
-
infoToPrint,
|
35337
|
-
columnsToRemove: [...new Set(columnsToRemove)],
|
35338
|
-
schemasToRemove: [...new Set(schemasToRemove)],
|
35339
|
-
tablesToTruncate: [...new Set(tablesToTruncate)],
|
35340
|
-
tablesToRemove: [...new Set(tablesToRemove)]
|
35341
|
-
};
|
35342
|
-
};
|
35343
|
-
|
35344
35945
|
// src/api.ts
|
35946
|
+
init_sqlitePushUtils();
|
35345
35947
|
init_global();
|
35346
35948
|
init_migrationPreparator();
|
35347
35949
|
init_mysqlSchema();
|