@prisma-next/target-postgres 0.12.0-dev.6 → 0.12.0-dev.60
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-DliyCWPY.d.mts → codec-ids-B1vOchLE.d.mts} +3 -2
- package/dist/codec-ids-B1vOchLE.d.mts.map +1 -0
- package/dist/{codec-ids-C5qzBqus.mjs → codec-ids-CTikp1if.mjs} +3 -2
- package/dist/codec-ids-CTikp1if.mjs.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-BF1DXTPs.d.mts → codec-types-CnFiNML4.d.mts} +8 -9
- package/dist/codec-types-CnFiNML4.d.mts.map +1 -0
- package/dist/codec-types.d.mts +2 -2
- package/dist/{codecs-DuP3d9Au.d.mts → codecs-CBpEv4s5.d.mts} +33 -35
- package/dist/codecs-CBpEv4s5.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +37 -2
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +75 -0
- package/dist/contract-free.d.mts.map +1 -0
- package/dist/contract-free.mjs +139 -0
- package/dist/contract-free.mjs.map +1 -0
- package/dist/control.d.mts +1 -1
- package/dist/control.mjs +62 -36
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-CRkv2T_U.mjs → data-transform-D25tLeYU.mjs} +1 -1
- package/dist/{data-transform-CRkv2T_U.mjs.map → data-transform-D25tLeYU.mjs.map} +1 -1
- package/dist/{data-transform-CAPmAdxS.d.mts → data-transform-lq3NGdIt.d.mts} +2 -2
- package/dist/{data-transform-CAPmAdxS.d.mts.map → data-transform-lq3NGdIt.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/ddl.d.mts +2 -0
- package/dist/ddl.mjs +2 -0
- package/dist/{default-normalizer-DaAhmzBV.mjs → default-normalizer-DyyCHQWs.mjs} +1 -1
- package/dist/{default-normalizer-DaAhmzBV.mjs.map → default-normalizer-DyyCHQWs.mjs.map} +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/{descriptor-meta-Uu8QaClr.mjs → descriptor-meta-DKmj-IMN.mjs} +3 -2
- package/dist/descriptor-meta-DKmj-IMN.mjs.map +1 -0
- package/dist/{descriptor-meta-runtime-DMRX39kp.mjs → descriptor-meta-runtime-My8_s4cs.mjs} +2 -2
- package/dist/{descriptor-meta-runtime-DMRX39kp.mjs.map → descriptor-meta-runtime-My8_s4cs.mjs.map} +1 -1
- package/dist/{enum-planning-DRA9LaMU.mjs → enum-planning-BCyvlFHk.mjs} +0 -0
- package/dist/{enum-planning-DRA9LaMU.mjs.map → enum-planning-BCyvlFHk.mjs.map} +1 -1
- package/dist/enum-planning.d.mts +1 -1
- package/dist/enum-planning.mjs +1 -1
- package/dist/{errors-BbnITmAD.mjs → errors-CUk87ByX.mjs} +1 -1
- package/dist/{errors-BbnITmAD.mjs.map → errors-CUk87ByX.mjs.map} +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/{issue-planner-BtaL6OfW.mjs → issue-planner-DFr4gqfy.mjs} +22 -23
- package/dist/issue-planner-DFr4gqfy.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.mjs +3 -3
- package/dist/{native-type-normalizer-BNEQ9VDs.mjs → native-type-normalizer-Bc9XJzWC.mjs} +1 -1
- package/dist/{native-type-normalizer-BNEQ9VDs.mjs.map → native-type-normalizer-Bc9XJzWC.mjs.map} +1 -1
- package/dist/native-type-normalizer.mjs +1 -1
- package/dist/nodes-Dm1XR7UL.mjs +42 -0
- package/dist/nodes-Dm1XR7UL.mjs.map +1 -0
- package/dist/nodes-Dq0ALHOk.d.mts +38 -0
- package/dist/nodes-Dq0ALHOk.d.mts.map +1 -0
- package/dist/{op-factory-call-ewOd5q6L.mjs → op-factory-call-BsqXS6Hl.mjs} +2 -2
- package/dist/{op-factory-call-ewOd5q6L.mjs.map → op-factory-call-BsqXS6Hl.mjs.map} +1 -1
- package/dist/{op-factory-call-CDlImOF_.d.mts → op-factory-call-D47zfLOp.d.mts} +3 -3
- package/dist/op-factory-call-D47zfLOp.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +5 -6
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-C-ynXbEZ.mjs +340 -0
- package/dist/planner-C-ynXbEZ.mjs.map +1 -0
- package/dist/{planner-ddl-builders-BNMfSE9r.mjs → planner-ddl-builders-DMfNR28t.mjs} +3 -3
- package/dist/{planner-ddl-builders-BNMfSE9r.mjs.map → planner-ddl-builders-DMfNR28t.mjs.map} +1 -1
- package/dist/planner-ddl-builders.d.mts +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-nhVj0hp-.mjs → planner-identity-values-BIpa5p2I.mjs} +1 -1
- package/dist/{planner-identity-values-nhVj0hp-.mjs.map → planner-identity-values-BIpa5p2I.mjs.map} +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs → planner-produced-postgres-migration-BCy50btZ.mjs} +4 -4
- package/dist/{planner-produced-postgres-migration-D_nsXbhl.mjs.map → planner-produced-postgres-migration-BCy50btZ.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-D02NOhVQ.d.mts → planner-produced-postgres-migration-CpsGhewL.d.mts} +3 -3
- package/dist/planner-produced-postgres-migration-CpsGhewL.d.mts.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-CGxxYfnD.mjs → planner-schema-lookup-CiVaAQP-.mjs} +1 -1
- package/dist/{planner-schema-lookup-CGxxYfnD.mjs.map → planner-schema-lookup-CiVaAQP-.mjs.map} +1 -1
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/{planner-sql-checks-CfEiTXoQ.mjs → planner-sql-checks-ErSyqc0x.mjs} +39 -12
- package/dist/planner-sql-checks-ErSyqc0x.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-a_wuOiYf.d.mts → planner-target-details-DyUHJ7MY.d.mts} +1 -1
- package/dist/{planner-target-details-a_wuOiYf.d.mts.map → planner-target-details-DyUHJ7MY.d.mts.map} +1 -1
- package/dist/planner-target-details.d.mts +2 -2
- package/dist/planner.d.mts +3 -2
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-BnOboPWs.mjs → postgres-contract-serializer-DYTyXjPf.mjs} +33 -24
- package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +1 -0
- package/dist/{postgres-enum-type-CSzsvXrO.d.mts → postgres-enum-type-BVn63a89.d.mts} +1 -1
- package/dist/{postgres-enum-type-CSzsvXrO.d.mts.map → postgres-enum-type-BVn63a89.d.mts.map} +1 -1
- package/dist/{postgres-enum-type-BMgyxNyy.mjs → postgres-enum-type-DPKqCBem.mjs} +1 -1
- package/dist/{postgres-enum-type-BMgyxNyy.mjs.map → postgres-enum-type-DPKqCBem.mjs.map} +1 -1
- package/dist/{postgres-migration-DRY8V-bQ.d.mts → postgres-migration--iqDr7rB.d.mts} +3 -3
- package/dist/{postgres-migration-DRY8V-bQ.d.mts.map → postgres-migration--iqDr7rB.d.mts.map} +1 -1
- package/dist/{postgres-migration-BatbEvU6.mjs → postgres-migration-DcymFlMG.mjs} +3 -3
- package/dist/{postgres-migration-BatbEvU6.mjs.map → postgres-migration-DcymFlMG.mjs.map} +1 -1
- package/dist/{postgres-schema-BxAuNFX0.mjs → postgres-schema-BuxCxbvB.mjs} +29 -14
- package/dist/postgres-schema-BuxCxbvB.mjs.map +1 -0
- package/dist/{render-ops-XhICjX_P.mjs → render-ops-Wb6SCGmj.mjs} +1 -1
- package/dist/{render-ops-XhICjX_P.mjs.map → render-ops-Wb6SCGmj.mjs.map} +1 -1
- package/dist/render-ops.d.mts +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-K125n-RZ.mjs → render-typescript-BShM6uyS.mjs} +1 -1
- package/dist/{render-typescript-K125n-RZ.mjs.map → render-typescript-BShM6uyS.mjs.map} +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{shared-Do_a5ymU.d.mts → shared-C3gXQyxj.d.mts} +2 -2
- package/dist/{shared-Do_a5ymU.d.mts.map → shared-C3gXQyxj.d.mts.map} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs → sql-utils-DcfMz4MQ.mjs} +1 -1
- package/dist/{sql-utils-CggjWNij.mjs.map → sql-utils-DcfMz4MQ.mjs.map} +1 -1
- package/dist/sql-utils.mjs +1 -1
- package/dist/{tables-DoA39Yqo.mjs → tables-CGFE4dED.mjs} +3 -3
- package/dist/{tables-DoA39Yqo.mjs.map → tables-CGFE4dED.mjs.map} +1 -1
- package/dist/{types-O40IcFV9.d.mts → types-BDKkx8MA.d.mts} +1 -1
- package/dist/types-BDKkx8MA.d.mts.map +1 -0
- package/dist/types.d.mts +16 -11
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -2
- package/package.json +21 -20
- package/src/contract-free/columns.ts +49 -0
- package/src/contract-free/control-bootstrap.ts +55 -0
- package/src/contract-free/ddl.ts +32 -0
- package/src/core/ast/table-source.ts +23 -0
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codecs.ts +44 -0
- package/src/core/ddl/nodes.ts +59 -0
- package/src/core/descriptor-meta.ts +1 -0
- package/src/core/migrations/control-policy.ts +234 -0
- package/src/core/migrations/issue-planner.ts +3 -3
- package/src/core/migrations/planner-sql-checks.ts +9 -9
- package/src/core/migrations/planner-strategies.ts +16 -10
- package/src/core/migrations/planner.ts +55 -6
- package/src/core/migrations/runner.ts +78 -50
- package/src/core/postgres-contract-serializer.ts +52 -46
- package/src/core/postgres-schema.ts +43 -25
- package/src/exports/contract-free.ts +7 -0
- package/src/exports/ddl.ts +7 -0
- package/dist/codec-ids-C5qzBqus.mjs.map +0 -1
- package/dist/codec-ids-DliyCWPY.d.mts.map +0 -1
- package/dist/codec-types-BF1DXTPs.d.mts.map +0 -1
- package/dist/codecs-DuP3d9Au.d.mts.map +0 -1
- package/dist/descriptor-meta-Uu8QaClr.mjs.map +0 -1
- package/dist/issue-planner-BtaL6OfW.mjs.map +0 -1
- package/dist/op-factory-call-CDlImOF_.d.mts.map +0 -1
- package/dist/planner-Bjz5pnLa.mjs +0 -177
- package/dist/planner-Bjz5pnLa.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-D02NOhVQ.d.mts.map +0 -1
- package/dist/planner-sql-checks-CfEiTXoQ.mjs.map +0 -1
- package/dist/postgres-contract-serializer-BnOboPWs.mjs.map +0 -1
- package/dist/postgres-schema-BxAuNFX0.mjs.map +0 -1
- package/dist/statement-builders-DVI5IVAa.mjs +0 -131
- package/dist/statement-builders-DVI5IVAa.mjs.map +0 -1
- package/dist/statement-builders.d.mts +0 -51
- package/dist/statement-builders.d.mts.map +0 -1
- package/dist/statement-builders.mjs +0 -2
- package/dist/types-O40IcFV9.d.mts.map +0 -1
- package/src/core/migrations/statement-builders.ts +0 -183
- package/src/exports/statement-builders.ts +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-planning-DRA9LaMU.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 { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\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';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgStorageTypesMap(\n value: unknown,\n): Readonly<Record<string, PgStorageTypeEntry>> | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const entries: Record<string, PgStorageTypeEntry> = {};\n for (const [key, entryValue] of Object.entries(value)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n entries[key] = entry;\n }\n }\n return Object.keys(entries).length > 0 ? entries : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const storageTypes = readPgStorageTypesMap(Reflect.get(raw, 'storageTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(storageTypes !== undefined ? { storageTypes } : {}),\n };\n}\n\n/**\n * Separator for `(schemaName, nativeType)` keys in introspected\n * `schema.annotations.pg.storageTypes`. NUL cannot appear in Postgres\n * identifiers, so the pair is unambiguous.\n */\nexport const ENUM_STORAGE_KEY_SEP = '\\u0000';\n\n/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */\nexport function enumStorageCompoundKey(schemaName: string, nativeType: string): string {\n return `${schemaName}${ENUM_STORAGE_KEY_SEP}${nativeType}`;\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\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 `(schemaName, 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 schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const storageTypes = readPostgresSchemaIrAnnotations(schema).storageTypes;\n const existing = storageTypes?.[enumStorageCompoundKey(schemaName, 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;\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":";;;;;;;;;;AA6BA,SAAS,mBAAmB,OAAoC;CAC9D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,uBAAuB,OAAgD;CAC9E,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE;CAEF,MAAM,UAAU,QAAQ,IAAI,OAAO,SAAS;CAC5C,MAAM,gBAAgB,QAAQ,IAAI,OAAO,YAAY;CACrD,MAAM,aACJ,kBAAkB,KAAA,KAClB,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,CAAC,MAAM,QAAQ,aAAa,IACxB,EAAE,QAAQ,QAAQ,IAAI,eAAe,QAAQ,EAAE,IAC/C,KAAA;CACN,OAAO;EACL,GAAI,OAAO,YAAY,WAAW,EAAE,QAAQ,IAAI,CAAC;EACjD,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;CACnD;AACF;AAEA,SAAS,sBACP,OAC0D;CAC1D,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE;CAEF,MAAM,UAA8C,CAAC;CACrD,KAAK,MAAM,CAAC,KAAK,eAAe,OAAO,QAAQ,KAAK,GAAG;EACrD,MAAM,QAAQ,uBAAuB,UA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OAAO,MAAM,OAAO,MAAM,QAAQ,GAC9E,OAAO;CAET,OAAO;AACT;;;;;;;;;AAUA,SAAgB,kBACd,UACA,SACU;CACV,IAAI,YAAY,UAAU,OAAO,GAC/B,OAAO,EAAE,MAAM,YAAY;CAE7B,MAAM,cAAc,IAAI,IAAI,QAAQ;CACpC,MAAM,aAAa,IAAI,IAAI,OAAO;CAClC,MAAM,gBAAgB,QAAQ,QAAQ,UAAU,CAAC,YAAY,IAAI,KAAK,CAAC;CACvE,MAAM,gBAAgB,SAAS,QAAQ,UAAU,CAAC,WAAW,IAAI,KAAK,CAAC;CACvE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,OAAO;CAC5F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;CAAc;CAE1C,OAAO;EAAE,MAAM;EAAc,QAAQ;CAAc;AACrD;;;;;AAMA,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa;AACtB"}
|
|
1
|
+
{"version":3,"file":"enum-planning-BCyvlFHk.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 { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\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';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.storageTypes[(schemaName, nativeType)]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly storageTypes?: Readonly<Record<string, PgStorageTypeEntry>>;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgStorageTypesMap(\n value: unknown,\n): Readonly<Record<string, PgStorageTypeEntry>> | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const entries: Record<string, PgStorageTypeEntry> = {};\n for (const [key, entryValue] of Object.entries(value)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n entries[key] = entry;\n }\n }\n return Object.keys(entries).length > 0 ? entries : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const storageTypes = readPgStorageTypesMap(Reflect.get(raw, 'storageTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(storageTypes !== undefined ? { storageTypes } : {}),\n };\n}\n\n/**\n * Separator for `(schemaName, nativeType)` keys in introspected\n * `schema.annotations.pg.storageTypes`. NUL cannot appear in Postgres\n * identifiers, so the pair is unambiguous.\n */\nexport const ENUM_STORAGE_KEY_SEP = '\\u0000';\n\n/** Builds the schema-qualified storageTypes map key for a live Postgres enum. */\nexport function enumStorageCompoundKey(schemaName: string, nativeType: string): string {\n return `${schemaName}${ENUM_STORAGE_KEY_SEP}${nativeType}`;\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\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 `(schemaName, 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 schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const storageTypes = readPostgresSchemaIrAnnotations(schema).storageTypes;\n const existing = storageTypes?.[enumStorageCompoundKey(schemaName, 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;\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 getDesiredE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CAAC;CACvE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,OAAO;CAC5F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;CAAc;CAE1C,OAAO;EAAE,MAAM;EAAc,QAAQ;CAAc;AACrD;;;;;AAMA,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa;AACtB"}
|
package/dist/enum-planning.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-
|
|
1
|
+
import { t as PostgresEnumType } from "./postgres-enum-type-BVn63a89.mjs";
|
|
2
2
|
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
3
3
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
4
|
|
package/dist/enum-planning.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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-
|
|
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-BCyvlFHk.mjs";
|
|
2
2
|
export { createResolveExistingEnumValues, determineEnumDiff, enumStorageCompoundKey, getDesiredEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations, resolveDdlSchemaForNamespaceStorage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-CUk87ByX.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;;;;AAAwE;;;;;;;;;;;;;iBAAxD,kCAAA,
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/core/errors.ts"],"mappings":";;;;;AAqBA;;;;AAAwE;;;;;;;;;;;;;iBAAxD,kCAAA,IAAsC,kBAAkB"}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as errorPostgresMigrationStackMissing } from "./errors-
|
|
1
|
+
import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
|
|
2
2
|
export { errorPostgresMigrationStackMissing };
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-
|
|
2
|
-
import { i as quoteIdentifier } from "./sql-utils-
|
|
3
|
-
import { r as isPostgresSchema } from "./postgres-schema-
|
|
4
|
-
import { a as readExistingEnumValues, n as determineEnumDiff, s as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-
|
|
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-
|
|
1
|
+
import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
|
|
2
|
+
import { i as quoteIdentifier } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
|
+
import { r as isPostgresSchema } from "./postgres-schema-BuxCxbvB.mjs";
|
|
4
|
+
import { a as readExistingEnumValues, n as determineEnumDiff, s as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-BCyvlFHk.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-ErSyqc0x.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-BsqXS6Hl.mjs";
|
|
7
|
+
import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-DMfNR28t.mjs";
|
|
8
|
+
import { n as resolveIdentityValue } from "./planner-identity-values-BIpa5p2I.mjs";
|
|
9
|
+
import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-CiVaAQP-.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";
|
|
13
13
|
import { arraysEqual } from "@prisma-next/family-sql/schema-verify";
|
|
14
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
14
15
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
15
16
|
//#region src/core/migrations/planner-target-details.ts
|
|
16
17
|
function buildTargetDetails(objectType, name, schema, table) {
|
|
@@ -99,7 +100,7 @@ const REBUILD_SUFFIX = "__prisma_next_new";
|
|
|
99
100
|
* contracts where two namespaces can carry the same table name).
|
|
100
101
|
*/
|
|
101
102
|
function tableAt(storage, namespaceId, tableName) {
|
|
102
|
-
return storage.namespaces[namespaceId]?.
|
|
103
|
+
return storage.namespaces[namespaceId]?.entries.table[tableName];
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
106
|
* Default namespace coordinate for an issue that does not carry one
|
|
@@ -134,8 +135,8 @@ function resolveDdlSchemaForNamespace(ctx, namespaceId) {
|
|
|
134
135
|
const DEFAULT_ENUM_NAMESPACE_ID = "public";
|
|
135
136
|
function namespaceHasEnum(storage, namespaceId, typeName) {
|
|
136
137
|
const ns = storage.namespaces[namespaceId];
|
|
137
|
-
if (!
|
|
138
|
-
return ns.
|
|
138
|
+
if (!isPostgresSchema(ns)) return false;
|
|
139
|
+
return ns.entries.type[typeName] !== void 0;
|
|
139
140
|
}
|
|
140
141
|
/**
|
|
141
142
|
* Resolves which namespace's enum a column's bare `typeRef` binds to.
|
|
@@ -158,14 +159,14 @@ function resolveColumnEnumNamespace(storage, columnNamespaceId, typeName) {
|
|
|
158
159
|
}
|
|
159
160
|
/**
|
|
160
161
|
* Finds a type entry by explicit namespace coordinate. Namespace types (e.g.
|
|
161
|
-
* Postgres enums) live under `storage.namespaces[nsId].
|
|
162
|
+
* Postgres enums) live under `storage.namespaces[nsId].entries.type`. Returns the
|
|
162
163
|
* entry from the named namespace only — never scans other namespaces, so two
|
|
163
164
|
* namespaces that hold an enum with the same name resolve independently.
|
|
164
165
|
*/
|
|
165
166
|
function locateNamespaceType(storage, namespaceId, typeName) {
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
167
|
+
const raw = storage.namespaces[namespaceId]?.entries["type"]?.[typeName];
|
|
168
|
+
if (raw === void 0) return void 0;
|
|
169
|
+
return blindCast(raw);
|
|
169
170
|
}
|
|
170
171
|
function buildColumnSpec(namespaceId, table, column, ctx, overrides) {
|
|
171
172
|
const col = tableAt(ctx.toContract.storage, namespaceId, table)?.columns[column];
|
|
@@ -282,7 +283,7 @@ function enumRebuildCallRecipe(namespaceId, typeName, ctx) {
|
|
|
282
283
|
const tempName = `${nativeType}${REBUILD_SUFFIX}`;
|
|
283
284
|
const ddlSchema = resolveDdlSchemaForNamespaceStorage(ctx.toContract.storage, namespaceId, ctx.schema);
|
|
284
285
|
const columnRefs = [];
|
|
285
|
-
for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const [tableName, tableNode] of Object.entries(ns.
|
|
286
|
+
for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) for (const [tableName, tableNode] of Object.entries(ns.entries.table)) {
|
|
286
287
|
const table = tableNode;
|
|
287
288
|
for (const [columnName, column] of Object.entries(table.columns)) if (column.typeRef === typeName && resolveColumnEnumNamespace(ctx.toContract.storage, nsId, typeName) === namespaceId) columnRefs.push({
|
|
288
289
|
namespaceId: nsId,
|
|
@@ -410,9 +411,8 @@ const nativeEnumPlanCallStrategy = (issues, ctx) => {
|
|
|
410
411
|
function collectPostgresEnumTypes(storage) {
|
|
411
412
|
const result = /* @__PURE__ */ new Map();
|
|
412
413
|
for (const [nsId, ns] of Object.entries(storage.namespaces)) {
|
|
413
|
-
if (!(
|
|
414
|
-
const
|
|
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);
|
|
414
|
+
if (!isPostgresSchema(ns)) continue;
|
|
415
|
+
for (const [name, instance] of Object.entries(ns.entries.type).sort(([a], [b]) => a.localeCompare(b))) if (instance instanceof PostgresEnumType) result.set(enumCompoundKey(nsId, name), instance);
|
|
416
416
|
}
|
|
417
417
|
return result;
|
|
418
418
|
}
|
|
@@ -619,8 +619,7 @@ const postgresPlannerStrategies = [
|
|
|
619
619
|
*/
|
|
620
620
|
function locateNamespaceTypeInStorage(storage, namespaceId, typeName) {
|
|
621
621
|
const ns = storage.namespaces[namespaceId];
|
|
622
|
-
|
|
623
|
-
return ns.enum[typeName];
|
|
622
|
+
return isPostgresSchema(ns) ? ns.entries.type[typeName] : void 0;
|
|
624
623
|
}
|
|
625
624
|
const ISSUE_KIND_ORDER = {
|
|
626
625
|
missing_schema: 1,
|
|
@@ -1033,4 +1032,4 @@ function planIssues(options) {
|
|
|
1033
1032
|
//#endregion
|
|
1034
1033
|
export { postgresPlannerStrategies as n, planIssues as t };
|
|
1035
1034
|
|
|
1036
|
-
//# sourceMappingURL=issue-planner-
|
|
1035
|
+
//# sourceMappingURL=issue-planner-DFr4gqfy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue-planner-DFr4gqfy.mjs","names":[],"sources":["../src/core/migrations/planner-target-details.ts","../src/core/migrations/planner-recipes.ts","../src/core/migrations/planner-strategies.ts","../src/core/migrations/issue-planner.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\n\nexport type OperationClass =\n | 'dependency'\n | 'type'\n | 'table'\n | 'column'\n | 'primaryKey'\n | 'unique'\n | 'index'\n | 'foreignKey';\n\nexport interface PostgresPlanTargetDetails {\n readonly schema: string;\n readonly objectType: OperationClass;\n readonly name: string;\n readonly table?: string;\n}\n\nexport function buildTargetDetails(\n objectType: OperationClass,\n name: string,\n schema: string,\n table?: string,\n): PostgresPlanTargetDetails {\n return {\n schema,\n objectType,\n name,\n ...ifDefined('table', table),\n };\n}\n","import type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type {\n PostgresEnumStorageEntry,\n StorageColumn,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { quoteIdentifier } from '../sql-utils';\nimport { buildAddColumnSql } from './planner-ddl-builders';\nimport {\n columnExistsCheck,\n columnHasNoDefaultCheck,\n columnNullabilityCheck,\n qualifyTableName,\n} from './planner-sql-checks';\nimport { buildTargetDetails, type PostgresPlanTargetDetails } from './planner-target-details';\n\nexport function buildAddColumnOperationIdentity(\n schema: string,\n tableName: string,\n columnName: string,\n): Pick<\n SqlMigrationPlanOperation<PostgresPlanTargetDetails>,\n 'id' | 'label' | 'summary' | 'target'\n> {\n return {\n id: `column.${tableName}.${columnName}`,\n label: `Add column ${columnName} to ${tableName}`,\n summary: `Adds column ${columnName} to table ${tableName}`,\n target: {\n id: 'postgres',\n details: buildTargetDetails('table', tableName, schema),\n },\n };\n}\n\nexport function buildAddNotNullColumnWithTemporaryDefaultOperation(options: {\n readonly schema: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly column: StorageColumn;\n readonly codecHooks: Map<string, CodecControlHooks>;\n readonly storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>;\n readonly temporaryDefault: string;\n}): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault } =\n options;\n const qualified = qualifyTableName(schema, tableName);\n\n return {\n ...buildAddColumnOperationIdentity(schema, tableName, columnName),\n operationClass: 'additive',\n precheck: [\n {\n description: `ensure column \"${columnName}\" is missing`,\n sql: columnExistsCheck({ schema, table: tableName, column: columnName, exists: false }),\n },\n ],\n execute: [\n {\n description: `add column \"${columnName}\"`,\n sql: buildAddColumnSql(\n qualified,\n columnName,\n column,\n codecHooks,\n temporaryDefault,\n storageTypes,\n ),\n },\n {\n description: `drop temporary default from column \"${columnName}\"`,\n sql: `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP DEFAULT`,\n },\n ],\n postcheck: [\n {\n description: `verify column \"${columnName}\" exists`,\n sql: columnExistsCheck({ schema, table: tableName, column: columnName }),\n },\n {\n description: `verify column \"${columnName}\" is NOT NULL`,\n sql: columnNullabilityCheck({\n schema,\n table: tableName,\n column: columnName,\n nullable: false,\n }),\n },\n {\n description: `verify column \"${columnName}\" has no default after temporary default removal`,\n sql: columnHasNoDefaultCheck({ schema, table: tableName, column: columnName }),\n },\n ],\n };\n}\n","/**\n * Migration strategies.\n *\n * Each strategy examines the issue list, consumes issues it handles, and\n * returns the `PostgresOpFactoryCall[]` to address them. The issue planner\n * runs each strategy in order and routes whatever's left through\n * `mapIssueToCall`.\n *\n * The full ordered list is exported as `postgresPlannerStrategies` and is\n * used unchanged by both `migration plan` and `db update` / `db init`. The\n * two journeys differ only in `policy.allowedOperationClasses`:\n *\n * - When `'data'` is in the policy, data-safe strategies (NOT NULL backfill,\n * nullability tightening, unsafe type changes, enum shrink/rebuild) emit\n * `DataTransformCall` placeholders that the user fills in.\n * - When `'data'` is excluded, those strategies short-circuit so the\n * downstream walk-schema strategies (codec-hook type ops and temp-default\n * backfill) and `mapIssueToCall` defaults emit direct DDL instead.\n */\n\nimport type { Contract } from '@prisma-next/contract/types';\nimport type {\n CodecControlHooks,\n MigrationOperationPolicy,\n SqlMigrationPlanOperation,\n} from '@prisma-next/family-sql/control';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type SqlStorage,\n type StorageTable,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\nimport {\n determineEnumDiff,\n readExistingEnumValues,\n resolveDdlSchemaForNamespaceStorage,\n} from './enum-planning';\nimport {\n AddColumnCall,\n AddEnumValuesCall,\n AlterColumnTypeCall,\n CreateEnumTypeCall,\n DataTransformCall,\n DropEnumTypeCall,\n type PostgresOpFactoryCall,\n RawSqlCall,\n RenameTypeCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport {\n buildAddColumnSql,\n buildColumnDefaultSql,\n buildColumnTypeSql,\n} from './planner-ddl-builders';\nimport { resolveIdentityValue } from './planner-identity-values';\nimport {\n buildAddColumnOperationIdentity,\n buildAddNotNullColumnWithTemporaryDefaultOperation,\n} from './planner-recipes';\nimport { buildSchemaLookupMap, hasForeignKey, hasUniqueConstraint } from './planner-schema-lookup';\nimport {\n buildExpectedFormatType,\n columnExistsCheck,\n columnNullabilityCheck,\n qualifyTableName,\n tableIsEmptyCheck,\n} from './planner-sql-checks';\nimport { buildTargetDetails, type PostgresPlanTargetDetails } from './planner-target-details';\n\nconst REBUILD_SUFFIX = '__prisma_next_new';\n\n/**\n * Look up a storage table by its explicit namespace coordinate. Returns\n * `undefined` when the namespace has no table by that name (or no such\n * namespace exists). Callers that get `undefined` MUST treat it as an\n * explicit conflict — never silently fall back to a global default\n * schema or a name-only walk, because that footgun would resolve a\n * stale or duplicate table name to whichever namespace the iteration\n * order surfaced first (a real data-loss hazard in multi-namespace\n * contracts where two namespaces can carry the same table name).\n */\nexport function tableAt(\n storage: SqlStorage,\n namespaceId: string,\n tableName: string,\n): StorageTable | undefined {\n // Namespace.tables is typed as Record<string, IRNode> at the interface level;\n // SQL family namespaces always hold StorageTable instances.\n return storage.namespaces[namespaceId]?.entries.table[tableName] as StorageTable | undefined;\n}\n\n/**\n * Default namespace coordinate for an issue that does not carry one\n * explicitly. Hand-crafted unit-test issues and `extra_table` issues\n * fall back to `__unbound__`, the only namespace any single-namespace\n * contract carries — verifier-emitted issues for legacy\n * single-namespace contracts already stamp this id explicitly. Typed\n * structurally so issue variants without a `namespaceId` slot\n * (e.g. `EnumValuesChangedIssue`) flow through to the same fallback.\n */\nexport function resolveNamespaceIdForIssue(issue: { readonly namespaceId?: string }): string {\n return issue.namespaceId ?? UNBOUND_NAMESPACE_ID;\n}\n\n/**\n * Resolve the DDL schema name for a namespace coordinate. Postgres-aware\n * namespaces dispatch to their polymorphic `ddlSchemaName` override —\n * named schemas return their own id; the unbound singleton returns\n * `UNBOUND_NAMESPACE_ID`. Legacy single-namespace contracts whose\n * `__unbound__` slot is the framework-default `SqlUnboundNamespace`\n * (rather than the Postgres-aware `PostgresUnboundSchema`) flow the\n * coordinate through unchanged so downstream `qualifyTableName`\n * resolves polymorphically.\n */\nexport function resolveDdlSchemaForNamespace(ctx: StrategyContext, namespaceId: string): string {\n const namespace = ctx.toContract.storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(ctx.toContract.storage);\n }\n return namespaceId;\n}\n\n/** Default Postgres enum landing namespace — where contract-level (`types:`)\n * enums are placed by the authoring builder when no explicit namespace is\n * given. Mirrors `POSTGRES_ENUM_NAMESPACE_ID` in the contract-ts builder. */\nconst DEFAULT_ENUM_NAMESPACE_ID = 'public';\n\nfunction namespaceHasEnum(storage: SqlStorage, namespaceId: string, typeName: string): boolean {\n const ns = storage.namespaces[namespaceId];\n if (!isPostgresSchema(ns)) return false;\n return ns.entries.type[typeName] !== undefined;\n}\n\n/**\n * Resolves which namespace's enum a column's bare `typeRef` binds to.\n *\n * Columns carry a bare (non-namespace-qualified) `typeRef`; the enum it names\n * may live in a different namespace than the column's own (the authoring\n * builder places contract-level `types:` enums in the default `public`\n * namespace while a model's table may sit in the unbound namespace). The\n * binding rule: an enum declared in the column's *own* namespace shadows\n * everything; otherwise the column references the ambient enum — the sole\n * namespace that defines `typeName`, preferring the default `public`\n * namespace when several do. Returns `undefined` when no namespace defines it.\n */\nfunction resolveColumnEnumNamespace(\n storage: SqlStorage,\n columnNamespaceId: string,\n typeName: string,\n): string | undefined {\n if (namespaceHasEnum(storage, columnNamespaceId, typeName)) return columnNamespaceId;\n const owners = Object.keys(storage.namespaces).filter((nsId) =>\n namespaceHasEnum(storage, nsId, typeName),\n );\n if (owners.length === 1) return owners[0];\n if (owners.includes(DEFAULT_ENUM_NAMESPACE_ID)) return DEFAULT_ENUM_NAMESPACE_ID;\n return owners[0];\n}\n\n/**\n * Finds a type entry by explicit namespace coordinate. Namespace types (e.g.\n * Postgres enums) live under `storage.namespaces[nsId].entries.type`. Returns the\n * entry from the named namespace only — never scans other namespaces, so two\n * namespaces that hold an enum with the same name resolve independently.\n */\nfunction locateNamespaceType(\n storage: SqlStorage,\n namespaceId: string,\n typeName: string,\n): PostgresEnumStorageEntry | undefined {\n const ns = storage.namespaces[namespaceId];\n const raw = ns?.entries['type']?.[typeName];\n if (raw === undefined) return undefined;\n return blindCast<\n PostgresEnumStorageEntry,\n 'postgres type slot carries PostgresEnumStorageEntry at the postgres target layer'\n >(raw);\n}\n\n// ============================================================================\n// Strategy types\n// ============================================================================\n\n/**\n * Context passed to each migration strategy.\n *\n * Strategies read the source (`fromContract`), target (`toContract`), current\n * database state (`schema`), operation policy (`policy`), and component list\n * (`frameworkComponents`) to make planning decisions. `fromContract` is null\n * when no prior contract is available (e.g. `db update`, where the current\n * DB state is approximated via `schema`).\n */\nexport interface StrategyContext {\n readonly toContract: Contract<SqlStorage>;\n readonly fromContract: Contract<SqlStorage> | null;\n readonly schemaName: string;\n readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;\n readonly storageTypes: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>;\n readonly schema: SqlSchemaIR;\n readonly policy: MigrationOperationPolicy;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n}\n\n// ============================================================================\n// Call strategies (for issue planner)\n// ============================================================================\n\nexport type CallMigrationStrategy = (\n issues: readonly SchemaIssue[],\n context: StrategyContext,\n) =>\n | {\n kind: 'match';\n issues: readonly SchemaIssue[];\n calls: readonly PostgresOpFactoryCall[];\n /**\n * `true` for strategies that emit cohesive sequential recipes whose\n * calls must stay contiguous and in the returned order — e.g.\n * `nativeEnumPlanCallStrategy` (createEnumType → alterColumnType →\n * dropEnumType → renameType, optionally prefixed by a\n * `DataTransformCall` placeholder), `notNullBackfillCallStrategy`\n * (addColumn → dataTransform → setNotNull). Defaults to `false`,\n * which lets `planIssues` hoist individual calls into their DDL\n * sequencing bucket.\n */\n recipe?: boolean;\n }\n | { kind: 'no_match' };\n\nfunction buildColumnSpec(\n namespaceId: string,\n table: string,\n column: string,\n ctx: StrategyContext,\n overrides?: { nullable?: boolean },\n) {\n const col = tableAt(ctx.toContract.storage, namespaceId, table)?.columns[column];\n if (!col) throw new Error(`Column \"${table}\".\"${column}\" not found in destination contract`);\n const mutableHooks = ctx.codecHooks as Map<string, CodecControlHooks>;\n const mutableTypes = ctx.storageTypes as Record<\n string,\n StorageTypeInstance | PostgresEnumStorageEntry\n >;\n return {\n name: column,\n typeSql: buildColumnTypeSql(col, mutableHooks, mutableTypes),\n defaultSql: buildColumnDefaultSql(col.default, col),\n nullable: overrides?.nullable ?? col.nullable,\n };\n}\n\nfunction buildAlterTypeOptions(\n namespaceId: string,\n table: string,\n column: string,\n ctx: StrategyContext,\n using?: string,\n) {\n const col = tableAt(ctx.toContract.storage, namespaceId, table)?.columns[column];\n if (!col) throw new Error(`Column \"${table}\".\"${column}\" not found in destination contract`);\n const mutableHooks = ctx.codecHooks as Map<string, CodecControlHooks>;\n const mutableTypes = ctx.storageTypes as Record<\n string,\n StorageTypeInstance | PostgresEnumStorageEntry\n >;\n const qualifiedTargetType = buildColumnTypeSql(col, mutableHooks, mutableTypes, false);\n const formatTypeExpected = buildExpectedFormatType(col, mutableHooks, mutableTypes);\n return {\n qualifiedTargetType,\n formatTypeExpected,\n rawTargetTypeForLabel: qualifiedTargetType,\n ...(using !== undefined ? { using } : {}),\n };\n}\n\nexport const notNullBackfillCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n // `DataTransformCall` is operation class `'data'`. When the policy excludes\n // it (`db update` / `db init`), skip so `notNullAddColumnCallStrategy`\n // (temp-default backfill) or `mapIssueToCall` can take the issue.\n if (!ctx.policy.allowedOperationClasses.includes('data')) return { kind: 'no_match' };\n\n const matched: SchemaIssue[] = [];\n const calls: PostgresOpFactoryCall[] = [];\n\n for (const issue of issues) {\n if (issue.kind !== 'missing_column' || !issue.table || !issue.column) continue;\n\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[issue.column];\n if (!column) continue;\n if (column.nullable === true || column.default !== undefined) continue;\n\n matched.push(issue);\n const spec = buildColumnSpec(namespaceId, issue.table, issue.column, ctx, { nullable: true });\n const schemaForTable = resolveDdlSchemaForNamespace(ctx, namespaceId);\n calls.push(\n new AddColumnCall(schemaForTable, issue.table, spec),\n new DataTransformCall(\n `backfill-${issue.table}-${issue.column}`,\n `backfill-${issue.table}-${issue.column}:check`,\n `backfill-${issue.table}-${issue.column}:run`,\n ),\n new SetNotNullCall(schemaForTable, issue.table, issue.column),\n );\n }\n\n if (matched.length === 0) return { kind: 'no_match' };\n return {\n kind: 'match',\n issues: issues.filter((i) => !matched.includes(i)),\n calls,\n recipe: true,\n };\n};\n\nconst SAFE_WIDENINGS = new Set(['int2→int4', 'int2→int8', 'int4→int8', 'float4→float8']);\n\nexport const typeChangeCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n // For unsafe widenings this strategy emits a `DataTransformCall` placeholder\n // (operation class `'data'`); when the policy excludes `'data'`\n // (`db update` / `db init`), skip those issues so `mapIssueToCall` can\n // emit a direct `ALTER COLUMN TYPE`. Safe widenings still flow through\n // here because the resulting `AlterColumnTypeCall` is `widening`-class.\n const dataAllowed = ctx.policy.allowedOperationClasses.includes('data');\n\n const matched: SchemaIssue[] = [];\n const calls: PostgresOpFactoryCall[] = [];\n\n for (const issue of issues) {\n if (issue.kind !== 'type_mismatch') continue;\n if (!issue.table || !issue.column) continue;\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const fromColumn = ctx.fromContract\n ? tableAt(ctx.fromContract.storage, namespaceId, issue.table)?.columns[issue.column]\n : undefined;\n const toColumn = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!fromColumn || !toColumn) continue;\n const fromType = fromColumn.nativeType;\n const toType = toColumn.nativeType;\n if (fromType === toType) continue;\n const isSafeWidening = SAFE_WIDENINGS.has(`${fromType}→${toType}`);\n if (!isSafeWidening && !dataAllowed) continue;\n matched.push(issue);\n const alterOpts = buildAlterTypeOptions(namespaceId, issue.table, issue.column, ctx);\n const schemaForTable = resolveDdlSchemaForNamespace(ctx, namespaceId);\n if (isSafeWidening) {\n calls.push(new AlterColumnTypeCall(schemaForTable, issue.table, issue.column, alterOpts));\n } else {\n calls.push(\n new DataTransformCall(\n `typechange-${issue.table}-${issue.column}`,\n `typechange-${issue.table}-${issue.column}:check`,\n `typechange-${issue.table}-${issue.column}:run`,\n ),\n new AlterColumnTypeCall(schemaForTable, issue.table, issue.column, alterOpts),\n );\n }\n }\n if (matched.length === 0) return { kind: 'no_match' };\n return {\n kind: 'match',\n issues: issues.filter((i) => !matched.includes(i)),\n calls,\n recipe: true,\n };\n};\n\nexport const nullableTighteningCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n // `DataTransformCall` is operation class `'data'`. When the policy excludes\n // it (`db update` / `db init`), skip so `mapIssueToCall` emits a direct\n // `SET NOT NULL` instead.\n if (!ctx.policy.allowedOperationClasses.includes('data')) return { kind: 'no_match' };\n\n const matched: SchemaIssue[] = [];\n const calls: PostgresOpFactoryCall[] = [];\n\n for (const issue of issues) {\n if (issue.kind !== 'nullability_mismatch' || !issue.table || !issue.column) continue;\n\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[issue.column];\n if (!column) continue;\n if (column.nullable === true) continue;\n\n matched.push(issue);\n const schemaForTable = resolveDdlSchemaForNamespace(ctx, namespaceId);\n calls.push(\n new DataTransformCall(\n `handle-nulls-${issue.table}-${issue.column}`,\n `handle-nulls-${issue.table}-${issue.column}:check`,\n `handle-nulls-${issue.table}-${issue.column}:run`,\n ),\n new SetNotNullCall(schemaForTable, issue.table, issue.column),\n );\n }\n\n if (matched.length === 0) return { kind: 'no_match' };\n return {\n kind: 'match',\n issues: issues.filter((i) => !matched.includes(i)),\n calls,\n recipe: true,\n };\n};\n\nfunction enumRebuildCallRecipe(\n namespaceId: string,\n typeName: string,\n ctx: StrategyContext,\n): readonly PostgresOpFactoryCall[] {\n const toType = locateNamespaceType(ctx.toContract.storage, namespaceId, typeName);\n if (!toType) return [];\n const isEnum = isPostgresEnumStorageEntry(toType);\n const nativeType = toType.nativeType;\n const desiredValues: readonly string[] = isEnum\n ? toType.values\n : (((toType as StorageTypeInstance).typeParams['values'] ?? []) as readonly string[]);\n const tempName = `${nativeType}${REBUILD_SUFFIX}`;\n // Type DDL targets the enum's real schema — the unbound coordinate resolves\n // to the introspected `current_schema()`, never the `__unbound__` sentinel.\n const ddlSchema = resolveDdlSchemaForNamespaceStorage(\n ctx.toContract.storage,\n namespaceId,\n ctx.schema,\n );\n\n // Migrate every column whose `typeRef` binds to *this* enum. The column's\n // bare `typeRef` resolves to an enum namespace (own-namespace shadows;\n // otherwise the ambient/default `public` enum), so a column in the unbound\n // namespace correctly binds to a `public`-namespace enum, while two\n // same-named enums in distinct namespaces keep their columns disjoint.\n const columnRefs: { namespaceId: string; table: string; column: string }[] = [];\n for (const [nsId, ns] of Object.entries(ctx.toContract.storage.namespaces)) {\n for (const [tableName, tableNode] of Object.entries(ns.entries.table)) {\n const table = tableNode as StorageTable;\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (\n column.typeRef === typeName &&\n resolveColumnEnumNamespace(ctx.toContract.storage, nsId, typeName) === namespaceId\n ) {\n columnRefs.push({ namespaceId: nsId, table: tableName, column: columnName });\n }\n }\n }\n }\n\n return [\n new CreateEnumTypeCall(ddlSchema, tempName, desiredValues),\n ...columnRefs.map((ref) => {\n const using = `${ref.column}::text::${tempName}`;\n return new AlterColumnTypeCall(\n resolveDdlSchemaForNamespace(ctx, ref.namespaceId),\n ref.table,\n ref.column,\n {\n qualifiedTargetType: tempName,\n formatTypeExpected: tempName,\n rawTargetTypeForLabel: tempName,\n using,\n },\n );\n }),\n new DropEnumTypeCall(ddlSchema, nativeType),\n new RenameTypeCall(ddlSchema, tempName, nativeType),\n ];\n}\n\n// ============================================================================\n// Native enum planner strategy\n// ============================================================================\n\n/**\n * Single planner strategy for `PostgresEnumType` instances. Walks\n * `toContract.storage.types` directly (no codec-hook dispatch) and\n * resolves existing values via `readExistingEnumValues`, the same\n * Postgres bridging adapter the verifier uses.\n *\n * Per-enum dispatch:\n *\n * - No existing type → `CreateEnumTypeCall` with the contract's desired\n * values.\n * - Diff is `unchanged` → no calls emitted (consumes the matching\n * `enum_values_changed` issue if present).\n * - Diff is `add_values` → `AddEnumValuesCall` with the new labels.\n * - Diff is `rebuild` → the create-temp / migrate-columns /\n * drop-original / rename rebuild recipe. When\n * `policy.allowedOperationClasses` includes `'data'` and the rebuild\n * removes labels (`removedValues.length > 0`), prepend a\n * `DataTransformCall` placeholder so the user can author the value\n * remap before the destructive recipe runs. Without `'data'` in the\n * policy (`db update` / `db init`), the rebuild's PG `USING ::text`\n * cast surfaces any value-removal data loss as a runtime error rather\n * than silent loss.\n *\n * Returns `recipe: true` only when a rebuild recipe was emitted (its\n * `createEnumType(temp) → alterColumnType → dropEnumType(orig) →\n * renameType` sequence mixes `dep`-class and `alter`-class calls that\n * would mis-order if the planner hoisted them into its DDL sequencing\n * buckets). For the create-only and add-values paths the strategy\n * returns `recipe: false` so the planner hoists `CreateEnumTypeCall`\n * into the `dep` bucket — i.e. `CREATE TYPE` runs before any\n * `CreateTableCall` that references the new enum.\n */\n/**\n * Separator character for compound enum map keys (`namespaceId\\u0000typeName`).\n * NUL (`\\u0000`) is invalid in both Postgres identifiers and TypeScript symbol\n * names so it cannot appear in either component — unambiguous separator.\n */\nconst COMPOUND_KEY_SEP = '\\u0000';\n\n/** Builds the compound map key for a namespace-qualified enum entry. */\nfunction enumCompoundKey(namespaceId: string, typeName: string): string {\n return `${namespaceId}${COMPOUND_KEY_SEP}${typeName}`;\n}\n\nexport const nativeEnumPlanCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n const enumTypes = collectPostgresEnumTypes(ctx.toContract.storage);\n if (enumTypes.size === 0) return { kind: 'no_match' };\n\n const dataAllowed = ctx.policy.allowedOperationClasses.includes('data');\n\n const calls: PostgresOpFactoryCall[] = [];\n const handledKeys = new Set<string>();\n const introducedKeys = new Set<string>();\n const rebuiltKeys = new Set<string>();\n let emittedRebuildRecipe = false;\n\n for (const [key, enumType] of enumTypes) {\n const sepIdx = key.indexOf(COMPOUND_KEY_SEP);\n const enumNamespaceId = key.slice(0, sepIdx);\n const typeName = key.slice(sepIdx + 1);\n\n const desired = enumType.values;\n // The enum's live schema: for the unbound coordinate this resolves to the\n // introspected `current_schema()` (e.g. `public`), never the `__unbound__`\n // DDL-emit sentinel — so both the existing-values lookup key and the\n // emitted `CREATE TYPE` / `ALTER TYPE` target the real schema the type\n // lives in. Named namespaces resolve to their own DDL schema.\n const ddlSchema = resolveDdlSchemaForNamespaceStorage(\n ctx.toContract.storage,\n enumNamespaceId,\n ctx.schema,\n );\n const existing = readExistingEnumValues(ctx.schema, ddlSchema, enumType.nativeType);\n if (!existing) {\n calls.push(new CreateEnumTypeCall(ddlSchema, typeName, desired, enumType.nativeType));\n handledKeys.add(key);\n introducedKeys.add(key);\n continue;\n }\n const diff = determineEnumDiff(existing, desired);\n if (diff.kind === 'unchanged') {\n handledKeys.add(key);\n continue;\n }\n if (diff.kind === 'add_values') {\n calls.push(new AddEnumValuesCall(ddlSchema, typeName, enumType.nativeType, diff.values));\n handledKeys.add(key);\n continue;\n }\n if (dataAllowed && diff.removedValues.length > 0) {\n calls.push(\n new DataTransformCall(\n `migrate-${typeName}-values`,\n `migrate-${typeName}-values:check`,\n `migrate-${typeName}-values:run`,\n ),\n );\n }\n calls.push(...enumRebuildCallRecipe(enumNamespaceId, typeName, ctx));\n emittedRebuildRecipe = true;\n handledKeys.add(key);\n rebuiltKeys.add(key);\n }\n\n // The strategy emits a single `recipe` flag for the entire pass,\n // which routes every emitted call to either the contiguous recipe\n // slot (rebuild path) or the `dep` bucket (introduce / add-values\n // path). A plan that needs both shapes simultaneously cannot be\n // expressed today — the introduced `CreateEnumTypeCall` would land\n // in the recipe slot and any `CreateTableCall` referencing the new\n // enum would fail at runtime with a confusing `type \"X\" does not\n // exist` error. Surface the unrepresentable case here as a\n // planner-time error so the failure mode is loud, not silent.\n if (introducedKeys.size > 0 && rebuiltKeys.size > 0) {\n const introducedDisplay = [...introducedKeys]\n .sort()\n .map((k) => k.replace(COMPOUND_KEY_SEP, '.'))\n .join(', ');\n const rebuiltDisplay = [...rebuiltKeys]\n .sort()\n .map((k) => k.replace(COMPOUND_KEY_SEP, '.'))\n .join(', ');\n throw new Error(\n `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.`,\n );\n }\n\n const remaining = issues.filter(\n (issue) =>\n !(\n (issue.kind === 'type_missing' || issue.kind === 'enum_values_changed') &&\n issue.typeName &&\n handledKeys.has(enumCompoundKey(resolveNamespaceIdForIssue(issue), issue.typeName))\n ),\n );\n\n if (calls.length === 0 && remaining.length === issues.length) {\n return { kind: 'no_match' };\n }\n // `recipe: true` is required for the rebuild path — its\n // `createEnumType(temp) → alterColumnType → dropEnumType(orig) →\n // renameType` mixes `dep`-class and `alter`-class calls that would\n // mis-order if the planner hoisted them into its DDL sequencing\n // buckets. For the type_missing / add_values paths we want the\n // opposite: hoisted into the `dep` bucket so a brand-new\n // `CreateEnumTypeCall` runs *before* the `CreateTableCall` that\n // references it. The two cases never co-occur in the same plan\n // (introducing a new enum type and rebuilding an existing one in\n // one shot would require both buckets — a shape today's interface\n // does not surface; if that combination ever needs to land we'd\n // split this strategy or grow the `match` return type).\n return { kind: 'match', issues: remaining, calls, recipe: emittedRebuildRecipe };\n};\n\n/**\n * Collects every `PostgresEnumType` instance across all declared namespaces,\n * returning a compound-keyed map (`${namespaceId}\\u0000${typeName}`). Two\n * namespaces that declare an enum with the same name produce two distinct\n * entries — no name collision, no last-write-wins.\n *\n * Entries within each namespace are sorted by name for deterministic ordering.\n */\nfunction collectPostgresEnumTypes(storage: SqlStorage): ReadonlyMap<string, PostgresEnumType> {\n const result = new Map<string, PostgresEnumType>();\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (!isPostgresSchema(ns)) continue;\n for (const [name, instance] of Object.entries(ns.entries.type).sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n if (instance instanceof PostgresEnumType) {\n result.set(enumCompoundKey(nsId, name), instance);\n }\n }\n }\n return result;\n}\n\n/**\n * Dispatches non-enum codec-typed storage types through their codec's\n * `planTypeOperations` hook (the authoritative source for codec-driven DDL\n * such as custom type creation). Enum dispatch lives in\n * `nativeEnumPlanCallStrategy` and no longer relies on codec hooks.\n */\nexport const storageTypePlanCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n const storageTypes = ctx.toContract.storage.types ?? {};\n if (Object.keys(storageTypes).length === 0) return { kind: 'no_match' };\n\n const calls: PostgresOpFactoryCall[] = [];\n const handledTypeNames = new Set<string>();\n\n for (const [typeName, typeInstance] of Object.entries(storageTypes).sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n // Enums walk natively in `nativeEnumPlanCallStrategy`; codec-hook\n // dispatch here is reserved for genuinely codec-typed entries\n // (decimal, varchar, pgvector, …).\n if (isPostgresEnumStorageEntry(typeInstance)) continue;\n const codecInstance = typeInstance as StorageTypeInstance;\n const hook = ctx.codecHooks.get(codecInstance.codecId);\n if (!hook?.planTypeOperations) continue;\n const planResult = hook.planTypeOperations({\n typeName,\n typeInstance: codecInstance,\n contract: ctx.toContract,\n schema: ctx.schema,\n schemaName: ctx.schemaName,\n policy: ctx.policy,\n });\n if (!planResult) continue;\n if (planResult.operations.length === 0) {\n handledTypeNames.add(typeName);\n continue;\n }\n handledTypeNames.add(typeName);\n for (const op of planResult.operations) {\n calls.push(\n new RawSqlCall({\n ...op,\n target: {\n id: op.target.id,\n details: buildTargetDetails('type', typeName, ctx.schemaName),\n },\n } as SqlMigrationPlanOperation<PostgresPlanTargetDetails>),\n );\n }\n }\n\n const remaining = issues.filter(\n (issue) =>\n !(\n (issue.kind === 'type_missing' || issue.kind === 'enum_values_changed') &&\n issue.typeName &&\n handledTypeNames.has(issue.typeName)\n ),\n );\n\n if (calls.length === 0 && remaining.length === issues.length) {\n return { kind: 'no_match' };\n }\n\n return { kind: 'match', issues: remaining, calls };\n};\n\n/**\n * Handles `missing_column` issues for NOT NULL columns without a contract\n * default. Replaces the walk-schema `buildAddColumnItem` non-default branches.\n *\n * Two shapes:\n * - Shared-temp-default safe: emit a single atomic composite op (add\n * nullable → backfill identity value → `SET NOT NULL` → `DROP DEFAULT`).\n * - Empty-table guarded: emit a hand-built op with a `tableIsEmptyCheck`\n * precheck so the failure message is \"table is not empty\" rather than the\n * raw PG NOT NULL violation.\n *\n * \"Normal\" missing_column cases (nullable or has a contract default) are left\n * for `mapIssueToCall`'s default `AddColumnCall` emission.\n */\nexport const notNullAddColumnCallStrategy: CallMigrationStrategy = (issues, ctx) => {\n const matched: SchemaIssue[] = [];\n const calls: PostgresOpFactoryCall[] = [];\n\n const schemaLookups = buildSchemaLookupMap(ctx.schema);\n\n const mutableCodecHooks = ctx.codecHooks as Map<string, CodecControlHooks>;\n const mutableStorageTypes = ctx.storageTypes as Record<\n string,\n StorageTypeInstance | PostgresEnumType\n >;\n\n for (const issue of issues) {\n if (issue.kind !== 'missing_column' || !issue.table || !issue.column) continue;\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const contractTable = tableAt(ctx.toContract.storage, namespaceId, issue.table);\n const column = contractTable?.columns[issue.column];\n if (!column) continue;\n\n const notNull = column.nullable !== true;\n const hasDefault = column.default !== undefined;\n if (!notNull || hasDefault) continue;\n\n const schemaTable = ctx.schema.tables[issue.table];\n if (!schemaTable) continue;\n\n const temporaryDefault = resolveIdentityValue(column, mutableCodecHooks, mutableStorageTypes);\n const schemaLookup = schemaLookups.get(issue.table);\n const canUseSharedTempDefault =\n temporaryDefault !== null &&\n canUseSharedTemporaryDefaultStrategy({\n table: contractTable,\n schemaTable,\n schemaLookup,\n columnName: issue.column,\n });\n\n matched.push(issue);\n\n const schemaForTable = resolveDdlSchemaForNamespace(ctx, namespaceId);\n\n if (canUseSharedTempDefault && temporaryDefault !== null) {\n calls.push(\n new RawSqlCall(\n buildAddNotNullColumnWithTemporaryDefaultOperation({\n schema: schemaForTable,\n tableName: issue.table,\n columnName: issue.column,\n column,\n codecHooks: mutableCodecHooks,\n storageTypes: mutableStorageTypes,\n temporaryDefault,\n }),\n ),\n );\n continue;\n }\n\n const qualified = qualifyTableName(schemaForTable, issue.table);\n calls.push(\n new RawSqlCall({\n ...buildAddColumnOperationIdentity(schemaForTable, issue.table, issue.column),\n operationClass: 'additive',\n precheck: [\n {\n description: `ensure column \"${issue.column}\" is missing`,\n sql: columnExistsCheck({\n schema: schemaForTable,\n table: issue.table,\n column: issue.column,\n exists: false,\n }),\n },\n {\n description: `ensure table \"${issue.table}\" is empty before adding NOT NULL column without default`,\n sql: tableIsEmptyCheck(qualified),\n },\n ],\n execute: [\n {\n description: `add column \"${issue.column}\"`,\n sql: buildAddColumnSql(\n qualified,\n issue.column,\n column,\n mutableCodecHooks,\n undefined,\n mutableStorageTypes,\n ),\n },\n ],\n postcheck: [\n {\n description: `verify column \"${issue.column}\" exists`,\n sql: columnExistsCheck({\n schema: schemaForTable,\n table: issue.table,\n column: issue.column,\n }),\n },\n {\n description: `verify column \"${issue.column}\" is NOT NULL`,\n sql: columnNullabilityCheck({\n schema: schemaForTable,\n table: issue.table,\n column: issue.column,\n nullable: false,\n }),\n },\n ],\n }),\n );\n }\n\n if (matched.length === 0) return { kind: 'no_match' };\n return {\n kind: 'match',\n issues: issues.filter((i) => !matched.includes(i)),\n calls,\n };\n};\n\n// ============================================================================\n// Strategy helpers\n// ============================================================================\n\nfunction canUseSharedTemporaryDefaultStrategy(options: {\n readonly table: StorageTable;\n readonly schemaTable: SqlSchemaIR['tables'][string];\n readonly schemaLookup: ReturnType<typeof buildSchemaLookupMap> extends ReadonlyMap<\n string,\n infer V\n >\n ? V | undefined\n : never;\n readonly columnName: string;\n}): boolean {\n const { table, schemaTable, schemaLookup, columnName } = options;\n\n if (table.primaryKey?.columns.includes(columnName) && !schemaTable.primaryKey) {\n return false;\n }\n\n for (const unique of table.uniques) {\n if (!unique.columns.includes(columnName)) continue;\n if (!schemaLookup || !hasUniqueConstraint(schemaLookup, unique.columns)) return false;\n }\n\n for (const foreignKey of table.foreignKeys) {\n if (foreignKey.constraint === false || !foreignKey.source.columns.includes(columnName))\n continue;\n if (!schemaLookup || !hasForeignKey(schemaLookup, foreignKey)) return false;\n }\n\n return true;\n}\n\n/**\n * Ordered list of Postgres planner strategies, shared by `migration plan`\n * and `db update` / `db init`. The issue planner runs each strategy in\n * order, letting it consume any issues it handles, and routes whatever's\n * left through `mapIssueToCall`. Behavior diverges purely on\n * `policy.allowedOperationClasses`:\n *\n * - When `'data'` is allowed (`migration plan`), the data-safe strategies\n * (`notNullBackfillCallStrategy`, `typeChangeCallStrategy`,\n * `nullableTighteningCallStrategy`) and the enum walk\n * (`nativeEnumPlanCallStrategy`) consume their matching issues and emit\n * `DataTransformCall` placeholders or recipe ops.\n *\n * - When `'data'` is not allowed (`db update` / `db init`), the\n * placeholder-emitting strategies short-circuit to `no_match`, leaving\n * the issue for the downstream walk-schema strategies\n * (`storageTypePlanCallStrategy`, `notNullAddColumnCallStrategy`) or the\n * `mapIssueToCall` default to handle with direct DDL.\n * `nativeEnumPlanCallStrategy` runs in both modes; under `db update` /\n * `db init` it emits the rebuild recipe without the data-transform\n * placeholder so value-removal data loss surfaces as a runtime cast\n * error rather than silent loss.\n *\n * Enum dispatch is unified into a single strategy: the\n * `nativeEnumPlanCallStrategy` decides per-emission whether to emit a\n * rebuild recipe (`recipe: true`, contiguous slot) or hoist the call\n * into the `dep` bucket (`recipe: false`, so a brand-new\n * `CreateEnumTypeCall` runs before any `CreateTableCall` referencing\n * it). Codec-typed entries continue through `storageTypePlanCallStrategy`.\n */\nexport const postgresPlannerStrategies: readonly CallMigrationStrategy[] = [\n notNullBackfillCallStrategy,\n typeChangeCallStrategy,\n nullableTighteningCallStrategy,\n nativeEnumPlanCallStrategy,\n storageTypePlanCallStrategy,\n notNullAddColumnCallStrategy,\n];\n","/**\n * Postgres migration planner.\n *\n * Takes schema issues (from verifySqlSchema) and emits migration IR\n * (`PostgresOpFactoryCall[]`). Strategies consume issues they recognize and\n * produce specialized call sequences (e.g. NOT NULL backfill →\n * addColumn(nullable) + dataTransform + setNotNull); remaining issues flow\n * through `mapIssueToCall` for the default case.\n */\n\nimport type { Contract } from '@prisma-next/contract/types';\nimport type {\n CodecControlHooks,\n MigrationOperationPolicy,\n SqlPlannerConflict,\n SqlPlannerConflictLocation,\n} from '@prisma-next/family-sql/control';\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport type {\n PostgresEnumStorageEntry,\n SqlStorage,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport type { Result } from '@prisma-next/utils/result';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\nimport {\n AddColumnCall,\n AddForeignKeyCall,\n AddPrimaryKeyCall,\n AddUniqueCall,\n AlterColumnTypeCall,\n CreateEnumTypeCall,\n CreateIndexCall,\n CreateSchemaCall,\n CreateTableCall,\n DropColumnCall,\n DropConstraintCall,\n DropDefaultCall,\n DropIndexCall,\n DropNotNullCall,\n DropTableCall,\n type PostgresOpFactoryCall,\n SetDefaultCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport type { ColumnSpec, ForeignKeySpec } from './operations/shared';\nimport { buildColumnDefaultSql, buildColumnTypeSql } from './planner-ddl-builders';\nimport { buildExpectedFormatType } from './planner-sql-checks';\nimport {\n type CallMigrationStrategy,\n postgresPlannerStrategies,\n resolveDdlSchemaForNamespace,\n resolveNamespaceIdForIssue,\n type StrategyContext,\n tableAt,\n} from './planner-strategies';\n\nexport type { CallMigrationStrategy, StrategyContext };\n\n/**\n * Finds a type entry by explicit namespace coordinate. Reads the named\n * namespace's `enum` slot directly — never scans other namespaces.\n */\nfunction locateNamespaceTypeInStorage(\n storage: SqlStorage,\n namespaceId: string,\n typeName: string,\n): unknown {\n const ns = storage.namespaces[namespaceId];\n return isPostgresSchema(ns) ? ns.entries.type[typeName] : undefined;\n}\n\n// ============================================================================\n// Issue kind ordering (dependency order)\n// ============================================================================\n\nconst ISSUE_KIND_ORDER: Record<string, number> = {\n // Schemas first — the database container must exist before any DDL\n // that targets it can run.\n missing_schema: 1,\n\n // Types next\n type_missing: 2,\n type_values_mismatch: 3,\n enum_values_changed: 3,\n\n // Drops (reconciliation — clear the way for creates)\n // FKs dropped first (they depend on other constraints)\n extra_foreign_key: 10,\n extra_unique_constraint: 11,\n extra_primary_key: 12,\n extra_index: 13,\n extra_default: 14,\n extra_column: 15,\n extra_table: 16,\n\n // Tables before columns\n missing_table: 20,\n\n // Columns before constraints\n missing_column: 30,\n\n // Reconciliation alters (on existing objects)\n type_mismatch: 40,\n nullability_mismatch: 41,\n default_missing: 42,\n default_mismatch: 43,\n\n // Constraints after columns exist\n primary_key_mismatch: 50,\n unique_constraint_mismatch: 51,\n index_mismatch: 52,\n foreign_key_mismatch: 60,\n};\n\nfunction issueOrder(issue: SchemaIssue): number {\n return ISSUE_KIND_ORDER[issue.kind] ?? 99;\n}\n\n// ============================================================================\n// Conflict helpers\n// ============================================================================\n\nfunction issueConflict(\n kind: SqlPlannerConflict['kind'],\n summary: string,\n location?: SqlPlannerConflict['location'],\n): SqlPlannerConflict {\n return {\n kind,\n summary,\n why: 'Use `migration new` to author a custom migration for this change.',\n ...(location ? { location } : {}),\n };\n}\n\nfunction isMissing(issue: SchemaIssue): boolean {\n if (issue.kind === 'enum_values_changed') return false;\n return issue.actual === undefined;\n}\n\n// ============================================================================\n// Issue planner\n// ============================================================================\n\nexport interface IssuePlannerOptions {\n readonly issues: readonly SchemaIssue[];\n readonly toContract: Contract<SqlStorage>;\n readonly fromContract: Contract<SqlStorage> | null;\n readonly schemaName: string;\n readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;\n readonly storageTypes: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>;\n /**\n * Current database schema IR. Strategies read this to detect whether a\n * structure already exists (e.g. `buildSchemaLookupMap` for shared-temp-\n * default safety, extension dependency checks). Defaults to an empty schema\n * when omitted so the planner can still run over \"fresh DB\" contract\n * snapshots.\n */\n readonly schema?: SqlSchemaIR;\n /**\n * Operation-class policy. `planIssues` filters calls whose `operationClass`\n * is not in `policy.allowedOperationClasses` and surfaces them as conflicts\n * instead of emitting disallowed DDL. Defaults to additive-only.\n */\n readonly policy?: MigrationOperationPolicy;\n /**\n * Framework components participating in this composition. Available to\n * future strategies that may consult component metadata at plan time.\n */\n readonly frameworkComponents?: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n readonly strategies?: readonly CallMigrationStrategy[];\n}\n\nexport interface IssuePlannerValue {\n readonly calls: readonly PostgresOpFactoryCall[];\n}\n\nfunction toColumnSpec(\n name: string,\n column: StorageColumn,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n storageTypes: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>,\n): ColumnSpec {\n return {\n name,\n typeSql: buildColumnTypeSql(\n column,\n codecHooks as Map<string, CodecControlHooks>,\n storageTypes as Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,\n ),\n defaultSql: buildColumnDefaultSql(column.default, column),\n nullable: column.nullable,\n };\n}\n\nfunction mapIssueToCall(\n issue: SchemaIssue,\n ctx: StrategyContext,\n): Result<readonly PostgresOpFactoryCall[], SqlPlannerConflict> {\n const { schemaName, codecHooks, storageTypes } = ctx;\n // Per-table effective schema. `extra_table` issues intentionally\n // omit `namespaceId` — the live DB carries a table that\n // is not claimed by any contract namespace, so there is no contract\n // coordinate to project from. Those issues fall back to the planner's\n // global `ctx.schemaName`; every other issue dispatches through the\n // resolved namespace's polymorphic `ddlSchemaName`.\n const tableSchema = (issue: SchemaIssue): string => {\n if (issue.kind === 'extra_table') return schemaName;\n if (!('table' in issue) || !issue.table) return schemaName;\n return resolveDdlSchemaForNamespace(ctx, resolveNamespaceIdForIssue(issue));\n };\n\n switch (issue.kind) {\n case 'missing_schema': {\n const namespaceId = issue.namespaceId;\n if (!namespaceId)\n return notOk(\n issueConflict('unsupportedOperation', 'Missing schema issue has no namespaceId'),\n );\n const ddlSchemaName = resolveDdlSchemaForNamespace(ctx, namespaceId);\n return ok([new CreateSchemaCall(ddlSchemaName)]);\n }\n\n case 'missing_table': {\n if (!issue.table)\n return notOk(\n issueConflict('unsupportedOperation', 'Missing table issue has no table name'),\n );\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const contractTable = tableAt(ctx.toContract.storage, namespaceId, issue.table);\n if (!contractTable) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Table \"${issue.table}\" in namespace \"${namespaceId}\" reported missing but not found in destination contract`,\n ),\n );\n }\n const schemaForTable = tableSchema(issue);\n const columns: ColumnSpec[] = Object.entries(contractTable.columns).map(([name, column]) =>\n toColumnSpec(name, column, codecHooks, storageTypes),\n );\n const primaryKey = contractTable.primaryKey\n ? { columns: contractTable.primaryKey.columns }\n : undefined;\n const calls: PostgresOpFactoryCall[] = [\n new CreateTableCall(schemaForTable, issue.table, columns, primaryKey),\n ];\n for (const index of contractTable.indexes) {\n const indexName = index.name ?? `${issue.table}_${index.columns.join('_')}_idx`;\n const extras: { type?: string; options?: Record<string, unknown> } = {};\n if (index.type !== undefined) extras.type = index.type;\n if (index.options !== undefined) extras.options = index.options;\n calls.push(\n new CreateIndexCall(schemaForTable, issue.table, indexName, [...index.columns], extras),\n );\n }\n const explicitIndexColumnSets = new Set(\n contractTable.indexes.map((idx) => idx.columns.join(',')),\n );\n for (const fk of contractTable.foreignKeys) {\n if (fk.constraint) {\n const fkName = fk.name ?? `${issue.table}_${fk.source.columns.join('_')}_fkey`;\n const fkSpec: ForeignKeySpec = {\n name: fkName,\n columns: fk.source.columns,\n references: {\n schema: fk.target.namespaceId,\n table: fk.target.tableName,\n columns: fk.target.columns,\n },\n ...(fk.onDelete !== undefined && { onDelete: fk.onDelete }),\n ...(fk.onUpdate !== undefined && { onUpdate: fk.onUpdate }),\n };\n calls.push(new AddForeignKeyCall(schemaForTable, issue.table, fkSpec));\n }\n if (fk.index && !explicitIndexColumnSets.has(fk.source.columns.join(','))) {\n const indexName = `${issue.table}_${fk.source.columns.join('_')}_idx`;\n calls.push(\n new CreateIndexCall(schemaForTable, issue.table, indexName, [...fk.source.columns]),\n );\n }\n }\n for (const unique of contractTable.uniques) {\n const constraintName = unique.name ?? `${issue.table}_${unique.columns.join('_')}_key`;\n calls.push(\n new AddUniqueCall(schemaForTable, issue.table, constraintName, [...unique.columns]),\n );\n }\n return ok(calls);\n }\n\n case 'missing_column':\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('unsupportedOperation', 'Missing column issue has no table/column name'),\n );\n {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!column)\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Column \"${issue.table}\".\"${issue.column}\" not in destination contract`,\n ),\n );\n return ok([\n new AddColumnCall(\n tableSchema(issue),\n issue.table,\n toColumnSpec(issue.column, column, codecHooks, storageTypes),\n ),\n ]);\n }\n\n case 'default_missing':\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('unsupportedOperation', 'Default missing issue has no table/column name'),\n );\n {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!column?.default) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Column \"${issue.table}\".\"${issue.column}\" has no default in contract`,\n ),\n );\n }\n const defaultSql = buildColumnDefaultSql(column.default, column);\n if (!defaultSql) return ok([]);\n return ok([new SetDefaultCall(tableSchema(issue), issue.table, issue.column, defaultSql)]);\n }\n\n case 'extra_table':\n if (!issue.table)\n return notOk(issueConflict('unsupportedOperation', 'Extra table issue has no table name'));\n return ok([new DropTableCall(tableSchema(issue), issue.table)]);\n\n case 'extra_column':\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('unsupportedOperation', 'Extra column issue has no table/column name'),\n );\n return ok([new DropColumnCall(tableSchema(issue), issue.table, issue.column)]);\n\n case 'extra_index':\n if (!issue.table || !issue.indexOrConstraint)\n return notOk(\n issueConflict('unsupportedOperation', 'Extra index issue has no table/index name'),\n );\n return ok([new DropIndexCall(tableSchema(issue), issue.table, issue.indexOrConstraint)]);\n\n case 'extra_unique_constraint':\n case 'extra_foreign_key':\n case 'extra_primary_key': {\n if (!issue.table)\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n 'Extra constraint issue has no table/constraint name',\n ),\n );\n // `extra_primary_key` issues don't carry a constraint name — the\n // verifier only has the table. Fall back to `<table>_pkey`, matching\n // Postgres' default PK constraint naming and the old reconciliation\n // planner's behavior.\n const constraintName =\n issue.indexOrConstraint ??\n (issue.kind === 'extra_primary_key' ? `${issue.table}_pkey` : undefined);\n if (!constraintName)\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n 'Extra constraint issue has no table/constraint name',\n ),\n );\n const kindMap = {\n extra_unique_constraint: 'unique' as const,\n extra_foreign_key: 'foreignKey' as const,\n extra_primary_key: 'primaryKey' as const,\n };\n return ok([\n new DropConstraintCall(\n tableSchema(issue),\n issue.table,\n constraintName,\n kindMap[issue.kind],\n ),\n ]);\n }\n\n case 'extra_default':\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('unsupportedOperation', 'Extra default issue has no table/column name'),\n );\n return ok([new DropDefaultCall(tableSchema(issue), issue.table, issue.column)]);\n\n case 'nullability_mismatch': {\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('nullabilityConflict', 'Nullability mismatch has no table/column name'),\n );\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!column)\n return notOk(\n issueConflict(\n 'nullabilityConflict',\n `Column \"${issue.table}\".\"${issue.column}\" not found in destination contract`,\n ),\n );\n const schemaForTable = tableSchema(issue);\n return ok(\n column.nullable\n ? [new DropNotNullCall(schemaForTable, issue.table, issue.column)]\n : [new SetNotNullCall(schemaForTable, issue.table, issue.column)],\n );\n }\n\n case 'type_mismatch':\n if (!issue.table || !issue.column)\n return notOk(issueConflict('typeMismatch', 'Type mismatch has no table/column name'));\n {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!column)\n return notOk(\n issueConflict(\n 'typeMismatch',\n `Column \"${issue.table}\".\"${issue.column}\" not in destination contract`,\n ),\n );\n const hooksMap = codecHooks as Map<string, CodecControlHooks>;\n const typesMap = storageTypes as Record<\n string,\n StorageTypeInstance | PostgresEnumStorageEntry\n >;\n const qualifiedTargetType = buildColumnTypeSql(column, hooksMap, typesMap, false);\n const formatTypeExpected = buildExpectedFormatType(column, hooksMap, typesMap);\n return ok([\n new AlterColumnTypeCall(tableSchema(issue), issue.table, issue.column, {\n qualifiedTargetType,\n formatTypeExpected,\n rawTargetTypeForLabel: qualifiedTargetType,\n }),\n ]);\n }\n\n case 'default_mismatch':\n if (!issue.table || !issue.column)\n return notOk(\n issueConflict('unsupportedOperation', 'Default mismatch has no table/column name'),\n );\n {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const column = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.columns[\n issue.column\n ];\n if (!column?.default) return ok([]);\n const defaultSql = buildColumnDefaultSql(column.default, column);\n if (!defaultSql) return ok([]);\n return ok([\n new SetDefaultCall(tableSchema(issue), issue.table, issue.column, defaultSql, 'widening'),\n ]);\n }\n\n case 'primary_key_mismatch':\n if (!issue.table)\n return notOk(issueConflict('indexIncompatible', 'Primary key issue has no table name'));\n if (isMissing(issue)) {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const pk = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.primaryKey;\n if (!pk)\n return notOk(\n issueConflict('indexIncompatible', `No primary key in contract for \"${issue.table}\"`),\n );\n const constraintName = pk.name ?? `${issue.table}_pkey`;\n return ok([\n new AddPrimaryKeyCall(tableSchema(issue), issue.table, constraintName, pk.columns),\n ]);\n }\n return notOk(\n issueConflict(\n 'indexIncompatible',\n `Primary key on \"${issue.table}\" has different columns (expected: ${issue.expected}, actual: ${issue.actual})`,\n { table: issue.table },\n ),\n );\n\n case 'unique_constraint_mismatch':\n if (!issue.table)\n return notOk(\n issueConflict('indexIncompatible', 'Unique constraint issue has no table name'),\n );\n if (isMissing(issue) && issue.expected) {\n const columns = issue.expected.split(', ');\n const constraintName = `${issue.table}_${columns.join('_')}_key`;\n return ok([new AddUniqueCall(tableSchema(issue), issue.table, constraintName, columns)]);\n }\n return notOk(\n issueConflict(\n 'indexIncompatible',\n `Unique constraint on \"${issue.table}\" differs (expected: ${issue.expected}, actual: ${issue.actual})`,\n { table: issue.table },\n ),\n );\n\n case 'index_mismatch':\n if (!issue.table)\n return notOk(issueConflict('indexIncompatible', 'Index issue has no table name'));\n if (isMissing(issue) && issue.expected) {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const columns = issue.expected.split(', ');\n const contractIndex = tableAt(\n ctx.toContract.storage,\n namespaceId,\n issue.table,\n )?.indexes.find((idx: StorageTable['indexes'][number]) =>\n arraysEqual(idx.columns, columns),\n );\n const indexName = contractIndex?.name ?? `${issue.table}_${columns.join('_')}_idx`;\n const extras: { type?: string; options?: Record<string, unknown> } = {};\n if (contractIndex?.type !== undefined) extras.type = contractIndex.type;\n if (contractIndex?.options !== undefined) extras.options = contractIndex.options;\n return ok([\n new CreateIndexCall(tableSchema(issue), issue.table, indexName, columns, extras),\n ]);\n }\n return notOk(\n issueConflict(\n 'indexIncompatible',\n `Index on \"${issue.table}\" differs (expected: ${issue.expected}, actual: ${issue.actual})`,\n { table: issue.table },\n ),\n );\n\n case 'foreign_key_mismatch':\n if (!issue.table)\n return notOk(issueConflict('foreignKeyConflict', 'Foreign key issue has no table name'));\n if (isMissing(issue) && issue.expected) {\n const arrowIdx = issue.expected.indexOf(' -> ');\n if (arrowIdx >= 0) {\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const columns = issue.expected.slice(0, arrowIdx).split(', ');\n const fkName = `${issue.table}_${columns.join('_')}_fkey`;\n const fk = tableAt(ctx.toContract.storage, namespaceId, issue.table)?.foreignKeys.find(\n (k) => k.source.columns.join(', ') === columns.join(', '),\n );\n if (fk) {\n const fkSpec: ForeignKeySpec = {\n name: fkName,\n columns: fk.source.columns,\n references: {\n schema: fk.target.namespaceId,\n table: fk.target.tableName,\n columns: fk.target.columns,\n },\n ...(fk.onDelete !== undefined && { onDelete: fk.onDelete }),\n ...(fk.onUpdate !== undefined && { onUpdate: fk.onUpdate }),\n };\n return ok([new AddForeignKeyCall(tableSchema(issue), issue.table, fkSpec)]);\n }\n return notOk(\n issueConflict(\n 'foreignKeyConflict',\n `Foreign key on \"${issue.table}\" (${columns.join(', ')}) not found in destination contract`,\n { table: issue.table },\n ),\n );\n }\n }\n return notOk(\n issueConflict(\n 'foreignKeyConflict',\n `Foreign key on \"${issue.table}\" differs (expected: ${issue.expected}, actual: ${issue.actual})`,\n { table: issue.table },\n ),\n );\n\n case 'type_missing': {\n if (!issue.typeName)\n return notOk(issueConflict('unsupportedOperation', 'Type missing issue has no typeName'));\n // Codec aliases live in storage.types; enum types live in namespace.entries.type.\n // Check types first; fall back to the namespace-keyed enum slot using the\n // issue's namespace coordinate (populated by the verifier for enum-related\n // issues per the BaseSchemaIssue.namespaceId contract).\n const namespaceId = resolveNamespaceIdForIssue(issue);\n const typeInstance: unknown =\n ctx.toContract.storage.types?.[issue.typeName] ??\n locateNamespaceTypeInStorage(ctx.toContract.storage, namespaceId, issue.typeName);\n if (!typeInstance) {\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Type \"${issue.typeName}\" reported missing but not found in destination contract`,\n ),\n );\n }\n if (typeInstance instanceof PostgresEnumType) {\n const ddlSchema = resolveDdlSchemaForNamespace(ctx, namespaceId);\n return ok([\n new CreateEnumTypeCall(\n ddlSchema,\n issue.typeName,\n typeInstance.values,\n typeInstance.nativeType,\n ),\n ]);\n }\n const codecInstance = typeInstance as StorageTypeInstance;\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Type \"${issue.typeName}\" uses codec \"${codecInstance.codecId}\" — only enum types are supported`,\n ),\n );\n }\n\n case 'type_values_mismatch':\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Type \"${issue.typeName ?? 'unknown'}\" values differ — type alteration not yet supported`,\n ),\n );\n\n default:\n return notOk(\n issueConflict(\n 'unsupportedOperation',\n `Unhandled issue kind: ${(issue as SchemaIssue).kind}`,\n ),\n );\n }\n}\n\n/**\n * Classifies calls into dependency order categories for correct DDL sequencing.\n */\ntype CallCategory =\n | 'dep'\n | 'drop'\n | 'table'\n | 'column'\n | 'alter'\n | 'primaryKey'\n | 'unique'\n | 'index'\n | 'foreignKey';\n\n/**\n * Classifies calls into DDL sequencing buckets. The order matches the\n * legacy walk-schema planner's emission order so `db init` and `db update`\n * produce byte-identical plans for the shared shape (deps → drops → tables\n * → columns → alters → PKs → uniques → indexes → FKs).\n */\nfunction classifyCall(call: PostgresOpFactoryCall): CallCategory {\n switch (call.factoryName) {\n case 'createExtension':\n case 'createSchema':\n case 'createEnumType':\n case 'addEnumValues':\n case 'dropEnumType':\n case 'renameType':\n return 'dep';\n case 'dropTable':\n case 'dropColumn':\n case 'dropConstraint':\n case 'dropIndex':\n case 'dropDefault':\n return 'drop';\n case 'createTable':\n return 'table';\n case 'addColumn':\n return 'column';\n case 'alterColumnType':\n case 'setNotNull':\n case 'dropNotNull':\n case 'setDefault':\n return 'alter';\n case 'addPrimaryKey':\n return 'primaryKey';\n case 'addUnique':\n return 'unique';\n case 'createIndex':\n return 'index';\n case 'addForeignKey':\n return 'foreignKey';\n case 'rawSql': {\n // Type ops lifted through `RawSqlCall` by `storageTypePlanCallStrategy`\n // to preserve the codec-emitted label and precheck/postcheck.\n // Classification falls back to inspecting the underlying op's target\n // details (`objectType: 'type'`).\n const op = (\n call as {\n op?: {\n target?: { details?: { objectType?: string } };\n };\n }\n ).op;\n const objectType = op?.target?.details?.objectType;\n if (objectType === 'type') return 'dep';\n return 'alter';\n }\n default:\n return 'alter';\n }\n}\n\n/** Stable lexical key used to order issues within the same kind bucket. */\nfunction issueKey(issue: SchemaIssue): string {\n const table = 'table' in issue && typeof issue.table === 'string' ? issue.table : '';\n const column = 'column' in issue && typeof issue.column === 'string' ? issue.column : '';\n const name =\n 'indexOrConstraint' in issue && typeof issue.indexOrConstraint === 'string'\n ? issue.indexOrConstraint\n : '';\n return `${table}\\u0000${column}\\u0000${name}`;\n}\n\n// When no policy is explicitly supplied (test-only path; production callers\n// always pass one), allow every class so strategies that gate on\n// `'data'` (data-safe placeholders) still fire — the test is treated as\n// trusted. Filtering of actual emitted calls only runs when a policy was\n// explicitly provided (see `policyProvided` below).\nconst DEFAULT_POLICY: MigrationOperationPolicy = {\n allowedOperationClasses: ['additive', 'widening', 'destructive', 'data'],\n};\n\nfunction emptySchemaIR(): SqlSchemaIR {\n return { tables: {} };\n}\n\nfunction conflictKindForCall(call: PostgresOpFactoryCall): SqlPlannerConflict['kind'] {\n switch (call.factoryName) {\n case 'alterColumnType':\n return 'typeMismatch';\n case 'setNotNull':\n case 'dropNotNull':\n return 'nullabilityConflict';\n case 'addForeignKey':\n case 'dropConstraint':\n return 'foreignKeyConflict';\n case 'createIndex':\n case 'dropIndex':\n return 'indexIncompatible';\n default:\n return 'missingButNonAdditive';\n }\n}\n\nfunction locationForCall(call: PostgresOpFactoryCall): SqlPlannerConflict['location'] | undefined {\n // Most Postgres call classes expose `tableName`/`columnName`/`indexName`/\n // `constraintName` as readonly fields. We avoid `toOp()` here because a\n // `DataTransformCall` intentionally throws from `toOp`.\n const anyCall = call as unknown as {\n tableName?: string;\n columnName?: string;\n indexName?: string;\n constraintName?: string;\n typeName?: string;\n };\n const location: {\n table?: string;\n column?: string;\n index?: string;\n constraint?: string;\n type?: string;\n } = {};\n if (anyCall.tableName) location.table = anyCall.tableName;\n if (anyCall.columnName) location.column = anyCall.columnName;\n if (anyCall.indexName) location.index = anyCall.indexName;\n if (anyCall.constraintName) location.constraint = anyCall.constraintName;\n if (anyCall.typeName) location.type = anyCall.typeName;\n return Object.keys(location).length > 0 ? (location as SqlPlannerConflictLocation) : undefined;\n}\n\nfunction conflictForDisallowedCall(\n call: PostgresOpFactoryCall,\n allowed: readonly string[],\n): SqlPlannerConflict {\n const summary = `Operation \"${call.label}\" requires class \"${call.operationClass}\", but policy allows only: ${allowed.join(', ')}`;\n const location = locationForCall(call);\n return {\n kind: conflictKindForCall(call),\n summary,\n why: 'Use `migration new` to author a custom migration for this change.',\n ...(location ? { location } : {}),\n };\n}\n\nexport function planIssues(\n options: IssuePlannerOptions,\n): Result<IssuePlannerValue, readonly SqlPlannerConflict[]> {\n // When no policy is supplied, `planIssues` treats the call as trusted (the\n // caller — typically a test — has already vetted the issues). Only explicit\n // policies gate operation classes into conflicts.\n // `PostgresMigrationPlanner` always passes an explicit policy.\n const policyProvided = options.policy !== undefined;\n const policy = options.policy ?? DEFAULT_POLICY;\n const schema = options.schema ?? emptySchemaIR();\n const frameworkComponents = options.frameworkComponents ?? [];\n\n const context: StrategyContext = {\n toContract: options.toContract,\n fromContract: options.fromContract,\n schemaName: options.schemaName,\n codecHooks: options.codecHooks,\n storageTypes: options.storageTypes,\n schema,\n policy,\n frameworkComponents,\n };\n\n const strategies = options.strategies ?? postgresPlannerStrategies;\n\n let remaining = options.issues;\n const recipeCalls: PostgresOpFactoryCall[] = [];\n const bucketablePatternCalls: PostgresOpFactoryCall[] = [];\n\n for (const strategy of strategies) {\n const result = strategy(remaining, context);\n if (result.kind === 'match') {\n remaining = result.issues;\n if (result.recipe) {\n recipeCalls.push(...result.calls);\n } else {\n bucketablePatternCalls.push(...result.calls);\n }\n }\n }\n\n const sorted = [...remaining].sort((a, b) => {\n const kindDelta = issueOrder(a) - issueOrder(b);\n if (kindDelta !== 0) return kindDelta;\n const keyA = issueKey(a);\n const keyB = issueKey(b);\n return keyA < keyB ? -1 : keyA > keyB ? 1 : 0;\n });\n\n const defaultCalls: PostgresOpFactoryCall[] = [];\n const conflicts: SqlPlannerConflict[] = [];\n\n for (const issue of sorted) {\n const result = mapIssueToCall(issue, context);\n if (result.ok) {\n defaultCalls.push(...result.value);\n } else {\n conflicts.push(result.failure);\n }\n }\n\n // Policy gating: drop calls whose operation class is not allowed and\n // surface a conflict describing the disallowed op. Applies to both strategy\n // output and default-mapped output. Only active when the caller explicitly\n // supplied a policy — direct unit-test invocations (which pass no policy)\n // stay as pass-through and keep destructive recipe steps intact.\n const allowed = policy.allowedOperationClasses;\n let gatedDefault = defaultCalls;\n let gatedRecipe = recipeCalls;\n let gatedBucketable = bucketablePatternCalls;\n if (policyProvided) {\n const keepIfAllowed = (bucket: PostgresOpFactoryCall[]) => (call: PostgresOpFactoryCall) => {\n if (allowed.includes(call.operationClass)) {\n bucket.push(call);\n return;\n }\n conflicts.push(conflictForDisallowedCall(call, allowed));\n };\n const gatedDefaultBucket: PostgresOpFactoryCall[] = [];\n const gatedRecipeBucket: PostgresOpFactoryCall[] = [];\n const gatedBucketableBucket: PostgresOpFactoryCall[] = [];\n defaultCalls.forEach(keepIfAllowed(gatedDefaultBucket));\n recipeCalls.forEach(keepIfAllowed(gatedRecipeBucket));\n bucketablePatternCalls.forEach(keepIfAllowed(gatedBucketableBucket));\n gatedDefault = gatedDefaultBucket;\n gatedRecipe = gatedRecipeBucket;\n gatedBucketable = gatedBucketableBucket;\n }\n\n if (conflicts.length > 0) {\n return notOk(conflicts);\n }\n\n // Recipe strategies (`nativeEnumPlanCallStrategy`,\n // `notNullBackfillCallStrategy`, etc.) emit a cohesive sequence that must\n // stay contiguous. They are inserted at a single pattern slot. Non-recipe\n // pattern strategies (`dependencyInstallCallStrategy`,\n // `storageTypePlanCallStrategy`, `notNullAddColumnCallStrategy`) produce\n // individually classifiable calls that slot into DDL buckets alongside\n // default-mapped calls.\n const combinedBucketable = [...gatedDefault, ...gatedBucketable];\n const byCategory = (cat: CallCategory) =>\n combinedBucketable.filter((c) => classifyCall(c) === cat);\n\n const calls: PostgresOpFactoryCall[] = [\n ...byCategory('dep'),\n ...byCategory('drop'),\n ...byCategory('table'),\n ...byCategory('column'),\n ...gatedRecipe,\n ...byCategory('alter'),\n ...byCategory('primaryKey'),\n ...byCategory('unique'),\n ...byCategory('index'),\n ...byCategory('foreignKey'),\n ];\n\n return ok({ calls });\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,mBACd,YACA,MACA,QACA,OAC2B;CAC3B,OAAO;EACL;EACA;EACA;EACA,GAAG,UAAU,SAAS,KAAK;CAC7B;AACF;;;ACfA,SAAgB,gCACd,QACA,WACA,YAIA;CACA,OAAO;EACL,IAAI,UAAU,UAAU,GAAG;EAC3B,OAAO,cAAc,WAAW,MAAM;EACtC,SAAS,eAAe,WAAW,YAAY;EAC/C,QAAQ;GACN,IAAI;GACJ,SAAS,mBAAmB,SAAS,WAAW,MAAM;EACxD;CACF;AACF;AAEA,SAAgB,mDAAmD,SAQV;CACvD,MAAM,EAAE,QAAQ,WAAW,YAAY,QAAQ,YAAY,cAAc,qBACvE;CACF,MAAM,YAAY,iBAAiB,QAAQ,SAAS;CAEpD,OAAO;EACL,GAAG,gCAAgC,QAAQ,WAAW,UAAU;EAChE,gBAAgB;EAChB,UAAU,CACR;GACE,aAAa,kBAAkB,WAA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D,CAAC;EACxD,aAAa,QAAQ,cAAc,kBAAkB,CAAC;EACtD,YAAY,QAAQ,cAAc,iBAAiB,CAAC;EACpD,uBAAuB,QAAQ,cAAc,qBAAqB,CAAC;EACnE,eAAe;EACf,cAAc;EACd,kBAAkB;CACpB;CAEA,IAAI,UAAU,SAAS,GACrB,OAAO,MAAM,SAAS;CAUxB,MAAM,qBAAqB,CAAC,GAAG,cAAc,GAAG,eAAe;CAC/D,MAAM,cAAc,QAClB,mBAAmB,QAAQ,MAAM,aAAa,CAAC,MAAM,GAAG;CAe1D,OAAO,GAAG,EAAE,OAAA;EAZV,GAAG,WAAW,KAAK;EACnB,GAAG,WAAW,MAAM;EACpB,GAAG,WAAW,OAAO;EACrB,GAAG,WAAW,QAAQ;EACtB,GAAG;EACH,GAAG,WAAW,OAAO;EACrB,GAAG,WAAW,YAAY;EAC1B,GAAG,WAAW,QAAQ;EACtB,GAAG,WAAW,OAAO;EACrB,GAAG,WAAW,YAAY;CAGZ,EAAE,CAAC;AACrB"}
|
package/dist/issue-planner.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as PostgresOpFactoryCall } from "./op-factory-call-
|
|
1
|
+
import { b as PostgresOpFactoryCall } from "./op-factory-call-D47zfLOp.mjs";
|
|
2
2
|
import { CodecControlHooks, MigrationOperationPolicy, SqlPlannerConflict } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { PostgresEnumStorageEntry, SqlStorage, StorageTable, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
4
4
|
import { Result } from "@prisma-next/utils/result";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"issue-planner.d.mts","names":[],"sources":["../src/core/migrations/planner-strategies.ts","../src/core/migrations/issue-planner.ts"],"mappings":";;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"issue-planner.d.mts","names":[],"sources":["../src/core/migrations/planner-strategies.ts","../src/core/migrations/issue-planner.ts"],"mappings":";;;;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ner-
|
|
1
|
+
import { t as planIssues } from "./issue-planner-DFr4gqfy.mjs";
|
|
2
2
|
export { planIssues };
|
package/dist/migration.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as DataTransformOptions, r as dataTransform, t as DataTransformClosure } from "./data-transform-
|
|
2
|
-
import { n as ForeignKeySpec, r as Op, t as ColumnSpec } from "./shared-
|
|
3
|
-
import { t as PostgresMigration } from "./postgres-migration
|
|
1
|
+
import { n as DataTransformOptions, r as dataTransform, t as DataTransformClosure } from "./data-transform-lq3NGdIt.mjs";
|
|
2
|
+
import { n as ForeignKeySpec, r as Op, t as ColumnSpec } from "./shared-C3gXQyxj.mjs";
|
|
3
|
+
import { t as PostgresMigration } from "./postgres-migration--iqDr7rB.mjs";
|
|
4
4
|
import { placeholder } from "@prisma-next/errors/migration";
|
|
5
5
|
import { MigrationCLI } from "@prisma-next/cli/migration-cli";
|
|
6
6
|
|
package/dist/migration.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as setNotNull, _ as alterColumnType, a as addEnumValues, b as dropNotNull, c as renameType, d as installExtension, f as addForeignKey, g as addColumn, h as dropConstraint, i as dropIndex, l as createExtension, m as addUnique, n as dropTable, o as createEnumType, p as addPrimaryKey, r as createIndex, s as dropEnumType, t as createTable, u as createSchema, v as dropColumn, x as setDefault, y as dropDefault } from "./tables-
|
|
2
|
-
import { t as dataTransform } from "./data-transform-
|
|
3
|
-
import { t as PostgresMigration } from "./postgres-migration-
|
|
1
|
+
import { S as setNotNull, _ as alterColumnType, a as addEnumValues, b as dropNotNull, c as renameType, d as installExtension, f as addForeignKey, g as addColumn, h as dropConstraint, i as dropIndex, l as createExtension, m as addUnique, n as dropTable, o as createEnumType, p as addPrimaryKey, r as createIndex, s as dropEnumType, t as createTable, u as createSchema, v as dropColumn, x as setDefault, y as dropDefault } from "./tables-CGFE4dED.mjs";
|
|
2
|
+
import { t as dataTransform } from "./data-transform-D25tLeYU.mjs";
|
|
3
|
+
import { t as PostgresMigration } from "./postgres-migration-DcymFlMG.mjs";
|
|
4
4
|
import { placeholder } from "@prisma-next/errors/migration";
|
|
5
5
|
import { MigrationCLI } from "@prisma-next/cli/migration-cli";
|
|
6
6
|
//#region src/core/migrations/operations/raw.ts
|
package/dist/{native-type-normalizer-BNEQ9VDs.mjs.map → native-type-normalizer-Bc9XJzWC.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-type-normalizer-
|
|
1
|
+
{"version":3,"file":"native-type-normalizer-Bc9XJzWC.mjs","names":[],"sources":["../src/core/native-type-normalizer.ts"],"sourcesContent":["/**\n * Postgres native-type normalization.\n *\n * Lives in `target-postgres` because both the migration planner/runner (control\n * plane) and the introspection adapter (control plane) need to normalize raw\n * native-type strings to the same canonical form for comparison.\n */\n\n/**\n * Lookup map for simple prefix-based type normalization.\n *\n * Using a Map for O(1) lookup instead of multiple startsWith checks.\n */\nconst TYPE_PREFIX_MAP: ReadonlyMap<string, string> = new Map([\n ['varchar', 'character varying'],\n ['bpchar', 'character'],\n ['varbit', 'bit varying'],\n]);\n\n/**\n * Normalizes a Postgres schema native type to its canonical form for comparison.\n *\n * Uses a pre-computed lookup map for simple prefix replacements (O(1))\n * and handles complex temporal type normalization separately.\n */\nexport function normalizeSchemaNativeType(nativeType: string): string {\n const trimmed = nativeType.trim();\n\n for (const [prefix, replacement] of TYPE_PREFIX_MAP) {\n if (trimmed.startsWith(prefix)) {\n return replacement + trimmed.slice(prefix.length);\n }\n }\n\n if (trimmed.includes(' with time zone')) {\n if (trimmed.startsWith('timestamp')) {\n return `timestamptz${trimmed.slice(9).replace(' with time zone', '')}`;\n }\n if (trimmed.startsWith('time')) {\n return `timetz${trimmed.slice(4).replace(' with time zone', '')}`;\n }\n }\n\n if (trimmed.includes(' without time zone')) {\n return trimmed.replace(' without time zone', '');\n }\n\n return trimmed;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,kBAA+C,IAAI,IAAI;CAC3D,CAAC,WAAW,mBAAmB;CAC/B,CAAC,UAAU,WAAW;CACtB,CAAC,UAAU,aAAa;AAC1B,CAAC;;;;;;;AAQD,SAAgB,0BAA0B,YAA4B;CACpE,MAAM,UAAU,WAAW,KAAK;CAEhC,KAAK,MAAM,CAAC,QAAQ,gBAAgB,iBAClC,IAAI,QAAQ,WAAW,MAAM,GAC3B,OAAO,cAAc,QAAQ,MAAM,OAAO,MAAM;CAIpD,IAAI,QAAQ,SAAS,iBAAiB,GAAG;EACvC,IAAI,QAAQ,WAAW,WAAW,GAChC,OAAO,cAAc,QAAQ,MAAM,CAAC,CAAC,CAAC,QAAQ,mBAAmB,EAAE;EAErE,IAAI,QAAQ,WAAW,MAAM,GAC3B,OAAO,SAAS,QAAQ,MAAM,CAAC,CAAC,CAAC,QAAQ,mBAAmB,EAAE;CAElE;CAEA,IAAI,QAAQ,SAAS,oBAAoB,GACvC,OAAO,QAAQ,QAAQ,sBAAsB,EAAE;CAGjD,OAAO;AACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-
|
|
1
|
+
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-Bc9XJzWC.mjs";
|
|
2
2
|
export { normalizeSchemaNativeType };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DdlNode } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
//#region src/core/ddl/nodes.ts
|
|
3
|
+
var PostgresDdlNode = class extends DdlNode {};
|
|
4
|
+
function freezeDdlColumns(columns) {
|
|
5
|
+
return Object.freeze([...columns]);
|
|
6
|
+
}
|
|
7
|
+
var PostgresCreateTable = class extends PostgresDdlNode {
|
|
8
|
+
kind = "create-table";
|
|
9
|
+
table;
|
|
10
|
+
schema;
|
|
11
|
+
ifNotExists;
|
|
12
|
+
columns;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super();
|
|
15
|
+
this.table = options.table;
|
|
16
|
+
this.schema = options.schema;
|
|
17
|
+
this.ifNotExists = options.ifNotExists;
|
|
18
|
+
this.columns = freezeDdlColumns(options.columns);
|
|
19
|
+
this.freeze();
|
|
20
|
+
}
|
|
21
|
+
accept(visitor) {
|
|
22
|
+
return visitor.createTable(this);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var PostgresCreateSchema = class extends PostgresDdlNode {
|
|
26
|
+
kind = "create-schema";
|
|
27
|
+
schema;
|
|
28
|
+
ifNotExists;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super();
|
|
31
|
+
this.schema = options.schema;
|
|
32
|
+
this.ifNotExists = options.ifNotExists;
|
|
33
|
+
this.freeze();
|
|
34
|
+
}
|
|
35
|
+
accept(visitor) {
|
|
36
|
+
return visitor.createSchema(this);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { PostgresCreateTable as n, PostgresDdlNode as r, PostgresCreateSchema as t };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=nodes-Dm1XR7UL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes-Dm1XR7UL.mjs","names":[],"sources":["../src/core/ddl/nodes.ts"],"sourcesContent":["import { type DdlColumn, DdlNode } from '@prisma-next/sql-relational-core/ast';\n\nexport interface PostgresDdlVisitor<R> {\n createTable(node: PostgresCreateTable): R;\n createSchema(node: PostgresCreateSchema): R;\n}\n\nexport abstract class PostgresDdlNode extends DdlNode {\n abstract accept<R>(visitor: PostgresDdlVisitor<R>): R;\n}\n\nfunction freezeDdlColumns(columns: readonly DdlColumn[]): ReadonlyArray<DdlColumn> {\n return Object.freeze([...columns]);\n}\n\nexport class PostgresCreateTable extends PostgresDdlNode {\n readonly kind = 'create-table' as const;\n readonly table: string;\n readonly schema: string | undefined;\n readonly ifNotExists: boolean | undefined;\n readonly columns: ReadonlyArray<DdlColumn>;\n\n constructor(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n }) {\n super();\n this.table = options.table;\n this.schema = options.schema;\n this.ifNotExists = options.ifNotExists;\n this.columns = freezeDdlColumns(options.columns);\n this.freeze();\n }\n\n override accept<R>(visitor: PostgresDdlVisitor<R>): R {\n return visitor.createTable(this);\n }\n}\n\nexport class PostgresCreateSchema extends PostgresDdlNode {\n readonly kind = 'create-schema' as const;\n readonly schema: string;\n readonly ifNotExists: boolean | undefined;\n\n constructor(options: { readonly schema: string; readonly ifNotExists?: boolean }) {\n super();\n this.schema = options.schema;\n this.ifNotExists = options.ifNotExists;\n this.freeze();\n }\n\n override accept<R>(visitor: PostgresDdlVisitor<R>): R {\n return visitor.createSchema(this);\n }\n}\n\nexport type AnyPostgresDdlNode = PostgresCreateTable | PostgresCreateSchema;\n"],"mappings":";;AAOA,IAAsB,kBAAtB,cAA8C,QAAQ,CAEtD;AAEA,SAAS,iBAAiB,SAAyD;CACjF,OAAO,OAAO,OAAO,CAAC,GAAG,OAAO,CAAC;AACnC;AAEA,IAAa,sBAAb,cAAyC,gBAAgB;CACvD,OAAgB;CAChB;CACA;CACA;CACA;CAEA,YAAY,SAKT;EACD,MAAM;EACN,KAAK,QAAQ,QAAQ;EACrB,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,UAAU,iBAAiB,QAAQ,OAAO;EAC/C,KAAK,OAAO;CACd;CAEA,OAAmB,SAAmC;EACpD,OAAO,QAAQ,YAAY,IAAI;CACjC;AACF;AAEA,IAAa,uBAAb,cAA0C,gBAAgB;CACxD,OAAgB;CAChB;CACA;CAEA,YAAY,SAAsE;EAChF,MAAM;EACN,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,OAAO;CACd;CAEA,OAAmB,SAAmC;EACpD,OAAO,QAAQ,aAAa,IAAI;CAClC;AACF"}
|