orchid-orm 1.50.0 → 1.50.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/migrations.js +32 -24
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +32 -24
- package/dist/migrations.mjs.map +1 -1
- package/package.json +5 -5
package/dist/migrations.mjs
CHANGED
|
@@ -21,7 +21,7 @@ const compareSqlExpressions = async (tableExpressions, adapter) => {
|
|
|
21
21
|
// that's why SQLs are combined into a single query.
|
|
22
22
|
text: [
|
|
23
23
|
`CREATE TEMPORARY VIEW ${viewName} AS (SELECT ${compare.map(
|
|
24
|
-
({ inDb
|
|
24
|
+
({ inDb, inCode }, i) => `${inDb} AS "*inDb-${i}*", ${inCode.map(
|
|
25
25
|
(s, j) => `(${typeof s === "string" ? s : s.toSQL({ values })}) "*inCode-${i}-${j}*"`
|
|
26
26
|
).join(", ")}`
|
|
27
27
|
).join(", ")} FROM ${source})`,
|
|
@@ -37,33 +37,41 @@ const compareSqlExpressions = async (tableExpressions, adapter) => {
|
|
|
37
37
|
handle();
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let codeI = 0;
|
|
46
|
-
const matches = compare[0].inCode.map(() => true);
|
|
47
|
-
while (match = rgx.exec(v)) {
|
|
48
|
-
const sql = v.slice(pos, rgx.lastIndex - match[0].length).trim();
|
|
49
|
-
const arr = match[1].split("-");
|
|
50
|
-
if (arr.length === 2) {
|
|
51
|
-
inDb = sql;
|
|
52
|
-
codeI = 0;
|
|
53
|
-
} else {
|
|
54
|
-
if (inDb !== sql) {
|
|
55
|
-
matches[codeI] = false;
|
|
56
|
-
}
|
|
57
|
-
codeI++;
|
|
58
|
-
}
|
|
59
|
-
pos = rgx.lastIndex;
|
|
60
|
-
}
|
|
61
|
-
const firstMatching = matches.indexOf(true);
|
|
62
|
-
handle(firstMatching === -1 ? void 0 : firstMatching);
|
|
40
|
+
const match = compareSqlExpressionResult(
|
|
41
|
+
result.rows[0].v,
|
|
42
|
+
compare[0].inCode
|
|
43
|
+
);
|
|
44
|
+
handle(match);
|
|
63
45
|
})
|
|
64
46
|
);
|
|
65
47
|
}
|
|
66
48
|
};
|
|
49
|
+
const compareSqlExpressionResult = (resultSql, inCode) => {
|
|
50
|
+
let pos = 7;
|
|
51
|
+
const rgx = /\s+AS\s+"\*(inDb-\d+|inCode-\d+-\d+)\*",?/g;
|
|
52
|
+
let match;
|
|
53
|
+
let inDb = "";
|
|
54
|
+
let codeI = 0;
|
|
55
|
+
const matches = inCode.map(() => true);
|
|
56
|
+
while (match = rgx.exec(resultSql)) {
|
|
57
|
+
const sql = resultSql.slice(pos, rgx.lastIndex - match[0].length).trim();
|
|
58
|
+
const arr = match[1].split("-");
|
|
59
|
+
if (arr.length === 2) {
|
|
60
|
+
inDb = sql;
|
|
61
|
+
codeI = 0;
|
|
62
|
+
} else {
|
|
63
|
+
if (inDb !== sql && // Comparing `(sql) = sql` and `sql = (sql)` below.
|
|
64
|
+
// Could not reproduce this case in integration tests, but it was reported in #494.
|
|
65
|
+
!(inDb.startsWith("(") && inDb.endsWith(")") && inDb.slice(1, -1) === sql) && !(sql.startsWith("(") && sql.endsWith(")") && sql.slice(1, -1) === inDb)) {
|
|
66
|
+
matches[codeI] = false;
|
|
67
|
+
}
|
|
68
|
+
codeI++;
|
|
69
|
+
}
|
|
70
|
+
pos = rgx.lastIndex;
|
|
71
|
+
}
|
|
72
|
+
const firstMatching = matches.indexOf(true);
|
|
73
|
+
return firstMatching === -1 ? void 0 : firstMatching;
|
|
74
|
+
};
|
|
67
75
|
const promptCreateOrRename = (kind, name, drop, verifying) => {
|
|
68
76
|
if (verifying) throw new AbortSignal();
|
|
69
77
|
let hintPos = name.length + 4;
|