@prisma-next/target-postgres 0.14.0-dev.4 → 0.14.0-dev.41
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/authoring-BX1WHIdN.mjs +220 -0
- package/dist/authoring-BX1WHIdN.mjs.map +1 -0
- package/dist/canonicalize-Bn3BM1Cn.mjs +46 -0
- package/dist/canonicalize-Bn3BM1Cn.mjs.map +1 -0
- package/dist/canonicalize-CAbXtVtB.d.mts +37 -0
- package/dist/canonicalize-CAbXtVtB.d.mts.map +1 -0
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-CueCoGD0.d.mts} +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts.map → codec-types-CueCoGD0.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Ca8upop6.d.mts} +12 -1
- package/dist/codecs-Ca8upop6.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +34 -1
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +8 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +3 -3
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +639 -21
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-qKy1U5V9.d.mts} +2 -2
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-qKy1U5V9.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-BmLIe1z_.mjs} +62 -5
- package/dist/ddl-BmLIe1z_.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/{default-normalizer-DyyCHQWs.mjs → default-normalizer-Dug8Fez9.mjs} +119 -2
- package/dist/default-normalizer-Dug8Fez9.mjs.map +1 -0
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/descriptor-meta-tjatyhtZ.mjs +18 -0
- package/dist/descriptor-meta-tjatyhtZ.mjs.map +1 -0
- package/dist/{issue-planner-DL6g3CmE.mjs → issue-planner-DbFvaAgu.mjs} +35 -10
- package/dist/issue-planner-DbFvaAgu.mjs.map +1 -0
- package/dist/issue-planner.d.mts +3 -3
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +5 -5
- package/dist/migration.mjs +4 -4
- package/dist/nodes-CSkPX3rI.d.mts +120 -0
- package/dist/nodes-CSkPX3rI.d.mts.map +1 -0
- package/dist/{nodes-Bbhs2rwj.mjs → nodes-Dh__NS58.mjs} +56 -2
- package/dist/nodes-Dh__NS58.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CJWUxyUW.d.mts} +44 -13
- package/dist/op-factory-call-CJWUxyUW.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-t65c4jyY.mjs} +201 -28
- package/dist/op-factory-call-t65c4jyY.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +74 -2
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-CG2pLHk-.mjs +640 -0
- package/dist/planner-CG2pLHk-.mjs.map +1 -0
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-B8Nn6nHN.mjs} +12 -27
- package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +2 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-BolD0Mvc.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-BolD0Mvc.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-Cz9--XOT.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-Cz9--XOT.d.mts.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-DE9c4519.mjs} +2 -2
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-DE9c4519.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +82 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-BegduLr6.mjs} +50 -23
- package/dist/postgres-contract-view-BegduLr6.mjs.map +1 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/postgres-database-schema-node-os8ogEap.d.mts +183 -0
- package/dist/postgres-database-schema-node-os8ogEap.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-BfMmK6tv.mjs} +21 -2
- package/dist/postgres-migration-BfMmK6tv.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-D7kNVWVG.d.mts} +19 -6
- package/dist/postgres-migration-D7kNVWVG.d.mts.map +1 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-BLIHBEfX.mjs} +108 -5
- package/dist/postgres-schema-BLIHBEfX.mjs.map +1 -0
- package/dist/postgres-schema-BywoeKlt.d.mts +189 -0
- package/dist/postgres-schema-BywoeKlt.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-1nNc8XDT.mjs +248 -0
- package/dist/postgres-table-schema-node-1nNc8XDT.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
- package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/resolve-ddl-schema-CL1RR1mx.mjs +20 -0
- package/dist/resolve-ddl-schema-CL1RR1mx.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +2 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +7 -6
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-ir-annotations.d.mts +14 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +3 -2
- package/package.json +22 -17
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/ddl.ts +45 -1
- package/src/core/authoring.ts +115 -1
- package/src/core/codecs.ts +35 -1
- package/src/core/ddl/nodes.ts +94 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +4 -0
- package/src/core/entity-kinds.ts +16 -0
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +125 -0
- package/src/core/migrations/control-policy.ts +3 -0
- package/src/core/migrations/diff-database-schema.ts +191 -0
- package/src/core/migrations/issue-planner.ts +44 -3
- package/src/core/migrations/op-factory-call.ts +109 -21
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/rls.ts +106 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +15 -56
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-strategies.ts +3 -11
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +165 -33
- package/src/core/migrations/postgres-migration.ts +34 -4
- package/src/core/migrations/render-typescript.ts +42 -15
- package/src/core/migrations/resolve-ddl-schema.ts +24 -0
- package/src/core/migrations/runner.ts +13 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +24 -19
- package/src/core/postgres-contract-serializer.ts +50 -33
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +37 -0
- package/src/core/postgres-schema.ts +37 -13
- package/src/core/postgres-validators.ts +20 -0
- package/src/core/psl-infer/infer-psl-contract.ts +834 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +157 -0
- package/src/core/rls/canonicalize.ts +48 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +63 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +93 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +66 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +107 -0
- package/src/core/schema-ir/schema-node-kinds.ts +28 -0
- package/src/exports/contract-free.ts +7 -1
- package/src/exports/control.ts +39 -12
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +1 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner.ts +2 -0
- package/src/exports/rls-canonicalize.ts +6 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/types.ts +28 -0
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
- package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
- package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
- package/dist/nodes-pLeLgdis.d.mts +0 -67
- package/dist/nodes-pLeLgdis.d.mts.map +0 -1
- package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
- package/dist/planner-Bs_baQax.mjs +0 -324
- package/dist/planner-Bs_baQax.mjs.map +0 -1
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
- package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
- package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/render-typescript-KMgosran.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
import { n as qualifyTableName } from "./planner-sql-checks-
|
|
4
|
-
import {
|
|
2
|
+
import { _ as rlsPolicyExistsAst, a as createTable, c as columnDefaultAst, d as columnTypeAst, f as constraintExistsAst, g as rlsEnabledAst, h as noNullValuesAst, i as createSchema, l as columnExistsAst, m as indexExistsAst, n as alterTable, o as dropDefaultAction, p as extensionExistsAst, r as createPolicy, s as dropPolicy, t as addColumnAction, u as columnNullabilityAst, v as tableExistsAst, y as tableIsEmptyAst } from "./ddl-BmLIe1z_.mjs";
|
|
3
|
+
import { n as qualifyTableName } from "./planner-sql-checks-DE9c4519.mjs";
|
|
4
|
+
import { n as buildColumnTypeSql } from "./planner-ddl-builders-B8Nn6nHN.mjs";
|
|
5
5
|
import { FunctionColumnDefault, LiteralColumnDefault } from "@prisma-next/sql-relational-core/ast";
|
|
6
6
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
7
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
8
8
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
9
|
+
import { col } from "@prisma-next/sql-relational-core/contract-free";
|
|
9
10
|
import { errorUnfilledPlaceholder } from "@prisma-next/errors/migration";
|
|
10
11
|
import { TsExpression, jsonToTsSource } from "@prisma-next/ts-render";
|
|
11
12
|
import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
|
|
13
|
+
//#region src/core/migrations/bound-schema.ts
|
|
14
|
+
/**
|
|
15
|
+
* Maps a planner schema name to the contract-free DDL builder's optional
|
|
16
|
+
* `schema` field: the unbound sentinel becomes `undefined` (the builder omits
|
|
17
|
+
* the schema qualifier), every other name passes through.
|
|
18
|
+
*/
|
|
19
|
+
function boundSchema(schemaName) {
|
|
20
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
12
23
|
//#region src/core/migrations/operations/shared.ts
|
|
13
24
|
function step(description, sql, params) {
|
|
14
25
|
return {
|
|
@@ -171,12 +182,16 @@ async function setDefault(schemaName, tableName, columnName, defaultSql, lowerer
|
|
|
171
182
|
};
|
|
172
183
|
}
|
|
173
184
|
async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
174
|
-
const qualified = qualifyTableName(schemaName, tableName);
|
|
175
185
|
const { present } = await columnExistsSteps(lowerer, {
|
|
176
186
|
schema: schemaName,
|
|
177
187
|
table: tableName,
|
|
178
188
|
column: columnName
|
|
179
189
|
});
|
|
190
|
+
const dropDefaultExec = await lowerer.lowerToExecuteRequest(alterTable({
|
|
191
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
192
|
+
table: tableName,
|
|
193
|
+
actions: [dropDefaultAction(columnName)]
|
|
194
|
+
}));
|
|
180
195
|
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
181
196
|
schema: schemaName,
|
|
182
197
|
table: tableName,
|
|
@@ -188,17 +203,23 @@ async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
|
188
203
|
operationClass: "destructive",
|
|
189
204
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
190
205
|
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
191
|
-
execute: [step(`drop default on "${columnName}"`,
|
|
206
|
+
execute: [step(`drop default on "${columnName}"`, dropDefaultExec.sql)],
|
|
192
207
|
postcheck: [step(`verify column "${columnName}" has no default`, noDefault.sql, noDefault.params)]
|
|
193
208
|
};
|
|
194
209
|
}
|
|
195
210
|
/**
|
|
196
211
|
* Builds the op for adding a NOT NULL column (no contract default) to a
|
|
197
212
|
* non-empty table. Prechecks assert the column is absent and the table is
|
|
198
|
-
* empty; the execute step
|
|
199
|
-
*
|
|
213
|
+
* empty; the execute step lowers the typed `AddColumn` DDL node through the
|
|
214
|
+
* adapter; postchecks assert the column exists and is NOT NULL.
|
|
200
215
|
*/
|
|
201
|
-
async function addNotNullColumnDirect(schemaName, tableName,
|
|
216
|
+
async function addNotNullColumnDirect(schemaName, tableName, column, lowerer) {
|
|
217
|
+
const columnName = column.name;
|
|
218
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
219
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
220
|
+
table: tableName,
|
|
221
|
+
actions: [addColumnAction(column)]
|
|
222
|
+
}));
|
|
202
223
|
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
203
224
|
schema: schemaName,
|
|
204
225
|
table: tableName,
|
|
@@ -223,7 +244,7 @@ async function addNotNullColumnDirect(schemaName, tableName, columnName, execute
|
|
|
223
244
|
operationClass: "additive",
|
|
224
245
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
225
246
|
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params), step(`ensure table "${tableName}" is empty before adding NOT NULL column without default`, tableEmpty.sql, tableEmpty.params)],
|
|
226
|
-
execute: [step(`add column "${columnName}"`,
|
|
247
|
+
execute: [step(`add column "${columnName}"`, addColumn.sql)],
|
|
227
248
|
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params), step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
228
249
|
};
|
|
229
250
|
}
|
|
@@ -463,6 +484,81 @@ async function dropIndex(schemaName, tableName, indexName, lowerer) {
|
|
|
463
484
|
};
|
|
464
485
|
}
|
|
465
486
|
//#endregion
|
|
487
|
+
//#region src/core/migrations/operations/rls.ts
|
|
488
|
+
const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
489
|
+
function validateRoleName(role) {
|
|
490
|
+
if (!PLAIN_IDENTIFIER.test(role)) throw new Error(`Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`);
|
|
491
|
+
return role;
|
|
492
|
+
}
|
|
493
|
+
async function createRlsPolicy(schemaName, tableName, policy, lowerer) {
|
|
494
|
+
const validatedRoles = policy.roles.map(validateRoleName);
|
|
495
|
+
const ddlNode = createPolicy({
|
|
496
|
+
schema: schemaName,
|
|
497
|
+
table: tableName,
|
|
498
|
+
name: policy.name,
|
|
499
|
+
permissive: policy.permissive,
|
|
500
|
+
operation: policy.operation,
|
|
501
|
+
roles: validatedRoles,
|
|
502
|
+
...ifDefined("using", policy.using),
|
|
503
|
+
...ifDefined("withCheck", policy.withCheck)
|
|
504
|
+
});
|
|
505
|
+
const checks = rlsPolicyExistsAst({
|
|
506
|
+
schema: schemaName,
|
|
507
|
+
table: tableName,
|
|
508
|
+
policyName: policy.name
|
|
509
|
+
});
|
|
510
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
511
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
512
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
513
|
+
return {
|
|
514
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policy.name}`,
|
|
515
|
+
label: `Create RLS policy "${policy.name}" on "${tableName}"`,
|
|
516
|
+
operationClass: "additive",
|
|
517
|
+
target: targetDetails("rlsPolicy", policy.name, schemaName, tableName),
|
|
518
|
+
precheck: [step(`ensure RLS policy "${policy.name}" does not exist`, absent.sql, absent.params)],
|
|
519
|
+
execute: [step(`create RLS policy "${policy.name}"`, execute.sql, execute.params)],
|
|
520
|
+
postcheck: [step(`verify RLS policy "${policy.name}" exists`, present.sql, present.params)]
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
async function dropRlsPolicy(schemaName, tableName, policyName, lowerer) {
|
|
524
|
+
const ddlNode = dropPolicy({
|
|
525
|
+
schema: schemaName,
|
|
526
|
+
table: tableName,
|
|
527
|
+
name: policyName
|
|
528
|
+
});
|
|
529
|
+
const checks = rlsPolicyExistsAst({
|
|
530
|
+
schema: schemaName,
|
|
531
|
+
table: tableName,
|
|
532
|
+
policyName
|
|
533
|
+
});
|
|
534
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
535
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
536
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
537
|
+
return {
|
|
538
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policyName}.drop`,
|
|
539
|
+
label: `Drop RLS policy "${policyName}" on "${tableName}"`,
|
|
540
|
+
operationClass: "destructive",
|
|
541
|
+
target: targetDetails("rlsPolicy", policyName, schemaName, tableName),
|
|
542
|
+
precheck: [step(`ensure RLS policy "${policyName}" exists`, present.sql, present.params)],
|
|
543
|
+
execute: [step(`drop RLS policy "${policyName}"`, execute.sql, execute.params)],
|
|
544
|
+
postcheck: [step(`verify RLS policy "${policyName}" is absent`, absent.sql, absent.params)]
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
async function enableRowLevelSecurity(schemaName, tableName, lowerer) {
|
|
548
|
+
const checks = rlsEnabledAst(schemaName, tableName);
|
|
549
|
+
const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
|
|
550
|
+
const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
|
|
551
|
+
return {
|
|
552
|
+
id: `rowLevelSecurity.${schemaName}.${tableName}`,
|
|
553
|
+
label: `Enable row-level security on "${tableName}"`,
|
|
554
|
+
operationClass: "additive",
|
|
555
|
+
target: targetDetails("rowLevelSecurity", tableName, schemaName),
|
|
556
|
+
precheck: [step(`check RLS is not already enabled on "${tableName}"`, disabled.sql, disabled.params)],
|
|
557
|
+
execute: [step(`enable row-level security on "${tableName}"`, `ALTER TABLE ${qualifyTableName(schemaName, tableName)} ENABLE ROW LEVEL SECURITY`)],
|
|
558
|
+
postcheck: [step(`verify row-level security is enabled on "${tableName}"`, enabled.sql, enabled.params)]
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
//#endregion
|
|
466
562
|
//#region src/core/migrations/operations/tables.ts
|
|
467
563
|
async function dropTable(schemaName, tableName, lowerer) {
|
|
468
564
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
@@ -504,7 +600,20 @@ function buildAddColumnOperationIdentity(schema, tableName, columnName) {
|
|
|
504
600
|
}
|
|
505
601
|
async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
506
602
|
const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault, lowerer } = options;
|
|
507
|
-
const
|
|
603
|
+
const ddlColumn = col(columnName, buildColumnTypeSql(column, codecHooks, storageTypes), {
|
|
604
|
+
notNull: true,
|
|
605
|
+
default: new FunctionColumnDefault(temporaryDefault)
|
|
606
|
+
});
|
|
607
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
608
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
609
|
+
table: tableName,
|
|
610
|
+
actions: [addColumnAction(ddlColumn)]
|
|
611
|
+
}));
|
|
612
|
+
const dropTempDefault = await lowerer.lowerToExecuteRequest(alterTable({
|
|
613
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
614
|
+
table: tableName,
|
|
615
|
+
actions: [dropDefaultAction(columnName)]
|
|
616
|
+
}));
|
|
508
617
|
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
509
618
|
schema,
|
|
510
619
|
table: tableName,
|
|
@@ -532,10 +641,10 @@ async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
|
532
641
|
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
533
642
|
execute: [{
|
|
534
643
|
description: `add column "${columnName}"`,
|
|
535
|
-
sql:
|
|
644
|
+
sql: addColumn.sql
|
|
536
645
|
}, {
|
|
537
646
|
description: `drop temporary default from column "${columnName}"`,
|
|
538
|
-
sql:
|
|
647
|
+
sql: dropTempDefault.sql
|
|
539
648
|
}],
|
|
540
649
|
postcheck: [
|
|
541
650
|
step(`verify column "${columnName}" exists`, present.sql, present.params),
|
|
@@ -568,9 +677,6 @@ async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
|
568
677
|
* `PostgresOpFactoryCall` union.
|
|
569
678
|
*/
|
|
570
679
|
const POSTGRES_MIGRATION_FACADE = "@prisma-next/postgres/migration";
|
|
571
|
-
function boundSchema(schemaName) {
|
|
572
|
-
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
573
|
-
}
|
|
574
680
|
var PostgresOpFactoryCallNode = class extends TsExpression {
|
|
575
681
|
importRequirements() {
|
|
576
682
|
return [{
|
|
@@ -625,6 +731,7 @@ function renderDdlConstraintAsTsCall(constraint) {
|
|
|
625
731
|
const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
|
|
626
732
|
return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
|
|
627
733
|
}
|
|
734
|
+
case "check-expression": return `checkExpression(${jsonToTsSource(constraint.name)}, ${jsonToTsSource(constraint.expression)})`;
|
|
628
735
|
}
|
|
629
736
|
}
|
|
630
737
|
function needsColOrConstraintImport(columns) {
|
|
@@ -636,6 +743,7 @@ function constraintImportSymbols(constraints) {
|
|
|
636
743
|
for (const c of constraints) if (c.kind === "primary-key") symbols.add("primaryKey");
|
|
637
744
|
else if (c.kind === "foreign-key") symbols.add("foreignKey");
|
|
638
745
|
else if (c.kind === "unique") symbols.add("unique");
|
|
746
|
+
else if (c.kind === "check-expression") symbols.add("checkExpression");
|
|
639
747
|
return [...symbols];
|
|
640
748
|
}
|
|
641
749
|
function defaultImportSymbols(columns) {
|
|
@@ -998,10 +1106,8 @@ var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
998
1106
|
};
|
|
999
1107
|
/**
|
|
1000
1108
|
* Planner-internal call for adding a NOT NULL column (no contract default) to
|
|
1001
|
-
* a table that must be empty at migration time. Carries the
|
|
1002
|
-
*
|
|
1003
|
-
* DDL) plus the parameters needed to lower the typed pre/postchecks at render
|
|
1004
|
-
* time.
|
|
1109
|
+
* a table that must be empty at migration time. Carries the typed `DdlColumn`
|
|
1110
|
+
* and lowers it to an ADD COLUMN execute step via the adapter at `toOp` time.
|
|
1005
1111
|
*
|
|
1006
1112
|
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1007
1113
|
* planner, never hand-written by migration authors.
|
|
@@ -1012,20 +1118,20 @@ var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
|
1012
1118
|
schemaName;
|
|
1013
1119
|
tableName;
|
|
1014
1120
|
columnName;
|
|
1015
|
-
|
|
1121
|
+
column;
|
|
1016
1122
|
label;
|
|
1017
|
-
constructor(schemaName, tableName, columnName,
|
|
1123
|
+
constructor(schemaName, tableName, columnName, column) {
|
|
1018
1124
|
super();
|
|
1019
1125
|
this.schemaName = schemaName;
|
|
1020
1126
|
this.tableName = tableName;
|
|
1021
1127
|
this.columnName = columnName;
|
|
1022
|
-
this.
|
|
1128
|
+
this.column = column;
|
|
1023
1129
|
this.label = `Add column ${columnName} to ${tableName}`;
|
|
1024
1130
|
this.freeze();
|
|
1025
1131
|
}
|
|
1026
1132
|
async toOp(lowerer) {
|
|
1027
1133
|
if (lowerer === void 0) throw new Error(`AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1028
|
-
return addNotNullColumnDirect(this.schemaName, this.tableName, this.
|
|
1134
|
+
return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
|
|
1029
1135
|
}
|
|
1030
1136
|
renderTypeScript() {
|
|
1031
1137
|
return `rawSql(${jsonToTsSource({
|
|
@@ -1041,9 +1147,9 @@ var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
|
1041
1147
|
/**
|
|
1042
1148
|
* Planner-internal call for adding a NOT NULL column (no contract default)
|
|
1043
1149
|
* using a temporary default value for non-empty tables. Carries all parameters
|
|
1044
|
-
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the
|
|
1045
|
-
* pre/postchecks are lowered
|
|
1046
|
-
*
|
|
1150
|
+
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; both the
|
|
1151
|
+
* typed ADD COLUMN execute step and the pre/postchecks are lowered via the
|
|
1152
|
+
* adapter at `toOp` time.
|
|
1047
1153
|
*
|
|
1048
1154
|
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1049
1155
|
* planner, never hand-written by migration authors.
|
|
@@ -1484,7 +1590,74 @@ var DataTransformCall = class extends PostgresOpFactoryCallNode {
|
|
|
1484
1590
|
}];
|
|
1485
1591
|
}
|
|
1486
1592
|
};
|
|
1593
|
+
var CreatePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1594
|
+
factoryName = "createRlsPolicy";
|
|
1595
|
+
operationClass = "additive";
|
|
1596
|
+
schemaName;
|
|
1597
|
+
tableName;
|
|
1598
|
+
policy;
|
|
1599
|
+
label;
|
|
1600
|
+
constructor(schemaName, tableName, policy) {
|
|
1601
|
+
super();
|
|
1602
|
+
this.schemaName = schemaName;
|
|
1603
|
+
this.tableName = tableName;
|
|
1604
|
+
this.policy = policy;
|
|
1605
|
+
this.label = `Create RLS policy "${policy.name}" on "${tableName}"`;
|
|
1606
|
+
this.freeze();
|
|
1607
|
+
}
|
|
1608
|
+
async toOp(lowerer) {
|
|
1609
|
+
if (lowerer === void 0) throw new Error(`CreatePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policy.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1610
|
+
return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
|
|
1611
|
+
}
|
|
1612
|
+
renderTypeScript() {
|
|
1613
|
+
return `createRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policy)})`;
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
var DropPostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1617
|
+
factoryName = "dropRlsPolicy";
|
|
1618
|
+
operationClass = "destructive";
|
|
1619
|
+
schemaName;
|
|
1620
|
+
tableName;
|
|
1621
|
+
policyName;
|
|
1622
|
+
label;
|
|
1623
|
+
constructor(schemaName, tableName, policyName) {
|
|
1624
|
+
super();
|
|
1625
|
+
this.schemaName = schemaName;
|
|
1626
|
+
this.tableName = tableName;
|
|
1627
|
+
this.policyName = policyName;
|
|
1628
|
+
this.label = `Drop RLS policy "${policyName}" on "${tableName}"`;
|
|
1629
|
+
this.freeze();
|
|
1630
|
+
}
|
|
1631
|
+
async toOp(lowerer) {
|
|
1632
|
+
if (lowerer === void 0) throw new Error(`DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1633
|
+
return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
|
|
1634
|
+
}
|
|
1635
|
+
renderTypeScript() {
|
|
1636
|
+
return `dropRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policyName)})`;
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
var EnableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
|
|
1640
|
+
factoryName = "enableRowLevelSecurity";
|
|
1641
|
+
operationClass = "additive";
|
|
1642
|
+
schemaName;
|
|
1643
|
+
tableName;
|
|
1644
|
+
label;
|
|
1645
|
+
constructor(schemaName, tableName) {
|
|
1646
|
+
super();
|
|
1647
|
+
this.schemaName = schemaName;
|
|
1648
|
+
this.tableName = tableName;
|
|
1649
|
+
this.label = `Enable row-level security on "${tableName}"`;
|
|
1650
|
+
this.freeze();
|
|
1651
|
+
}
|
|
1652
|
+
async toOp(lowerer) {
|
|
1653
|
+
if (lowerer === void 0) throw new Error(`EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`);
|
|
1654
|
+
return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
|
|
1655
|
+
}
|
|
1656
|
+
renderTypeScript() {
|
|
1657
|
+
return `enableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1487
1660
|
//#endregion
|
|
1488
|
-
export {
|
|
1661
|
+
export { installExtension as A, EnableRowLevelSecurityCall as C, postgresDefaultToDdlColumnDefault as D, SetNotNullCall as E, buildTargetDetails as O, DropTableCall as S, SetDefaultCall as T, DropConstraintCall as _, AddNotNullColumnWithTempDefaultCall as a, DropNotNullCall as b, AlterColumnTypeCall as c, CreatePostgresRlsPolicyCall as d, CreateSchemaCall as f, DropColumnCall as g, DropCheckConstraintCall as h, AddNotNullColumnDirectCall as i, createExtension as k, CreateExtensionCall as l, DataTransformCall as m, AddColumnCall as n, AddPrimaryKeyCall as o, CreateTableCall as p, AddForeignKeyCall as r, AddUniqueCall as s, AddCheckConstraintCall as t, CreateIndexCall as u, DropDefaultCall as v, RawSqlCall as w, DropPostgresRlsPolicyCall as x, DropIndexCall as y };
|
|
1489
1662
|
|
|
1490
|
-
//# sourceMappingURL=op-factory-call-
|
|
1663
|
+
//# sourceMappingURL=op-factory-call-t65c4jyY.mjs.map
|