@prisma/orm-target-postgres 8.0.0-rc.22-dev.7 → 8.0.0-rc.22-dev.9
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/{control-policy-RIiGtzLL-dMGUsj7L.mjs → control-policy-K52VpMX0-CateWffI.mjs} +7 -3
- package/dist/control-policy-K52VpMX0-CateWffI.mjs.map +1 -0
- package/dist/{diff-database-schema-CvA43-eB-BVodpxgx.mjs → diff-database-schema-D_vOsC7_-CtLt0OwZ.mjs} +3 -3
- package/dist/{diff-database-schema-CvA43-eB-BVodpxgx.mjs.map → diff-database-schema-D_vOsC7_-CtLt0OwZ.mjs.map} +1 -1
- package/dist/{issue-planner-BUo9S9Ge.d.mts → issue-planner-CbixMGS1.d.mts} +2 -2
- package/dist/{issue-planner-BUo9S9Ge.d.mts.map → issue-planner-CbixMGS1.d.mts.map} +1 -1
- package/dist/migration-Be_iuIpn.mjs.map +1 -1
- package/dist/{migration-Drs_EeiM.d.mts → migration-XqRvlRWn.d.mts} +2 -2
- package/dist/{migration-Drs_EeiM.d.mts.map → migration-XqRvlRWn.d.mts.map} +1 -1
- package/dist/op-factory-call-DO-2Ul_8.d.mts +1 -0
- package/dist/{op-factory-call-Ek2u4dEh-CIUcdOdr.mjs → op-factory-call-DQW9c0ec-C3qv_STE.mjs} +478 -38
- package/dist/op-factory-call-DQW9c0ec-C3qv_STE.mjs.map +1 -0
- package/dist/{op-factory-call-L1gqYhhk-DMnspvjf.d.mts → op-factory-call-fPC4Yzy6-B6JHyh7J.d.mts} +80 -9
- package/dist/op-factory-call-fPC4Yzy6-B6JHyh7J.d.mts.map +1 -0
- package/dist/{pack-ClOo5FU_.d.mts → pack-BhLR51a_.d.mts} +2 -2
- package/dist/{pack-ClOo5FU_.d.mts.map → pack-BhLR51a_.d.mts.map} +1 -1
- package/dist/{planner-CXGxEHRs-DnblCRvf.mjs → planner-BsSEbzfm-BrBEb_M1.mjs} +87 -68
- package/dist/planner-BsSEbzfm-BrBEb_M1.mjs.map +1 -0
- package/dist/{planner-Bl3kIyMG.d.mts → planner-Cw5KV0_B.d.mts} +2 -2
- package/dist/{planner-Bl3kIyMG.d.mts.map → planner-Cw5KV0_B.d.mts.map} +1 -1
- package/dist/planner-produced-postgres-migration-CoX6OBqo.d.mts +1 -0
- package/dist/{planner-produced-postgres-migration-Cx9bERx3-DRNnR16E.d.mts → planner-produced-postgres-migration-DgUtdqVh-DEhVIDmO.d.mts} +3 -3
- package/dist/planner-produced-postgres-migration-DgUtdqVh-DEhVIDmO.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-rvb49AcU-Cg2CikBV.mjs → planner-produced-postgres-migration-bn60skNP-CKjpb3S_.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-rvb49AcU-Cg2CikBV.mjs.map → planner-produced-postgres-migration-bn60skNP-CKjpb3S_.mjs.map} +1 -1
- package/dist/{postgres-migration-D0tEWVZ9-tr0Nt3a2.mjs → postgres-migration-CVWCygKt-DEXT0FE_.mjs} +48 -8
- package/dist/postgres-migration-CVWCygKt-DEXT0FE_.mjs.map +1 -0
- package/dist/{postgres-migration-DNnmFBsR-BJU9865a.d.mts → postgres-migration-MVAsm-Co-CcN0UJd7.d.mts} +53 -3
- package/dist/postgres-migration-MVAsm-Co-CcN0UJd7.d.mts.map +1 -0
- package/dist/{prisma7-binding-Bb8yzr_1.d.mts → prisma7-binding-DixgLN05.d.mts} +2 -2
- package/dist/{prisma7-binding-Bb8yzr_1.d.mts.map → prisma7-binding-DixgLN05.d.mts.map} +1 -1
- package/dist/{render-ops-B0eNPFAw-BgUftmhY.mjs → render-ops-BKDfKgOJ-DmoHztdY.mjs} +3 -3
- package/dist/{render-ops-B0eNPFAw-BgUftmhY.mjs.map → render-ops-BKDfKgOJ-DmoHztdY.mjs.map} +1 -1
- package/dist/target.d.mts +11 -11
- package/dist/target.mjs +8 -8
- package/dist/target__control.mjs +30 -32
- package/dist/target__control.mjs.map +1 -1
- package/dist/target__diff-database-schema.mjs +1 -1
- package/dist/target__issue-planner.d.mts +1 -1
- package/dist/target__issue-planner.mjs +1 -1
- package/dist/target__migration.d.mts +2 -2
- package/dist/target__migration.mjs +2 -2
- package/dist/target__op-factory-call.d.mts +3 -3
- package/dist/target__op-factory-call.mjs +2 -2
- package/dist/target__pack.d.mts +1 -1
- package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
- package/dist/target__planner-produced-postgres-migration.mjs +1 -1
- package/dist/target__planner.d.mts +1 -1
- package/dist/target__planner.mjs +2 -2
- package/dist/target__prisma7-binding.d.mts +1 -1
- package/dist/target__render-ops.mjs +1 -1
- package/package.json +10 -10
- package/dist/control-policy-RIiGtzLL-dMGUsj7L.mjs.map +0 -1
- package/dist/op-factory-call-D2HXLJQJ.d.mts +0 -1
- package/dist/op-factory-call-Ek2u4dEh-CIUcdOdr.mjs.map +0 -1
- package/dist/op-factory-call-L1gqYhhk-DMnspvjf.d.mts.map +0 -1
- package/dist/planner-CXGxEHRs-DnblCRvf.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-Cx9bERx3-DRNnR16E.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-DRPVY4iL.d.mts +0 -1
- package/dist/postgres-migration-D0tEWVZ9-tr0Nt3a2.mjs.map +0 -1
- package/dist/postgres-migration-DNnmFBsR-BJU9865a.d.mts.map +0 -1
package/dist/{op-factory-call-Ek2u4dEh-CIUcdOdr.mjs → op-factory-call-DQW9c0ec-C3qv_STE.mjs}
RENAMED
|
@@ -11,17 +11,18 @@ import { t as buildTargetDetails } from "./planner-target-details-CUEF0s90-6g-mO
|
|
|
11
11
|
import { DdlColumn, FunctionColumnDefault, LiteralColumnDefault, opaqueSql } from "@prisma/orm-family-sql/relational-core/ast";
|
|
12
12
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
13
13
|
import { InternalError, assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
14
|
+
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
14
15
|
import { type } from "arktype";
|
|
15
16
|
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
16
17
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
17
18
|
import { expectAbsent, expectPresent } from "@prisma/orm-framework/components/control";
|
|
18
19
|
import { namingOf } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
19
20
|
import { checkExpression, col } from "@prisma/orm-family-sql/relational-core/contract-free";
|
|
20
|
-
import { checkSqlDefaultText, checkSqlExpressionText, convertedColumnMeta, createSqlTextSources, encodeStoredValue, isUnfilledSlot, requiredColumnMeta, rowsHoldingValueMeta, slotSource, sqlOfSlot } from "@prisma/orm-family-sql/family/control";
|
|
21
|
-
import { unfilledPlaceholderOperation } from "@prisma/orm-framework/errors/migration";
|
|
21
|
+
import { UnfilledValue, checkSqlDefaultText, checkSqlExpressionText, convertedColumnMeta, createSqlTextSources, encodeStoredValue, fillKeyProblem, fillValueProblem, isUnfilledSlot, keyPathOf, parseJsonPath, requiredColumnMeta, rowsHoldingValueMeta, slotSource, sqlOfSlot } from "@prisma/orm-family-sql/family/control";
|
|
22
|
+
import { errorUnfilledPlaceholder, unfilledPlaceholderOperation } from "@prisma/orm-framework/errors/migration";
|
|
22
23
|
import { TsExpression, jsonToTsSource, tsObjectSource } from "@prisma/orm-framework/ts-render";
|
|
23
24
|
import { REFERENTIAL_ACTION_SQL } from "@prisma/orm-family-sql/contract/referential-action-sql";
|
|
24
|
-
//#region ../../../3-targets/postgres/1-target/dist/op-factory-call-
|
|
25
|
+
//#region ../../../3-targets/postgres/1-target/dist/op-factory-call-DQW9c0ec.mjs
|
|
25
26
|
/**
|
|
26
27
|
* Maps a planner schema name to the contract-free DDL builder's optional
|
|
27
28
|
* `schema` field: the unbound sentinel becomes `undefined` (the builder omits
|
|
@@ -1130,6 +1131,133 @@ async function dropSchema(schemaName, lowerer) {
|
|
|
1130
1131
|
postcheck: [step(`verify schema "${schemaName}" does not exist`, absent.sql, absent.params)]
|
|
1131
1132
|
};
|
|
1132
1133
|
}
|
|
1134
|
+
/**
|
|
1135
|
+
* A column read as `jsonb`, so a `json` column takes the same path operations. A rewrite assigned
|
|
1136
|
+
* back to a `json` column is cast to `json` by the assignment, so each row it rewrites is stored in
|
|
1137
|
+
* `jsonb` form: key order and spacing change, and duplicate keys collapse to the last one.
|
|
1138
|
+
*/
|
|
1139
|
+
function asJsonb(column) {
|
|
1140
|
+
return `(${column}::jsonb)`;
|
|
1141
|
+
}
|
|
1142
|
+
function keyLiteral(name) {
|
|
1143
|
+
return `'${escapeLiteral(name)}'`;
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* The children of a list or an object rewritten one by one, keeping a list's order; `kept` filters
|
|
1147
|
+
* them. Any other value is left as it is.
|
|
1148
|
+
*/
|
|
1149
|
+
function rewrittenChildren(value, depth, rewrite, kept) {
|
|
1150
|
+
const e = `e${depth}`;
|
|
1151
|
+
const where = kept === void 0 ? "" : ` WHERE ${kept(`${e}.v`)}`;
|
|
1152
|
+
const rewritten = rewrite(`${e}.v`);
|
|
1153
|
+
return `CASE jsonb_typeof(${value}) WHEN 'array' THEN ${`(SELECT coalesce(jsonb_agg(${rewritten} ORDER BY ${e}.i), '[]'::jsonb) FROM jsonb_array_elements(${value}) WITH ORDINALITY AS ${e}(v, i)${where})`} WHEN 'object' THEN ${`(SELECT coalesce(jsonb_object_agg(${e}.k, ${rewritten}), '{}'::jsonb) FROM jsonb_each(${value}) AS ${e}(k, v)${where})`} ELSE ${value} END`;
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* The `jsonb` expression that rewrites `value` along `steps` with `leaf`. A member step that meets
|
|
1157
|
+
* no object with the member, or a wildcard step that meets neither a list nor an object, leaves the
|
|
1158
|
+
* value as it is.
|
|
1159
|
+
*/
|
|
1160
|
+
function jsonRewrite(value, steps, leaf, depth = 0) {
|
|
1161
|
+
const [first, ...rest] = steps;
|
|
1162
|
+
if (first === void 0) return leaf(value, depth);
|
|
1163
|
+
if (first.kind === "member") {
|
|
1164
|
+
const key = keyLiteral(first.name);
|
|
1165
|
+
return `CASE WHEN jsonb_typeof(${value}) = 'object' AND ${value} ? ${key} THEN jsonb_set(${value}, ARRAY[${key}], ${jsonRewrite(`(${value} -> ${key})`, rest, leaf, depth)}) ELSE ${value} END`;
|
|
1166
|
+
}
|
|
1167
|
+
return rewrittenChildren(value, depth, (child) => jsonRewrite(child, rest, leaf, depth + 1));
|
|
1168
|
+
}
|
|
1169
|
+
function jsonPathString(text) {
|
|
1170
|
+
return JSON.stringify(text);
|
|
1171
|
+
}
|
|
1172
|
+
/** A typed strict SQL/JSON path filter that tests whether the object `@` has member `name`. */
|
|
1173
|
+
function hasMemberFilter(name) {
|
|
1174
|
+
return `exists(@.keyvalue() ? (@.key == ${jsonPathString(name)}))`;
|
|
1175
|
+
}
|
|
1176
|
+
/** A typed strict SQL/JSON path filter that tests whether the object `@` has member `name` with a value other than JSON `null`. */
|
|
1177
|
+
function hasValueFilter(name) {
|
|
1178
|
+
return `exists(@.keyvalue() ? (@.key == ${jsonPathString(name)} && @.value.type() != "null"))`;
|
|
1179
|
+
}
|
|
1180
|
+
/** A typed strict SQL/JSON path filter that tests whether member `name` of the object `@` equals `$v`. */
|
|
1181
|
+
function memberEqualsFilter(name) {
|
|
1182
|
+
return `exists(@.keyvalue() ? (@.key == ${jsonPathString(name)} && @.value == $v))`;
|
|
1183
|
+
}
|
|
1184
|
+
const CONTAINER = "(@.type() == \"array\" || @.type() == \"object\")";
|
|
1185
|
+
/** A strict SQL/JSON path filter that tests whether the list or object `@` has a child equal to `$v`. */
|
|
1186
|
+
const CHILD_EQUALS_FILTER = "exists(@.**{1} ? (@ == $v))";
|
|
1187
|
+
/**
|
|
1188
|
+
* Whether `column` holds, at the end of `steps`, an item that passes `filter`: an object, or with
|
|
1189
|
+
* `container`, a list or an object. Each step tests the type of the item it reads first, so a
|
|
1190
|
+
* SQL/JSON `null`, a missing member, a value of another type or a `null` element or member value
|
|
1191
|
+
* never fails the match or hides another item. A wildcard step reads every child, as `.**{1}` does:
|
|
1192
|
+
* the elements of a list and the member values of an object.
|
|
1193
|
+
*/
|
|
1194
|
+
function jsonPathMatches(column, steps, type, filter, valueParam) {
|
|
1195
|
+
const jsonPath = `strict $${steps.map((step) => step.kind === "member" ? ` ? (@.type() == "object").keyvalue() ? (@.key == ${jsonPathString(step.name)}).value` : ` ? ${CONTAINER}.**{1}`).join("")} ? (${type === "object" ? "@.type() == \"object\"" : CONTAINER} && ${filter})`;
|
|
1196
|
+
const vars = valueParam === void 0 ? "" : `, jsonb_build_object('v', ${valueParam})`;
|
|
1197
|
+
return `jsonb_path_exists(${column}, '${escapeLiteral(jsonPath)}'${vars})`;
|
|
1198
|
+
}
|
|
1199
|
+
function at(keyPath) {
|
|
1200
|
+
return `at path ${JSON.stringify(keyPath.objectsText)}`;
|
|
1201
|
+
}
|
|
1202
|
+
/** Where in a column a key operation acts, as its label and step descriptions write it. */
|
|
1203
|
+
function keyPlace(keyPath, tableName, columnName) {
|
|
1204
|
+
return `${at(keyPath)} in column "${columnName}" of "${tableName}"`;
|
|
1205
|
+
}
|
|
1206
|
+
function noRowWhere(schemaName, tableName, condition) {
|
|
1207
|
+
return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifyTableName(schemaName, tableName)} WHERE ${condition}) AS result`;
|
|
1208
|
+
}
|
|
1209
|
+
function where(columnName, keyPath, filter) {
|
|
1210
|
+
return jsonPathMatches(asJsonb(quoteIdentifier(columnName)), keyPath.objects, "object", filter);
|
|
1211
|
+
}
|
|
1212
|
+
function renameStoredKey(schemaName, tableName, columnName, keyPath, to) {
|
|
1213
|
+
const column = quoteIdentifier(columnName);
|
|
1214
|
+
const from = keyLiteral(keyPath.key);
|
|
1215
|
+
const renamed = jsonRewrite(asJsonb(column), keyPath.objects, (object) => `CASE WHEN jsonb_typeof(${object}) = 'object' AND ${object} ? ${from} THEN (${object} - ${from}) || jsonb_build_object(${keyLiteral(to)}, ${object} -> ${from}) ELSE ${object} END`);
|
|
1216
|
+
const holdsKey = where(columnName, keyPath, hasMemberFilter(keyPath.key));
|
|
1217
|
+
const place = keyPlace(keyPath, tableName, columnName);
|
|
1218
|
+
return {
|
|
1219
|
+
id: `renameStoredKey.${tableName}.${columnName}.${keyPath.path.text}`,
|
|
1220
|
+
label: `Rename key "${keyPath.key}" to "${to}" ${place}`,
|
|
1221
|
+
operationClass: "widening",
|
|
1222
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1223
|
+
precheck: [step(`ensure no object ${place} has both key "${keyPath.key}" and key "${to}"; remove one of the two keys from those objects`, noRowWhere(schemaName, tableName, where(columnName, keyPath, `${hasMemberFilter(keyPath.key)} && ${hasMemberFilter(to)}`)))],
|
|
1224
|
+
execute: [step(`rename key "${keyPath.key}" to "${to}" ${place}`, `UPDATE ${qualifyTableName(schemaName, tableName)} SET ${column} = ${renamed} WHERE ${holdsKey}`)],
|
|
1225
|
+
postcheck: [step(`verify no object ${place} has key "${keyPath.key}"`, noRowWhere(schemaName, tableName, holdsKey))]
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
function removeStoredKey(schemaName, tableName, columnName, keyPath) {
|
|
1229
|
+
const column = quoteIdentifier(columnName);
|
|
1230
|
+
const key = keyLiteral(keyPath.key);
|
|
1231
|
+
const removed = jsonRewrite(asJsonb(column), keyPath.objects, (object) => `CASE WHEN jsonb_typeof(${object}) = 'object' THEN ${object} - ${key} ELSE ${object} END`);
|
|
1232
|
+
const holdsKey = where(columnName, keyPath, hasMemberFilter(keyPath.key));
|
|
1233
|
+
const place = keyPlace(keyPath, tableName, columnName);
|
|
1234
|
+
return {
|
|
1235
|
+
id: `removeStoredKey.${tableName}.${columnName}.${keyPath.path.text}`,
|
|
1236
|
+
label: `Remove key "${keyPath.key}" ${place}`,
|
|
1237
|
+
operationClass: "destructive",
|
|
1238
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1239
|
+
precheck: [],
|
|
1240
|
+
execute: [step(`remove key "${keyPath.key}" ${place}`, `UPDATE ${qualifyTableName(schemaName, tableName)} SET ${column} = ${removed} WHERE ${holdsKey}`)],
|
|
1241
|
+
postcheck: [step(`verify no object ${place} has key "${keyPath.key}"`, noRowWhere(schemaName, tableName, holdsKey))]
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
/** `value` is the JSON text of the value the key takes, passed as a parameter. A key that holds JSON `null` is filled too, as a member that becomes required needs. */
|
|
1245
|
+
function fillStoredKey(schemaName, tableName, columnName, keyPath, value) {
|
|
1246
|
+
const column = quoteIdentifier(columnName);
|
|
1247
|
+
const key = keyLiteral(keyPath.key);
|
|
1248
|
+
const filled = jsonRewrite(asJsonb(column), keyPath.objects, (object) => `CASE WHEN jsonb_typeof(${object}) = 'object' AND coalesce(${object} -> ${key}, 'null'::jsonb) = 'null'::jsonb THEN ${object} || jsonb_build_object(${key}, $1::jsonb) ELSE ${object} END`);
|
|
1249
|
+
const lacksKey = where(columnName, keyPath, `!(${hasValueFilter(keyPath.key)})`);
|
|
1250
|
+
const place = keyPlace(keyPath, tableName, columnName);
|
|
1251
|
+
return {
|
|
1252
|
+
id: `fillStoredKey.${tableName}.${columnName}.${keyPath.path.text}`,
|
|
1253
|
+
label: `Fill key "${keyPath.key}" ${place}`,
|
|
1254
|
+
operationClass: "widening",
|
|
1255
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1256
|
+
precheck: [],
|
|
1257
|
+
execute: [step(`fill key "${keyPath.key}" ${place} in every object that lacks it or holds JSON null there`, `UPDATE ${qualifyTableName(schemaName, tableName)} SET ${column} = ${filled} WHERE ${lacksKey}`, [value])],
|
|
1258
|
+
postcheck: [step(`verify every object ${place} has key "${keyPath.key}"`, noRowWhere(schemaName, tableName, lacksKey))]
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1133
1261
|
/** A stored value as operation ids, labels and step descriptions write it. */
|
|
1134
1262
|
function storedValueText(value) {
|
|
1135
1263
|
return JSON.stringify(value);
|
|
@@ -1173,18 +1301,121 @@ function removeStoredValue(schemaName, tableName, columnName, value, many, mark)
|
|
|
1173
1301
|
tableName,
|
|
1174
1302
|
columnName
|
|
1175
1303
|
]),
|
|
1176
|
-
...mark === void 0 ? {} : { meta: rowsHoldingValueMeta(
|
|
1304
|
+
...mark === void 0 ? {} : { meta: rowsHoldingValueMeta({
|
|
1305
|
+
...mark,
|
|
1306
|
+
table: tableName,
|
|
1307
|
+
column: columnName,
|
|
1308
|
+
storedValue: value
|
|
1309
|
+
}) }
|
|
1177
1310
|
}],
|
|
1178
1311
|
execute: [step(`remove value ${storedValueText(value)} from column "${columnName}"`, `UPDATE ${qualified} SET ${column} = ${removed} WHERE ${holdingValue(column, many)}`, [value])],
|
|
1179
1312
|
postcheck: [valueAbsentCheck(schemaName, tableName, columnName, value, many)]
|
|
1180
1313
|
};
|
|
1181
1314
|
}
|
|
1315
|
+
function deleteRows(schemaName, tableName, columnName, value) {
|
|
1316
|
+
return {
|
|
1317
|
+
id: `deleteRows.${tableName}.${columnName}.${idText(value)}`,
|
|
1318
|
+
label: `Delete the rows of "${tableName}" that hold value ${storedValueText(value)} in column "${columnName}"`,
|
|
1319
|
+
operationClass: "destructive",
|
|
1320
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1321
|
+
precheck: [],
|
|
1322
|
+
execute: [step(`delete the rows of "${tableName}" that hold value ${storedValueText(value)} in column "${columnName}"`, `DELETE FROM ${qualifyTableName(schemaName, tableName)} WHERE ${quoteIdentifier(columnName)} = $1`, [value])],
|
|
1323
|
+
postcheck: [valueAbsentCheck(schemaName, tableName, columnName, value, false)]
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1182
1326
|
function schemaSqlExpression(schemaName) {
|
|
1183
1327
|
return postgresCreateNamespace({
|
|
1184
1328
|
id: schemaName,
|
|
1185
1329
|
entries: { table: {} }
|
|
1186
1330
|
}).schemaSqlExpression();
|
|
1187
1331
|
}
|
|
1332
|
+
function pathParts(path) {
|
|
1333
|
+
const last = path.steps.at(-1);
|
|
1334
|
+
if (last === void 0) throw new InternalError("A stored value path ends at a selector");
|
|
1335
|
+
return {
|
|
1336
|
+
reach: path.steps.slice(0, -1),
|
|
1337
|
+
last
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
/** Whether `column` holds the JSON value of parameter `param` at the end of `path`. */
|
|
1341
|
+
function holdsAtPath(columnSql, path, param) {
|
|
1342
|
+
const column = asJsonb(columnSql);
|
|
1343
|
+
const { reach, last } = pathParts(path);
|
|
1344
|
+
return last.kind === "member" ? jsonPathMatches(column, reach, "object", memberEqualsFilter(last.name), `${param}::jsonb`) : jsonPathMatches(column, reach, "container", CHILD_EQUALS_FILTER, `${param}::jsonb`);
|
|
1345
|
+
}
|
|
1346
|
+
/** The `jsonb` expression that sets the value at the end of `path` that equals `$1` to `replacement`, or, when `replacement` is undefined, removes it from a list or removes the member of an object that holds it. */
|
|
1347
|
+
function rewriteAtPath(columnSql, path, replacement) {
|
|
1348
|
+
const column = asJsonb(columnSql);
|
|
1349
|
+
const { reach, last } = pathParts(path);
|
|
1350
|
+
if (last.kind === "member") {
|
|
1351
|
+
const key = keyLiteral(last.name);
|
|
1352
|
+
return jsonRewrite(column, reach, (object) => `CASE WHEN jsonb_typeof(${object}) = 'object' AND ${object} -> ${key} = $1::jsonb THEN jsonb_set(${object}, ARRAY[${key}], ${replacement ?? "'null'::jsonb"}) ELSE ${object} END`);
|
|
1353
|
+
}
|
|
1354
|
+
return jsonRewrite(column, reach, (container, depth) => replacement === void 0 ? rewrittenChildren(container, depth, (child) => child, (child) => `${child} <> $1::jsonb`) : rewrittenChildren(container, depth, (child) => `CASE WHEN ${child} = $1::jsonb THEN ${replacement} ELSE ${child} END`));
|
|
1355
|
+
}
|
|
1356
|
+
function atPath(path, tableName, columnName) {
|
|
1357
|
+
return `at path ${JSON.stringify(path.text)} in column "${columnName}" of "${tableName}"`;
|
|
1358
|
+
}
|
|
1359
|
+
function valueAbsentAtPathCheck(schemaName, tableName, columnName, value, path) {
|
|
1360
|
+
return step(`verify no row holds value ${JSON.stringify(value)} ${atPath(path, tableName, columnName)}`, `SELECT NOT EXISTS (SELECT 1 FROM ${qualifyTableName(schemaName, tableName)} WHERE ${holdsAtPath(quoteIdentifier(columnName), path, "$1")}) AS result`, [JSON.stringify(value)]);
|
|
1361
|
+
}
|
|
1362
|
+
/** The condition and parameters that find the rows of a column that hold a stored value, at `path` inside its JSON when it is given. */
|
|
1363
|
+
function holdingStoredValue(columnName, storedValue, path) {
|
|
1364
|
+
const column = quoteIdentifier(columnName);
|
|
1365
|
+
if (path === void 0) return {
|
|
1366
|
+
condition: `${column} = $1`,
|
|
1367
|
+
params: [storedValue]
|
|
1368
|
+
};
|
|
1369
|
+
const parsed = parseJsonPath(path);
|
|
1370
|
+
if (!parsed.ok) throw new InternalError(`A stored value path is a JSON path: ${parsed.failure}`);
|
|
1371
|
+
return {
|
|
1372
|
+
condition: holdsAtPath(column, parsed.value, "$1"),
|
|
1373
|
+
params: [JSON.stringify(storedValue)]
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
function replaceStoredValueAtPath(schemaName, tableName, columnName, from, to, path) {
|
|
1377
|
+
const column = quoteIdentifier(columnName);
|
|
1378
|
+
const place = atPath(path, tableName, columnName);
|
|
1379
|
+
return {
|
|
1380
|
+
id: `replaceStoredValue.${tableName}.${columnName}.${path.text}.${idText(from)}`,
|
|
1381
|
+
label: `Replace value ${storedValueText(from)} with ${storedValueText(to)} ${place}`,
|
|
1382
|
+
operationClass: "widening",
|
|
1383
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1384
|
+
precheck: [],
|
|
1385
|
+
execute: [step(`replace value ${storedValueText(from)} with ${storedValueText(to)} ${place}`, `UPDATE ${qualifyTableName(schemaName, tableName)} SET ${column} = ${rewriteAtPath(column, path, "$2::jsonb")} WHERE ${holdsAtPath(column, path, "$1")}`, [JSON.stringify(from), JSON.stringify(to)])],
|
|
1386
|
+
postcheck: [valueAbsentAtPathCheck(schemaName, tableName, columnName, from, path)]
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Removes a stored value inside JSON: takes it out of a list, or removes its member from an object,
|
|
1391
|
+
* when `path` ends at a wildcard, else sets the member to JSON `null`. When the member takes no
|
|
1392
|
+
* null, the check fails while a row holds the value.
|
|
1393
|
+
*/
|
|
1394
|
+
function removeStoredValueAtPath(schemaName, tableName, columnName, value, path, nullable, mark) {
|
|
1395
|
+
const column = quoteIdentifier(columnName);
|
|
1396
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
1397
|
+
const place = atPath(path, tableName, columnName);
|
|
1398
|
+
const holds = holdsAtPath(column, path, "$1");
|
|
1399
|
+
const required = pathParts(path).last.kind === "member" && !nullable;
|
|
1400
|
+
return {
|
|
1401
|
+
id: `removeStoredValue.${tableName}.${columnName}.${path.text}.${idText(value)}`,
|
|
1402
|
+
label: `Remove value ${storedValueText(value)} ${place}`,
|
|
1403
|
+
operationClass: "destructive",
|
|
1404
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1405
|
+
precheck: required ? [{
|
|
1406
|
+
...step(`ensure no row holds ${storedValueText(value)} ${place}, a member that takes no null`, `SELECT NOT EXISTS (SELECT 1 FROM ${qualified} WHERE ${holds}) AS result`, [JSON.stringify(value)]),
|
|
1407
|
+
...mark === void 0 ? {} : { meta: rowsHoldingValueMeta({
|
|
1408
|
+
...mark,
|
|
1409
|
+
table: tableName,
|
|
1410
|
+
column: columnName,
|
|
1411
|
+
storedValue: value,
|
|
1412
|
+
path: path.text
|
|
1413
|
+
}) }
|
|
1414
|
+
}] : [],
|
|
1415
|
+
execute: [step(`remove value ${storedValueText(value)} ${place}`, `UPDATE ${qualified} SET ${column} = ${rewriteAtPath(column, path, void 0)} WHERE ${holds}`, [JSON.stringify(value)])],
|
|
1416
|
+
postcheck: [valueAbsentAtPathCheck(schemaName, tableName, columnName, value, path)]
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1188
1419
|
async function dropTable(schemaName, tableName, lowerer) {
|
|
1189
1420
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
1190
1421
|
const checks = tableExistsAst(schemaName, tableName);
|
|
@@ -1295,27 +1526,6 @@ async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
|
1295
1526
|
]
|
|
1296
1527
|
};
|
|
1297
1528
|
}
|
|
1298
|
-
/**
|
|
1299
|
-
* Postgres migration IR: one concrete `*Call` class per pure factory under
|
|
1300
|
-
* `operations/`, plus a shared `PostgresOpFactoryCallNode` abstract base.
|
|
1301
|
-
*
|
|
1302
|
-
* Every call class carries the literal arguments its backing factory would
|
|
1303
|
-
* receive, computes a human-readable `label` in its constructor, and
|
|
1304
|
-
* implements two polymorphic hooks:
|
|
1305
|
-
*
|
|
1306
|
-
* - `toOp()` — converts the IR node to a runtime
|
|
1307
|
-
* `SqlMigrationPlanOperation` by delegating to the matching pure factory
|
|
1308
|
-
* under `operations/`. `DataTransformCall.toOp()` always rejects with
|
|
1309
|
-
* `MIGRATION.UNFILLED_PLACEHOLDER` because a planner-generated data transform is an
|
|
1310
|
-
* unfilled authoring stub by construction.
|
|
1311
|
-
* - `renderTypeScript()` / `importRequirements()` — inherited from
|
|
1312
|
-
* `TsExpression`. Used by `renderCallsToTypeScript` to emit the call as
|
|
1313
|
-
* a TypeScript expression inside the scaffolded `migration.ts`.
|
|
1314
|
-
*
|
|
1315
|
-
* The abstract base and all concrete classes are package-private. External
|
|
1316
|
-
* consumers see only the framework-level `OpFactoryCall` interface and the
|
|
1317
|
-
* `PostgresOpFactoryCall` union.
|
|
1318
|
-
*/
|
|
1319
1529
|
const POSTGRES_MIGRATION_FACADE = "@internal/postgres/migration";
|
|
1320
1530
|
var PostgresOpFactoryCallNode = class extends TsExpression {
|
|
1321
1531
|
/** The operations this call lowers to, in order: one, unless the call carries companions. */
|
|
@@ -2762,15 +2972,33 @@ var AddNativeEnumValueCall = class extends PostgresOpFactoryCallNode {
|
|
|
2762
2972
|
return [];
|
|
2763
2973
|
}
|
|
2764
2974
|
};
|
|
2765
|
-
function replaceStoredValueSource(location, from, to, many, codec) {
|
|
2975
|
+
function replaceStoredValueSource(location, from, to, many, codec, path) {
|
|
2766
2976
|
return `this.replaceStoredValue({ ${[
|
|
2767
2977
|
...location,
|
|
2978
|
+
...pathSource(path),
|
|
2768
2979
|
`from: ${from}`,
|
|
2769
2980
|
`to: ${to}`,
|
|
2770
2981
|
...many ? ["many: true"] : [],
|
|
2771
2982
|
...codecRefSource(codec)
|
|
2772
2983
|
].join(", ")} })`;
|
|
2773
2984
|
}
|
|
2985
|
+
function pathSource(path) {
|
|
2986
|
+
return path === void 0 ? [] : [`path: ${jsonToTsSource(path.text)}`];
|
|
2987
|
+
}
|
|
2988
|
+
function storedValuePlace(path, tableName, columnName) {
|
|
2989
|
+
return path === void 0 ? `in column "${columnName}" of "${tableName}"` : `at path ${JSON.stringify(path.text)} in column "${columnName}" of "${tableName}"`;
|
|
2990
|
+
}
|
|
2991
|
+
/**
|
|
2992
|
+
* The path a stored value call acts at inside JSON: it ends at a member name or at a list
|
|
2993
|
+
* wildcard, and the value is compared as a JSON value, so it takes no codec and no list column.
|
|
2994
|
+
*/
|
|
2995
|
+
function requireValuePath(path, options, factory, location) {
|
|
2996
|
+
if (path === void 0) return void 0;
|
|
2997
|
+
const parsed = requirePath(path, factory, location);
|
|
2998
|
+
if (parsed.steps.length === 0) refusedArgument(factory, location, "path", `path ${JSON.stringify(path)} does not end at a member name or a wildcard ([*] or .*)`);
|
|
2999
|
+
if (options.many || options.codec !== void 0) refusedArgument(factory, location, "path", "path takes neither many nor codecRef: a value inside JSON is compared as a JSON value");
|
|
3000
|
+
return parsed;
|
|
3001
|
+
}
|
|
2774
3002
|
function codecRefSource(codec) {
|
|
2775
3003
|
return codec === void 0 ? [] : [`codecRef: ${jsonToTsSource(codec.codecRef)}`];
|
|
2776
3004
|
}
|
|
@@ -2779,7 +3007,7 @@ function requireStoredValue(value, factory, location, argument) {
|
|
|
2779
3007
|
const got = value;
|
|
2780
3008
|
throw postgresError("CONTRACT.ARGUMENT_INVALID", `${factory}({ ${location.join(", ")} }): ${argument} must be a string or a number; got ${typeof got === "number" || got === void 0 ? String(got) : JSON.stringify(got)}`, { meta: { what: `${factory} ${argument}` } });
|
|
2781
3009
|
}
|
|
2782
|
-
/** Changes one stored value of a column to another, in every row, or in every list of a list column. */
|
|
3010
|
+
/** Changes one stored value of a column to another, in every row, or in every list of a list column, or at a path inside the JSON of the column. */
|
|
2783
3011
|
var ReplaceStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
2784
3012
|
factoryName = "replaceStoredValue";
|
|
2785
3013
|
operationClass = "widening";
|
|
@@ -2791,8 +3019,10 @@ var ReplaceStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
|
2791
3019
|
many;
|
|
2792
3020
|
/** The column's codec, which writes `from` and `to` as the database stores them. */
|
|
2793
3021
|
codec;
|
|
3022
|
+
/** The path inside the column's JSON at which the value is replaced, compared as a JSON value. */
|
|
3023
|
+
path;
|
|
2794
3024
|
label;
|
|
2795
|
-
constructor(schemaName, tableName, columnName, from, to, many, codec) {
|
|
3025
|
+
constructor(schemaName, tableName, columnName, from, to, many, codec, path) {
|
|
2796
3026
|
super();
|
|
2797
3027
|
const location = columnCallLocation(schemaName, tableName, columnName);
|
|
2798
3028
|
this.codec = codec;
|
|
@@ -2802,20 +3032,25 @@ var ReplaceStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
|
2802
3032
|
this.from = requireStoredValue(from, this.factoryName, location, "from");
|
|
2803
3033
|
this.to = requireStoredValue(to, this.factoryName, location, "to");
|
|
2804
3034
|
this.many = many;
|
|
2805
|
-
this.
|
|
3035
|
+
this.path = requireValuePath(path, {
|
|
3036
|
+
many,
|
|
3037
|
+
codec
|
|
3038
|
+
}, this.factoryName, location);
|
|
3039
|
+
this.label = `Replace value ${storedValueText(from)} with ${storedValueText(to)} ${storedValuePlace(this.path, tableName, columnName)}`;
|
|
2806
3040
|
this.freeze();
|
|
2807
3041
|
}
|
|
2808
3042
|
async toOp() {
|
|
3043
|
+
if (this.path !== void 0) return replaceStoredValueAtPath(this.schemaName, this.tableName, this.columnName, this.from, this.to, this.path);
|
|
2809
3044
|
return replaceStoredValue(this.schemaName, this.tableName, this.columnName, await encodeStoredValue(this.from, this.codec), await encodeStoredValue(this.to, this.codec), this.many);
|
|
2810
3045
|
}
|
|
2811
3046
|
renderTypeScript() {
|
|
2812
|
-
return replaceStoredValueSource(columnCallLocation(this.schemaName, this.tableName, this.columnName), jsonToTsSource(this.from), jsonToTsSource(this.to), this.many, this.codec);
|
|
3047
|
+
return replaceStoredValueSource(columnCallLocation(this.schemaName, this.tableName, this.columnName), jsonToTsSource(this.from), jsonToTsSource(this.to), this.many, this.codec, this.path);
|
|
2813
3048
|
}
|
|
2814
3049
|
importRequirements() {
|
|
2815
3050
|
return [];
|
|
2816
3051
|
}
|
|
2817
3052
|
};
|
|
2818
|
-
/** Removes one stored value of a column: sets it to NULL, or takes it out of every list of a list column. */
|
|
3053
|
+
/** Removes one stored value of a column: sets it to NULL, or takes it out of every list of a list column, or removes it at a path inside the JSON of the column. */
|
|
2819
3054
|
var RemoveStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
2820
3055
|
factoryName = "removeStoredValue";
|
|
2821
3056
|
operationClass = "destructive";
|
|
@@ -2828,31 +3063,46 @@ var RemoveStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
|
2828
3063
|
codec;
|
|
2829
3064
|
/** The enum value whose stored value is removed, which the check that fails while rows of a required column hold it names. */
|
|
2830
3065
|
enumValue;
|
|
3066
|
+
/** The path inside the column's JSON at which the value is removed, compared as a JSON value. */
|
|
3067
|
+
path;
|
|
3068
|
+
/** Whether the member at `path` takes JSON `null`; when it does not, the check fails while a row holds the value. */
|
|
3069
|
+
nullable;
|
|
2831
3070
|
label;
|
|
2832
|
-
constructor(schemaName, tableName, columnName, value, many, codec, enumValue) {
|
|
3071
|
+
constructor(schemaName, tableName, columnName, value, many, codec, enumValue, path, nullable) {
|
|
2833
3072
|
super();
|
|
3073
|
+
const location = columnCallLocation(schemaName, tableName, columnName);
|
|
2834
3074
|
this.codec = codec;
|
|
2835
3075
|
this.enumValue = enumValue;
|
|
2836
3076
|
this.schemaName = schemaName;
|
|
2837
3077
|
this.tableName = tableName;
|
|
2838
3078
|
this.columnName = columnName;
|
|
2839
|
-
this.value = requireStoredValue(value, this.factoryName,
|
|
3079
|
+
this.value = requireStoredValue(value, this.factoryName, location, "value");
|
|
2840
3080
|
this.many = many;
|
|
2841
|
-
this.
|
|
3081
|
+
this.path = requireValuePath(path, {
|
|
3082
|
+
many,
|
|
3083
|
+
codec
|
|
3084
|
+
}, this.factoryName, location);
|
|
3085
|
+
if (nullable !== void 0 && this.path === void 0) refusedArgument(this.factoryName, location, "nullable", "nullable needs a path: a column says itself whether it takes NULL");
|
|
3086
|
+
this.nullable = nullable === true;
|
|
3087
|
+
this.label = `Remove value ${storedValueText(value)} ${this.path === void 0 ? `from column "${columnName}" of "${tableName}"` : storedValuePlace(this.path, tableName, columnName)}`;
|
|
2842
3088
|
this.freeze();
|
|
2843
3089
|
}
|
|
2844
3090
|
async toOp() {
|
|
2845
|
-
|
|
3091
|
+
const mark = this.enumValue === void 0 ? void 0 : {
|
|
2846
3092
|
enumValue: this.enumValue,
|
|
2847
3093
|
value: this.value,
|
|
2848
3094
|
...this.codec === void 0 ? {} : { codecRef: this.codec.codecRef }
|
|
2849
|
-
}
|
|
3095
|
+
};
|
|
3096
|
+
if (this.path !== void 0) return removeStoredValueAtPath(this.schemaName, this.tableName, this.columnName, this.value, this.path, this.nullable, mark);
|
|
3097
|
+
return removeStoredValue(this.schemaName, this.tableName, this.columnName, await encodeStoredValue(this.value, this.codec), this.many, mark);
|
|
2850
3098
|
}
|
|
2851
3099
|
renderTypeScript() {
|
|
2852
3100
|
return `this.removeStoredValue({ ${[
|
|
2853
3101
|
...columnCallLocation(this.schemaName, this.tableName, this.columnName),
|
|
3102
|
+
...pathSource(this.path),
|
|
2854
3103
|
`value: ${jsonToTsSource(this.value)}`,
|
|
2855
3104
|
...this.many ? ["many: true"] : [],
|
|
3105
|
+
...this.nullable ? ["nullable: true"] : [],
|
|
2856
3106
|
...codecRefSource(this.codec),
|
|
2857
3107
|
...this.enumValue === void 0 ? [] : [`enumValue: ${jsonToTsSource(this.enumValue)}`]
|
|
2858
3108
|
].join(", ")} })`;
|
|
@@ -2861,6 +3111,196 @@ var RemoveStoredValueCall = class extends PostgresOpFactoryCallNode {
|
|
|
2861
3111
|
return [];
|
|
2862
3112
|
}
|
|
2863
3113
|
};
|
|
3114
|
+
/** Deletes the rows whose column holds one stored value. */
|
|
3115
|
+
var DeleteRowsCall = class extends PostgresOpFactoryCallNode {
|
|
3116
|
+
factoryName = "deleteRows";
|
|
3117
|
+
operationClass = "destructive";
|
|
3118
|
+
schemaName;
|
|
3119
|
+
tableName;
|
|
3120
|
+
columnName;
|
|
3121
|
+
value;
|
|
3122
|
+
/** The column's codec, which writes `value` as the database stores it. */
|
|
3123
|
+
codec;
|
|
3124
|
+
label;
|
|
3125
|
+
constructor(schemaName, tableName, columnName, value, codec) {
|
|
3126
|
+
super();
|
|
3127
|
+
this.codec = codec;
|
|
3128
|
+
this.schemaName = schemaName;
|
|
3129
|
+
this.tableName = tableName;
|
|
3130
|
+
this.columnName = columnName;
|
|
3131
|
+
this.value = requireStoredValue(value, this.factoryName, columnCallLocation(schemaName, tableName, columnName), "value");
|
|
3132
|
+
this.label = `Delete the rows of "${tableName}" that hold value ${storedValueText(value)} in column "${columnName}"`;
|
|
3133
|
+
this.freeze();
|
|
3134
|
+
}
|
|
3135
|
+
async toOp() {
|
|
3136
|
+
return deleteRows(this.schemaName, this.tableName, this.columnName, await encodeStoredValue(this.value, this.codec));
|
|
3137
|
+
}
|
|
3138
|
+
renderTypeScript() {
|
|
3139
|
+
return `this.deleteRows({ ${[
|
|
3140
|
+
...columnCallLocation(this.schemaName, this.tableName, this.columnName),
|
|
3141
|
+
`value: ${jsonToTsSource(this.value)}`,
|
|
3142
|
+
...codecRefSource(this.codec)
|
|
3143
|
+
].join(", ")} })`;
|
|
3144
|
+
}
|
|
3145
|
+
importRequirements() {
|
|
3146
|
+
return [];
|
|
3147
|
+
}
|
|
3148
|
+
};
|
|
3149
|
+
function refusedArgument(factory, location, argument, why) {
|
|
3150
|
+
throw postgresError("CONTRACT.ARGUMENT_INVALID", `${factory}({ ${location.join(", ")} }): ${why}`, { meta: { what: `${factory} ${argument}` } });
|
|
3151
|
+
}
|
|
3152
|
+
function requirePath(text, factory, location) {
|
|
3153
|
+
const parsed = parseJsonPath(text);
|
|
3154
|
+
return parsed.ok ? parsed.value : refusedArgument(factory, location, "path", parsed.failure);
|
|
3155
|
+
}
|
|
3156
|
+
function requireKeyPath(text, factory, location) {
|
|
3157
|
+
return keyPathOf(requirePath(text, factory, location)) ?? refusedArgument(factory, location, "path", `path ${JSON.stringify(text)} does not end at a member name, the key the operation acts on`);
|
|
3158
|
+
}
|
|
3159
|
+
/** Renames the key at the end of a JSON path, in every object of a column the path reaches. */
|
|
3160
|
+
var RenameStoredKeyCall = class extends PostgresOpFactoryCallNode {
|
|
3161
|
+
factoryName = "renameStoredKey";
|
|
3162
|
+
operationClass = "widening";
|
|
3163
|
+
schemaName;
|
|
3164
|
+
tableName;
|
|
3165
|
+
columnName;
|
|
3166
|
+
path;
|
|
3167
|
+
to;
|
|
3168
|
+
label;
|
|
3169
|
+
constructor(schemaName, tableName, columnName, path, to) {
|
|
3170
|
+
super();
|
|
3171
|
+
const location = columnCallLocation(schemaName, tableName, columnName);
|
|
3172
|
+
this.schemaName = schemaName;
|
|
3173
|
+
this.tableName = tableName;
|
|
3174
|
+
this.columnName = columnName;
|
|
3175
|
+
this.path = requireKeyPath(path, this.factoryName, location);
|
|
3176
|
+
if (typeof to !== "string" || to === this.path.key) refusedArgument(this.factoryName, location, "to", `to must be a key other than ${JSON.stringify(this.path.key)}; got ${JSON.stringify(to)}`);
|
|
3177
|
+
this.to = to;
|
|
3178
|
+
this.label = `Rename key "${this.path.key}" to "${to}" ${keyPlace(this.path, tableName, columnName)}`;
|
|
3179
|
+
this.freeze();
|
|
3180
|
+
}
|
|
3181
|
+
toOp() {
|
|
3182
|
+
return renameStoredKey(this.schemaName, this.tableName, this.columnName, this.path, this.to);
|
|
3183
|
+
}
|
|
3184
|
+
renderTypeScript() {
|
|
3185
|
+
return `this.renameStoredKey({ ${[
|
|
3186
|
+
...columnCallLocation(this.schemaName, this.tableName, this.columnName),
|
|
3187
|
+
`path: ${jsonToTsSource(this.path.path.text)}`,
|
|
3188
|
+
`to: ${jsonToTsSource(this.to)}`
|
|
3189
|
+
].join(", ")} })`;
|
|
3190
|
+
}
|
|
3191
|
+
importRequirements() {
|
|
3192
|
+
return [];
|
|
3193
|
+
}
|
|
3194
|
+
};
|
|
3195
|
+
/** Removes the key at the end of a JSON path, from every object of a column the path reaches. */
|
|
3196
|
+
var RemoveStoredKeyCall = class extends PostgresOpFactoryCallNode {
|
|
3197
|
+
factoryName = "removeStoredKey";
|
|
3198
|
+
operationClass = "destructive";
|
|
3199
|
+
schemaName;
|
|
3200
|
+
tableName;
|
|
3201
|
+
columnName;
|
|
3202
|
+
path;
|
|
3203
|
+
label;
|
|
3204
|
+
constructor(schemaName, tableName, columnName, path) {
|
|
3205
|
+
super();
|
|
3206
|
+
this.schemaName = schemaName;
|
|
3207
|
+
this.tableName = tableName;
|
|
3208
|
+
this.columnName = columnName;
|
|
3209
|
+
this.path = requireKeyPath(path, this.factoryName, columnCallLocation(schemaName, tableName, columnName));
|
|
3210
|
+
this.label = `Remove key "${this.path.key}" ${keyPlace(this.path, tableName, columnName)}`;
|
|
3211
|
+
this.freeze();
|
|
3212
|
+
}
|
|
3213
|
+
toOp() {
|
|
3214
|
+
return removeStoredKey(this.schemaName, this.tableName, this.columnName, this.path);
|
|
3215
|
+
}
|
|
3216
|
+
renderTypeScript() {
|
|
3217
|
+
return `this.removeStoredKey({ ${[...columnCallLocation(this.schemaName, this.tableName, this.columnName), `path: ${jsonToTsSource(this.path.path.text)}`].join(", ")} })`;
|
|
3218
|
+
}
|
|
3219
|
+
importRequirements() {
|
|
3220
|
+
return [];
|
|
3221
|
+
}
|
|
3222
|
+
};
|
|
3223
|
+
function requireJsonValue(value, factory, location) {
|
|
3224
|
+
return JSON.stringify(value) === void 0 ? refusedArgument(factory, location, "value", "value must be a JSON value; got undefined") : value;
|
|
3225
|
+
}
|
|
3226
|
+
function requireFillValue(value, field, factory, location) {
|
|
3227
|
+
const json = requireJsonValue(value, factory, location);
|
|
3228
|
+
const problem = fillValueProblem(json, field);
|
|
3229
|
+
return problem === void 0 ? json : refusedArgument(factory, location, "value", problem);
|
|
3230
|
+
}
|
|
3231
|
+
/**
|
|
3232
|
+
* The operation of a fill whose value is an unfilled placeholder: a promise that rejects with
|
|
3233
|
+
* `MIGRATION.UNFILLED_PLACEHOLDER`, whose meta names the operation it stands for, so that a plan can
|
|
3234
|
+
* list it before the user fills the value.
|
|
3235
|
+
*/
|
|
3236
|
+
function unfilledFillOperation(slot, standsFor) {
|
|
3237
|
+
const unfilled = errorUnfilledPlaceholder(slot);
|
|
3238
|
+
const operation = Promise.reject(new CliStructuredError(unfilled.code, unfilled.message, {
|
|
3239
|
+
...ifDefined("why", unfilled.why),
|
|
3240
|
+
...ifDefined("fix", unfilled.fix),
|
|
3241
|
+
meta: {
|
|
3242
|
+
slot,
|
|
3243
|
+
operation: {
|
|
3244
|
+
id: standsFor.id,
|
|
3245
|
+
label: standsFor.label,
|
|
3246
|
+
operationClass: standsFor.operationClass
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
}));
|
|
3250
|
+
operation.catch(() => void 0);
|
|
3251
|
+
return operation;
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Sets the key at the end of a JSON path to a value, in every object of a column the path reaches that lacks it or holds JSON `null` there. An unfilled value is a placeholder the user fills in `migration.ts`; until then the call lowers to no operation.
|
|
3255
|
+
*/
|
|
3256
|
+
var FillStoredKeyCall = class extends PostgresOpFactoryCallNode {
|
|
3257
|
+
factoryName = "fillStoredKey";
|
|
3258
|
+
operationClass = "widening";
|
|
3259
|
+
schemaName;
|
|
3260
|
+
tableName;
|
|
3261
|
+
columnName;
|
|
3262
|
+
path;
|
|
3263
|
+
value;
|
|
3264
|
+
/** The value object field the key holds, which must take `value`. */
|
|
3265
|
+
field;
|
|
3266
|
+
label;
|
|
3267
|
+
constructor(schemaName, tableName, columnName, path, value, field) {
|
|
3268
|
+
super();
|
|
3269
|
+
const location = columnCallLocation(schemaName, tableName, columnName);
|
|
3270
|
+
this.schemaName = schemaName;
|
|
3271
|
+
this.tableName = tableName;
|
|
3272
|
+
this.columnName = columnName;
|
|
3273
|
+
this.path = requireKeyPath(path, this.factoryName, location);
|
|
3274
|
+
const keyProblem = fillKeyProblem({
|
|
3275
|
+
key: this.path.key,
|
|
3276
|
+
path: this.path.path.text
|
|
3277
|
+
}, field);
|
|
3278
|
+
if (keyProblem !== void 0) refusedArgument(this.factoryName, location, "field", keyProblem);
|
|
3279
|
+
this.field = field;
|
|
3280
|
+
this.value = value instanceof UnfilledValue ? value : requireFillValue(value, field, this.factoryName, location);
|
|
3281
|
+
this.label = `Fill key "${this.path.key}" ${keyPlace(this.path, tableName, columnName)}`;
|
|
3282
|
+
this.freeze();
|
|
3283
|
+
}
|
|
3284
|
+
toOp() {
|
|
3285
|
+
if (this.value instanceof UnfilledValue) return unfilledFillOperation(this.value.slot, fillStoredKey(this.schemaName, this.tableName, this.columnName, this.path, "null"));
|
|
3286
|
+
return fillStoredKey(this.schemaName, this.tableName, this.columnName, this.path, JSON.stringify(this.value));
|
|
3287
|
+
}
|
|
3288
|
+
renderTypeScript() {
|
|
3289
|
+
const value = this.value instanceof UnfilledValue ? `placeholder(${jsonToTsSource(this.value.slot)})` : jsonToTsSource(this.value);
|
|
3290
|
+
return `this.fillStoredKey({ ${[
|
|
3291
|
+
...columnCallLocation(this.schemaName, this.tableName, this.columnName),
|
|
3292
|
+
`path: ${jsonToTsSource(this.path.path.text)}`,
|
|
3293
|
+
`value: ${value}`,
|
|
3294
|
+
...this.field === void 0 ? [] : [`field: ${jsonToTsSource(this.field.text)}`]
|
|
3295
|
+
].join(", ")} })`;
|
|
3296
|
+
}
|
|
3297
|
+
importRequirements() {
|
|
3298
|
+
return this.value instanceof UnfilledValue ? [{
|
|
3299
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
3300
|
+
symbol: "placeholder"
|
|
3301
|
+
}] : [];
|
|
3302
|
+
}
|
|
3303
|
+
};
|
|
2864
3304
|
/**
|
|
2865
3305
|
* A planner-generated data-transform stub. `checkSlot` and `runSlot` name
|
|
2866
3306
|
* the unfilled authoring slots that the rendered `migration.ts` will expose
|
|
@@ -3066,6 +3506,6 @@ function columnNameOfCall(call) {
|
|
|
3066
3506
|
if ("column" in call && call.column instanceof DdlColumn) return call.column.name;
|
|
3067
3507
|
}
|
|
3068
3508
|
//#endregion
|
|
3069
|
-
export {
|
|
3509
|
+
export { installExtension as $, EnableRowLevelSecurityCall as A, RenameStoredKeyCall as B, DropExtensionCall as C, DropPostgresRlsPolicyCall as D, DropNotNullCall as E, RenameColumnCall as F, SetExtensionSchemaCall as G, ReplaceStoredValueCall as H, RenameConstraintCall as I, alterColumnTypeCallText as J, SetNotNullCall as K, RenameIndexCall as L, RawSqlCall as M, RemoveStoredKeyCall as N, DropSchemaCall as O, RemoveStoredValueCall as P, holdingStoredValue as Q, RenamePostgresRlsPolicyCall as R, DropDefaultCall as S, DropNativeEnumTypeCall as T, SCHEMA_OBJECTS_SQL as U, RenameTableCall as V, SetDefaultCall as W, createExtension as X, columnNameOfCall as Y, dropCheckConstraintId as Z, DeleteRowsCall as _, AddNativeEnumValueCall as a, schemaObjectsSummary as at, DropColumnCall as b, AddUniqueCall as c, CreateIndexCall as d, isPostgresOpFactoryCall as et, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddForeignKeyCall as i, schemaContentsOf as it, FillStoredKeyCall as j, DropTableCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, renameTableStatement as nt, AddPrimaryKeyCall as o, CreatePostgresRlsPolicyCall as p, SetTableSchemaCall as q, AddColumnWithTemporaryDefaultCall as r, schemaBlockingObjects as rt, AddRequiredColumnToEmptyTableCall as s, AddCheckConstraintCall as t, postgresDefaultToDdlColumnDefault as tt, CreateExtensionCall as u, DisableRowLevelSecurityCall as v, DropIndexCall as w, DropConstraintCall as x, DropCheckConstraintCall as y, RenameSchemaCall as z };
|
|
3070
3510
|
|
|
3071
|
-
//# sourceMappingURL=op-factory-call-
|
|
3511
|
+
//# sourceMappingURL=op-factory-call-DQW9c0ec-C3qv_STE.mjs.map
|