orchid-orm 1.58.6 → 1.58.8
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 +58 -40
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +58 -40
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +58 -40
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +58 -40
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -9,38 +9,37 @@ export * from 'rake-db/node-postgres';
|
|
|
9
9
|
const compareSqlExpressions = async (tableExpressions, adapter) => {
|
|
10
10
|
if (!tableExpressions.length) return;
|
|
11
11
|
let id = 1;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
12
|
+
for (const { source, compare, handle } of tableExpressions) {
|
|
13
|
+
const viewName = `orchidTmpView${id++}`;
|
|
14
|
+
const values = [];
|
|
15
|
+
const combinedQueries = [
|
|
16
|
+
`CREATE TEMPORARY VIEW ${viewName} AS (SELECT ${compare.map(
|
|
17
|
+
({ inDb, inCode }, i) => `${inDb} AS "*inDb-${i}*", ${inCode.map(
|
|
18
|
+
(s, j) => `(${typeof s === "string" ? s : s.toSQL({ values })}) "*inCode-${i}-${j}*"`
|
|
19
|
+
).join(", ")}`
|
|
20
|
+
).join(", ")} FROM ${source})`,
|
|
21
|
+
`SELECT pg_get_viewdef('${viewName}') v`,
|
|
22
|
+
`DROP VIEW ${viewName}`
|
|
23
|
+
].join("; ");
|
|
24
|
+
const result = await adapter.query(combinedQueries, values, viewName).then(
|
|
25
|
+
(res) => res[1],
|
|
26
|
+
async (err) => {
|
|
27
|
+
await adapter.query(`ROLLBACK TO SAVEPOINT "${viewName}"`);
|
|
28
|
+
if (err.code !== "42704") {
|
|
29
|
+
throw err;
|
|
31
30
|
}
|
|
32
|
-
);
|
|
33
|
-
if (!result) {
|
|
34
|
-
handle();
|
|
35
|
-
return;
|
|
36
31
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
);
|
|
33
|
+
if (!result) {
|
|
34
|
+
handle();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const match = compareSqlExpressionResult(
|
|
38
|
+
result.rows[0].v,
|
|
39
|
+
compare[0].inCode
|
|
40
|
+
);
|
|
41
|
+
handle(match);
|
|
42
|
+
}
|
|
44
43
|
};
|
|
45
44
|
const compareSqlExpressionResult = (resultSql, inCode) => {
|
|
46
45
|
let pos = 7;
|
|
@@ -605,27 +604,23 @@ const getColumnDbType = (column, currentSchema) => {
|
|
|
605
604
|
const [schema = currentSchema, name] = getSchemaAndTableFromName(
|
|
606
605
|
column.enumName
|
|
607
606
|
);
|
|
608
|
-
return
|
|
607
|
+
return `${schema}.${name}`;
|
|
609
608
|
} else if (column instanceof ArrayColumn) {
|
|
610
609
|
const { item } = column.data;
|
|
611
610
|
let type = item instanceof EnumColumn ? item.enumName : item.dataType;
|
|
612
611
|
type = type.startsWith(currentSchema + ".") ? type.slice(currentSchema.length + 1) : type;
|
|
613
612
|
return type + "[]".repeat(column.data.arrayDims);
|
|
614
|
-
} else {
|
|
613
|
+
} else if (column.data.isOfCustomType) {
|
|
615
614
|
let type = column.dataType;
|
|
616
615
|
const i = type.indexOf("(");
|
|
617
616
|
if (i !== -1) {
|
|
618
617
|
type = type.slice(0, i);
|
|
619
618
|
}
|
|
620
|
-
return
|
|
619
|
+
return type.includes(".") ? type : currentSchema + "." + type;
|
|
620
|
+
} else {
|
|
621
|
+
return column.dataType;
|
|
621
622
|
}
|
|
622
623
|
};
|
|
623
|
-
const getColumnDbTypeQuoted = (column, currentSchema) => {
|
|
624
|
-
const [schema, type] = getSchemaAndTableFromName(
|
|
625
|
-
getColumnDbType(column, currentSchema)
|
|
626
|
-
);
|
|
627
|
-
return schema ? `"${schema}"."${type}"` : `"${type}"`;
|
|
628
|
-
};
|
|
629
624
|
const renameColumn = (columns, from, to) => {
|
|
630
625
|
for (let i = 0; i < columns.length; i++) {
|
|
631
626
|
if (columns[i] === from) {
|
|
@@ -1984,7 +1979,7 @@ const applyChangeTables = async (adapter, changeTables, structureToAstCtx, dbStr
|
|
|
1984
1979
|
const column = codeTable.shape[key];
|
|
1985
1980
|
if (!column.dataType) continue;
|
|
1986
1981
|
const name = column.data.name ?? key;
|
|
1987
|
-
const type =
|
|
1982
|
+
const type = getColumnDbTypeForComparison(column, currentSchema);
|
|
1988
1983
|
if (!pendingDbTypes.set.has(type)) {
|
|
1989
1984
|
names.push(name);
|
|
1990
1985
|
types.push(type);
|
|
@@ -1998,6 +1993,29 @@ const applyChangeTables = async (adapter, changeTables, structureToAstCtx, dbStr
|
|
|
1998
1993
|
}
|
|
1999
1994
|
}
|
|
2000
1995
|
};
|
|
1996
|
+
const getColumnDbTypeForComparison = (column, currentSchema) => {
|
|
1997
|
+
if (column instanceof EnumColumn) {
|
|
1998
|
+
return "text";
|
|
1999
|
+
}
|
|
2000
|
+
if (column instanceof ArrayColumn) {
|
|
2001
|
+
return getColumnDbTypeForComparison(column.data.item, currentSchema) + "[]".repeat(column.data.arrayDims);
|
|
2002
|
+
}
|
|
2003
|
+
let type = column.dataType;
|
|
2004
|
+
const i = type.indexOf("(");
|
|
2005
|
+
let append = "";
|
|
2006
|
+
if (i !== -1) {
|
|
2007
|
+
type = type.slice(0, i);
|
|
2008
|
+
append = type.slice(i);
|
|
2009
|
+
}
|
|
2010
|
+
const j = type.indexOf(".");
|
|
2011
|
+
if (j === -1) {
|
|
2012
|
+
let result = `"${type}"${append}`;
|
|
2013
|
+
if (column.data.isOfCustomType) result = `"${currentSchema}".${result}`;
|
|
2014
|
+
return result;
|
|
2015
|
+
} else {
|
|
2016
|
+
return `"${type.slice(j)}"."${type.slice(0, j)}"${append}`;
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2001
2019
|
const applyCompareSql = async (compareSql, adapter) => {
|
|
2002
2020
|
if (compareSql.expressions.length) {
|
|
2003
2021
|
const {
|