@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
|
@@ -40,6 +40,9 @@ export const ensureLedgerTableStatement: SqlStatement = {
|
|
|
40
40
|
sql: `create table if not exists prisma_contract.ledger (
|
|
41
41
|
id bigserial primary key,
|
|
42
42
|
created_at timestamptz not null default now(),
|
|
43
|
+
space text not null,
|
|
44
|
+
migration_name text not null,
|
|
45
|
+
migration_hash text not null,
|
|
43
46
|
origin_core_hash text,
|
|
44
47
|
origin_profile_hash text,
|
|
45
48
|
destination_core_hash text not null,
|
|
@@ -56,7 +59,7 @@ export interface MergeMarkerInput {
|
|
|
56
59
|
* Logical space identifier for this marker row. Required at every
|
|
57
60
|
* call site so the type system surfaces every place that needs to
|
|
58
61
|
* thread the value (rather than letting an `?? APP_SPACE_ID`
|
|
59
|
-
* fall-through silently collapse
|
|
62
|
+
* fall-through silently collapse per-space markers onto the
|
|
60
63
|
* `'app'` row). App-plan callers pass {@link APP_SPACE_ID}
|
|
61
64
|
* (`'app'`); per-extension callers (planner / runner / verifier
|
|
62
65
|
* extensions over contract spaces) pass the extension's space id.
|
|
@@ -138,6 +141,9 @@ export function buildMergeMarkerStatements(input: MergeMarkerInput): {
|
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
export interface LedgerInsertInput {
|
|
144
|
+
readonly space: string;
|
|
145
|
+
readonly migrationName: string;
|
|
146
|
+
readonly migrationHash: string;
|
|
141
147
|
readonly originStorageHash?: string | null;
|
|
142
148
|
readonly originProfileHash?: string | null;
|
|
143
149
|
readonly destinationStorageHash: string;
|
|
@@ -150,6 +156,9 @@ export interface LedgerInsertInput {
|
|
|
150
156
|
export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {
|
|
151
157
|
return {
|
|
152
158
|
sql: `insert into prisma_contract.ledger (
|
|
159
|
+
space,
|
|
160
|
+
migration_name,
|
|
161
|
+
migration_hash,
|
|
153
162
|
origin_core_hash,
|
|
154
163
|
origin_profile_hash,
|
|
155
164
|
destination_core_hash,
|
|
@@ -162,11 +171,17 @@ export function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStateme
|
|
|
162
171
|
$2,
|
|
163
172
|
$3,
|
|
164
173
|
$4,
|
|
165
|
-
$5
|
|
166
|
-
$6
|
|
167
|
-
$7
|
|
174
|
+
$5,
|
|
175
|
+
$6,
|
|
176
|
+
$7,
|
|
177
|
+
$8::jsonb,
|
|
178
|
+
$9::jsonb,
|
|
179
|
+
$10::jsonb
|
|
168
180
|
)`,
|
|
169
181
|
params: [
|
|
182
|
+
input.space,
|
|
183
|
+
input.migrationName,
|
|
184
|
+
input.migrationHash,
|
|
170
185
|
input.originStorageHash ?? null,
|
|
171
186
|
input.originProfileHash ?? null,
|
|
172
187
|
input.destinationStorageHash,
|
|
@@ -52,12 +52,12 @@ function existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {
|
|
|
52
52
|
*
|
|
53
53
|
* A namespace's live container is the schema returned by its
|
|
54
54
|
* polymorphic `ddlSchemaName(storage)` method — named schemas resolve
|
|
55
|
-
* to their own id
|
|
56
|
-
*
|
|
57
|
-
* emitted only when the resolved name is a real,
|
|
58
|
-
* (not the unbound sentinel) and is missing from the
|
|
59
|
-
* list. `public` is suppressed implicitly because the
|
|
60
|
-
* (or its sensible default) always carries it.
|
|
55
|
+
* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`
|
|
56
|
+
* and is skipped explicitly (late-bound namespaces have no fixed DDL
|
|
57
|
+
* schema). Issues are emitted only when the resolved name is a real,
|
|
58
|
+
* creatable schema (not the unbound sentinel) and is missing from the
|
|
59
|
+
* introspected list. `public` is suppressed implicitly because the
|
|
60
|
+
* introspection (or its sensible default) always carries it.
|
|
61
61
|
*
|
|
62
62
|
* Each emitted issue stamps `namespaceId` with the contract namespace
|
|
63
63
|
* coordinate so the downstream `mapIssueToCall` re-resolves the DDL
|
|
@@ -94,19 +94,19 @@ export class PostgresContractSerializer extends SqlContractSerializerBase<Contra
|
|
|
94
94
|
const hydrated = super.hydrateSqlNamespaceEntry(nsId, raw) as {
|
|
95
95
|
id: string;
|
|
96
96
|
tables: Readonly<Record<string, StorageTable>>;
|
|
97
|
-
|
|
97
|
+
enum?: Readonly<Record<string, PostgresEnumType>>;
|
|
98
98
|
};
|
|
99
|
-
const { id, tables,
|
|
99
|
+
const { id, tables, enum: hydratedNsEnums } = hydrated;
|
|
100
100
|
|
|
101
101
|
const emptyTables = Object.keys(tables).length === 0;
|
|
102
|
-
const
|
|
103
|
-
if (id === UNBOUND_NAMESPACE_ID && emptyTables &&
|
|
102
|
+
const emptyEnums = !hydratedNsEnums || Object.keys(hydratedNsEnums).length === 0;
|
|
103
|
+
if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyEnums) {
|
|
104
104
|
return PostgresSchema.unbound;
|
|
105
105
|
}
|
|
106
106
|
return new PostgresSchema({
|
|
107
107
|
id,
|
|
108
108
|
tables,
|
|
109
|
-
...(
|
|
109
|
+
...(hydratedNsEnums !== undefined ? { enum: hydratedNsEnums } : {}),
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -117,15 +117,15 @@ export class PostgresContractSerializer extends SqlContractSerializerBase<Contra
|
|
|
117
117
|
if (isPostgresSchema(ns)) {
|
|
118
118
|
namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);
|
|
119
119
|
} else {
|
|
120
|
-
// Family-level
|
|
121
|
-
// been promoted to a PostgresSchema instance
|
|
122
|
-
// straight from the TS builder
|
|
123
|
-
//
|
|
120
|
+
// Family-level SqlUnboundNamespace or other family-built SQL
|
|
121
|
+
// namespaces haven't been promoted to a PostgresSchema instance
|
|
122
|
+
// yet (e.g. they came straight from the TS builder before a target
|
|
123
|
+
// `createNamespace` factory ran). Serialise them as postgres-schema /
|
|
124
124
|
// postgres-unbound-schema so the round-trip through
|
|
125
125
|
// deserializeContract hydrates them back into PostgresSchema
|
|
126
126
|
// instances.
|
|
127
127
|
const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;
|
|
128
|
-
const
|
|
128
|
+
const nsEnums = (ns as { readonly enum?: Readonly<Record<string, unknown>> }).enum ?? {};
|
|
129
129
|
namespacesJson[nsId] = {
|
|
130
130
|
id: nsId,
|
|
131
131
|
kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',
|
|
@@ -135,8 +135,8 @@ export class PostgresContractSerializer extends SqlContractSerializerBase<Contra
|
|
|
135
135
|
this.serializeJsonValue(table) as JsonObject,
|
|
136
136
|
]),
|
|
137
137
|
),
|
|
138
|
-
|
|
139
|
-
Object.entries(
|
|
138
|
+
enum: Object.fromEntries(
|
|
139
|
+
Object.entries(nsEnums).map(([typeName, entry]) => [
|
|
140
140
|
typeName,
|
|
141
141
|
this.serializeJsonValue(entry) as JsonObject,
|
|
142
142
|
]),
|
|
@@ -166,15 +166,15 @@ export class PostgresContractSerializer extends SqlContractSerializerBase<Contra
|
|
|
166
166
|
for (const [tableName, table] of Object.entries(ns.tables)) {
|
|
167
167
|
tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;
|
|
168
168
|
}
|
|
169
|
-
const
|
|
170
|
-
for (const [typeName, ty] of Object.entries(ns.
|
|
171
|
-
|
|
169
|
+
const enumOut: Record<string, JsonObject> = {};
|
|
170
|
+
for (const [typeName, ty] of Object.entries(ns.enum)) {
|
|
171
|
+
enumOut[typeName] = this.serializeJsonValue(ty) as JsonObject;
|
|
172
172
|
}
|
|
173
173
|
return {
|
|
174
174
|
id: ns.id,
|
|
175
175
|
kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',
|
|
176
176
|
tables: tablesOut,
|
|
177
|
-
|
|
177
|
+
enum: enumOut,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ControlPolicy } from '@prisma-next/contract/types';
|
|
1
2
|
import { freezeNode } from '@prisma-next/framework-components/ir';
|
|
2
3
|
import { SqlNode } from '@prisma-next/sql-contract/types';
|
|
3
4
|
|
|
@@ -18,6 +19,7 @@ export interface PostgresEnumTypeInput<
|
|
|
18
19
|
*/
|
|
19
20
|
readonly nativeType?: string;
|
|
20
21
|
readonly values: TValues;
|
|
22
|
+
readonly control?: ControlPolicy;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/** Codec id used by Postgres enum-typed columns (text wire format). */
|
|
@@ -64,6 +66,7 @@ export class PostgresEnumType<
|
|
|
64
66
|
* dispatching through the prototype-only `codecBinding` accessor.
|
|
65
67
|
*/
|
|
66
68
|
readonly codecId: typeof PG_ENUM_CODEC_ID = PG_ENUM_CODEC_ID;
|
|
69
|
+
declare readonly control?: ControlPolicy;
|
|
67
70
|
|
|
68
71
|
constructor(input: PostgresEnumTypeInput<TName, TValues>) {
|
|
69
72
|
super();
|
|
@@ -73,6 +76,7 @@ export class PostgresEnumType<
|
|
|
73
76
|
// `TValues` literal tuple. Cast preserves the caller-supplied
|
|
74
77
|
// tuple shape so inferred contract types retain literal narrowing.
|
|
75
78
|
this.values = Object.freeze([...input.values] as unknown as TValues);
|
|
79
|
+
if (input.control !== undefined) this.control = input.control;
|
|
76
80
|
freezeNode(this);
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -15,7 +15,7 @@ import { escapeLiteral } from './sql-utils';
|
|
|
15
15
|
export interface PostgresSchemaInput {
|
|
16
16
|
readonly id: string;
|
|
17
17
|
readonly tables?: Record<string, StorageTable | StorageTableInput>;
|
|
18
|
-
readonly
|
|
18
|
+
readonly enum?: Record<string, PostgresEnumType | PostgresEnumTypeInput>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -44,7 +44,7 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
44
44
|
declare readonly kind: 'schema';
|
|
45
45
|
readonly id: string;
|
|
46
46
|
readonly tables: Readonly<Record<string, StorageTable>>;
|
|
47
|
-
readonly
|
|
47
|
+
readonly enum: Readonly<Record<string, PostgresEnumType>>;
|
|
48
48
|
|
|
49
49
|
constructor(input: PostgresSchemaInput) {
|
|
50
50
|
super();
|
|
@@ -57,9 +57,9 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
57
57
|
]),
|
|
58
58
|
),
|
|
59
59
|
);
|
|
60
|
-
this.
|
|
60
|
+
this.enum = Object.freeze(
|
|
61
61
|
Object.fromEntries(
|
|
62
|
-
Object.entries(input.
|
|
62
|
+
Object.entries(input.enum ?? {}).map(([name, ty]) => [
|
|
63
63
|
name,
|
|
64
64
|
ty instanceof PostgresEnumType ? ty : new PostgresEnumType(ty),
|
|
65
65
|
]),
|
|
@@ -120,10 +120,11 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
120
120
|
* statements that need to identify this namespace in the live
|
|
121
121
|
* database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
|
|
122
122
|
* catalog filters, planner conflict lookups). Named schemas resolve
|
|
123
|
-
* to their own id
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
123
|
+
* to their own id. The `PostgresUnboundSchema` singleton inherits
|
|
124
|
+
* this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
|
|
125
|
+
* through `qualifyTableName` / `toRegclassLiteral` route through the
|
|
126
|
+
* polymorphic `PostgresUnboundSchema` overrides and produce
|
|
127
|
+
* unqualified (search-path-resolved) output automatically.
|
|
127
128
|
*/
|
|
128
129
|
ddlSchemaName(_storage: SqlStorage): string {
|
|
129
130
|
return this.id;
|
|
@@ -143,6 +144,11 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
143
144
|
* sentinel; Postgres decides what late-bound means here (the table
|
|
144
145
|
* name, naked — the schema is supplied by the live connection's
|
|
145
146
|
* `search_path`).
|
|
147
|
+
*
|
|
148
|
+
* `ddlSchemaName` is inherited from `PostgresSchema` and returns
|
|
149
|
+
* `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,
|
|
150
|
+
* `toRegclassLiteral`) route through the polymorphic factory and
|
|
151
|
+
* produce unqualified output automatically.
|
|
146
152
|
*/
|
|
147
153
|
export class PostgresUnboundSchema extends PostgresSchema {
|
|
148
154
|
static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();
|
|
@@ -162,22 +168,6 @@ export class PostgresUnboundSchema extends PostgresSchema {
|
|
|
162
168
|
override schemaSqlExpression(): string {
|
|
163
169
|
return 'current_schema()';
|
|
164
170
|
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* The unbound slot has no schema name of its own, so DDL emission
|
|
168
|
-
* projects it onto a sibling when one is available: if the contract
|
|
169
|
-
* carries a `public` namespace, the late-bound slot resolves to
|
|
170
|
-
* `'public'` (the default Postgres landing schema); otherwise it
|
|
171
|
-
* resolves to the framework sentinel `UNBOUND_NAMESPACE_ID` so the
|
|
172
|
-
* planner can recognise the unprojected case and route accordingly
|
|
173
|
-
* (e.g. emit a conflict instead of silently picking a schema).
|
|
174
|
-
*/
|
|
175
|
-
override ddlSchemaName(storage: SqlStorage): string {
|
|
176
|
-
if (storage.namespaces['public'] !== undefined) {
|
|
177
|
-
return 'public';
|
|
178
|
-
}
|
|
179
|
-
return UNBOUND_NAMESPACE_ID;
|
|
180
|
-
}
|
|
181
171
|
}
|
|
182
172
|
|
|
183
173
|
PostgresSchema.unbound = PostgresUnboundSchema.instance;
|
package/src/exports/control.ts
CHANGED
|
@@ -12,6 +12,10 @@ import type {
|
|
|
12
12
|
import type { SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';
|
|
13
13
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
14
14
|
import { postgresTargetDescriptorMeta } from '../core/descriptor-meta';
|
|
15
|
+
import {
|
|
16
|
+
enumStorageCompoundKey,
|
|
17
|
+
resolveDdlSchemaForNamespaceStorage,
|
|
18
|
+
} from '../core/migrations/enum-planning';
|
|
15
19
|
import { createPostgresMigrationPlanner } from '../core/migrations/planner';
|
|
16
20
|
import { renderDefaultLiteral } from '../core/migrations/planner-ddl-builders';
|
|
17
21
|
import type { PostgresPlanTargetDetails } from '../core/migrations/planner-target-details';
|
|
@@ -78,6 +82,18 @@ const postgresTargetDescriptor: SqlControlTargetDescriptor<'postgres', PostgresP
|
|
|
78
82
|
annotationNamespace: 'pg',
|
|
79
83
|
...ifDefined('expandNativeType', expander),
|
|
80
84
|
renderDefault: postgresRenderDefault,
|
|
85
|
+
// Schema-qualify enum annotation keys so the projected "from" IR's
|
|
86
|
+
// `storageTypes` match `readExistingEnumValues` on the read side
|
|
87
|
+
// (the contract-to-contract `migration plan` path). The DDL-schema
|
|
88
|
+
// resolution + compound-key format stay here in the target layer;
|
|
89
|
+
// the family projector treats the returned string as opaque.
|
|
90
|
+
// `undefined` schema IR ⇒ the unbound coordinate resolves to the
|
|
91
|
+
// default `public` landing schema, matching the read-side fallback.
|
|
92
|
+
resolveEnumStorageKey: (storage, namespaceId, nativeType) =>
|
|
93
|
+
enumStorageCompoundKey(
|
|
94
|
+
resolveDdlSchemaForNamespaceStorage(storage, namespaceId, undefined),
|
|
95
|
+
nativeType,
|
|
96
|
+
),
|
|
81
97
|
});
|
|
82
98
|
},
|
|
83
99
|
},
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export {
|
|
2
|
+
createResolveExistingEnumValues,
|
|
2
3
|
determineEnumDiff,
|
|
3
4
|
type EnumDiff,
|
|
5
|
+
enumStorageCompoundKey,
|
|
4
6
|
getDesiredEnumValues,
|
|
7
|
+
type PostgresSchemaIrAnnotations,
|
|
5
8
|
readExistingEnumValues,
|
|
9
|
+
readPostgresSchemaIrAnnotations,
|
|
10
|
+
resolveDdlSchemaForNamespaceStorage,
|
|
6
11
|
} from '../core/migrations/enum-planning';
|
package/src/exports/runtime.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
RuntimeTargetDescriptor,
|
|
4
4
|
RuntimeTargetInstance,
|
|
5
5
|
} from '@prisma-next/framework-components/execution';
|
|
6
|
-
import {
|
|
6
|
+
import { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';
|
|
7
7
|
|
|
8
8
|
export { PostgresContractSerializer } from '../core/postgres-contract-serializer';
|
|
9
9
|
|
|
@@ -22,7 +22,7 @@ const postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<
|
|
|
22
22
|
> & {
|
|
23
23
|
readonly codecs: () => readonly AnyCodecDescriptor[];
|
|
24
24
|
} = {
|
|
25
|
-
...
|
|
25
|
+
...postgresTargetDescriptorMetaRuntime,
|
|
26
26
|
codecs: () => [],
|
|
27
27
|
create(): PostgresRuntimeTargetInstance {
|
|
28
28
|
return {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-CRlHq7Cz.d.mts","names":[],"sources":["../src/core/codec-type-map.ts","../src/exports/codec-types.ts"],"mappings":";;;;;;cA4Ca,kBAAA;EAAA,eA8BH,uCAAA,CAAA,iBAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAEE,OAAA,6BAAoC,CAAA,0BAA2B,CAAA,CAAE,CAAA,IAAK,CAAA,CAAE,CAAA,EAAG,CAAA;AAAA,KAE3E,kBAAA,UAA4B,kBAAA;AAAA,KAE5B,mBAAA,GAAsB,iBAAA,CAAkB,kBAAA;;;KCrExC,UAAA,GAAa,OAAA,CAAQ,mBAAA;AAAA,KAI5B,OAAA,kBAAyB,MAAA,qBAA2B,CAAA,0BAClC,KAAA,GAAQ,KAAA,CAAM,CAAA;AAAA,KAGhC,aAAA,eAA4B,MAAA,qBAA2B,OAAA,SAAgB,KAAA;AAAA,KAEhE,IAAA,qBAAyB,aAAA;EAAgB,YAAA,EAAc,CAAA;AAAA;AAAA,KACvD,OAAA,qBAA4B,aAAA;EAAgB,eAAA,EAAiB,CAAA;AAAA;AAAA,KAC7D,OAAA,+DAAsE,aAAA;EAChF,kBAAA,EAAoB,CAAA;EACpB,cAAA,EAAgB,CAAA;AAAA;AAAA,KAEN,GAAA,qBAAwB,aAAA;EAAgB,WAAA,EAAa,CAAA;AAAA;AAAA,KACrD,MAAA,qBAA2B,aAAA;EAAgB,cAAA,EAAgB,CAAA;AAAA;AAAA,KAC3D,SAAA,6CAAsD,aAAA;EAChE,oBAAA,EAAsB,CAAA;AAAA;AAAA,KAEZ,WAAA,6CAAwD,aAAA;EAClE,sBAAA,EAAwB,CAAA;AAAA;AAAA,KAEd,IAAA,6CAAiD,aAAA;EAAgB,eAAA,EAAiB,CAAA;AAAA;AAAA,KAClF,MAAA,6CAAmD,aAAA;EAC7D,iBAAA,EAAmB,CAAA;AAAA;AAAA,KAET,QAAA,6CAAqD,aAAA;EAC/D,mBAAA,EAAqB,CAAA;AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-transform-bmOKkygi.d.mts","names":[],"sources":["../src/core/migrations/operations/data-transform.ts"],"mappings":";;;;;;;;UAqEU,SAAA;EACR,KAAA,IAAS,YAAA,CAAa,CAAA;AAAA;;;;;KAOZ,oBAAA,SAA6B,YAAA,GAAe,SAAA;AAAA,UAEvC,oBAAA;;;;;;WAMN,WAAA;;;;;;;;WAQA,KAAA,GAAQ,oBAAA;;WAER,GAAA,EAAK,oBAAA,YAAgC,oBAAA;AAAA;AAAA,iBAGhC,aAAA,mBAAgC,QAAA,CAAS,UAAA,EAAA,CACvD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,EACT,OAAA,EAAS,iBAAA,eACR,yBAAA,CAA0B,yBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-DLA2xV6B.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport type { PostgresEnumStorageEntry } from '@prisma-next/sql-contract/types';\nimport { PostgresEnumTypeSchema } from '@prisma-next/sql-contract/validators';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\n\nexport const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;\n\n/**\n * Entity type contributions surface as top-level helpers on the\n * composed-helpers shape (e.g. `helpers.enum({...})`), flattened\n * alongside the built-in `model` / `rel` helpers. Pack contributions\n * still ship via the contribution data structure\n * `authoring.entityTypes.<name>`; the composed-helpers template\n * performs the rename in the type system.\n *\n * `enum` is the first real consumer of the entities-namespace mechanism:\n * the factory constructs a `PostgresEnumType` IR-class instance from\n * the user-supplied input. Both authoring runtimes (TS DSL and PSL)\n * dispatch through this single contribution — PSL `enum Status { … }`\n * declarations are lowered by the interpreter into a factory call\n * with the parsed name + value list; TS DSL `helpers.enum({...})`\n * resolves through the same path. Removing this contribution makes\n * both surfaces fail with a \"no entity helper named `enum`\" type\n * error at the contract-definition site.\n */\n/**\n * The factory constructs a `PostgresEnumType` instance natively — the\n * `SqlStorage.types` slot accepts polymorphic IR (the framework\n * `StorageType` alphabet), so no cast is needed at the contribution\n * surface. The declared return type is the structural\n * `PostgresEnumStorageEntry` so the inferred contract type stays\n * portable (it names a type exported from\n * `@prisma-next/sql-contract/types`, a public surface every consumer\n * already imports). Sharpening the inferred contract type to surface\n * enum-specific narrowing through `EntityHelperFunction` is a\n * separable refinement and lives outside this PR.\n */\nexport const postgresAuthoringEntityTypes = {\n enum: {\n kind: 'entity',\n discriminator: 'postgres-enum',\n validatorSchema: PostgresEnumTypeSchema,\n output: {\n factory: (input: PostgresEnumTypeInput): PostgresEnumStorageEntry =>\n new PostgresEnumType(input),\n },\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n */\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n} as const satisfies AuthoringFieldNamespace;\n","import type { CodecTypes } from '../exports/codec-types';\nimport {\n postgresAuthoringEntityTypes,\n postgresAuthoringFieldPresets,\n postgresAuthoringTypes,\n} from './authoring';\n\nconst postgresTargetDescriptorMetaBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n entityTypes: postgresAuthoringEntityTypes,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";;;;AAUA,MAAa,yBAAyB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCxC,MAAa,+BAA+B,EAC1C,MAAM;CACJ,MAAM;CACN,eAAe;CACf,iBAAiB;CACjB,QAAQ,EACN,UAAU,UACR,IAAI,iBAAiB,MAAM,EAC9B;CACF,EACF;AC/BD,MAAa,+BAET;CAfF,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,EAAE;CAChB,WAAW;EACT,MAAM;EACN,OAAO;GD+CT,MAAM;IACJ,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,KAAK;IACH,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,QAAQ;IACN,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,OAAO;IACL,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,SAAS;IACP,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,SAAS;IACP,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,MAAM;IACJ,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,OAAO;IACL,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,UAAU;IACR,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,UAAU,yBAAyB;IACjC,SAAS;IACT,YAAY;IACb,CAAC;GCjHO;EACP,aAAa;EACd;CAKC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import "./codec-ids-C5qzBqus.mjs";
|
|
2
|
-
import { arraysEqual } from "@prisma-next/family-sql/schema-verify";
|
|
3
|
-
//#region src/core/migrations/enum-planning.ts
|
|
4
|
-
/**
|
|
5
|
-
* Pure planning helpers for Postgres enum types: the diff/rebuild logic
|
|
6
|
-
* that the verifier and planner use to walk `PostgresEnumType` instances
|
|
7
|
-
* natively. Op builders live in `./operations/enums.ts`.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Reads existing enum values for `nativeType` from the
|
|
11
|
-
* Postgres-introspected `schema.annotations.pg.storageTypes` map.
|
|
12
|
-
*
|
|
13
|
-
* Schema IR's `storageTypes` slots are always codec-typed
|
|
14
|
-
* (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector
|
|
15
|
-
* writes that shape, and the Contract→Schema IR projector resolves
|
|
16
|
-
* `PostgresEnumType` instances down to the same codec-typed triple before
|
|
17
|
-
* they ever land in Schema IR. There is no second on-disk shape to
|
|
18
|
-
* accept here.
|
|
19
|
-
*
|
|
20
|
-
* Returns `null` when no enum entry exists for the given native type.
|
|
21
|
-
*/
|
|
22
|
-
function readExistingEnumValues(schema, nativeType) {
|
|
23
|
-
const existing = ((schema.annotations?.["pg"])?.["storageTypes"])?.[nativeType];
|
|
24
|
-
if (!existing || existing.codecId !== "pg/enum@1") return null;
|
|
25
|
-
const enumValues = existing.typeParams?.values;
|
|
26
|
-
if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === "string")) return null;
|
|
27
|
-
return enumValues;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Determines what changes are needed to transform existing enum values to
|
|
31
|
-
* desired values.
|
|
32
|
-
*
|
|
33
|
-
* Postgres enums can only have values added (not removed or reordered)
|
|
34
|
-
* without a full type rebuild involving temp type creation and column
|
|
35
|
-
* migration; `'rebuild'` covers the value-removal and reorder cases.
|
|
36
|
-
*/
|
|
37
|
-
function determineEnumDiff(existing, desired) {
|
|
38
|
-
if (arraysEqual(existing, desired)) return { kind: "unchanged" };
|
|
39
|
-
const existingSet = new Set(existing);
|
|
40
|
-
const desiredSet = new Set(desired);
|
|
41
|
-
const missingValues = desired.filter((value) => !existingSet.has(value));
|
|
42
|
-
const removedValues = existing.filter((value) => !desiredSet.has(value));
|
|
43
|
-
const orderMismatch = missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);
|
|
44
|
-
if (removedValues.length > 0 || orderMismatch) return {
|
|
45
|
-
kind: "rebuild",
|
|
46
|
-
removedValues
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
kind: "add_values",
|
|
50
|
-
values: missingValues
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Convenience accessor — returns the enum's desired values from a
|
|
55
|
-
* `PostgresEnumType` IR instance.
|
|
56
|
-
*/
|
|
57
|
-
function getDesiredEnumValues(typeInstance) {
|
|
58
|
-
return typeInstance.values;
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
export { getDesiredEnumValues as n, readExistingEnumValues as r, determineEnumDiff as t };
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=enum-planning-Bqp96iIw.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"enum-planning-Bqp96iIw.mjs","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"sourcesContent":["/**\n * Pure planning helpers for Postgres enum types: the diff/rebuild logic\n * that the verifier and planner use to walk `PostgresEnumType` instances\n * natively. Op builders live in `./operations/enums.ts`.\n */\n\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '../codec-ids';\nimport type { PostgresEnumType } from '../postgres-enum-type';\n\n/**\n * Categorisation of how an existing enum type's values relate to the\n * desired set in the contract.\n */\nexport type EnumDiff =\n | { readonly kind: 'unchanged' }\n | { readonly kind: 'add_values'; readonly values: readonly string[] }\n | { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };\n\n/**\n * Reads existing enum values for `nativeType` from the\n * Postgres-introspected `schema.annotations.pg.storageTypes` map.\n *\n * Schema IR's `storageTypes` slots are always codec-typed\n * (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector\n * writes that shape, and the Contract→Schema IR projector resolves\n * `PostgresEnumType` instances down to the same codec-typed triple before\n * they ever land in Schema IR. There is no second on-disk shape to\n * accept here.\n *\n * Returns `null` when no enum entry exists for the given native type.\n */\nexport function readExistingEnumValues(\n schema: SqlSchemaIR,\n nativeType: string,\n): readonly string[] | null {\n const storageTypes = (schema.annotations?.['pg'] as Record<string, unknown> | undefined)?.[\n 'storageTypes'\n ] as\n | Record<\n string,\n {\n codecId?: string;\n typeParams?: { values?: unknown };\n }\n >\n | undefined;\n const existing = storageTypes?.[nativeType];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n const enumValues = existing.typeParams?.values;\n if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {\n return null;\n }\n return enumValues as readonly string[];\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to\n * desired values.\n *\n * Postgres enums can only have values added (not removed or reordered)\n * without a full type rebuild involving temp type creation and column\n * migration; `'rebuild'` covers the value-removal and reorder cases.\n */\nexport function determineEnumDiff(\n existing: readonly string[],\n desired: readonly string[],\n): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n return { kind: 'add_values', values: missingValues };\n}\n\n/**\n * Convenience accessor — returns the enum's desired values from a\n * `PostgresEnumType` IR instance.\n */\nexport function getDesiredEnumValues(typeInstance: PostgresEnumType): readonly string[] {\n return typeInstance.values;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,uBACd,QACA,YAC0B;CAY1B,MAAM,aAXgB,OAAO,cAAc,SACzC,mBAU8B;CAChC,IAAI,CAAC,YAAY,SAAS,YAAA,aACxB,OAAO;CAET,MAAM,aAAa,SAAS,YAAY;CACxC,IAAI,CAAC,MAAM,QAAQ,WAAW,IAAI,CAAC,WAAW,OAAO,MAAM,OAAO,MAAM,SAAS,EAC/E,OAAO;CAET,OAAO;;;;;;;;;;AAWT,SAAgB,kBACd,UACA,SACU;CACV,IAAI,YAAY,UAAU,QAAQ,EAChC,OAAO,EAAE,MAAM,aAAa;CAE9B,MAAM,cAAc,IAAI,IAAI,SAAS;CACrC,MAAM,aAAa,IAAI,IAAI,QAAQ;CACnC,MAAM,gBAAgB,QAAQ,QAAQ,UAAU,CAAC,YAAY,IAAI,MAAM,CAAC;CACxE,MAAM,gBAAgB,SAAS,QAAQ,UAAU,CAAC,WAAW,IAAI,MAAM,CAAC;CACxE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,QAAQ;CAC7F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;EAAe;CAE3C,OAAO;EAAE,MAAM;EAAc,QAAQ;EAAe;;;;;;AAOtD,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa"}
|