@prisma-next/target-postgres 0.14.0-dev.7 → 0.14.0-dev.71
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-Bi9aa8zG.mjs +574 -0
- package/dist/authoring-Bi9aa8zG.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-BiIWziRO.d.mts} +3 -2
- package/dist/codec-types-BiIWziRO.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/codecs-Cl_hQHg-.mjs +913 -0
- package/dist/codecs-Cl_hQHg-.mjs.map +1 -0
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Cm-nS4mQ.d.mts} +111 -4
- package/dist/codecs-Cm-nS4mQ.d.mts.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-CuUhjWnn.mjs +1258 -0
- package/dist/control-policy-CuUhjWnn.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +866 -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-Dqgs-bDc.mjs} +93 -6
- package/dist/ddl-Dqgs-bDc.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-UugzVM-U.mjs +22 -0
- package/dist/descriptor-meta-UugzVM-U.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-ClN3bkRS.mjs +305 -0
- package/dist/diff-database-schema-ClN3bkRS.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-Bc2N3tMy.d.mts +170 -0
- package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
- package/dist/nodes-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CSIg5XDu.d.mts} +91 -15
- package/dist/op-factory-call-CSIg5XDu.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DtVSP_7Y.mjs} +400 -32
- package/dist/op-factory-call-DtVSP_7Y.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 +300 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-ChVasl04.mjs +390 -0
- package/dist/planner-ChVasl04.mjs.map +1 -0
- 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-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-CXue-6M9.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-CXue-6M9.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-qpU05c__.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-qpU05c__.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-CDXn2uaS.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CDXn2uaS.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-serializer-k3TAcPMY.mjs → postgres-contract-view-C3LPCLP_.mjs} +45 -41
- package/dist/postgres-contract-view-C3LPCLP_.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-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-DkmgGNcv.d.mts} +47 -9
- package/dist/postgres-migration-DkmgGNcv.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-fndp3Mbm.mjs} +69 -45
- package/dist/postgres-migration-fndp3Mbm.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-DKq6s1P3.d.mts +269 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DYATroNx.mjs} +200 -11
- package/dist/postgres-schema-DYATroNx.mjs.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-DpGte50u.mjs +22 -0
- package/dist/resolve-ddl-schema-DpGte50u.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +20 -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-rHHtr1h0.mjs +75 -0
- package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +509 -2
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +180 -1
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +10 -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 +769 -656
- package/src/core/migrations/op-factory-call.ts +273 -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/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 +101 -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 +1273 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +128 -0
- package/src/core/rls/canonicalize.ts +48 -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 +3 -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 +3 -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 +7 -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
|
@@ -2,17 +2,26 @@ import type { CodecTypes } from '../exports/codec-types';
|
|
|
2
2
|
import {
|
|
3
3
|
postgresAuthoringEntityTypes,
|
|
4
4
|
postgresAuthoringFieldPresets,
|
|
5
|
+
postgresAuthoringModelAttributes,
|
|
6
|
+
postgresAuthoringPslBlockDescriptors,
|
|
5
7
|
postgresAuthoringTypes,
|
|
6
8
|
} from './authoring';
|
|
9
|
+
import { postgresQualifyColumnType } from './codecs';
|
|
7
10
|
import { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';
|
|
11
|
+
import { DEFAULT_NAMESPACE_ID } from './namespace-ids';
|
|
12
|
+
import { postgresCreateNamespace } from './postgres-schema';
|
|
8
13
|
|
|
9
14
|
const postgresTargetDescriptorMetaBase = {
|
|
10
15
|
...postgresTargetDescriptorMetaRuntime,
|
|
11
|
-
defaultNamespaceId:
|
|
16
|
+
defaultNamespaceId: DEFAULT_NAMESPACE_ID,
|
|
12
17
|
authoring: {
|
|
13
18
|
type: postgresAuthoringTypes,
|
|
14
19
|
field: postgresAuthoringFieldPresets,
|
|
15
20
|
entityTypes: postgresAuthoringEntityTypes,
|
|
21
|
+
pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,
|
|
22
|
+
modelAttributes: postgresAuthoringModelAttributes,
|
|
23
|
+
createNamespace: postgresCreateNamespace,
|
|
24
|
+
qualifyColumnType: postgresQualifyColumnType,
|
|
16
25
|
},
|
|
17
26
|
} as const;
|
|
18
27
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { EntityKindDescriptor } from '@prisma-next/framework-components/ir';
|
|
2
|
+
import { PostgresNativeEnum, type PostgresNativeEnumInput } from './postgres-native-enum';
|
|
3
|
+
import { PostgresRlsEnablement, type PostgresRlsEnablementInput } from './postgres-rls-enablement';
|
|
4
|
+
import { PostgresRlsPolicy, type PostgresRlsPolicyInput } from './postgres-rls-policy';
|
|
5
|
+
import { PostgresRole, type PostgresRoleInput } from './postgres-role';
|
|
6
|
+
import {
|
|
7
|
+
PostgresNativeEnumSchema,
|
|
8
|
+
PostgresRlsEnablementSchema,
|
|
9
|
+
PostgresRlsPolicySchema,
|
|
10
|
+
PostgresRoleSchema,
|
|
11
|
+
} from './postgres-validators';
|
|
12
|
+
|
|
13
|
+
export const policyEntityKind: EntityKindDescriptor<PostgresRlsPolicyInput, PostgresRlsPolicy> = {
|
|
14
|
+
kind: 'policy',
|
|
15
|
+
schema: PostgresRlsPolicySchema,
|
|
16
|
+
construct: (input) => new PostgresRlsPolicy(input),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const roleEntityKind: EntityKindDescriptor<PostgresRoleInput, PostgresRole> = {
|
|
20
|
+
kind: 'role',
|
|
21
|
+
schema: PostgresRoleSchema,
|
|
22
|
+
construct: (input) => new PostgresRole(input),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const rlsEnablementEntityKind: EntityKindDescriptor<
|
|
26
|
+
PostgresRlsEnablementInput,
|
|
27
|
+
PostgresRlsEnablement
|
|
28
|
+
> = {
|
|
29
|
+
kind: 'rls',
|
|
30
|
+
schema: PostgresRlsEnablementSchema,
|
|
31
|
+
construct: (input) => new PostgresRlsEnablement(input),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const nativeEnumEntityKind: EntityKindDescriptor<
|
|
35
|
+
PostgresNativeEnumInput,
|
|
36
|
+
PostgresNativeEnum
|
|
37
|
+
> = {
|
|
38
|
+
kind: 'native_enum',
|
|
39
|
+
schema: PostgresNativeEnumSchema,
|
|
40
|
+
construct: (input) => new PostgresNativeEnum(input),
|
|
41
|
+
};
|
package/src/core/errors.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { CliStructuredError } from '@prisma-next/errors/control';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A `PostgresMigration`
|
|
5
|
-
*
|
|
6
|
-
* migration was constructed without a `ControlStack`.
|
|
7
|
-
* usage always goes through the migration CLI entrypoint,
|
|
8
|
-
* a stack from the loaded `prisma-next.config.ts`; reaching this
|
|
9
|
-
* means a test fixture or ad-hoc consumer instantiated `PostgresMigration`
|
|
10
|
-
* with the no-arg form (legal for `operations` / `describe` introspection
|
|
11
|
-
*
|
|
4
|
+
* A `PostgresMigration` operation that needs the materialized control adapter
|
|
5
|
+
* — named by `operation` (e.g. `createTable`, `dropColumn`, `dataTransform`) —
|
|
6
|
+
* was invoked, but the migration was constructed without a `ControlStack`.
|
|
7
|
+
* Concrete authoring usage always goes through the migration CLI entrypoint,
|
|
8
|
+
* which assembles a stack from the loaded `prisma-next.config.ts`; reaching this
|
|
9
|
+
* error means a test fixture or ad-hoc consumer instantiated `PostgresMigration`
|
|
10
|
+
* with the no-arg form (legal for `operations` / `describe` introspection only).
|
|
11
|
+
*
|
|
12
|
+
* The `operation` argument is required so every throw site names the operation
|
|
13
|
+
* that actually failed; a new operation cannot inherit a misattributed message.
|
|
12
14
|
*
|
|
13
15
|
* Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`
|
|
14
16
|
* (data-transform query plan against wrong contract) because the missing
|
|
@@ -19,15 +21,15 @@ import { CliStructuredError } from '@prisma-next/errors/control';
|
|
|
19
21
|
* the contract it talks about (`PostgresMigration`, the Postgres control
|
|
20
22
|
* adapter, the Postgres-target stack) only exists in this package.
|
|
21
23
|
*/
|
|
22
|
-
export function errorPostgresMigrationStackMissing(): CliStructuredError {
|
|
24
|
+
export function errorPostgresMigrationStackMissing(operation: string): CliStructuredError {
|
|
23
25
|
return new CliStructuredError(
|
|
24
26
|
'2007',
|
|
25
|
-
|
|
27
|
+
`PostgresMigration.${operation} requires a control adapter`,
|
|
26
28
|
{
|
|
27
29
|
domain: 'MIG',
|
|
28
|
-
why:
|
|
30
|
+
why: `PostgresMigration.${operation} was invoked on an instance constructed without a ControlStack, so the stored controlAdapter is undefined and the operation cannot lower its plan.`,
|
|
29
31
|
fix: 'Construct the migration via the migration CLI entrypoint (which assembles a ControlStack from the loaded prisma-next.config.ts), or pass a ControlStack containing a Postgres adapter to the migration constructor in test fixtures.',
|
|
30
|
-
meta: {},
|
|
32
|
+
meta: { operation },
|
|
31
33
|
},
|
|
32
34
|
);
|
|
33
35
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps a planner schema name to the contract-free DDL builder's optional
|
|
5
|
+
* `schema` field: the unbound sentinel becomes `undefined` (the builder omits
|
|
6
|
+
* the schema qualifier), every other name passes through.
|
|
7
|
+
*/
|
|
8
|
+
export function boundSchema(schemaName: string): string | undefined {
|
|
9
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? undefined : schemaName;
|
|
10
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CodecControlHooks } from '@prisma-next/family-sql/control';
|
|
2
|
+
import type { StorageColumn } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { DdlColumn } from '@prisma-next/sql-relational-core/ast';
|
|
4
|
+
import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
|
|
5
|
+
import type { SqlColumnDefaultIR, SqlColumnIR } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
7
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
8
|
+
import { postgresDefaultToDdlColumnDefault } from './op-factory-call';
|
|
9
|
+
import { buildColumnDefaultSql, buildColumnTypeSql } from './planner-ddl-builders';
|
|
10
|
+
import { resolveIdentityValue } from './planner-identity-values';
|
|
11
|
+
import { buildExpectedFormatType } from './planner-sql-checks';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reconstructs the `StorageColumn`-shaped fields the DDL builder functions
|
|
15
|
+
* (`buildColumnTypeSql`, `buildExpectedFormatType`, `resolveIdentityValue`)
|
|
16
|
+
* expect, from a column node's own stamped codec identity (`codecRef` /
|
|
17
|
+
* `codecBaseNativeType` / `codecNamedType`, Decision 5) — never the
|
|
18
|
+
* contract. The builders were written against `StorageColumn` and are
|
|
19
|
+
* unchanged here; only the shape feeding them moves from the contract to
|
|
20
|
+
* the node. An empty `storageTypes` catalog is passed alongside: the
|
|
21
|
+
* node's fields are already resolved past any `typeRef` indirection, so no
|
|
22
|
+
* live lookup is needed, and passing a non-empty catalog would risk a
|
|
23
|
+
* false `typeRef` hit against an unrelated storage type.
|
|
24
|
+
*/
|
|
25
|
+
function columnLike(
|
|
26
|
+
column: SqlColumnIR,
|
|
27
|
+
): Pick<
|
|
28
|
+
StorageColumn,
|
|
29
|
+
'nativeType' | 'codecId' | 'nullable' | 'many' | 'typeParams' | 'typeRef' | 'default'
|
|
30
|
+
> {
|
|
31
|
+
if (column.codecRef === undefined || column.codecBaseNativeType === undefined) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`columnLike: expected column "${column.name}" carries no codec identity — the expected tree must be derived via contractToSchemaIR for planning`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
nativeType: column.codecBaseNativeType,
|
|
38
|
+
codecId: column.codecRef.codecId,
|
|
39
|
+
nullable: column.nullable,
|
|
40
|
+
// `column.many` is unset on contract-derived columns (array-ness rides
|
|
41
|
+
// on the `nativeType` `[]` suffix there instead) — `codecRef.many`
|
|
42
|
+
// carries it. Hand-built/introspected columns set `column.many` directly.
|
|
43
|
+
...ifDefined('many', column.many ?? column.codecRef.many),
|
|
44
|
+
...ifDefined(
|
|
45
|
+
'typeParams',
|
|
46
|
+
column.codecRef.typeParams !== undefined
|
|
47
|
+
? blindCast<
|
|
48
|
+
Record<string, unknown>,
|
|
49
|
+
'CodecRef.typeParams is JsonValue-shaped; the DDL builders only ever read it as the Record the contract column originally carried'
|
|
50
|
+
>(column.codecRef.typeParams)
|
|
51
|
+
: undefined,
|
|
52
|
+
),
|
|
53
|
+
...(column.codecNamedType ? { typeRef: '<resolved>' } : {}),
|
|
54
|
+
...ifDefined('default', column.resolvedDefault),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Builds the `CREATE TABLE` / `ADD COLUMN` DDL column for an expected column
|
|
60
|
+
* node, resolving type rendering from the node's codec identity against the
|
|
61
|
+
* codec hooks the caller holds — the same builder the pre-`plan(start, end)`
|
|
62
|
+
* op-path called, so the output is byte-identical.
|
|
63
|
+
*/
|
|
64
|
+
export function renderColumnDdl(
|
|
65
|
+
name: string,
|
|
66
|
+
column: SqlColumnIR,
|
|
67
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
68
|
+
): DdlColumn {
|
|
69
|
+
const like = columnLike(column);
|
|
70
|
+
const typeSql = buildColumnTypeSql(like, codecHooks, {});
|
|
71
|
+
const ddlDefault = postgresDefaultToDdlColumnDefault(like.default);
|
|
72
|
+
return contractFree.col(name, typeSql, {
|
|
73
|
+
...(!column.nullable ? { notNull: true } : {}),
|
|
74
|
+
...ifDefined('default', ddlDefault),
|
|
75
|
+
...ifDefined('codecRef', column.codecRef),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Builds the `ALTER COLUMN … TYPE` operands for an expected column node.
|
|
81
|
+
*/
|
|
82
|
+
export function renderColumnAlterType(
|
|
83
|
+
column: SqlColumnIR,
|
|
84
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
85
|
+
): { readonly qualifiedTargetType: string; readonly formatTypeExpected: string } {
|
|
86
|
+
const like = columnLike(column);
|
|
87
|
+
return {
|
|
88
|
+
qualifiedTargetType: buildColumnTypeSql(like, codecHooks, {}, false),
|
|
89
|
+
formatTypeExpected: buildExpectedFormatType(like, codecHooks, {}),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the identity value (monoid neutral element) SQL literal used as
|
|
95
|
+
* the temporary default when adding a NOT-NULL column with no contract
|
|
96
|
+
* default (`notNullAddColumnCallStrategy`'s shared-temp-default backfill).
|
|
97
|
+
* `null` when the column's type has no built-in/codec-provided identity
|
|
98
|
+
* value.
|
|
99
|
+
*/
|
|
100
|
+
export function resolveColumnTemporaryDefault(
|
|
101
|
+
column: SqlColumnIR,
|
|
102
|
+
codecHooks: ReadonlyMap<string, CodecControlHooks>,
|
|
103
|
+
): string | null {
|
|
104
|
+
return resolveIdentityValue(columnLike(column), codecHooks, {});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The column's `SET DEFAULT` clause SQL, resolved from a column-default
|
|
109
|
+
* diff node. `''` when the node carries no resolved default.
|
|
110
|
+
*/
|
|
111
|
+
export function renderColumnDefaultSql(defaultNode: SqlColumnDefaultIR): string {
|
|
112
|
+
if (defaultNode.resolved === undefined) return '';
|
|
113
|
+
return buildColumnDefaultSql(defaultNode.resolved, {
|
|
114
|
+
nativeType: defaultNode.nativeTypeContext ?? '',
|
|
115
|
+
...ifDefined('many', defaultNode.many),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -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
|
+
}
|