@prisma-next/target-postgres 0.11.0 → 0.12.0-dev.10
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/{codec-ids-D9fJ4HP5.d.mts → codec-ids-DliyCWPY.d.mts} +1 -1
- package/dist/{codec-ids-D9fJ4HP5.d.mts.map → codec-ids-DliyCWPY.d.mts.map} +1 -1
- package/dist/codec-ids.d.mts +1 -1
- package/dist/{codec-types-CRlHq7Cz.d.mts → codec-types-BF1DXTPs.d.mts} +2 -2
- package/dist/codec-types-BF1DXTPs.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-Dud5KDNk.d.mts → codecs-DuP3d9Au.d.mts} +2 -2
- package/dist/{codecs-Dud5KDNk.d.mts.map → codecs-DuP3d9Au.d.mts.map} +1 -1
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.d.mts.map +1 -1
- package/dist/codecs.mjs.map +1 -1
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +46 -53
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-bmOKkygi.d.mts → data-transform-CAPmAdxS.d.mts} +2 -2
- package/dist/data-transform-CAPmAdxS.d.mts.map +1 -0
- package/dist/{data-transform-CdtGUWp2.mjs → data-transform-CRkv2T_U.mjs} +1 -1
- package/dist/{data-transform-CdtGUWp2.mjs.map → data-transform-CRkv2T_U.mjs.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/{default-normalizer-DHCsbfjc.mjs → default-normalizer-DaAhmzBV.mjs} +1 -1
- package/dist/{default-normalizer-DHCsbfjc.mjs.map → default-normalizer-DaAhmzBV.mjs.map} +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/descriptor-meta-Uu8QaClr.mjs +13 -0
- package/dist/descriptor-meta-Uu8QaClr.mjs.map +1 -0
- package/dist/{descriptor-meta-DLA2xV6B.mjs → descriptor-meta-runtime-DMRX39kp.mjs} +82 -78
- package/dist/descriptor-meta-runtime-DMRX39kp.mjs.map +1 -0
- package/dist/enum-planning-DRA9LaMU.mjs +0 -0
- package/dist/enum-planning-DRA9LaMU.mjs.map +1 -0
- package/dist/enum-planning.d.mts +42 -4
- package/dist/enum-planning.d.mts.map +1 -1
- package/dist/enum-planning.mjs +2 -2
- package/dist/{errors--zafB5_n.mjs → errors-BbnITmAD.mjs} +1 -1
- package/dist/{errors--zafB5_n.mjs.map → errors-BbnITmAD.mjs.map} +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{issue-planner-OthDciOe.mjs → issue-planner-BtaL6OfW.mjs} +116 -59
- package/dist/issue-planner-BtaL6OfW.mjs.map +1 -0
- package/dist/issue-planner.d.mts +1 -1
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +3 -3
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +3 -3
- package/dist/migration.mjs.map +1 -1
- package/dist/{native-type-normalizer-DMikJJ1V.mjs → native-type-normalizer-BNEQ9VDs.mjs} +1 -1
- package/dist/{native-type-normalizer-DMikJJ1V.mjs.map → native-type-normalizer-BNEQ9VDs.mjs.map} +1 -1
- package/dist/native-type-normalizer.d.mts.map +1 -1
- package/dist/native-type-normalizer.mjs +1 -1
- package/dist/{op-factory-call-Drccm_JD.d.mts → op-factory-call-CDlImOF_.d.mts} +3 -3
- package/dist/op-factory-call-CDlImOF_.d.mts.map +1 -0
- package/dist/{op-factory-call-Bgb_ghPb.mjs → op-factory-call-ewOd5q6L.mjs} +2 -2
- package/dist/{op-factory-call-Bgb_ghPb.mjs.map → op-factory-call-ewOd5q6L.mjs.map} +1 -1
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +10 -8
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-DZG1dsSW.mjs → planner-Bjz5pnLa.mjs} +17 -25
- package/dist/planner-Bjz5pnLa.mjs.map +1 -0
- package/dist/{planner-ddl-builders-DYMuN0w1.mjs → planner-ddl-builders-BNMfSE9r.mjs} +3 -3
- package/dist/{planner-ddl-builders-DYMuN0w1.mjs.map → planner-ddl-builders-BNMfSE9r.mjs.map} +1 -1
- package/dist/planner-ddl-builders.d.mts +1 -1
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-ojX-6cPV.mjs → planner-identity-values-nhVj0hp-.mjs} +1 -1
- package/dist/{planner-identity-values-ojX-6cPV.mjs.map → planner-identity-values-nhVj0hp-.mjs.map} +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-p-VKkCia.d.mts → planner-produced-postgres-migration-D02NOhVQ.d.mts} +3 -3
- package/dist/planner-produced-postgres-migration-D02NOhVQ.d.mts.map +1 -0
- package/dist/{planner-produced-postgres-migration-TJWH2m_x.mjs → planner-produced-postgres-migration-D_nsXbhl.mjs} +5 -7
- package/dist/planner-produced-postgres-migration-D_nsXbhl.mjs.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-schema-lookup-BGyukuzG.mjs → planner-schema-lookup-CGxxYfnD.mjs} +1 -1
- package/dist/{planner-schema-lookup-BGyukuzG.mjs.map → planner-schema-lookup-CGxxYfnD.mjs.map} +1 -1
- package/dist/planner-schema-lookup.d.mts.map +1 -1
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/{planner-sql-checks-K-mTBJDi.mjs → planner-sql-checks-CfEiTXoQ.mjs} +3 -3
- package/dist/{planner-sql-checks-K-mTBJDi.mjs.map → planner-sql-checks-CfEiTXoQ.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-CIj61DUj.d.mts → planner-target-details-a_wuOiYf.d.mts} +1 -1
- package/dist/{planner-target-details-CIj61DUj.d.mts.map → planner-target-details-a_wuOiYf.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +2 -7
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-CrET5Ov0.mjs → postgres-contract-serializer-BnOboPWs.mjs} +12 -12
- package/dist/postgres-contract-serializer-BnOboPWs.mjs.map +1 -0
- package/dist/{postgres-enum-type-DS-KLVRH.mjs → postgres-enum-type-BMgyxNyy.mjs} +2 -1
- package/dist/postgres-enum-type-BMgyxNyy.mjs.map +1 -0
- package/dist/{postgres-enum-type-CNhPTDhy.d.mts → postgres-enum-type-CSzsvXrO.d.mts} +4 -1
- package/dist/postgres-enum-type-CSzsvXrO.d.mts.map +1 -0
- package/dist/{postgres-migration-uADmx0dW.mjs → postgres-migration-BatbEvU6.mjs} +3 -3
- package/dist/{postgres-migration-uADmx0dW.mjs.map → postgres-migration-BatbEvU6.mjs.map} +1 -1
- package/dist/{postgres-migration-Fd4fQkBw.d.mts → postgres-migration-DRY8V-bQ.d.mts} +3 -3
- package/dist/{postgres-migration-Fd4fQkBw.d.mts.map → postgres-migration-DRY8V-bQ.d.mts.map} +1 -1
- package/dist/{postgres-schema-CK82EuWq.mjs → postgres-schema-BxAuNFX0.mjs} +15 -22
- package/dist/postgres-schema-BxAuNFX0.mjs.map +1 -0
- package/dist/{render-ops-BC2PtCkj.mjs → render-ops-XhICjX_P.mjs} +1 -1
- package/dist/{render-ops-BC2PtCkj.mjs.map → render-ops-XhICjX_P.mjs.map} +1 -1
- package/dist/render-ops.d.mts +1 -1
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-CI1wbgUc.mjs → render-typescript-K125n-RZ.mjs} +2 -3
- package/dist/render-typescript-K125n-RZ.mjs.map +1 -0
- package/dist/render-typescript.d.mts +0 -1
- package/dist/render-typescript.d.mts.map +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/{shared-ByhSooBS.d.mts → shared-Do_a5ymU.d.mts} +2 -2
- package/dist/shared-Do_a5ymU.d.mts.map +1 -0
- package/dist/{sql-utils-BewXAnsG.mjs → sql-utils-CggjWNij.mjs} +1 -1
- package/dist/{sql-utils-BewXAnsG.mjs.map → sql-utils-CggjWNij.mjs.map} +1 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +1 -1
- package/dist/{statement-builders-vImtdfmM.mjs → statement-builders-DgYQooDR.mjs} +16 -4
- package/dist/statement-builders-DgYQooDR.mjs.map +1 -0
- package/dist/statement-builders.d.mts +1 -1
- package/dist/statement-builders.d.mts.map +1 -1
- package/dist/statement-builders.mjs +1 -1
- package/dist/{tables-CWxZgD0H.mjs → tables-DoA39Yqo.mjs} +3 -3
- package/dist/{tables-CWxZgD0H.mjs.map → tables-DoA39Yqo.mjs.map} +1 -1
- package/dist/{types-D-XIpzHA.d.mts → types-O40IcFV9.d.mts} +1 -1
- package/dist/types-O40IcFV9.d.mts.map +1 -0
- package/dist/types.d.mts +14 -18
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -2
- package/package.json +29 -18
- package/src/core/authoring.ts +1 -1
- package/src/core/descriptor-meta-runtime.ts +28 -0
- package/src/core/descriptor-meta.ts +2 -6
- package/src/core/migrations/enum-planning.ts +134 -14
- package/src/core/migrations/issue-planner.ts +20 -11
- package/src/core/migrations/planner-produced-postgres-migration.ts +0 -2
- package/src/core/migrations/planner-strategies.ts +141 -43
- package/src/core/migrations/planner.ts +9 -21
- package/src/core/migrations/render-typescript.ts +1 -5
- package/src/core/migrations/runner.ts +70 -76
- package/src/core/migrations/statement-builders.ts +19 -4
- package/src/core/migrations/verify-postgres-namespaces.ts +6 -6
- package/src/core/postgres-contract-serializer.ts +16 -16
- package/src/core/postgres-enum-type.ts +4 -0
- package/src/core/postgres-schema.ts +14 -24
- package/src/exports/control.ts +16 -0
- package/src/exports/enum-planning.ts +5 -0
- package/src/exports/runtime.ts +2 -2
- package/dist/codec-types-CRlHq7Cz.d.mts.map +0 -1
- package/dist/data-transform-bmOKkygi.d.mts.map +0 -1
- package/dist/descriptor-meta-DLA2xV6B.mjs.map +0 -1
- package/dist/enum-planning-Bqp96iIw.mjs +0 -63
- package/dist/enum-planning-Bqp96iIw.mjs.map +0 -1
- package/dist/issue-planner-OthDciOe.mjs.map +0 -1
- package/dist/op-factory-call-Drccm_JD.d.mts.map +0 -1
- package/dist/planner-DZG1dsSW.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-TJWH2m_x.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-p-VKkCia.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-CrET5Ov0.mjs.map +0 -1
- package/dist/postgres-enum-type-CNhPTDhy.d.mts.map +0 -1
- package/dist/postgres-enum-type-DS-KLVRH.mjs.map +0 -1
- package/dist/postgres-schema-CK82EuWq.mjs.map +0 -1
- package/dist/render-typescript-CI1wbgUc.mjs.map +0 -1
- package/dist/shared-ByhSooBS.d.mts.map +0 -1
- package/dist/statement-builders-vImtdfmM.mjs.map +0 -1
- package/dist/types-D-XIpzHA.d.mts.map +0 -1
package/package.json
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-dev.10",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.
|
|
10
|
-
"@prisma-next/contract": "0.
|
|
11
|
-
"@prisma-next/errors": "0.
|
|
12
|
-
"@prisma-next/family-sql": "0.
|
|
13
|
-
"@prisma-next/framework-components": "0.
|
|
14
|
-
"@prisma-next/migration-tools": "0.
|
|
15
|
-
"@prisma-next/ts-render": "0.
|
|
16
|
-
"@prisma-next/sql-contract": "0.
|
|
17
|
-
"@prisma-next/sql-errors": "0.
|
|
18
|
-
"@prisma-next/sql-operations": "0.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.
|
|
21
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/cli": "0.12.0-dev.10",
|
|
10
|
+
"@prisma-next/contract": "0.12.0-dev.10",
|
|
11
|
+
"@prisma-next/errors": "0.12.0-dev.10",
|
|
12
|
+
"@prisma-next/family-sql": "0.12.0-dev.10",
|
|
13
|
+
"@prisma-next/framework-components": "0.12.0-dev.10",
|
|
14
|
+
"@prisma-next/migration-tools": "0.12.0-dev.10",
|
|
15
|
+
"@prisma-next/ts-render": "0.12.0-dev.10",
|
|
16
|
+
"@prisma-next/sql-contract": "0.12.0-dev.10",
|
|
17
|
+
"@prisma-next/sql-errors": "0.12.0-dev.10",
|
|
18
|
+
"@prisma-next/sql-operations": "0.12.0-dev.10",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.12.0-dev.10",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.12.0-dev.10",
|
|
21
|
+
"@prisma-next/utils": "0.12.0-dev.10",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.
|
|
28
|
-
"@prisma-next/tsconfig": "0.
|
|
29
|
-
"@prisma-next/tsdown": "0.
|
|
27
|
+
"@prisma-next/test-utils": "0.12.0-dev.10",
|
|
28
|
+
"@prisma-next/tsconfig": "0.12.0-dev.10",
|
|
29
|
+
"@prisma-next/tsdown": "0.12.0-dev.10",
|
|
30
30
|
"tsdown": "0.22.0",
|
|
31
31
|
"typescript": "5.9.3",
|
|
32
32
|
"vitest": "4.1.6"
|
|
33
33
|
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"typescript": ">=5.9"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"typescript": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
34
42
|
"files": [
|
|
35
43
|
"dist",
|
|
36
44
|
"src",
|
|
@@ -65,13 +73,16 @@
|
|
|
65
73
|
"./types": "./dist/types.mjs",
|
|
66
74
|
"./package.json": "./package.json"
|
|
67
75
|
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=24"
|
|
78
|
+
},
|
|
68
79
|
"repository": {
|
|
69
80
|
"type": "git",
|
|
70
81
|
"url": "https://github.com/prisma/prisma-next.git",
|
|
71
82
|
"directory": "packages/3-targets/3-targets/postgres"
|
|
72
83
|
},
|
|
73
84
|
"prismaNext": {
|
|
74
|
-
"minServerVersion": "
|
|
85
|
+
"minServerVersion": "17"
|
|
75
86
|
},
|
|
76
87
|
"scripts": {
|
|
77
88
|
"build": "tsdown",
|
package/src/core/authoring.ts
CHANGED
|
@@ -124,7 +124,7 @@ export const postgresAuthoringFieldPresets = {
|
|
|
124
124
|
nativeType: 'timestamptz',
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
|
-
temporal: temporalAuthoringPresets({
|
|
127
|
+
temporal: /* @__PURE__ */ temporalAuthoringPresets({
|
|
128
128
|
codecId: 'pg/timestamptz@1',
|
|
129
129
|
nativeType: 'timestamptz',
|
|
130
130
|
}),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Runtime-safe slice of the postgres target descriptor metadata.
|
|
2
|
+
//
|
|
3
|
+
// This file exists separately from ./descriptor-meta on purpose: the runtime
|
|
4
|
+
// plane reads only `kind/familyId/targetId/id/version/capabilities` (plus the
|
|
5
|
+
// `__codecTypes` phantom). The `authoring` slot lives on the pack/control
|
|
6
|
+
// descriptor only, because authoring contributions are consumed at
|
|
7
|
+
// contract-construction time by `assembleAuthoringContributions` (control
|
|
8
|
+
// plane) and the PSL interpreter — never at runtime.
|
|
9
|
+
//
|
|
10
|
+
// Keeping the runtime closure free of the `./authoring` import is what lets
|
|
11
|
+
// the bundler tree-shake `@prisma-next/family-sql/control` (and its
|
|
12
|
+
// transitive `verify-sql-schema` chunk) out of the runtime entry. Do not
|
|
13
|
+
// add an `authoring` field here — if you need to, the pack/control meta in
|
|
14
|
+
// `./descriptor-meta` is the right place. See TML-2766 for context.
|
|
15
|
+
import type { CodecTypes } from '../exports/codec-types';
|
|
16
|
+
|
|
17
|
+
const postgresTargetDescriptorMetaRuntimeBase = {
|
|
18
|
+
kind: 'target',
|
|
19
|
+
familyId: 'sql',
|
|
20
|
+
targetId: 'postgres',
|
|
21
|
+
id: 'postgres',
|
|
22
|
+
version: '0.0.1',
|
|
23
|
+
capabilities: {},
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
export const postgresTargetDescriptorMetaRuntime: typeof postgresTargetDescriptorMetaRuntimeBase & {
|
|
27
|
+
readonly __codecTypes?: CodecTypes;
|
|
28
|
+
} = postgresTargetDescriptorMetaRuntimeBase;
|
|
@@ -4,14 +4,10 @@ import {
|
|
|
4
4
|
postgresAuthoringFieldPresets,
|
|
5
5
|
postgresAuthoringTypes,
|
|
6
6
|
} from './authoring';
|
|
7
|
+
import { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';
|
|
7
8
|
|
|
8
9
|
const postgresTargetDescriptorMetaBase = {
|
|
9
|
-
|
|
10
|
-
familyId: 'sql',
|
|
11
|
-
targetId: 'postgres',
|
|
12
|
-
id: 'postgres',
|
|
13
|
-
version: '0.0.1',
|
|
14
|
-
capabilities: {},
|
|
10
|
+
...postgresTargetDescriptorMetaRuntime,
|
|
15
11
|
authoring: {
|
|
16
12
|
type: postgresAuthoringTypes,
|
|
17
13
|
field: postgresAuthoringFieldPresets,
|
|
@@ -5,9 +5,138 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { arraysEqual } from '@prisma-next/family-sql/schema-verify';
|
|
8
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
9
|
+
import type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
8
10
|
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
9
11
|
import { PG_ENUM_CODEC_ID } from '../codec-ids';
|
|
10
12
|
import type { PostgresEnumType } from '../postgres-enum-type';
|
|
13
|
+
import { isPostgresSchema } from '../postgres-schema';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Codec-typed enum entry shape stored under
|
|
17
|
+
* `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.
|
|
18
|
+
*/
|
|
19
|
+
interface PgStorageTypeEntry {
|
|
20
|
+
readonly codecId?: string;
|
|
21
|
+
readonly typeParams?: { readonly values?: unknown };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */
|
|
25
|
+
export interface PostgresSchemaIrAnnotations {
|
|
26
|
+
readonly schema?: string;
|
|
27
|
+
readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readOptionalString(value: unknown): string | undefined {
|
|
31
|
+
return typeof value === 'string' ? value : undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {
|
|
35
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const codecId = Reflect.get(value, 'codecId');
|
|
39
|
+
const typeParamsRaw = Reflect.get(value, 'typeParams');
|
|
40
|
+
const typeParams =
|
|
41
|
+
typeParamsRaw !== undefined &&
|
|
42
|
+
typeParamsRaw !== null &&
|
|
43
|
+
typeof typeParamsRaw === 'object' &&
|
|
44
|
+
!Array.isArray(typeParamsRaw)
|
|
45
|
+
? { values: Reflect.get(typeParamsRaw, 'values') }
|
|
46
|
+
: undefined;
|
|
47
|
+
return {
|
|
48
|
+
...(typeof codecId === 'string' ? { codecId } : {}),
|
|
49
|
+
...(typeParams !== undefined ? { typeParams } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function readPgStorageTypesMap(
|
|
54
|
+
value: unknown,
|
|
55
|
+
): Readonly<Record<string, PgStorageTypeEntry>> | undefined {
|
|
56
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const entries: Record<string, PgStorageTypeEntry> = {};
|
|
60
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
61
|
+
const entry = readPgStorageTypeEntry(entryValue);
|
|
62
|
+
if (entry !== undefined) {
|
|
63
|
+
entries[key] = entry;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return Object.keys(entries).length > 0 ? entries : undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reads the Postgres annotation envelope (`schema.annotations.pg`) from
|
|
71
|
+
* family Schema IR. `SqlAnnotations` is an open target-pack extensibility
|
|
72
|
+
* map (`Record<string, unknown>`); this accessor narrows the `pg` slot at
|
|
73
|
+
* runtime so Postgres code can read introspection fields without casts.
|
|
74
|
+
*/
|
|
75
|
+
export function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {
|
|
76
|
+
const raw = schema.annotations?.['pg'];
|
|
77
|
+
if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const schemaField = readOptionalString(Reflect.get(raw, 'schema'));
|
|
81
|
+
const storageTypes = readPgStorageTypesMap(Reflect.get(raw, 'storageTypes'));
|
|
82
|
+
return {
|
|
83
|
+
...(schemaField !== undefined ? { schema: schemaField } : {}),
|
|
84
|
+
...(storageTypes !== undefined ? { storageTypes } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Separator for `(schemaName, nativeType)` keys in introspected
|
|
90
|
+
* `schema.annotations.pg.storageTypes`. NUL cannot appear in Postgres
|
|
91
|
+
* identifiers, so the pair is unambiguous.
|
|
92
|
+
*/
|
|
93
|
+
export const ENUM_STORAGE_KEY_SEP = '\u0000';
|
|
94
|
+
|
|
95
|
+
/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */
|
|
96
|
+
export function enumStorageCompoundKey(schemaName: string, nativeType: string): string {
|
|
97
|
+
return `${schemaName}${ENUM_STORAGE_KEY_SEP}${nativeType}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Resolves the live-schema name a namespace's enums are introspected under,
|
|
102
|
+
* for keying `readExistingEnumValues` lookups. The unbound namespace's
|
|
103
|
+
* `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a
|
|
104
|
+
* real schema, so for the unbound coordinate we read the *introspected* schema
|
|
105
|
+
* recorded on `annotations.pg.schema` (the live `current_schema()` the adapter
|
|
106
|
+
* walked) — that is the schema the enum's `storageTypes` entry is keyed under.
|
|
107
|
+
* Named namespaces resolve to their own DDL schema, which matches the
|
|
108
|
+
* per-schema introspection key directly.
|
|
109
|
+
*/
|
|
110
|
+
export function resolveDdlSchemaForNamespaceStorage(
|
|
111
|
+
storage: SqlStorage,
|
|
112
|
+
namespaceId: string,
|
|
113
|
+
schemaIr?: SqlSchemaIR,
|
|
114
|
+
): string {
|
|
115
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) {
|
|
116
|
+
return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';
|
|
117
|
+
}
|
|
118
|
+
const namespace = storage.namespaces[namespaceId];
|
|
119
|
+
if (namespace && isPostgresSchema(namespace)) {
|
|
120
|
+
return namespace.ddlSchemaName(storage);
|
|
121
|
+
}
|
|
122
|
+
return namespaceId;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Contract-scoped bridge for the family verifier's enum value resolver. */
|
|
126
|
+
export function createResolveExistingEnumValues(
|
|
127
|
+
storage: SqlStorage,
|
|
128
|
+
): (
|
|
129
|
+
schema: SqlSchemaIR,
|
|
130
|
+
enumType: PostgresEnumStorageEntry,
|
|
131
|
+
namespaceId: string,
|
|
132
|
+
) => readonly string[] | null {
|
|
133
|
+
return (schema, enumType, namespaceId) =>
|
|
134
|
+
readExistingEnumValues(
|
|
135
|
+
schema,
|
|
136
|
+
resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),
|
|
137
|
+
enumType.nativeType,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
11
140
|
|
|
12
141
|
/**
|
|
13
142
|
* Categorisation of how an existing enum type's values relate to the
|
|
@@ -19,7 +148,7 @@ export type EnumDiff =
|
|
|
19
148
|
| { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };
|
|
20
149
|
|
|
21
150
|
/**
|
|
22
|
-
* Reads existing enum values for `nativeType` from the
|
|
151
|
+
* Reads existing enum values for `(schemaName, nativeType)` from the
|
|
23
152
|
* Postgres-introspected `schema.annotations.pg.storageTypes` map.
|
|
24
153
|
*
|
|
25
154
|
* Schema IR's `storageTypes` slots are always codec-typed
|
|
@@ -33,20 +162,11 @@ export type EnumDiff =
|
|
|
33
162
|
*/
|
|
34
163
|
export function readExistingEnumValues(
|
|
35
164
|
schema: SqlSchemaIR,
|
|
165
|
+
schemaName: string,
|
|
36
166
|
nativeType: string,
|
|
37
167
|
): readonly string[] | null {
|
|
38
|
-
const storageTypes = (schema.
|
|
39
|
-
|
|
40
|
-
] as
|
|
41
|
-
| Record<
|
|
42
|
-
string,
|
|
43
|
-
{
|
|
44
|
-
codecId?: string;
|
|
45
|
-
typeParams?: { values?: unknown };
|
|
46
|
-
}
|
|
47
|
-
>
|
|
48
|
-
| undefined;
|
|
49
|
-
const existing = storageTypes?.[nativeType];
|
|
168
|
+
const storageTypes = readPostgresSchemaIrAnnotations(schema).storageTypes;
|
|
169
|
+
const existing = storageTypes?.[enumStorageCompoundKey(schemaName, nativeType)];
|
|
50
170
|
if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {
|
|
51
171
|
return null;
|
|
52
172
|
}
|
|
@@ -54,7 +174,7 @@ export function readExistingEnumValues(
|
|
|
54
174
|
if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {
|
|
55
175
|
return null;
|
|
56
176
|
}
|
|
57
|
-
return enumValues
|
|
177
|
+
return enumValues;
|
|
58
178
|
}
|
|
59
179
|
|
|
60
180
|
/**
|
|
@@ -63,13 +63,18 @@ import {
|
|
|
63
63
|
|
|
64
64
|
export type { CallMigrationStrategy, StrategyContext };
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Finds a type entry by explicit namespace coordinate. Reads the named
|
|
68
|
+
* namespace's `enum` slot directly — never scans other namespaces.
|
|
69
|
+
*/
|
|
70
|
+
function locateNamespaceTypeInStorage(
|
|
71
|
+
storage: SqlStorage,
|
|
72
|
+
namespaceId: string,
|
|
73
|
+
typeName: string,
|
|
74
|
+
): unknown {
|
|
75
|
+
const ns = storage.namespaces[namespaceId];
|
|
76
|
+
if (!ns || !('enum' in ns) || ns.enum == null) return undefined;
|
|
77
|
+
return (ns.enum as Record<string, unknown>)[typeName];
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
// ============================================================================
|
|
@@ -596,11 +601,14 @@ function mapIssueToCall(
|
|
|
596
601
|
case 'type_missing': {
|
|
597
602
|
if (!issue.typeName)
|
|
598
603
|
return notOk(issueConflict('unsupportedOperation', 'Type missing issue has no typeName'));
|
|
599
|
-
//
|
|
600
|
-
// Check
|
|
604
|
+
// Codec aliases live in storage.types; enum types live in namespace.enum.
|
|
605
|
+
// Check types first; fall back to the namespace-keyed enum slot using the
|
|
606
|
+
// issue's namespace coordinate (populated by the verifier for enum-related
|
|
607
|
+
// issues per the BaseSchemaIssue.namespaceId contract).
|
|
608
|
+
const namespaceId = resolveNamespaceIdForIssue(issue);
|
|
601
609
|
const typeInstance: unknown =
|
|
602
610
|
ctx.toContract.storage.types?.[issue.typeName] ??
|
|
603
|
-
locateNamespaceTypeInStorage(ctx.toContract.storage, issue.typeName);
|
|
611
|
+
locateNamespaceTypeInStorage(ctx.toContract.storage, namespaceId, issue.typeName);
|
|
604
612
|
if (!typeInstance) {
|
|
605
613
|
return notOk(
|
|
606
614
|
issueConflict(
|
|
@@ -610,9 +618,10 @@ function mapIssueToCall(
|
|
|
610
618
|
);
|
|
611
619
|
}
|
|
612
620
|
if (typeInstance instanceof PostgresEnumType) {
|
|
621
|
+
const ddlSchema = resolveDdlSchemaForNamespace(ctx, namespaceId);
|
|
613
622
|
return ok([
|
|
614
623
|
new CreateEnumTypeCall(
|
|
615
|
-
|
|
624
|
+
ddlSchema,
|
|
616
625
|
issue.typeName,
|
|
617
626
|
typeInstance.values,
|
|
618
627
|
typeInstance.nativeType,
|
|
@@ -29,7 +29,6 @@ import type {
|
|
|
29
29
|
OpFactoryCall,
|
|
30
30
|
} from '@prisma-next/framework-components/control';
|
|
31
31
|
import type { MigrationMeta } from '@prisma-next/migration-tools/migration';
|
|
32
|
-
import { ifDefined } from '@prisma-next/utils/defined';
|
|
33
32
|
import type { PostgresPlanTargetDetails } from './planner-target-details';
|
|
34
33
|
import { PostgresMigration } from './postgres-migration';
|
|
35
34
|
import { renderOps } from './render-ops';
|
|
@@ -73,7 +72,6 @@ export class TypeScriptRenderablePostgresMigration
|
|
|
73
72
|
return renderCallsToTypeScript(this.#calls, {
|
|
74
73
|
from: this.#meta.from,
|
|
75
74
|
to: this.#meta.to,
|
|
76
|
-
...ifDefined('labels', this.#meta.labels),
|
|
77
75
|
});
|
|
78
76
|
}
|
|
79
77
|
}
|