orchid-orm 1.57.6 → 1.57.7
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/node-postgres.js +34 -38
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +35 -39
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +34 -38
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +35 -39
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -10,43 +10,33 @@ var typescript = require('typescript');
|
|
|
10
10
|
var postgresJs = require('rake-db/postgres-js');
|
|
11
11
|
|
|
12
12
|
const compareSqlExpressions = async (tableExpressions, adapter) => {
|
|
13
|
-
if (tableExpressions.length)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const match = compareSqlExpressionResult(
|
|
43
|
-
result.rows[0].v,
|
|
44
|
-
compare[0].inCode
|
|
45
|
-
);
|
|
46
|
-
handle(match);
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
}
|
|
13
|
+
if (!tableExpressions.length) return;
|
|
14
|
+
let id = 1;
|
|
15
|
+
await Promise.all(
|
|
16
|
+
tableExpressions.map(async ({ source, compare, handle }) => {
|
|
17
|
+
const viewName = `orchidTmpView${id++}`;
|
|
18
|
+
const values = [];
|
|
19
|
+
const combinedQueries = [
|
|
20
|
+
`CREATE TEMPORARY VIEW ${viewName} AS (SELECT ${compare.map(
|
|
21
|
+
({ inDb, inCode }, i) => `${inDb} AS "*inDb-${i}*", ${inCode.map(
|
|
22
|
+
(s, j) => `(${typeof s === "string" ? s : s.toSQL({ values })}) "*inCode-${i}-${j}*"`
|
|
23
|
+
).join(", ")}`
|
|
24
|
+
).join(", ")} FROM ${source})`,
|
|
25
|
+
`SELECT pg_get_viewdef('${viewName}') v`,
|
|
26
|
+
`DROP VIEW ${viewName}`
|
|
27
|
+
].join("; ");
|
|
28
|
+
const result = await adapter.query(combinedQueries, values).then((res) => res[1], orchidCore.noop);
|
|
29
|
+
if (!result) {
|
|
30
|
+
handle();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const match = compareSqlExpressionResult(
|
|
34
|
+
result.rows[0].v,
|
|
35
|
+
compare[0].inCode
|
|
36
|
+
);
|
|
37
|
+
handle(match);
|
|
38
|
+
})
|
|
39
|
+
);
|
|
50
40
|
};
|
|
51
41
|
const compareSqlExpressionResult = (resultSql, inCode) => {
|
|
52
42
|
let pos = 7;
|
|
@@ -628,6 +618,12 @@ const getColumnDbType = (column, currentSchema) => {
|
|
|
628
618
|
return column.dataType;
|
|
629
619
|
}
|
|
630
620
|
};
|
|
621
|
+
const getColumnDbTypeQuoted = (column, currentSchema) => {
|
|
622
|
+
const [schema, type] = rakeDb.getSchemaAndTableFromName(
|
|
623
|
+
getColumnDbType(column, currentSchema)
|
|
624
|
+
);
|
|
625
|
+
return schema ? `"${schema}"."${type}"` : `"${type}"`;
|
|
626
|
+
};
|
|
631
627
|
const renameColumn = (columns, from, to) => {
|
|
632
628
|
for (let i = 0; i < columns.length; i++) {
|
|
633
629
|
if (columns[i] === from) {
|
|
@@ -1977,7 +1973,7 @@ const applyChangeTables = async (adapter, changeTables, structureToAstCtx, dbStr
|
|
|
1977
1973
|
if (!column.dataType) continue;
|
|
1978
1974
|
const name = column.data.name ?? key;
|
|
1979
1975
|
names.push(name);
|
|
1980
|
-
types.push(
|
|
1976
|
+
types.push(getColumnDbTypeQuoted(column, currentSchema));
|
|
1981
1977
|
}
|
|
1982
1978
|
const tableName = codeTable.table;
|
|
1983
1979
|
const source = `(VALUES (${types.map((x) => `NULL::${x}`).join(", ")})) "${tableName}"(${names.map((x) => `"${x}"`).join(", ")})`;
|