@prisma-next/target-postgres 0.14.0-dev.5 → 0.14.0-dev.50
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-DzHOdWTl.mjs +364 -0
- package/dist/authoring-DzHOdWTl.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-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
- package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-BDVmvKAW.d.mts} +3 -2
- package/dist/codec-types-BDVmvKAW.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Dk2sxGLv.d.mts} +77 -4
- package/dist/codecs-Dk2sxGLv.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +117 -2
- 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 +4 -4
- package/dist/control-policy-DUFgy9jO.mjs +1103 -0
- package/dist/control-policy-DUFgy9jO.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +757 -35
- 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-DPzwBMhW.d.mts} +3 -3
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-ujxH2A7r.mjs} +63 -6
- package/dist/ddl-ujxH2A7r.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/descriptor-meta-CuGDsrG4.mjs +19 -0
- package/dist/descriptor-meta-CuGDsrG4.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs +313 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/issue-planner.d.mts +35 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +5 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- 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-D_p5vxwt.mjs → op-factory-call-BKRnMgrB.mjs} +205 -31
- package/dist/op-factory-call-BKRnMgrB.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Dt-Jx5JS.d.mts} +46 -15
- package/dist/op-factory-call-Dt-Jx5JS.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +115 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-BMBRPzsv.mjs +367 -0
- package/dist/planner-BMBRPzsv.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 +4 -6
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +8 -2
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-C0a7I1-e.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-C0a7I1-e.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-Dp6IO_gj.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-Dp6IO_gj.mjs.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-Cze3vMfe.mjs} +2 -2
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-Cze3vMfe.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.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 +55 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-3xfUgjnC.mjs} +44 -41
- package/dist/postgres-contract-view-3xfUgjnC.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-C9bTuMrd.d.mts +190 -0
- package/dist/postgres-database-schema-node-C9bTuMrd.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-D0jwzYDT.mjs} +21 -2
- package/dist/postgres-migration-D0jwzYDT.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DFaxuRyI.d.mts} +20 -7
- package/dist/postgres-migration-DFaxuRyI.d.mts.map +1 -0
- package/dist/postgres-native-enum-xdiqmBf_.mjs +41 -0
- package/dist/postgres-native-enum-xdiqmBf_.mjs.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-CajYAwny.mjs} +135 -7
- package/dist/postgres-schema-CajYAwny.mjs.map +1 -0
- package/dist/postgres-schema-DqnhQRvR.d.mts +226 -0
- package/dist/postgres-schema-DqnhQRvR.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-BgaSrxYN.mjs +249 -0
- package/dist/postgres-table-schema-node-BgaSrxYN.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-Bv1ZvjX8.mjs +22 -0
- package/dist/resolve-ddl-schema-Bv1ZvjX8.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +2 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +6 -8
- 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 +15 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/schema-node-kinds-ClScchhi.mjs +76 -0
- package/dist/schema-node-kinds-ClScchhi.mjs.map +1 -0
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +3 -2
- package/package.json +23 -17
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/ddl.ts +45 -1
- package/src/core/authoring.ts +287 -2
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +141 -1
- package/src/core/ddl/nodes.ts +94 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +6 -1
- package/src/core/entity-kinds.ts +30 -0
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +149 -0
- package/src/core/migrations/control-policy.ts +70 -47
- package/src/core/migrations/diff-database-schema.ts +280 -0
- package/src/core/migrations/issue-planner.ts +647 -652
- package/src/core/migrations/op-factory-call.ts +109 -21
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/dependencies.ts +2 -1
- 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 +20 -58
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -216
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +297 -59
- 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 +26 -0
- package/src/core/migrations/runner.ts +10 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +47 -30
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +41 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +51 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +37 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +62 -14
- package/src/core/postgres-validators.ts +27 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1068 -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 +60 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +60 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +63 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +118 -0
- package/src/core/schema-ir/schema-node-kinds.ts +106 -0
- package/src/exports/contract-free.ts +7 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +4 -0
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/migration.ts +1 -0
- package/src/exports/op-factory-call.ts +1 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +1 -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/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
- 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 +0 -824
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.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
- package/src/core/postgres-enum-type-schema.ts +0 -17
|
@@ -1,14 +1,26 @@
|
|
|
1
|
+
import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86.mjs";
|
|
1
2
|
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 {
|
|
3
|
+
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-ujxH2A7r.mjs";
|
|
4
|
+
import { n as qualifyTableName } from "./planner-sql-checks-Cze3vMfe.mjs";
|
|
5
|
+
import { n as buildColumnTypeSql } from "./planner-ddl-builders-B8Nn6nHN.mjs";
|
|
5
6
|
import { FunctionColumnDefault, LiteralColumnDefault } from "@prisma-next/sql-relational-core/ast";
|
|
7
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
6
8
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
9
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
8
|
-
import {
|
|
10
|
+
import { col } from "@prisma-next/sql-relational-core/contract-free";
|
|
9
11
|
import { errorUnfilledPlaceholder } from "@prisma-next/errors/migration";
|
|
10
12
|
import { TsExpression, jsonToTsSource } from "@prisma-next/ts-render";
|
|
11
13
|
import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
|
|
14
|
+
//#region src/core/migrations/bound-schema.ts
|
|
15
|
+
/**
|
|
16
|
+
* Maps a planner schema name to the contract-free DDL builder's optional
|
|
17
|
+
* `schema` field: the unbound sentinel becomes `undefined` (the builder omits
|
|
18
|
+
* the schema qualifier), every other name passes through.
|
|
19
|
+
*/
|
|
20
|
+
function boundSchema(schemaName) {
|
|
21
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
12
24
|
//#region src/core/migrations/operations/shared.ts
|
|
13
25
|
function step(description, sql, params) {
|
|
14
26
|
return {
|
|
@@ -171,12 +183,16 @@ async function setDefault(schemaName, tableName, columnName, defaultSql, lowerer
|
|
|
171
183
|
};
|
|
172
184
|
}
|
|
173
185
|
async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
174
|
-
const qualified = qualifyTableName(schemaName, tableName);
|
|
175
186
|
const { present } = await columnExistsSteps(lowerer, {
|
|
176
187
|
schema: schemaName,
|
|
177
188
|
table: tableName,
|
|
178
189
|
column: columnName
|
|
179
190
|
});
|
|
191
|
+
const dropDefaultExec = await lowerer.lowerToExecuteRequest(alterTable({
|
|
192
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
193
|
+
table: tableName,
|
|
194
|
+
actions: [dropDefaultAction(columnName)]
|
|
195
|
+
}));
|
|
180
196
|
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
181
197
|
schema: schemaName,
|
|
182
198
|
table: tableName,
|
|
@@ -188,17 +204,23 @@ async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
|
188
204
|
operationClass: "destructive",
|
|
189
205
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
190
206
|
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
191
|
-
execute: [step(`drop default on "${columnName}"`,
|
|
207
|
+
execute: [step(`drop default on "${columnName}"`, dropDefaultExec.sql)],
|
|
192
208
|
postcheck: [step(`verify column "${columnName}" has no default`, noDefault.sql, noDefault.params)]
|
|
193
209
|
};
|
|
194
210
|
}
|
|
195
211
|
/**
|
|
196
212
|
* Builds the op for adding a NOT NULL column (no contract default) to a
|
|
197
213
|
* non-empty table. Prechecks assert the column is absent and the table is
|
|
198
|
-
* empty; the execute step
|
|
199
|
-
*
|
|
214
|
+
* empty; the execute step lowers the typed `AddColumn` DDL node through the
|
|
215
|
+
* adapter; postchecks assert the column exists and is NOT NULL.
|
|
200
216
|
*/
|
|
201
|
-
async function addNotNullColumnDirect(schemaName, tableName,
|
|
217
|
+
async function addNotNullColumnDirect(schemaName, tableName, column, lowerer) {
|
|
218
|
+
const columnName = column.name;
|
|
219
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
220
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
221
|
+
table: tableName,
|
|
222
|
+
actions: [addColumnAction(column)]
|
|
223
|
+
}));
|
|
202
224
|
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
203
225
|
schema: schemaName,
|
|
204
226
|
table: tableName,
|
|
@@ -223,7 +245,7 @@ async function addNotNullColumnDirect(schemaName, tableName, columnName, execute
|
|
|
223
245
|
operationClass: "additive",
|
|
224
246
|
target: targetDetails("column", columnName, schemaName, tableName),
|
|
225
247
|
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}"`,
|
|
248
|
+
execute: [step(`add column "${columnName}"`, addColumn.sql)],
|
|
227
249
|
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params), step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
228
250
|
};
|
|
229
251
|
}
|
|
@@ -344,7 +366,7 @@ async function dropCheckConstraint(schemaName, tableName, constraintName, lowere
|
|
|
344
366
|
* `kind` feeds the operation's `target.details.objectType`. Descriptor-flow
|
|
345
367
|
* does not carry kind information in its drop-constraint descriptor, so the
|
|
346
368
|
* default is `'unique'`. The reconciliation planner passes the correct kind
|
|
347
|
-
* (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the
|
|
369
|
+
* (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the diff issue
|
|
348
370
|
* that produced the drop.
|
|
349
371
|
*/
|
|
350
372
|
async function dropConstraint(schemaName, tableName, constraintName, lowerer, kind = "unique") {
|
|
@@ -405,7 +427,7 @@ async function installExtension(options, lowerer) {
|
|
|
405
427
|
target: {
|
|
406
428
|
id: "postgres",
|
|
407
429
|
details: {
|
|
408
|
-
schema:
|
|
430
|
+
schema: DEFAULT_NAMESPACE_ID,
|
|
409
431
|
objectType: "dependency",
|
|
410
432
|
name: extensionName
|
|
411
433
|
}
|
|
@@ -463,6 +485,81 @@ async function dropIndex(schemaName, tableName, indexName, lowerer) {
|
|
|
463
485
|
};
|
|
464
486
|
}
|
|
465
487
|
//#endregion
|
|
488
|
+
//#region src/core/migrations/operations/rls.ts
|
|
489
|
+
const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
490
|
+
function validateRoleName(role) {
|
|
491
|
+
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_$]*$`);
|
|
492
|
+
return role;
|
|
493
|
+
}
|
|
494
|
+
async function createRlsPolicy(schemaName, tableName, policy, lowerer) {
|
|
495
|
+
const validatedRoles = policy.roles.map(validateRoleName);
|
|
496
|
+
const ddlNode = createPolicy({
|
|
497
|
+
schema: schemaName,
|
|
498
|
+
table: tableName,
|
|
499
|
+
name: policy.name,
|
|
500
|
+
permissive: policy.permissive,
|
|
501
|
+
operation: policy.operation,
|
|
502
|
+
roles: validatedRoles,
|
|
503
|
+
...ifDefined("using", policy.using),
|
|
504
|
+
...ifDefined("withCheck", policy.withCheck)
|
|
505
|
+
});
|
|
506
|
+
const checks = rlsPolicyExistsAst({
|
|
507
|
+
schema: schemaName,
|
|
508
|
+
table: tableName,
|
|
509
|
+
policyName: policy.name
|
|
510
|
+
});
|
|
511
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
512
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
513
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
514
|
+
return {
|
|
515
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policy.name}`,
|
|
516
|
+
label: `Create RLS policy "${policy.name}" on "${tableName}"`,
|
|
517
|
+
operationClass: "additive",
|
|
518
|
+
target: targetDetails("rlsPolicy", policy.name, schemaName, tableName),
|
|
519
|
+
precheck: [step(`ensure RLS policy "${policy.name}" does not exist`, absent.sql, absent.params)],
|
|
520
|
+
execute: [step(`create RLS policy "${policy.name}"`, execute.sql, execute.params)],
|
|
521
|
+
postcheck: [step(`verify RLS policy "${policy.name}" exists`, present.sql, present.params)]
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
async function dropRlsPolicy(schemaName, tableName, policyName, lowerer) {
|
|
525
|
+
const ddlNode = dropPolicy({
|
|
526
|
+
schema: schemaName,
|
|
527
|
+
table: tableName,
|
|
528
|
+
name: policyName
|
|
529
|
+
});
|
|
530
|
+
const checks = rlsPolicyExistsAst({
|
|
531
|
+
schema: schemaName,
|
|
532
|
+
table: tableName,
|
|
533
|
+
policyName
|
|
534
|
+
});
|
|
535
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
536
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
537
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
538
|
+
return {
|
|
539
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policyName}.drop`,
|
|
540
|
+
label: `Drop RLS policy "${policyName}" on "${tableName}"`,
|
|
541
|
+
operationClass: "destructive",
|
|
542
|
+
target: targetDetails("rlsPolicy", policyName, schemaName, tableName),
|
|
543
|
+
precheck: [step(`ensure RLS policy "${policyName}" exists`, present.sql, present.params)],
|
|
544
|
+
execute: [step(`drop RLS policy "${policyName}"`, execute.sql, execute.params)],
|
|
545
|
+
postcheck: [step(`verify RLS policy "${policyName}" is absent`, absent.sql, absent.params)]
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
async function enableRowLevelSecurity(schemaName, tableName, lowerer) {
|
|
549
|
+
const checks = rlsEnabledAst(schemaName, tableName);
|
|
550
|
+
const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
|
|
551
|
+
const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
|
|
552
|
+
return {
|
|
553
|
+
id: `rowLevelSecurity.${schemaName}.${tableName}`,
|
|
554
|
+
label: `Enable row-level security on "${tableName}"`,
|
|
555
|
+
operationClass: "additive",
|
|
556
|
+
target: targetDetails("rowLevelSecurity", tableName, schemaName),
|
|
557
|
+
precheck: [step(`check RLS is not already enabled on "${tableName}"`, disabled.sql, disabled.params)],
|
|
558
|
+
execute: [step(`enable row-level security on "${tableName}"`, `ALTER TABLE ${qualifyTableName(schemaName, tableName)} ENABLE ROW LEVEL SECURITY`)],
|
|
559
|
+
postcheck: [step(`verify row-level security is enabled on "${tableName}"`, enabled.sql, enabled.params)]
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
466
563
|
//#region src/core/migrations/operations/tables.ts
|
|
467
564
|
async function dropTable(schemaName, tableName, lowerer) {
|
|
468
565
|
const qualified = qualifyTableName(schemaName, tableName);
|
|
@@ -504,7 +601,20 @@ function buildAddColumnOperationIdentity(schema, tableName, columnName) {
|
|
|
504
601
|
}
|
|
505
602
|
async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
506
603
|
const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault, lowerer } = options;
|
|
507
|
-
const
|
|
604
|
+
const ddlColumn = col(columnName, buildColumnTypeSql(column, codecHooks, storageTypes), {
|
|
605
|
+
notNull: true,
|
|
606
|
+
default: new FunctionColumnDefault(temporaryDefault)
|
|
607
|
+
});
|
|
608
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
609
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
610
|
+
table: tableName,
|
|
611
|
+
actions: [addColumnAction(ddlColumn)]
|
|
612
|
+
}));
|
|
613
|
+
const dropTempDefault = await lowerer.lowerToExecuteRequest(alterTable({
|
|
614
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
615
|
+
table: tableName,
|
|
616
|
+
actions: [dropDefaultAction(columnName)]
|
|
617
|
+
}));
|
|
508
618
|
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
509
619
|
schema,
|
|
510
620
|
table: tableName,
|
|
@@ -532,10 +642,10 @@ async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
|
532
642
|
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
533
643
|
execute: [{
|
|
534
644
|
description: `add column "${columnName}"`,
|
|
535
|
-
sql:
|
|
645
|
+
sql: addColumn.sql
|
|
536
646
|
}, {
|
|
537
647
|
description: `drop temporary default from column "${columnName}"`,
|
|
538
|
-
sql:
|
|
648
|
+
sql: dropTempDefault.sql
|
|
539
649
|
}],
|
|
540
650
|
postcheck: [
|
|
541
651
|
step(`verify column "${columnName}" exists`, present.sql, present.params),
|
|
@@ -568,9 +678,6 @@ async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
|
568
678
|
* `PostgresOpFactoryCall` union.
|
|
569
679
|
*/
|
|
570
680
|
const POSTGRES_MIGRATION_FACADE = "@prisma-next/postgres/migration";
|
|
571
|
-
function boundSchema(schemaName) {
|
|
572
|
-
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
573
|
-
}
|
|
574
681
|
var PostgresOpFactoryCallNode = class extends TsExpression {
|
|
575
682
|
importRequirements() {
|
|
576
683
|
return [{
|
|
@@ -625,6 +732,7 @@ function renderDdlConstraintAsTsCall(constraint) {
|
|
|
625
732
|
const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
|
|
626
733
|
return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
|
|
627
734
|
}
|
|
735
|
+
case "check-expression": return `checkExpression(${jsonToTsSource(constraint.name)}, ${jsonToTsSource(constraint.expression)})`;
|
|
628
736
|
}
|
|
629
737
|
}
|
|
630
738
|
function needsColOrConstraintImport(columns) {
|
|
@@ -636,6 +744,7 @@ function constraintImportSymbols(constraints) {
|
|
|
636
744
|
for (const c of constraints) if (c.kind === "primary-key") symbols.add("primaryKey");
|
|
637
745
|
else if (c.kind === "foreign-key") symbols.add("foreignKey");
|
|
638
746
|
else if (c.kind === "unique") symbols.add("unique");
|
|
747
|
+
else if (c.kind === "check-expression") symbols.add("checkExpression");
|
|
639
748
|
return [...symbols];
|
|
640
749
|
}
|
|
641
750
|
function defaultImportSymbols(columns) {
|
|
@@ -998,10 +1107,8 @@ var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
|
998
1107
|
};
|
|
999
1108
|
/**
|
|
1000
1109
|
* 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.
|
|
1110
|
+
* a table that must be empty at migration time. Carries the typed `DdlColumn`
|
|
1111
|
+
* and lowers it to an ADD COLUMN execute step via the adapter at `toOp` time.
|
|
1005
1112
|
*
|
|
1006
1113
|
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1007
1114
|
* planner, never hand-written by migration authors.
|
|
@@ -1012,20 +1119,20 @@ var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
|
1012
1119
|
schemaName;
|
|
1013
1120
|
tableName;
|
|
1014
1121
|
columnName;
|
|
1015
|
-
|
|
1122
|
+
column;
|
|
1016
1123
|
label;
|
|
1017
|
-
constructor(schemaName, tableName, columnName,
|
|
1124
|
+
constructor(schemaName, tableName, columnName, column) {
|
|
1018
1125
|
super();
|
|
1019
1126
|
this.schemaName = schemaName;
|
|
1020
1127
|
this.tableName = tableName;
|
|
1021
1128
|
this.columnName = columnName;
|
|
1022
|
-
this.
|
|
1129
|
+
this.column = column;
|
|
1023
1130
|
this.label = `Add column ${columnName} to ${tableName}`;
|
|
1024
1131
|
this.freeze();
|
|
1025
1132
|
}
|
|
1026
1133
|
async toOp(lowerer) {
|
|
1027
1134
|
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.
|
|
1135
|
+
return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
|
|
1029
1136
|
}
|
|
1030
1137
|
renderTypeScript() {
|
|
1031
1138
|
return `rawSql(${jsonToTsSource({
|
|
@@ -1041,9 +1148,9 @@ var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
|
1041
1148
|
/**
|
|
1042
1149
|
* Planner-internal call for adding a NOT NULL column (no contract default)
|
|
1043
1150
|
* using a temporary default value for non-empty tables. Carries all parameters
|
|
1044
|
-
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; the
|
|
1045
|
-
* pre/postchecks are lowered
|
|
1046
|
-
*
|
|
1151
|
+
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; both the
|
|
1152
|
+
* typed ADD COLUMN execute step and the pre/postchecks are lowered via the
|
|
1153
|
+
* adapter at `toOp` time.
|
|
1047
1154
|
*
|
|
1048
1155
|
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1049
1156
|
* planner, never hand-written by migration authors.
|
|
@@ -1484,7 +1591,74 @@ var DataTransformCall = class extends PostgresOpFactoryCallNode {
|
|
|
1484
1591
|
}];
|
|
1485
1592
|
}
|
|
1486
1593
|
};
|
|
1594
|
+
var CreatePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1595
|
+
factoryName = "createRlsPolicy";
|
|
1596
|
+
operationClass = "additive";
|
|
1597
|
+
schemaName;
|
|
1598
|
+
tableName;
|
|
1599
|
+
policy;
|
|
1600
|
+
label;
|
|
1601
|
+
constructor(schemaName, tableName, policy) {
|
|
1602
|
+
super();
|
|
1603
|
+
this.schemaName = schemaName;
|
|
1604
|
+
this.tableName = tableName;
|
|
1605
|
+
this.policy = policy;
|
|
1606
|
+
this.label = `Create RLS policy "${policy.name}" on "${tableName}"`;
|
|
1607
|
+
this.freeze();
|
|
1608
|
+
}
|
|
1609
|
+
async toOp(lowerer) {
|
|
1610
|
+
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.`);
|
|
1611
|
+
return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
|
|
1612
|
+
}
|
|
1613
|
+
renderTypeScript() {
|
|
1614
|
+
return `createRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policy)})`;
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
var DropPostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1618
|
+
factoryName = "dropRlsPolicy";
|
|
1619
|
+
operationClass = "destructive";
|
|
1620
|
+
schemaName;
|
|
1621
|
+
tableName;
|
|
1622
|
+
policyName;
|
|
1623
|
+
label;
|
|
1624
|
+
constructor(schemaName, tableName, policyName) {
|
|
1625
|
+
super();
|
|
1626
|
+
this.schemaName = schemaName;
|
|
1627
|
+
this.tableName = tableName;
|
|
1628
|
+
this.policyName = policyName;
|
|
1629
|
+
this.label = `Drop RLS policy "${policyName}" on "${tableName}"`;
|
|
1630
|
+
this.freeze();
|
|
1631
|
+
}
|
|
1632
|
+
async toOp(lowerer) {
|
|
1633
|
+
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.`);
|
|
1634
|
+
return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
|
|
1635
|
+
}
|
|
1636
|
+
renderTypeScript() {
|
|
1637
|
+
return `dropRlsPolicy(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.policyName)})`;
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
var EnableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
|
|
1641
|
+
factoryName = "enableRowLevelSecurity";
|
|
1642
|
+
operationClass = "additive";
|
|
1643
|
+
schemaName;
|
|
1644
|
+
tableName;
|
|
1645
|
+
label;
|
|
1646
|
+
constructor(schemaName, tableName) {
|
|
1647
|
+
super();
|
|
1648
|
+
this.schemaName = schemaName;
|
|
1649
|
+
this.tableName = tableName;
|
|
1650
|
+
this.label = `Enable row-level security on "${tableName}"`;
|
|
1651
|
+
this.freeze();
|
|
1652
|
+
}
|
|
1653
|
+
async toOp(lowerer) {
|
|
1654
|
+
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.`);
|
|
1655
|
+
return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
|
|
1656
|
+
}
|
|
1657
|
+
renderTypeScript() {
|
|
1658
|
+
return `enableRowLevelSecurity(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1487
1661
|
//#endregion
|
|
1488
|
-
export {
|
|
1662
|
+
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
1663
|
|
|
1490
|
-
//# sourceMappingURL=op-factory-call-
|
|
1664
|
+
//# sourceMappingURL=op-factory-call-BKRnMgrB.mjs.map
|