rake-db 2.25.9 → 2.25.10
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/index.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -162,7 +162,7 @@ const encodeColumnDefault = (def, values, column) => {
|
|
|
162
162
|
return def.toSQL({ values });
|
|
163
163
|
} else {
|
|
164
164
|
return pqb.escapeForMigration(
|
|
165
|
-
column?.data.encode ? column.data.encode(def) : def
|
|
165
|
+
column instanceof pqb.ArrayColumn && Array.isArray(def) ? "{" + (column.data.item.data.encode ? def.map((x) => column.data.item.data.encode(x)) : def).join(",") + "}" : column?.data.encode ? column.data.encode(def) : def
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -1179,8 +1179,9 @@ const handleTableItemChange = (key, item, ast, alterTable, renameItems, values,
|
|
|
1179
1179
|
if (to.type && (from.type !== to.type || from.collate !== to.collate)) {
|
|
1180
1180
|
changeType = true;
|
|
1181
1181
|
const type = !to.column || to.column.data.isOfCustomType ? to.column && to.column instanceof pqb.DomainColumn ? quoteNameFromString(to.type) : quoteCustomType(to.type) : to.type;
|
|
1182
|
+
const using = item.using?.usingUp ? ` USING ${item.using.usingUp.toSQL({ values })}` : to.column instanceof pqb.EnumColumn ? ` USING "${name}"::text::${type}` : to.column instanceof pqb.ArrayColumn ? ` USING "${name}"::text[]::${type}` : "";
|
|
1182
1183
|
alterTable.push(
|
|
1183
|
-
`ALTER COLUMN "${name}" TYPE ${type}${to.collate ? ` COLLATE ${quoteNameFromString(to.collate)}` : ""}${
|
|
1184
|
+
`ALTER COLUMN "${name}" TYPE ${type}${to.collate ? ` COLLATE ${quoteNameFromString(to.collate)}` : ""}${using}`
|
|
1184
1185
|
);
|
|
1185
1186
|
}
|
|
1186
1187
|
if (typeof from.identity !== typeof to.identity || !orchidCore.deepCompare(from.identity, to.identity)) {
|
|
@@ -2483,11 +2484,15 @@ const recreateEnum = async (migration, { schema, name }, values, errorMessage) =
|
|
|
2483
2484
|
const { rows: tables } = await migration.adapter.query(
|
|
2484
2485
|
`SELECT n.nspname AS "schema",
|
|
2485
2486
|
c.relname AS "table",
|
|
2486
|
-
json_agg(
|
|
2487
|
+
json_agg(
|
|
2488
|
+
json_build_object('name', a.attname, 'arrayDims', a.attndims)
|
|
2489
|
+
ORDER BY a.attnum
|
|
2490
|
+
) AS "columns"
|
|
2487
2491
|
FROM pg_class c
|
|
2488
2492
|
JOIN pg_catalog.pg_namespace n ON n.oid = relnamespace
|
|
2489
|
-
JOIN
|
|
2490
|
-
JOIN pg_type t ON
|
|
2493
|
+
JOIN pg_type bt ON bt.typname = ${orchidCore.singleQuote(name)}
|
|
2494
|
+
JOIN pg_type t ON t.oid = bt.oid OR t.typelem = bt.oid
|
|
2495
|
+
JOIN pg_attribute a ON a.attrelid = c.oid AND a.atttypid = t.oid
|
|
2491
2496
|
JOIN pg_namespace tn ON tn.oid = t.typnamespace AND tn.nspname = ${orchidCore.singleQuote(
|
|
2492
2497
|
schema ?? defaultSchema
|
|
2493
2498
|
)}
|
|
@@ -2496,7 +2501,9 @@ GROUP BY n.nspname, c.relname`
|
|
|
2496
2501
|
);
|
|
2497
2502
|
const sql = tables.map(
|
|
2498
2503
|
(t) => `ALTER TABLE ${quoteTable(t.schema, t.table)}
|
|
2499
|
-
${t.columns.map(
|
|
2504
|
+
${t.columns.map(
|
|
2505
|
+
(c) => ` ALTER COLUMN "${c.name}" TYPE text${"[]".repeat(c.arrayDims)}`
|
|
2506
|
+
).join(",\n")}`
|
|
2500
2507
|
);
|
|
2501
2508
|
sql.push(
|
|
2502
2509
|
`DROP TYPE ${quotedName}`,
|
|
@@ -2506,14 +2513,17 @@ GROUP BY n.nspname, c.relname`
|
|
|
2506
2513
|
for (const t of tables) {
|
|
2507
2514
|
const table = quoteTable(t.schema, t.table);
|
|
2508
2515
|
for (const c of t.columns) {
|
|
2516
|
+
const type = quotedName + "[]".repeat(c.arrayDims);
|
|
2509
2517
|
try {
|
|
2510
2518
|
await migration.adapter.query(
|
|
2511
2519
|
`ALTER TABLE ${table}
|
|
2512
|
-
ALTER COLUMN "${c}" TYPE ${
|
|
2520
|
+
ALTER COLUMN "${c.name}" TYPE ${type} USING "${c.name}"::${type}`
|
|
2513
2521
|
);
|
|
2514
2522
|
} catch (err) {
|
|
2515
2523
|
if (err.code === "22P02") {
|
|
2516
|
-
throw new Error(errorMessage(quotedName, table, c), {
|
|
2524
|
+
throw new Error(errorMessage(quotedName, table, c.name), {
|
|
2525
|
+
cause: err
|
|
2526
|
+
});
|
|
2517
2527
|
}
|
|
2518
2528
|
throw err;
|
|
2519
2529
|
}
|
|
@@ -4240,7 +4250,8 @@ const instantiateDbColumn = (ctx, data, domains, dbColumn) => {
|
|
|
4240
4250
|
if (domainColumn) {
|
|
4241
4251
|
column = new pqb.DomainColumn(
|
|
4242
4252
|
ctx.columnSchemaConfig,
|
|
4243
|
-
|
|
4253
|
+
typeName,
|
|
4254
|
+
typeSchema,
|
|
4244
4255
|
dbColumn.extension
|
|
4245
4256
|
).as(domainColumn);
|
|
4246
4257
|
} else {
|
|
@@ -4257,7 +4268,8 @@ const instantiateDbColumn = (ctx, data, domains, dbColumn) => {
|
|
|
4257
4268
|
} else {
|
|
4258
4269
|
column = new pqb.CustomTypeColumn(
|
|
4259
4270
|
ctx.columnSchemaConfig,
|
|
4260
|
-
|
|
4271
|
+
typeName,
|
|
4272
|
+
typeSchema === "pg_catalog" ? void 0 : typeSchema,
|
|
4261
4273
|
dbColumn.extension
|
|
4262
4274
|
);
|
|
4263
4275
|
((_a = ctx.unsupportedTypes)[_b = dbColumn.type] ?? (_a[_b] = [])).push(
|
|
@@ -4941,7 +4953,7 @@ ${group.map(
|
|
|
4941
4953
|
return code;
|
|
4942
4954
|
};
|
|
4943
4955
|
const astEncoders = {
|
|
4944
|
-
table(ast, config) {
|
|
4956
|
+
table(ast, config, currentSchema) {
|
|
4945
4957
|
let code = [];
|
|
4946
4958
|
const result = code;
|
|
4947
4959
|
const hasOptions = Boolean(ast.comment || ast.noPrimaryKey === "ignore");
|
|
@@ -4975,6 +4987,7 @@ const astEncoders = {
|
|
|
4975
4987
|
const toCodeCtx = {
|
|
4976
4988
|
t: "t",
|
|
4977
4989
|
table: ast.name,
|
|
4990
|
+
currentSchema,
|
|
4978
4991
|
migration: true,
|
|
4979
4992
|
snakeCase: config.snakeCase
|
|
4980
4993
|
};
|
|
@@ -5030,6 +5043,7 @@ const astEncoders = {
|
|
|
5030
5043
|
const toCodeCtx = {
|
|
5031
5044
|
t: "t",
|
|
5032
5045
|
table: ast.name,
|
|
5046
|
+
currentSchema,
|
|
5033
5047
|
migration: true,
|
|
5034
5048
|
snakeCase: config.snakeCase
|
|
5035
5049
|
};
|
|
@@ -5062,6 +5076,7 @@ const astEncoders = {
|
|
|
5062
5076
|
{
|
|
5063
5077
|
t: "t",
|
|
5064
5078
|
table: ast.name,
|
|
5079
|
+
currentSchema,
|
|
5065
5080
|
migration: true,
|
|
5066
5081
|
snakeCase: config.snakeCase
|
|
5067
5082
|
},
|
|
@@ -5198,11 +5213,11 @@ const astEncoders = {
|
|
|
5198
5213
|
ast
|
|
5199
5214
|
)}, [${ast.fromValues.map(orchidCore.singleQuote).join(", ")}], [${ast.toValues.map(orchidCore.singleQuote).join(", ")}]);`;
|
|
5200
5215
|
},
|
|
5201
|
-
domain(ast) {
|
|
5216
|
+
domain(ast, _, currentSchema) {
|
|
5202
5217
|
return `await db.${ast.action}Domain(${quoteSchemaTable(
|
|
5203
5218
|
ast
|
|
5204
5219
|
)}, (t) => ${ast.baseType.toCode(
|
|
5205
|
-
{ t: "t", table: ast.name },
|
|
5220
|
+
{ t: "t", table: ast.name, currentSchema },
|
|
5206
5221
|
ast.baseType.data.name ?? ""
|
|
5207
5222
|
)});`;
|
|
5208
5223
|
},
|