@prisma-next/target-postgres 0.14.0-dev.9 → 0.14.0-dev.90
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-BtsOWgI3.mjs +674 -0
- package/dist/authoring-BtsOWgI3.mjs.map +1 -0
- package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
- package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-B10ZZHzw.mjs} +4 -2
- package/dist/codec-ids-B10ZZHzw.mjs.map +1 -0
- package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-CI144z7g.d.mts} +4 -2
- package/dist/codec-ids-CI144z7g.d.mts.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-CTfT4U4O.d.mts} +4 -2
- package/dist/codec-types-CTfT4U4O.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-D7W9O0Xx.d.mts} +134 -4
- package/dist/codecs-D7W9O0Xx.d.mts.map +1 -0
- package/dist/codecs-DRbb26Or.mjs +955 -0
- package/dist/codecs-DRbb26Or.mjs.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +3 -757
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +33 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +23 -7
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control-policy-DtbkLLGv.mjs +1285 -0
- package/dist/control-policy-DtbkLLGv.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +880 -36
- 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-GTTOvjx_.mjs} +128 -6
- package/dist/ddl-GTTOvjx_.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-CFQKLXl_.mjs +23 -0
- package/dist/descriptor-meta-CFQKLXl_.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-GncqMuSI.mjs +305 -0
- package/dist/diff-database-schema-GncqMuSI.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/errors-DO-w0EUS.mjs +35 -0
- package/dist/errors-DO-w0EUS.mjs.map +1 -0
- package/dist/errors.d.mts +11 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- 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-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/nodes-Dv5eCSq9.d.mts +170 -0
- package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Bn9zDx4_.d.mts} +114 -15
- package/dist/op-factory-call-Bn9zDx4_.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-C38NzvQD.mjs} +469 -32
- package/dist/op-factory-call-C38NzvQD.mjs.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 +321 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
- package/dist/planner-ddl-builders-BKlmGDJl.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-kql24i_F.mjs +390 -0
- package/dist/planner-kql24i_F.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BEY1T0Xm.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BEY1T0Xm.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-D7y-PEHK.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-D7y-PEHK.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-zqNfs2XZ.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-zqNfs2XZ.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 +72 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DM8sN1Ot.mjs} +45 -41
- package/dist/postgres-contract-view-DM8sN1Ot.mjs.map +1 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DbckK1su.d.mts} +58 -9
- package/dist/postgres-migration-DbckK1su.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-arMSWU9b.mjs} +78 -45
- package/dist/postgres-migration-arMSWU9b.mjs.map +1 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
- package/dist/postgres-native-enum-BwVNf0Ku.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-role-schema-node-Cm-j0ZGM.mjs +190 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-Cm4DtiGA.mjs} +200 -11
- package/dist/postgres-schema-Cm4DtiGA.mjs.map +1 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
- package/dist/postgres-table-schema-node-D6LvInCe.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-XyBaaenM.mjs +22 -0
- package/dist/resolve-ddl-schema-XyBaaenM.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +27 -0
- package/dist/rls-canonicalize.d.mts.map +1 -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/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
- package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
- package/dist/sql-utils.d.mts +8 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +5 -2
- package/dist/wire-name-DbQ9-2RC.mjs +104 -0
- package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +153 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +726 -2
- package/src/core/codec-helpers.ts +33 -7
- package/src/core/codec-ids.ts +2 -0
- package/src/core/codec-type-map.ts +4 -0
- package/src/core/codecs.ts +236 -12
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +12 -1
- package/src/core/entity-kinds.ts +41 -0
- package/src/core/errors.ts +14 -12
- 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 +189 -0
- package/src/core/migrations/control-policy.ts +217 -65
- package/src/core/migrations/diff-database-schema.ts +252 -0
- package/src/core/migrations/issue-planner.ts +817 -656
- package/src/core/migrations/op-factory-call.ts +383 -23
- 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/native-enum-types.ts +62 -0
- package/src/core/migrations/operations/rls.ts +187 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +31 -59
- 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 +357 -67
- package/src/core/migrations/postgres-migration.ts +118 -86
- 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 +11 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +46 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +61 -0
- package/src/core/postgres-rls-enablement.ts +34 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +59 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +85 -15
- package/src/core/postgres-validators.ts +34 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1290 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +129 -0
- package/src/core/rls/canonicalize.ts +65 -0
- package/src/core/rls/wire-name.ts +33 -0
- package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
- package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
- package/src/core/schema-ir/schema-node-kinds.ts +122 -0
- package/src/core/sql-utils.ts +15 -2
- package/src/exports/codecs.ts +5 -0
- package/src/exports/contract-free.ts +11 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +8 -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 +4 -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 +12 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/types.ts +37 -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/errors-CUk87ByX.mjs +0 -33
- package/dist/errors-CUk87ByX.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 +0 -76
- 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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { ContractToSchemaIROptions } from '@prisma-next/family-sql/control';
|
|
2
|
+
import { contractNamespaceToSchemaIR } from '@prisma-next/family-sql/control';
|
|
3
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
4
|
+
import { SqlForeignKeyIR } from '@prisma-next/sql-schema-ir/types';
|
|
5
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
6
|
+
import type { PostgresRlsPolicy } from '../postgres-rls-policy';
|
|
7
|
+
import type { PostgresContract } from '../postgres-schema';
|
|
8
|
+
import { isPostgresSchema } from '../postgres-schema';
|
|
9
|
+
import { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
|
|
10
|
+
import { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
|
|
11
|
+
import { PostgresNativeEnumSchemaNode } from '../schema-ir/postgres-native-enum-schema-node';
|
|
12
|
+
import { PostgresPolicySchemaNode } from '../schema-ir/postgres-policy-schema-node';
|
|
13
|
+
import { PostgresRoleSchemaNode } from '../schema-ir/postgres-role-schema-node';
|
|
14
|
+
import { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';
|
|
15
|
+
import { resolveDdlSchemaForNamespaceStorage } from './resolve-ddl-schema';
|
|
16
|
+
|
|
17
|
+
function toPolicyNode(policy: PostgresRlsPolicy, namespaceId: string): PostgresPolicySchemaNode {
|
|
18
|
+
return new PostgresPolicySchemaNode({
|
|
19
|
+
name: policy.name,
|
|
20
|
+
prefix: policy.prefix,
|
|
21
|
+
tableName: policy.tableName,
|
|
22
|
+
namespaceId,
|
|
23
|
+
operation: policy.operation,
|
|
24
|
+
roles: [...policy.roles],
|
|
25
|
+
...ifDefined('using', policy.using),
|
|
26
|
+
...ifDefined('withCheck', policy.withCheck),
|
|
27
|
+
permissive: policy.permissive,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Projects a Postgres contract into the expected schema-diff tree: a
|
|
33
|
+
* `PostgresDatabaseSchemaNode` root holding one `PostgresNamespaceSchemaNode`
|
|
34
|
+
* per Postgres namespace, each holding its `PostgresTableSchemaNode`s with
|
|
35
|
+
* their `PostgresPolicySchemaNode`s, plus the database roles on the root.
|
|
36
|
+
*
|
|
37
|
+
* Not a duplicate of the family's `contractToSchemaIR`: that builds a flat,
|
|
38
|
+
* single `{ tables }` map (and throws on cross-namespace name collisions, with
|
|
39
|
+
* no RLS/role concept) for SQLite's single-schema world. This is the
|
|
40
|
+
* Postgres-specific *tree* shape — multi-schema, RLS-policy-aware, role-aware.
|
|
41
|
+
* It reuses the family's per-namespace table conversion (`contractNamespaceToSchemaIR`)
|
|
42
|
+
* for column/FK/index building and only adds the Postgres tree/policy/role shape.
|
|
43
|
+
*
|
|
44
|
+
* Tables are grouped by their owning namespace (resolved DDL schema name) so
|
|
45
|
+
* the tree mirrors Postgres's object hierarchy. The DDL schema name is
|
|
46
|
+
* resolved once per namespace.
|
|
47
|
+
*
|
|
48
|
+
* A policy that references a table absent from its namespace is a malformed
|
|
49
|
+
* contract — the loop throws rather than fabricating a stub table.
|
|
50
|
+
*/
|
|
51
|
+
export function contractToPostgresDatabaseSchemaNode(
|
|
52
|
+
contract: PostgresContract | null,
|
|
53
|
+
options: ContractToSchemaIROptions,
|
|
54
|
+
): PostgresDatabaseSchemaNode {
|
|
55
|
+
if (contract === null) {
|
|
56
|
+
return new PostgresDatabaseSchemaNode({
|
|
57
|
+
namespaces: {},
|
|
58
|
+
roles: [],
|
|
59
|
+
existingSchemas: [],
|
|
60
|
+
pgVersion: '',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const namespaces: Record<string, PostgresNamespaceSchemaNode> = {};
|
|
65
|
+
const roles: PostgresRoleSchemaNode[] = [];
|
|
66
|
+
const ownedSchemas: string[] = [];
|
|
67
|
+
|
|
68
|
+
for (const ns of Object.values(contract.storage.namespaces)) {
|
|
69
|
+
if (!isPostgresSchema(ns)) continue;
|
|
70
|
+
|
|
71
|
+
// Role entries are root-level diff subjects: they hoist to the database
|
|
72
|
+
// root from every slot and never count toward whether a namespace
|
|
73
|
+
// materializes a schema node.
|
|
74
|
+
for (const role of Object.values(ns.role)) {
|
|
75
|
+
roles.push(new PostgresRoleSchemaNode({ name: role.name, namespaceId: role.namespaceId }));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The unbound slot resolves its DDL schema to 'public', so it
|
|
79
|
+
// materializes a schema node exactly when it has non-role content — a
|
|
80
|
+
// late-binding contract keeps today's behavior (the slot carries the
|
|
81
|
+
// tables), while a roles-only unbound slot alongside named namespaces
|
|
82
|
+
// contributes only root roles and no node (which would otherwise be a
|
|
83
|
+
// spurious empty 'public' node, clobbering a real bound 'public'
|
|
84
|
+
// namespace's node keyed by the same resolved schema name).
|
|
85
|
+
if (ns.id === UNBOUND_NAMESPACE_ID) {
|
|
86
|
+
const hasNonRoleContent = Object.entries(ns.entries).some(
|
|
87
|
+
([entriesKey, slot]) => entriesKey !== 'role' && Object.keys(slot).length > 0,
|
|
88
|
+
);
|
|
89
|
+
if (!hasNonRoleContent) continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, ns.id);
|
|
93
|
+
ownedSchemas.push(ddlSchema);
|
|
94
|
+
|
|
95
|
+
// Convert only THIS namespace's tables (passing the full storage for
|
|
96
|
+
// type/value-set/enum resolution that spans namespaces), so the same table
|
|
97
|
+
// name can exist in two schemas without colliding in a bare-keyed record.
|
|
98
|
+
const sqlTables = contractNamespaceToSchemaIR(contract.storage, ns.id, options).tables;
|
|
99
|
+
|
|
100
|
+
const policiesByTable = new Map<string, PostgresPolicySchemaNode[]>();
|
|
101
|
+
for (const policy of Object.values(ns.policy)) {
|
|
102
|
+
const list = policiesByTable.get(policy.tableName) ?? [];
|
|
103
|
+
list.push(toPolicyNode(policy, ddlSchema));
|
|
104
|
+
policiesByTable.set(policy.tableName, list);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const tables: Record<string, PostgresTableSchemaNode> = {};
|
|
108
|
+
for (const tableName of Object.keys(ns.table)) {
|
|
109
|
+
const sqlTable = sqlTables[tableName];
|
|
110
|
+
if (sqlTable === undefined) continue;
|
|
111
|
+
// The family conversion stamps `referencedSchema` only for bound FK
|
|
112
|
+
// targets; an absent value means the FK targets the unbound namespace.
|
|
113
|
+
// Postgres restores its own coordinate for that slot (the unbound
|
|
114
|
+
// singleton's id) so the raw coordinate keeps qualifying REFERENCES
|
|
115
|
+
// clauses, and resolves the real live DDL schema — introspected FKs
|
|
116
|
+
// already carry the live schema, so this is what lets an expected FK
|
|
117
|
+
// pair (by diff-node id) with its introspected counterpart.
|
|
118
|
+
const foreignKeys = sqlTable.foreignKeys.map(
|
|
119
|
+
(fk) =>
|
|
120
|
+
new SqlForeignKeyIR({
|
|
121
|
+
columns: fk.columns,
|
|
122
|
+
referencedTable: fk.referencedTable,
|
|
123
|
+
referencedColumns: fk.referencedColumns,
|
|
124
|
+
referencedSchema: fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
|
|
125
|
+
...ifDefined('name', fk.name),
|
|
126
|
+
...ifDefined('onDelete', fk.onDelete),
|
|
127
|
+
...ifDefined('onUpdate', fk.onUpdate),
|
|
128
|
+
...ifDefined('annotations', fk.annotations),
|
|
129
|
+
resolvedReferencedNamespace: resolveDdlSchemaForNamespaceStorage(
|
|
130
|
+
contract.storage,
|
|
131
|
+
fk.referencedSchema ?? UNBOUND_NAMESPACE_ID,
|
|
132
|
+
),
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
tables[tableName] = new PostgresTableSchemaNode({
|
|
136
|
+
name: sqlTable.name,
|
|
137
|
+
columns: sqlTable.columns,
|
|
138
|
+
foreignKeys,
|
|
139
|
+
uniques: sqlTable.uniques,
|
|
140
|
+
indexes: sqlTable.indexes,
|
|
141
|
+
...ifDefined('primaryKey', sqlTable.primaryKey),
|
|
142
|
+
...ifDefined('annotations', sqlTable.annotations),
|
|
143
|
+
...ifDefined('checks', sqlTable.checks),
|
|
144
|
+
policies: policiesByTable.get(tableName) ?? [],
|
|
145
|
+
// Marker-driven, never derived from the policy set: the `rls` entry
|
|
146
|
+
// is the single authored source of enablement.
|
|
147
|
+
rlsEnabled: Object.hasOwn(ns.rls, tableName),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (const [tableName, tablePolicies] of policiesByTable) {
|
|
152
|
+
if (!(tableName in tables)) {
|
|
153
|
+
const policyName = tablePolicies[0]?.name ?? '(unknown)';
|
|
154
|
+
throw new Error(
|
|
155
|
+
`contract-to-postgres-database-schema-node: policy "${policyName}" references table "${tableName}" not present in namespace "${ddlSchema}"`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (!Object.hasOwn(ns.rls, tableName)) {
|
|
159
|
+
const policyPrefix = tablePolicies[0]?.prefix ?? '(unknown)';
|
|
160
|
+
throw new Error(
|
|
161
|
+
`contract-to-postgres-database-schema-node: policy "${policyPrefix}" targets table "${tableName}" in namespace "${ddlSchema}", which is not RLS-controlled. Mark the model with @@rls (entries.rls["${tableName}"]) or remove the policy.`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const nativeEnums = Object.values(ns.entries.native_enum ?? {}).map(
|
|
167
|
+
(entity) =>
|
|
168
|
+
new PostgresNativeEnumSchemaNode({
|
|
169
|
+
typeName: entity.typeName,
|
|
170
|
+
namespaceId: ddlSchema,
|
|
171
|
+
members: entity.members,
|
|
172
|
+
...ifDefined('control', entity.control),
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
namespaces[ddlSchema] = new PostgresNamespaceSchemaNode({
|
|
177
|
+
schemaName: ddlSchema,
|
|
178
|
+
tables,
|
|
179
|
+
nativeEnums,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return new PostgresDatabaseSchemaNode({
|
|
184
|
+
namespaces,
|
|
185
|
+
roles,
|
|
186
|
+
existingSchemas: ownedSchemas,
|
|
187
|
+
pgVersion: '',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { Contract, ControlPolicy } from '@prisma-next/contract/types';
|
|
2
|
+
import type {
|
|
3
|
+
ControlPolicySubject,
|
|
4
|
+
SqlPlannerConflict,
|
|
5
|
+
SuppressionRecord,
|
|
6
|
+
} from '@prisma-next/family-sql/control';
|
|
7
|
+
import type { SchemaDiffIssue } from '@prisma-next/framework-components/control';
|
|
4
8
|
import { entityAt, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
5
9
|
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
10
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
6
11
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
12
|
+
import { type PostgresRole, ROLE_DEFAULT_CONTROL_POLICY } from '../postgres-role';
|
|
7
13
|
import { isPostgresSchema } from '../postgres-schema';
|
|
14
|
+
import { postgresNodeStorageCoordinate } from '../schema-ir/node-storage-coordinate';
|
|
15
|
+
import type { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
|
|
16
|
+
import { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';
|
|
17
|
+
import type { SqlSchemaDiffNode } from '../schema-ir/schema-node-kinds';
|
|
18
|
+
import { PostgresSchemaNodeKind } from '../schema-ir/schema-node-kinds';
|
|
19
|
+
import { issueColumnName } from './issue-planner';
|
|
8
20
|
import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
9
21
|
|
|
10
22
|
/**
|
|
@@ -17,11 +29,16 @@ import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
|
17
29
|
* and is fail-closed. Any call not listed here — including future or
|
|
18
30
|
* extension-contributed factories — is treated as NOT object-creation, so it
|
|
19
31
|
* is suppressed under `tolerated` rather than permissively emitted.
|
|
32
|
+
*
|
|
33
|
+
* Lists the creation factories that actually reach the call-side resolver
|
|
34
|
+
* (`resolvePostgresCallControlPolicySubject`) — today only RLS policy
|
|
35
|
+
* creation, from `planPostgresSchemaDiff`. Every other whole-object create
|
|
36
|
+
* (table, schema, native enum, and RLS enablement) is constructed inside
|
|
37
|
+
* `planIssues` and graded on the node side by
|
|
38
|
+
* `resolvePostgresNodeIssueCreationFactoryName`, so none of them are listed
|
|
39
|
+
* here.
|
|
20
40
|
*/
|
|
21
|
-
const OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>([
|
|
22
|
-
'createTable',
|
|
23
|
-
'createSchema',
|
|
24
|
-
]);
|
|
41
|
+
const OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>(['createRlsPolicy']);
|
|
25
42
|
|
|
26
43
|
function createsNewTopLevelObject(call: PostgresOpFactoryCall): boolean {
|
|
27
44
|
return OBJECT_CREATION_FACTORIES.has(call.factoryName);
|
|
@@ -32,18 +49,25 @@ function ddlSchemaNameForNamespace(contract: Contract<SqlStorage>, namespaceId:
|
|
|
32
49
|
return isPostgresSchema(namespace) ? namespace.ddlSchemaName(contract.storage) : namespaceId;
|
|
33
50
|
}
|
|
34
51
|
|
|
35
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the namespace a declared storage entity lives in by walking every
|
|
54
|
+
* namespace for one whose `entries` map actually contains the coordinate —
|
|
55
|
+
* a table by its name, a native enum by its physical type name (see
|
|
56
|
+
* {@link postgresNodeStorageCoordinate}). When `ddlSchemaName` is given, the
|
|
57
|
+
* match must also land in that DDL schema (disambiguates same-named entities
|
|
58
|
+
* declared under different namespaces); when omitted, the first namespace
|
|
59
|
+
* that declares the entity wins. Falls back to {@link UNBOUND_NAMESPACE_ID}
|
|
60
|
+
* when no namespace declares it — e.g. an extra/dropped entity the contract
|
|
61
|
+
* doesn't claim at all.
|
|
62
|
+
*/
|
|
63
|
+
function resolveNamespaceIdForEntity(
|
|
36
64
|
contract: Contract<SqlStorage>,
|
|
37
|
-
|
|
65
|
+
coordinate: { readonly entityKind: string; readonly entityName: string },
|
|
38
66
|
ddlSchemaName: string | undefined,
|
|
39
67
|
): string {
|
|
40
68
|
for (const namespaceId of Object.keys(contract.storage.namespaces)) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
entityKind: 'table',
|
|
44
|
-
entityName: tableName,
|
|
45
|
-
});
|
|
46
|
-
if (!table) continue;
|
|
69
|
+
const entity = entityAt(contract.storage, { namespaceId, ...coordinate });
|
|
70
|
+
if (!entity) continue;
|
|
47
71
|
if (
|
|
48
72
|
ddlSchemaName === undefined ||
|
|
49
73
|
ddlSchemaNameForNamespace(contract, namespaceId) === ddlSchemaName
|
|
@@ -54,7 +78,19 @@ function resolveNamespaceIdForTable(
|
|
|
54
78
|
return UNBOUND_NAMESPACE_ID;
|
|
55
79
|
}
|
|
56
80
|
|
|
57
|
-
function
|
|
81
|
+
function resolveNamespaceIdForTable(
|
|
82
|
+
contract: Contract<SqlStorage>,
|
|
83
|
+
tableName: string,
|
|
84
|
+
ddlSchemaName: string | undefined,
|
|
85
|
+
): string {
|
|
86
|
+
return resolveNamespaceIdForEntity(
|
|
87
|
+
contract,
|
|
88
|
+
{ entityKind: 'table', entityName: tableName },
|
|
89
|
+
ddlSchemaName,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function resolveNamespaceIdForDdlSchema(
|
|
58
94
|
contract: Contract<SqlStorage>,
|
|
59
95
|
ddlSchemaName: string,
|
|
60
96
|
): string {
|
|
@@ -84,16 +120,60 @@ function postgresCallFields(call: PostgresOpFactoryCall): PostgresCallFields {
|
|
|
84
120
|
};
|
|
85
121
|
}
|
|
86
122
|
|
|
87
|
-
|
|
88
|
-
factoryName: string,
|
|
123
|
+
function formatSuppressionSubjectLabel(
|
|
89
124
|
subject: ControlPolicySubject | undefined,
|
|
90
125
|
contract: Contract<SqlStorage>,
|
|
91
126
|
): string {
|
|
92
|
-
if (subject
|
|
93
|
-
|
|
94
|
-
|
|
127
|
+
if (subject === undefined) return 'unknown';
|
|
128
|
+
const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);
|
|
129
|
+
if (subject.entityKind !== undefined && subject.entityName !== undefined) {
|
|
130
|
+
return `${subject.entityKind} "${ddlSchema}.${subject.entityName}"`;
|
|
131
|
+
}
|
|
132
|
+
return `namespace "${ddlSchema}"`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function postgresSuppressionSummary(
|
|
136
|
+
subjectLabel: string,
|
|
137
|
+
subject: ControlPolicySubject | undefined,
|
|
138
|
+
policy: string,
|
|
139
|
+
): string {
|
|
140
|
+
const namespace = subject?.namespaceId ?? 'unknown';
|
|
141
|
+
const declared = subject?.explicitNodeControlPolicy;
|
|
142
|
+
if (policy === 'external' && declared === 'managed') {
|
|
143
|
+
return `control policy suppressed: ${subjectLabel} — namespace '${namespace}' has effective control 'external' but declared 'managed'`;
|
|
95
144
|
}
|
|
96
|
-
|
|
145
|
+
const declaredSuffix = declared ? ` but declared '${declared}'` : '';
|
|
146
|
+
return `control policy suppressed: ${subjectLabel} — namespace '${namespace}' has effective control '${policy}'${declaredSuffix}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Render one family {@link SuppressionRecord} into a target `SqlPlannerConflict`.
|
|
151
|
+
* The family decides *that* a subject is suppressed and hands over the raw
|
|
152
|
+
* coordinate + policy; the label, message, and location are rendered here,
|
|
153
|
+
* driven entirely by the subject's own `(entityKind, entityName)` coordinate
|
|
154
|
+
* — no target-owned table-vs-enum vocabulary.
|
|
155
|
+
*/
|
|
156
|
+
export function renderPostgresSuppression(
|
|
157
|
+
record: SuppressionRecord,
|
|
158
|
+
contract: Contract<SqlStorage>,
|
|
159
|
+
): SqlPlannerConflict {
|
|
160
|
+
const subject = record.subject;
|
|
161
|
+
const subjectLabel = formatSuppressionSubjectLabel(subject, contract);
|
|
162
|
+
return {
|
|
163
|
+
kind: 'controlPolicySuppressedCall',
|
|
164
|
+
summary: postgresSuppressionSummary(subjectLabel, subject, record.policy),
|
|
165
|
+
location: {
|
|
166
|
+
...ifDefined('namespaceId', subject?.namespaceId),
|
|
167
|
+
...ifDefined('entityKind', subject?.entityKind),
|
|
168
|
+
...ifDefined('entityName', subject?.entityName),
|
|
169
|
+
...ifDefined('column', subject?.column),
|
|
170
|
+
},
|
|
171
|
+
meta: {
|
|
172
|
+
controlPolicy: record.policy,
|
|
173
|
+
...ifDefined('factoryName', record.factoryName),
|
|
174
|
+
...ifDefined('declaredControlPolicy', subject?.explicitNodeControlPolicy),
|
|
175
|
+
},
|
|
176
|
+
};
|
|
97
177
|
}
|
|
98
178
|
|
|
99
179
|
export function resolvePostgresCallControlPolicySubject(
|
|
@@ -123,9 +203,10 @@ export function resolvePostgresCallControlPolicySubject(
|
|
|
123
203
|
})?.control;
|
|
124
204
|
return {
|
|
125
205
|
namespaceId,
|
|
126
|
-
|
|
127
|
-
|
|
206
|
+
entityKind: 'table',
|
|
207
|
+
entityName: callFields.tableName,
|
|
128
208
|
...ifDefined('column', callFields.columnName),
|
|
209
|
+
...ifDefined('explicitNodeControlPolicy', tableControlPolicy),
|
|
129
210
|
createsNewObject,
|
|
130
211
|
};
|
|
131
212
|
}
|
|
@@ -141,64 +222,135 @@ export function resolvePostgresCallControlPolicySubject(
|
|
|
141
222
|
}
|
|
142
223
|
|
|
143
224
|
/**
|
|
144
|
-
*
|
|
145
|
-
* object
|
|
146
|
-
*
|
|
147
|
-
*
|
|
225
|
+
* Node kinds whose *absence* is the creation of a whole, top-level Postgres
|
|
226
|
+
* object: a namespace, a table, or a native enum. Used by
|
|
227
|
+
* {@link resolvePostgresNodeIssueCreationFactoryName} to decide whether a
|
|
228
|
+
* `tolerated` subject permits the issue to flow into the planner
|
|
148
229
|
* (create-if-absent) and to seed the suppressed-subject warning's
|
|
149
|
-
* `factoryName` when the planner is skipped.
|
|
230
|
+
* `factoryName` when the planner is skipped. RLS policy creation is not
|
|
231
|
+
* listed here — policy issues never reach this issue-based partition (they
|
|
232
|
+
* are routed to `planPostgresSchemaDiff` and gated via the call-based
|
|
233
|
+
* {@link resolvePostgresCallControlPolicySubject} instead).
|
|
150
234
|
*/
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
235
|
+
const POSTGRES_NODE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({
|
|
236
|
+
[PostgresSchemaNodeKind.namespace]: 'createSchema',
|
|
237
|
+
[PostgresSchemaNodeKind.table]: 'createTable',
|
|
238
|
+
[PostgresSchemaNodeKind.nativeEnum]: 'createNativeEnumType',
|
|
154
239
|
});
|
|
155
240
|
|
|
156
|
-
|
|
157
|
-
|
|
241
|
+
/**
|
|
242
|
+
* A table `not-equal` issue whose `rlsEnabled` flips OFF→ON (expected on,
|
|
243
|
+
* actual off) is enablement toward `ENABLE ROW LEVEL SECURITY`. It is
|
|
244
|
+
* creation-class on the node side because `isEnablementCreationIssue` and
|
|
245
|
+
* {@link resolvePostgresNodeIssueCreationFactoryName} treat this OFF→ON delta
|
|
246
|
+
* as a creation: enabling RLS establishes the fail-closed guard the declared
|
|
247
|
+
* policy set attaches to, the same grant `tolerated` extends to creating the
|
|
248
|
+
* policies themselves. The opposite direction (`DISABLE`) is a modification
|
|
249
|
+
* and stays managed-only. Keying on the actual delta (not just the expected
|
|
250
|
+
* bit) keeps this correct if a second table attribute ever joins
|
|
251
|
+
* `isEqualTo`: a not-equal with no `rlsEnabled` delta is not enablement, so
|
|
252
|
+
* it is not admitted as creation-class here.
|
|
253
|
+
*/
|
|
254
|
+
function isEnablementCreationIssue(issue: SchemaDiffIssue<SqlSchemaDiffNode>): boolean {
|
|
255
|
+
if (issue.reason !== 'not-equal') return false;
|
|
256
|
+
const { expected, actual } = issue;
|
|
257
|
+
return (
|
|
258
|
+
expected !== undefined &&
|
|
259
|
+
actual !== undefined &&
|
|
260
|
+
PostgresTableSchemaNode.is(expected) &&
|
|
261
|
+
PostgresTableSchemaNode.is(actual) &&
|
|
262
|
+
expected.rlsEnabled === true &&
|
|
263
|
+
actual.rlsEnabled === false
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function resolvePostgresNodeIssueCreationFactoryName(
|
|
268
|
+
issue: SchemaDiffIssue<SqlSchemaDiffNode>,
|
|
269
|
+
): string | undefined {
|
|
270
|
+
if (isEnablementCreationIssue(issue)) {
|
|
271
|
+
return 'enableRowLevelSecurity';
|
|
272
|
+
}
|
|
273
|
+
if (issue.reason !== 'not-found') return undefined;
|
|
274
|
+
const node = issue.expected ?? issue.actual;
|
|
275
|
+
if (node === undefined) return undefined;
|
|
276
|
+
return POSTGRES_NODE_CREATION_FACTORY[node.nodeKind];
|
|
158
277
|
}
|
|
159
278
|
|
|
160
279
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* touches an existing object.
|
|
168
|
-
*
|
|
169
|
-
* An `extra_table` issue carries no contract namespace coordinate (the table
|
|
170
|
-
* isn't in any contract namespace), so the subject's `namespaceId` falls
|
|
171
|
-
* back to {@link UNBOUND_NAMESPACE_ID}; the call-side resolver does the same
|
|
172
|
-
* for the `DropTableCall` it produces.
|
|
280
|
+
* Resolves the control-policy subject for a node-typed {@link SchemaDiffIssue}
|
|
281
|
+
* (the issue-side mirror of `resolvePostgresCallControlPolicySubject`).
|
|
282
|
+
* Storage entities resolve off their node coordinate; a sub-entity issue
|
|
283
|
+
* resolves off the enclosing table read from the issue path; an unclaimed
|
|
284
|
+
* extra falls back to the unbound coordinate. A role always resolves
|
|
285
|
+
* `'external'` — roles are referenced, never owned.
|
|
173
286
|
*/
|
|
174
|
-
export function
|
|
175
|
-
issue:
|
|
287
|
+
export function resolvePostgresNodeIssueControlPolicySubject(
|
|
288
|
+
issue: SchemaDiffIssue<SqlSchemaDiffNode>,
|
|
176
289
|
contract: Contract<SqlStorage>,
|
|
177
290
|
): ControlPolicySubject | undefined {
|
|
178
|
-
const
|
|
291
|
+
const node = issue.expected ?? issue.actual;
|
|
292
|
+
if (node === undefined) return undefined;
|
|
293
|
+
|
|
294
|
+
if (node.nodeKind === PostgresSchemaNodeKind.namespace) {
|
|
295
|
+
const namespaceNode = blindCast<
|
|
296
|
+
PostgresNamespaceSchemaNode,
|
|
297
|
+
'a postgres-namespace diff node is always a PostgresNamespaceSchemaNode'
|
|
298
|
+
>(node);
|
|
299
|
+
return {
|
|
300
|
+
namespaceId: resolveNamespaceIdForDdlSchema(contract, namespaceNode.schemaName),
|
|
301
|
+
createsNewObject: issue.reason === 'not-found',
|
|
302
|
+
};
|
|
303
|
+
}
|
|
179
304
|
|
|
180
|
-
if (
|
|
181
|
-
|
|
305
|
+
if (node.nodeKind === PostgresSchemaNodeKind.role) {
|
|
306
|
+
const roleName = issue.path[1];
|
|
307
|
+
const roleEntity =
|
|
308
|
+
roleName === undefined
|
|
309
|
+
? undefined
|
|
310
|
+
: entityAt<PostgresRole>(contract.storage, {
|
|
311
|
+
namespaceId: UNBOUND_NAMESPACE_ID,
|
|
312
|
+
entityKind: 'role',
|
|
313
|
+
entityName: roleName,
|
|
314
|
+
});
|
|
315
|
+
return {
|
|
316
|
+
namespaceId: UNBOUND_NAMESPACE_ID,
|
|
317
|
+
explicitNodeControlPolicy: roleEntity?.control ?? ROLE_DEFAULT_CONTROL_POLICY,
|
|
318
|
+
createsNewObject: false,
|
|
319
|
+
};
|
|
182
320
|
}
|
|
183
321
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
: resolveNamespaceIdForTable(contract, issue.table, undefined);
|
|
189
|
-
const table = entityAt<StorageTable>(contract.storage, {
|
|
322
|
+
const coordinate = postgresNodeStorageCoordinate(node);
|
|
323
|
+
if (coordinate !== undefined) {
|
|
324
|
+
const namespaceId = resolveNamespaceIdForEntity(contract, coordinate, issue.path[1]);
|
|
325
|
+
const entityControl = entityAt<{ readonly control?: ControlPolicy }>(contract.storage, {
|
|
190
326
|
namespaceId,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
327
|
+
...coordinate,
|
|
328
|
+
})?.control;
|
|
194
329
|
return {
|
|
195
330
|
namespaceId,
|
|
196
|
-
...
|
|
197
|
-
|
|
198
|
-
...ifDefined('
|
|
199
|
-
createsNewObject,
|
|
331
|
+
...coordinate,
|
|
332
|
+
...ifDefined('column', issueColumnName(issue)),
|
|
333
|
+
...ifDefined('explicitNodeControlPolicy', entityControl),
|
|
334
|
+
createsNewObject: resolvePostgresNodeIssueCreationFactoryName(issue) !== undefined,
|
|
200
335
|
};
|
|
201
336
|
}
|
|
202
337
|
|
|
203
|
-
|
|
338
|
+
const tableName = issue.path[2];
|
|
339
|
+
if (tableName === undefined) return undefined;
|
|
340
|
+
const ddlSchemaName = issue.path[1];
|
|
341
|
+
const namespaceId = resolveNamespaceIdForTable(contract, tableName, ddlSchemaName);
|
|
342
|
+
const table = entityAt<StorageTable>(contract.storage, {
|
|
343
|
+
namespaceId,
|
|
344
|
+
entityKind: 'table',
|
|
345
|
+
entityName: tableName,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
namespaceId,
|
|
350
|
+
entityKind: 'table',
|
|
351
|
+
entityName: tableName,
|
|
352
|
+
...ifDefined('column', issueColumnName(issue)),
|
|
353
|
+
...ifDefined('explicitNodeControlPolicy', table?.control),
|
|
354
|
+
createsNewObject: resolvePostgresNodeIssueCreationFactoryName(issue) !== undefined,
|
|
355
|
+
};
|
|
204
356
|
}
|