@prisma-next/target-postgres 0.11.0 → 0.12.0-dev.1
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 +18 -41
- 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-Dvr_77Z3.mjs +13 -0
- package/dist/descriptor-meta-Dvr_77Z3.mjs.map +1 -0
- package/dist/{descriptor-meta-DLA2xV6B.mjs → descriptor-meta-runtime-ByjztWgs.mjs} +81 -77
- package/dist/descriptor-meta-runtime-ByjztWgs.mjs.map +1 -0
- package/dist/enum-planning-DrNWCtCp.mjs +0 -0
- package/dist/enum-planning-DrNWCtCp.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-2RgYsjUJ.mjs} +115 -58
- package/dist/issue-planner-2RgYsjUJ.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-C_K5ibAY.mjs} +2 -2
- package/dist/{op-factory-call-Bgb_ghPb.mjs.map → op-factory-call-C_K5ibAY.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 +9 -8
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-DZG1dsSW.mjs → planner-CC3r_uNJ.mjs} +17 -25
- package/dist/planner-CC3r_uNJ.mjs.map +1 -0
- package/dist/{planner-ddl-builders-DYMuN0w1.mjs → planner-ddl-builders-DgyqpFji.mjs} +3 -3
- package/dist/{planner-ddl-builders-DYMuN0w1.mjs.map → planner-ddl-builders-DgyqpFji.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-BMu3fiMc.mjs} +3 -3
- package/dist/{planner-sql-checks-K-mTBJDi.mjs.map → planner-sql-checks-BMu3fiMc.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-C0UtIDB8.mjs} +12 -12
- package/dist/postgres-contract-serializer-C0UtIDB8.mjs.map +1 -0
- package/dist/{postgres-enum-type-CNhPTDhy.d.mts → postgres-enum-type-5MBoKsIj.d.mts} +1 -1
- package/dist/postgres-enum-type-5MBoKsIj.d.mts.map +1 -0
- package/dist/postgres-enum-type-DS-KLVRH.mjs.map +1 -1
- 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-vp5rvbYg.mjs} +14 -21
- package/dist/postgres-schema-vp5rvbYg.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-DVI5IVAa.mjs} +1 -1
- package/dist/statement-builders-DVI5IVAa.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-C8RrPLUq.mjs} +3 -3
- package/dist/{tables-CWxZgD0H.mjs.map → tables-C8RrPLUq.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 +1 -1
- 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 +20 -61
- package/src/core/migrations/statement-builders.ts +1 -1
- package/src/core/migrations/verify-postgres-namespaces.ts +6 -6
- package/src/core/postgres-contract-serializer.ts +16 -16
- 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-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/dist/enum-planning.d.mts
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-
|
|
1
|
+
import { t as PostgresEnumType } from "./postgres-enum-type-5MBoKsIj.mjs";
|
|
2
|
+
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
2
3
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
3
4
|
|
|
4
5
|
//#region src/core/migrations/enum-planning.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Codec-typed enum entry shape stored under
|
|
8
|
+
* `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.
|
|
9
|
+
*/
|
|
10
|
+
interface PgStorageTypeEntry {
|
|
11
|
+
readonly codecId?: string;
|
|
12
|
+
readonly typeParams?: {
|
|
13
|
+
readonly values?: unknown;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */
|
|
17
|
+
interface PostgresSchemaIrAnnotations {
|
|
18
|
+
readonly schema?: string;
|
|
19
|
+
readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads the Postgres annotation envelope (`schema.annotations.pg`) from
|
|
23
|
+
* family Schema IR. `SqlAnnotations` is an open target-pack extensibility
|
|
24
|
+
* map (`Record<string, unknown>`); this accessor narrows the `pg` slot at
|
|
25
|
+
* runtime so Postgres code can read introspection fields without casts.
|
|
26
|
+
*/
|
|
27
|
+
declare function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations;
|
|
28
|
+
/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */
|
|
29
|
+
declare function enumStorageCompoundKey(schemaName: string, nativeType: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the live-schema name a namespace's enums are introspected under,
|
|
32
|
+
* for keying `readExistingEnumValues` lookups. The unbound namespace's
|
|
33
|
+
* `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a
|
|
34
|
+
* real schema, so for the unbound coordinate we read the *introspected* schema
|
|
35
|
+
* recorded on `annotations.pg.schema` (the live `current_schema()` the adapter
|
|
36
|
+
* walked) — that is the schema the enum's `storageTypes` entry is keyed under.
|
|
37
|
+
* Named namespaces resolve to their own DDL schema, which matches the
|
|
38
|
+
* per-schema introspection key directly.
|
|
39
|
+
*/
|
|
40
|
+
declare function resolveDdlSchemaForNamespaceStorage(storage: SqlStorage, namespaceId: string, schemaIr?: SqlSchemaIR): string;
|
|
41
|
+
/** Contract-scoped bridge for the family verifier's enum value resolver. */
|
|
42
|
+
declare function createResolveExistingEnumValues(storage: SqlStorage): (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
5
43
|
/**
|
|
6
44
|
* Categorisation of how an existing enum type's values relate to the
|
|
7
45
|
* desired set in the contract.
|
|
@@ -16,7 +54,7 @@ type EnumDiff = {
|
|
|
16
54
|
readonly removedValues: readonly string[];
|
|
17
55
|
};
|
|
18
56
|
/**
|
|
19
|
-
* Reads existing enum values for `nativeType` from the
|
|
57
|
+
* Reads existing enum values for `(schemaName, nativeType)` from the
|
|
20
58
|
* Postgres-introspected `schema.annotations.pg.storageTypes` map.
|
|
21
59
|
*
|
|
22
60
|
* Schema IR's `storageTypes` slots are always codec-typed
|
|
@@ -28,7 +66,7 @@ type EnumDiff = {
|
|
|
28
66
|
*
|
|
29
67
|
* Returns `null` when no enum entry exists for the given native type.
|
|
30
68
|
*/
|
|
31
|
-
declare function readExistingEnumValues(schema: SqlSchemaIR, nativeType: string): readonly string[] | null;
|
|
69
|
+
declare function readExistingEnumValues(schema: SqlSchemaIR, schemaName: string, nativeType: string): readonly string[] | null;
|
|
32
70
|
/**
|
|
33
71
|
* Determines what changes are needed to transform existing enum values to
|
|
34
72
|
* desired values.
|
|
@@ -44,5 +82,5 @@ declare function determineEnumDiff(existing: readonly string[], desired: readonl
|
|
|
44
82
|
*/
|
|
45
83
|
declare function getDesiredEnumValues(typeInstance: PostgresEnumType): readonly string[];
|
|
46
84
|
//#endregion
|
|
47
|
-
export { type EnumDiff, determineEnumDiff, getDesiredEnumValues, readExistingEnumValues };
|
|
85
|
+
export { type EnumDiff, type PostgresSchemaIrAnnotations, createResolveExistingEnumValues, determineEnumDiff, enumStorageCompoundKey, getDesiredEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations, resolveDdlSchemaForNamespaceStorage };
|
|
48
86
|
//# sourceMappingURL=enum-planning.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-planning.d.mts","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"enum-planning.d.mts","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"mappings":";;;;;;;;;UAkBU,kBAAA;EAAA,SACC,OAAA;EAAA,SACA,UAAA;IAAA,SAAwB,MAAA;EAAA;AAAA;;UAIlB,2BAAA;EAAA,SACN,MAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA,SAAe,kBAAA;AAAA;;;;;;AAAkB;iBAgDpD,+BAAA,CAAgC,MAAA,EAAQ,WAAA,GAAc,2BAA2B;;iBAqBjF,sBAAA,CAAuB,UAAA,UAAoB,UAAkB;AAA7E;;;;AAA6E;AAc7E;;;;;AAdA,iBAcgB,mCAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,QAAA,GAAW,WAAW;;iBAaR,+BAAA,CACd,OAAA,EAAS,UAAA,IAET,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;;;AAlBsB;AAaxB;KAmBY,QAAA;EAAA,SACG,IAAA;AAAA;EAAA,SACA,IAAA;EAAA,SAA6B,MAAA;AAAA;EAAA,SAC7B,IAAA;EAAA,SAA0B,aAAA;AAAA;;;;;;;AAjBpB;AAcrB;;;;;;iBAkBgB,sBAAA,CACd,MAAA,EAAQ,WAAW,EACnB,UAAA,UACA,UAAA;;;;AAlBoD;AAetD;;;;iBAyBgB,iBAAA,CACd,QAAA,qBACA,OAAA,sBACC,QAAQ;;;;;iBAoBK,oBAAA,CAAqB,YAA8B,EAAhB,gBAAgB"}
|
package/dist/enum-planning.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { determineEnumDiff, getDesiredEnumValues, readExistingEnumValues };
|
|
1
|
+
import { a as readExistingEnumValues, i as getDesiredEnumValues, n as determineEnumDiff, o as readPostgresSchemaIrAnnotations, r as enumStorageCompoundKey, s as resolveDdlSchemaForNamespaceStorage, t as createResolveExistingEnumValues } from "./enum-planning-DrNWCtCp.mjs";
|
|
2
|
+
export { createResolveExistingEnumValues, determineEnumDiff, enumStorageCompoundKey, getDesiredEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations, resolveDdlSchemaForNamespaceStorage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors
|
|
1
|
+
{"version":3,"file":"errors-BbnITmAD.mjs","names":[],"sources":["../src/core/errors.ts"],"sourcesContent":["import { CliStructuredError } from '@prisma-next/errors/control';\n\n/**\n * A `PostgresMigration` instance method that needs the materialized control\n * adapter (currently only `this.dataTransform(...)`) was invoked, but the\n * migration was constructed without a `ControlStack`. Concrete authoring\n * usage always goes through the migration CLI entrypoint, which assembles\n * a stack from the loaded `prisma-next.config.ts`; reaching this error\n * means a test fixture or ad-hoc consumer instantiated `PostgresMigration`\n * with the no-arg form (legal for `operations` / `describe` introspection\n * only).\n *\n * Distinct from `PN-MIG-2001` (placeholder not filled) and `PN-MIG-2005`\n * (data-transform query plan against wrong contract) because the missing\n * input is the stack itself, not the per-operation contract.\n *\n * Lives in `@prisma-next/target-postgres/errors` rather than the shared\n * framework migration errors module because the failure is target-specific:\n * the contract it talks about (`PostgresMigration`, the Postgres control\n * adapter, the Postgres-target stack) only exists in this package.\n */\nexport function errorPostgresMigrationStackMissing(): CliStructuredError {\n return new CliStructuredError(\n '2007',\n 'PostgresMigration.dataTransform requires a control adapter',\n {\n domain: 'MIG',\n why: 'PostgresMigration.dataTransform was invoked on an instance constructed without a ControlStack. The stored controlAdapter is undefined, so dataTransform cannot lower its query plan.',\n 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.',\n meta: {},\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qCAAyD;CACvE,OAAO,IAAI,mBACT,QACA,8DACA;EACE,QAAQ;EACR,KAAK;EACL,KAAK;EACL,MAAM,CAAC;CACT,CACF;AACF"}
|
package/dist/errors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAqBA
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAqBA;;;;AAAwE;;;;;;;;;;;;;iBAAxD,kCAAA,CAAA,GAAsC,kBAAkB"}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as errorPostgresMigrationStackMissing } from "./errors
|
|
1
|
+
import { t as errorPostgresMigrationStackMissing } from "./errors-BbnITmAD.mjs";
|
|
2
2
|
export { errorPostgresMigrationStackMissing };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { t as PostgresEnumType } from "./postgres-enum-type-DS-KLVRH.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-
|
|
6
|
-
import { C as SetNotNullCall, S as SetDefaultCall, _ as DropIndexCall, a as AddUniqueCall, b as RawSqlCall, d as CreateTableCall, f as DataTransformCall, g as DropEnumTypeCall, h as DropDefaultCall, i as AddPrimaryKeyCall, l as CreateIndexCall, m as DropConstraintCall, n as AddEnumValuesCall, o as AlterColumnTypeCall, p as DropColumnCall, r as AddForeignKeyCall, s as CreateEnumTypeCall, t as AddColumnCall, u as CreateSchemaCall, v as DropNotNullCall, x as RenameTypeCall, y as DropTableCall } from "./op-factory-call-
|
|
7
|
-
import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-
|
|
8
|
-
import { n as resolveIdentityValue } from "./planner-identity-values-
|
|
9
|
-
import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-
|
|
2
|
+
import { i as quoteIdentifier } from "./sql-utils-CggjWNij.mjs";
|
|
3
|
+
import { r as isPostgresSchema } from "./postgres-schema-vp5rvbYg.mjs";
|
|
4
|
+
import { a as readExistingEnumValues, n as determineEnumDiff, s as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-DrNWCtCp.mjs";
|
|
5
|
+
import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-BMu3fiMc.mjs";
|
|
6
|
+
import { C as SetNotNullCall, S as SetDefaultCall, _ as DropIndexCall, a as AddUniqueCall, b as RawSqlCall, d as CreateTableCall, f as DataTransformCall, g as DropEnumTypeCall, h as DropDefaultCall, i as AddPrimaryKeyCall, l as CreateIndexCall, m as DropConstraintCall, n as AddEnumValuesCall, o as AlterColumnTypeCall, p as DropColumnCall, r as AddForeignKeyCall, s as CreateEnumTypeCall, t as AddColumnCall, u as CreateSchemaCall, v as DropNotNullCall, x as RenameTypeCall, y as DropTableCall } from "./op-factory-call-C_K5ibAY.mjs";
|
|
7
|
+
import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-DgyqpFji.mjs";
|
|
8
|
+
import { n as resolveIdentityValue } from "./planner-identity-values-nhVj0hp-.mjs";
|
|
9
|
+
import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-CGxxYfnD.mjs";
|
|
10
10
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
11
11
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
12
12
|
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
@@ -116,29 +116,56 @@ function resolveNamespaceIdForIssue(issue) {
|
|
|
116
116
|
/**
|
|
117
117
|
* Resolve the DDL schema name for a namespace coordinate. Postgres-aware
|
|
118
118
|
* namespaces dispatch to their polymorphic `ddlSchemaName` override —
|
|
119
|
-
* named schemas return their own id
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
119
|
+
* named schemas return their own id; the unbound singleton returns
|
|
120
|
+
* `UNBOUND_NAMESPACE_ID`. Legacy single-namespace contracts whose
|
|
121
|
+
* `__unbound__` slot is the framework-default `SqlUnboundNamespace`
|
|
122
|
+
* (rather than the Postgres-aware `PostgresUnboundSchema`) flow the
|
|
123
|
+
* coordinate through unchanged so downstream `qualifyTableName`
|
|
124
|
+
* resolves polymorphically.
|
|
125
125
|
*/
|
|
126
126
|
function resolveDdlSchemaForNamespace(ctx, namespaceId) {
|
|
127
127
|
const namespace = ctx.toContract.storage.namespaces[namespaceId];
|
|
128
128
|
if (isPostgresSchema(namespace)) return namespace.ddlSchemaName(ctx.toContract.storage);
|
|
129
129
|
return namespaceId;
|
|
130
130
|
}
|
|
131
|
+
/** Default Postgres enum landing namespace — where contract-level (`types:`)
|
|
132
|
+
* enums are placed by the authoring builder when no explicit namespace is
|
|
133
|
+
* given. Mirrors `POSTGRES_ENUM_NAMESPACE_ID` in the contract-ts builder. */
|
|
134
|
+
const DEFAULT_ENUM_NAMESPACE_ID = "public";
|
|
135
|
+
function namespaceHasEnum(storage, namespaceId, typeName) {
|
|
136
|
+
const ns = storage.namespaces[namespaceId];
|
|
137
|
+
if (!ns || !("enum" in ns) || ns.enum == null) return false;
|
|
138
|
+
return ns.enum[typeName] !== void 0;
|
|
139
|
+
}
|
|
131
140
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* `
|
|
141
|
+
* Resolves which namespace's enum a column's bare `typeRef` binds to.
|
|
142
|
+
*
|
|
143
|
+
* Columns carry a bare (non-namespace-qualified) `typeRef`; the enum it names
|
|
144
|
+
* may live in a different namespace than the column's own (the authoring
|
|
145
|
+
* builder places contract-level `types:` enums in the default `public`
|
|
146
|
+
* namespace while a model's table may sit in the unbound namespace). The
|
|
147
|
+
* binding rule: an enum declared in the column's *own* namespace shadows
|
|
148
|
+
* everything; otherwise the column references the ambient enum — the sole
|
|
149
|
+
* namespace that defines `typeName`, preferring the default `public`
|
|
150
|
+
* namespace when several do. Returns `undefined` when no namespace defines it.
|
|
135
151
|
*/
|
|
136
|
-
function
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
function resolveColumnEnumNamespace(storage, columnNamespaceId, typeName) {
|
|
153
|
+
if (namespaceHasEnum(storage, columnNamespaceId, typeName)) return columnNamespaceId;
|
|
154
|
+
const owners = Object.keys(storage.namespaces).filter((nsId) => namespaceHasEnum(storage, nsId, typeName));
|
|
155
|
+
if (owners.length === 1) return owners[0];
|
|
156
|
+
if (owners.includes(DEFAULT_ENUM_NAMESPACE_ID)) return DEFAULT_ENUM_NAMESPACE_ID;
|
|
157
|
+
return owners[0];
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Finds a type entry by explicit namespace coordinate. Namespace types (e.g.
|
|
161
|
+
* Postgres enums) live under `storage.namespaces[nsId].enum`. Returns the
|
|
162
|
+
* entry from the named namespace only — never scans other namespaces, so two
|
|
163
|
+
* namespaces that hold an enum with the same name resolve independently.
|
|
164
|
+
*/
|
|
165
|
+
function locateNamespaceType(storage, namespaceId, typeName) {
|
|
166
|
+
const ns = storage.namespaces[namespaceId];
|
|
167
|
+
if (!ns || !("enum" in ns) || ns.enum == null) return void 0;
|
|
168
|
+
return ns.enum[typeName];
|
|
142
169
|
}
|
|
143
170
|
function buildColumnSpec(namespaceId, table, column, ctx, overrides) {
|
|
144
171
|
const col = tableAt(ctx.toContract.storage, namespaceId, table)?.columns[column];
|
|
@@ -246,24 +273,25 @@ const nullableTighteningCallStrategy = (issues, ctx) => {
|
|
|
246
273
|
recipe: true
|
|
247
274
|
};
|
|
248
275
|
};
|
|
249
|
-
function enumRebuildCallRecipe(typeName, ctx) {
|
|
250
|
-
const toType = locateNamespaceType(ctx.toContract.storage, typeName);
|
|
276
|
+
function enumRebuildCallRecipe(namespaceId, typeName, ctx) {
|
|
277
|
+
const toType = locateNamespaceType(ctx.toContract.storage, namespaceId, typeName);
|
|
251
278
|
if (!toType) return [];
|
|
252
279
|
const isEnum = isPostgresEnumStorageEntry(toType);
|
|
253
280
|
const nativeType = toType.nativeType;
|
|
254
281
|
const desiredValues = isEnum ? toType.values : toType.typeParams["values"] ?? [];
|
|
255
282
|
const tempName = `${nativeType}${REBUILD_SUFFIX}`;
|
|
283
|
+
const ddlSchema = resolveDdlSchemaForNamespaceStorage(ctx.toContract.storage, namespaceId, ctx.schema);
|
|
256
284
|
const columnRefs = [];
|
|
257
285
|
for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const [tableName, tableNode] of Object.entries(ns.tables)) {
|
|
258
286
|
const table = tableNode;
|
|
259
|
-
for (const [columnName, column] of Object.entries(table.columns)) if (column.typeRef === typeName) columnRefs.push({
|
|
287
|
+
for (const [columnName, column] of Object.entries(table.columns)) if (column.typeRef === typeName && resolveColumnEnumNamespace(ctx.toContract.storage, nsId, typeName) === namespaceId) columnRefs.push({
|
|
260
288
|
namespaceId: nsId,
|
|
261
289
|
table: tableName,
|
|
262
290
|
column: columnName
|
|
263
291
|
});
|
|
264
292
|
}
|
|
265
293
|
return [
|
|
266
|
-
new CreateEnumTypeCall(
|
|
294
|
+
new CreateEnumTypeCall(ddlSchema, tempName, desiredValues),
|
|
267
295
|
...columnRefs.map((ref) => {
|
|
268
296
|
const using = `${ref.column}::text::${tempName}`;
|
|
269
297
|
return new AlterColumnTypeCall(resolveDdlSchemaForNamespace(ctx, ref.namespaceId), ref.table, ref.column, {
|
|
@@ -273,8 +301,8 @@ function enumRebuildCallRecipe(typeName, ctx) {
|
|
|
273
301
|
using
|
|
274
302
|
});
|
|
275
303
|
}),
|
|
276
|
-
new DropEnumTypeCall(
|
|
277
|
-
new RenameTypeCall(
|
|
304
|
+
new DropEnumTypeCall(ddlSchema, nativeType),
|
|
305
|
+
new RenameTypeCall(ddlSchema, tempName, nativeType)
|
|
278
306
|
];
|
|
279
307
|
}
|
|
280
308
|
/**
|
|
@@ -309,42 +337,60 @@ function enumRebuildCallRecipe(typeName, ctx) {
|
|
|
309
337
|
* into the `dep` bucket — i.e. `CREATE TYPE` runs before any
|
|
310
338
|
* `CreateTableCall` that references the new enum.
|
|
311
339
|
*/
|
|
340
|
+
/**
|
|
341
|
+
* Separator character for compound enum map keys (`namespaceId\u0000typeName`).
|
|
342
|
+
* NUL (`\u0000`) is invalid in both Postgres identifiers and TypeScript symbol
|
|
343
|
+
* names so it cannot appear in either component — unambiguous separator.
|
|
344
|
+
*/
|
|
345
|
+
const COMPOUND_KEY_SEP = "\0";
|
|
346
|
+
/** Builds the compound map key for a namespace-qualified enum entry. */
|
|
347
|
+
function enumCompoundKey(namespaceId, typeName) {
|
|
348
|
+
return `${namespaceId}${COMPOUND_KEY_SEP}${typeName}`;
|
|
349
|
+
}
|
|
312
350
|
const nativeEnumPlanCallStrategy = (issues, ctx) => {
|
|
313
351
|
const enumTypes = collectPostgresEnumTypes(ctx.toContract.storage);
|
|
314
352
|
if (enumTypes.size === 0) return { kind: "no_match" };
|
|
315
353
|
const dataAllowed = ctx.policy.allowedOperationClasses.includes("data");
|
|
316
354
|
const calls = [];
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
const
|
|
355
|
+
const handledKeys = /* @__PURE__ */ new Set();
|
|
356
|
+
const introducedKeys = /* @__PURE__ */ new Set();
|
|
357
|
+
const rebuiltKeys = /* @__PURE__ */ new Set();
|
|
320
358
|
let emittedRebuildRecipe = false;
|
|
321
|
-
for (const [
|
|
359
|
+
for (const [key, enumType] of enumTypes) {
|
|
360
|
+
const sepIdx = key.indexOf(COMPOUND_KEY_SEP);
|
|
361
|
+
const enumNamespaceId = key.slice(0, sepIdx);
|
|
362
|
+
const typeName = key.slice(sepIdx + 1);
|
|
322
363
|
const desired = enumType.values;
|
|
323
|
-
const
|
|
364
|
+
const ddlSchema = resolveDdlSchemaForNamespaceStorage(ctx.toContract.storage, enumNamespaceId, ctx.schema);
|
|
365
|
+
const existing = readExistingEnumValues(ctx.schema, ddlSchema, enumType.nativeType);
|
|
324
366
|
if (!existing) {
|
|
325
|
-
calls.push(new CreateEnumTypeCall(
|
|
326
|
-
|
|
327
|
-
|
|
367
|
+
calls.push(new CreateEnumTypeCall(ddlSchema, typeName, desired, enumType.nativeType));
|
|
368
|
+
handledKeys.add(key);
|
|
369
|
+
introducedKeys.add(key);
|
|
328
370
|
continue;
|
|
329
371
|
}
|
|
330
372
|
const diff = determineEnumDiff(existing, desired);
|
|
331
373
|
if (diff.kind === "unchanged") {
|
|
332
|
-
|
|
374
|
+
handledKeys.add(key);
|
|
333
375
|
continue;
|
|
334
376
|
}
|
|
335
377
|
if (diff.kind === "add_values") {
|
|
336
|
-
calls.push(new AddEnumValuesCall(
|
|
337
|
-
|
|
378
|
+
calls.push(new AddEnumValuesCall(ddlSchema, typeName, enumType.nativeType, diff.values));
|
|
379
|
+
handledKeys.add(key);
|
|
338
380
|
continue;
|
|
339
381
|
}
|
|
340
382
|
if (dataAllowed && diff.removedValues.length > 0) calls.push(new DataTransformCall(`migrate-${typeName}-values`, `migrate-${typeName}-values:check`, `migrate-${typeName}-values:run`));
|
|
341
|
-
calls.push(...enumRebuildCallRecipe(typeName, ctx));
|
|
383
|
+
calls.push(...enumRebuildCallRecipe(enumNamespaceId, typeName, ctx));
|
|
342
384
|
emittedRebuildRecipe = true;
|
|
343
|
-
|
|
344
|
-
|
|
385
|
+
handledKeys.add(key);
|
|
386
|
+
rebuiltKeys.add(key);
|
|
345
387
|
}
|
|
346
|
-
if (
|
|
347
|
-
|
|
388
|
+
if (introducedKeys.size > 0 && rebuiltKeys.size > 0) {
|
|
389
|
+
const introducedDisplay = [...introducedKeys].sort().map((k) => k.replace(COMPOUND_KEY_SEP, ".")).join(", ");
|
|
390
|
+
const rebuiltDisplay = [...rebuiltKeys].sort().map((k) => k.replace(COMPOUND_KEY_SEP, ".")).join(", ");
|
|
391
|
+
throw new Error(`nativeEnumPlanCallStrategy: cannot emit both a brand-new enum and a rebuild on a different enum in the same plan; the single recipe flag cannot route them to different buckets. Introduced: [${introducedDisplay}]; rebuilt: [${rebuiltDisplay}]. Split the strategy or grow the \`match\` return type before this case lands.`);
|
|
392
|
+
}
|
|
393
|
+
const remaining = issues.filter((issue) => !((issue.kind === "type_missing" || issue.kind === "enum_values_changed") && issue.typeName && handledKeys.has(enumCompoundKey(resolveNamespaceIdForIssue(issue), issue.typeName))));
|
|
348
394
|
if (calls.length === 0 && remaining.length === issues.length) return { kind: "no_match" };
|
|
349
395
|
return {
|
|
350
396
|
kind: "match",
|
|
@@ -353,12 +399,20 @@ const nativeEnumPlanCallStrategy = (issues, ctx) => {
|
|
|
353
399
|
recipe: emittedRebuildRecipe
|
|
354
400
|
};
|
|
355
401
|
};
|
|
402
|
+
/**
|
|
403
|
+
* Collects every `PostgresEnumType` instance across all declared namespaces,
|
|
404
|
+
* returning a compound-keyed map (`${namespaceId}\u0000${typeName}`). Two
|
|
405
|
+
* namespaces that declare an enum with the same name produce two distinct
|
|
406
|
+
* entries — no name collision, no last-write-wins.
|
|
407
|
+
*
|
|
408
|
+
* Entries within each namespace are sorted by name for deterministic ordering.
|
|
409
|
+
*/
|
|
356
410
|
function collectPostgresEnumTypes(storage) {
|
|
357
411
|
const result = /* @__PURE__ */ new Map();
|
|
358
|
-
for (const ns of Object.
|
|
359
|
-
if (!("
|
|
360
|
-
const
|
|
361
|
-
for (const [name, instance] of Object.entries(
|
|
412
|
+
for (const [nsId, ns] of Object.entries(storage.namespaces)) {
|
|
413
|
+
if (!("enum" in ns) || ns.enum == null) continue;
|
|
414
|
+
const nsEnums = ns.enum;
|
|
415
|
+
for (const [name, instance] of Object.entries(nsEnums).sort(([a], [b]) => a.localeCompare(b))) if (instance instanceof PostgresEnumType) result.set(enumCompoundKey(nsId, name), instance);
|
|
362
416
|
}
|
|
363
417
|
return result;
|
|
364
418
|
}
|
|
@@ -559,12 +613,14 @@ const postgresPlannerStrategies = [
|
|
|
559
613
|
];
|
|
560
614
|
//#endregion
|
|
561
615
|
//#region src/core/migrations/issue-planner.ts
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
616
|
+
/**
|
|
617
|
+
* Finds a type entry by explicit namespace coordinate. Reads the named
|
|
618
|
+
* namespace's `enum` slot directly — never scans other namespaces.
|
|
619
|
+
*/
|
|
620
|
+
function locateNamespaceTypeInStorage(storage, namespaceId, typeName) {
|
|
621
|
+
const ns = storage.namespaces[namespaceId];
|
|
622
|
+
if (!ns || !("enum" in ns) || ns.enum == null) return void 0;
|
|
623
|
+
return ns.enum[typeName];
|
|
568
624
|
}
|
|
569
625
|
const ISSUE_KIND_ORDER = {
|
|
570
626
|
missing_schema: 1,
|
|
@@ -804,9 +860,10 @@ function mapIssueToCall(issue, ctx) {
|
|
|
804
860
|
return notOk(issueConflict("foreignKeyConflict", `Foreign key on "${issue.table}" differs (expected: ${issue.expected}, actual: ${issue.actual})`, { table: issue.table }));
|
|
805
861
|
case "type_missing": {
|
|
806
862
|
if (!issue.typeName) return notOk(issueConflict("unsupportedOperation", "Type missing issue has no typeName"));
|
|
807
|
-
const
|
|
863
|
+
const namespaceId = resolveNamespaceIdForIssue(issue);
|
|
864
|
+
const typeInstance = ctx.toContract.storage.types?.[issue.typeName] ?? locateNamespaceTypeInStorage(ctx.toContract.storage, namespaceId, issue.typeName);
|
|
808
865
|
if (!typeInstance) return notOk(issueConflict("unsupportedOperation", `Type "${issue.typeName}" reported missing but not found in destination contract`));
|
|
809
|
-
if (typeInstance instanceof PostgresEnumType) return ok([new CreateEnumTypeCall(
|
|
866
|
+
if (typeInstance instanceof PostgresEnumType) return ok([new CreateEnumTypeCall(resolveDdlSchemaForNamespace(ctx, namespaceId), issue.typeName, typeInstance.values, typeInstance.nativeType)]);
|
|
810
867
|
const codecInstance = typeInstance;
|
|
811
868
|
return notOk(issueConflict("unsupportedOperation", `Type "${issue.typeName}" uses codec "${codecInstance.codecId}" — only enum types are supported`));
|
|
812
869
|
}
|
|
@@ -976,4 +1033,4 @@ function planIssues(options) {
|
|
|
976
1033
|
//#endregion
|
|
977
1034
|
export { postgresPlannerStrategies as n, planIssues as t };
|
|
978
1035
|
|
|
979
|
-
//# sourceMappingURL=issue-planner-
|
|
1036
|
+
//# sourceMappingURL=issue-planner-2RgYsjUJ.mjs.map
|