@prisma-next/target-postgres 0.11.0-dev.3 → 0.11.0-dev.31

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.
Files changed (81) hide show
  1. package/dist/codec-types-CRlHq7Cz.d.mts.map +1 -1
  2. package/dist/codecs-Dud5KDNk.d.mts.map +1 -1
  3. package/dist/codecs.d.mts.map +1 -1
  4. package/dist/codecs.mjs.map +1 -1
  5. package/dist/control.d.mts.map +1 -1
  6. package/dist/control.mjs +3 -3
  7. package/dist/control.mjs.map +1 -1
  8. package/dist/data-transform-CdtGUWp2.mjs.map +1 -1
  9. package/dist/data-transform-bmOKkygi.d.mts.map +1 -1
  10. package/dist/default-normalizer-DHCsbfjc.mjs.map +1 -1
  11. package/dist/default-normalizer.d.mts.map +1 -1
  12. package/dist/descriptor-meta-DLA2xV6B.mjs.map +1 -1
  13. package/dist/enum-planning-Bqp96iIw.mjs.map +1 -1
  14. package/dist/enum-planning.d.mts.map +1 -1
  15. package/dist/errors--zafB5_n.mjs.map +1 -1
  16. package/dist/errors.d.mts.map +1 -1
  17. package/dist/{issue-planner-OthDciOe.mjs → issue-planner-Ct9xNqbr.mjs} +13 -13
  18. package/dist/issue-planner-Ct9xNqbr.mjs.map +1 -0
  19. package/dist/issue-planner.d.mts.map +1 -1
  20. package/dist/issue-planner.mjs +1 -1
  21. package/dist/migration.d.mts.map +1 -1
  22. package/dist/migration.mjs +1 -1
  23. package/dist/migration.mjs.map +1 -1
  24. package/dist/native-type-normalizer-DMikJJ1V.mjs.map +1 -1
  25. package/dist/native-type-normalizer.d.mts.map +1 -1
  26. package/dist/{op-factory-call-Bgb_ghPb.mjs → op-factory-call-CB6tPJ3f.mjs} +2 -2
  27. package/dist/{op-factory-call-Bgb_ghPb.mjs.map → op-factory-call-CB6tPJ3f.mjs.map} +1 -1
  28. package/dist/op-factory-call-Drccm_JD.d.mts.map +1 -1
  29. package/dist/op-factory-call.mjs +1 -1
  30. package/dist/pack.d.mts.map +1 -1
  31. package/dist/{planner-DZG1dsSW.mjs → planner-DlhK35aV.mjs} +3 -3
  32. package/dist/{planner-DZG1dsSW.mjs.map → planner-DlhK35aV.mjs.map} +1 -1
  33. package/dist/{planner-ddl-builders-DYMuN0w1.mjs → planner-ddl-builders--0TmW6Ey.mjs} +2 -2
  34. package/dist/{planner-ddl-builders-DYMuN0w1.mjs.map → planner-ddl-builders--0TmW6Ey.mjs.map} +1 -1
  35. package/dist/planner-ddl-builders.d.mts.map +1 -1
  36. package/dist/planner-ddl-builders.mjs +1 -1
  37. package/dist/planner-identity-values-ojX-6cPV.mjs.map +1 -1
  38. package/dist/planner-identity-values.d.mts.map +1 -1
  39. package/dist/planner-produced-postgres-migration-TJWH2m_x.mjs.map +1 -1
  40. package/dist/planner-produced-postgres-migration-p-VKkCia.d.mts.map +1 -1
  41. package/dist/planner-schema-lookup-BGyukuzG.mjs.map +1 -1
  42. package/dist/planner-schema-lookup.d.mts.map +1 -1
  43. package/dist/{planner-sql-checks-K-mTBJDi.mjs → planner-sql-checks-BDtJQ9WD.mjs} +2 -2
  44. package/dist/{planner-sql-checks-K-mTBJDi.mjs.map → planner-sql-checks-BDtJQ9WD.mjs.map} +1 -1
  45. package/dist/planner-sql-checks.d.mts.map +1 -1
  46. package/dist/planner-sql-checks.mjs +1 -1
  47. package/dist/planner-target-details-CIj61DUj.d.mts.map +1 -1
  48. package/dist/planner.d.mts.map +1 -1
  49. package/dist/planner.mjs +1 -1
  50. package/dist/{postgres-contract-serializer-CrET5Ov0.mjs → postgres-contract-serializer-CYct4Y7O.mjs} +11 -11
  51. package/dist/postgres-contract-serializer-CYct4Y7O.mjs.map +1 -0
  52. package/dist/postgres-enum-type-CNhPTDhy.d.mts.map +1 -1
  53. package/dist/postgres-enum-type-DS-KLVRH.mjs.map +1 -1
  54. package/dist/postgres-migration-uADmx0dW.mjs.map +1 -1
  55. package/dist/{postgres-schema-CK82EuWq.mjs → postgres-schema-BL0RAvew.mjs} +3 -3
  56. package/dist/postgres-schema-BL0RAvew.mjs.map +1 -0
  57. package/dist/render-ops-BC2PtCkj.mjs.map +1 -1
  58. package/dist/render-ops.d.mts.map +1 -1
  59. package/dist/render-typescript-CI1wbgUc.mjs.map +1 -1
  60. package/dist/runtime.d.mts.map +1 -1
  61. package/dist/runtime.mjs +1 -1
  62. package/dist/runtime.mjs.map +1 -1
  63. package/dist/shared-ByhSooBS.d.mts.map +1 -1
  64. package/dist/sql-utils-BewXAnsG.mjs.map +1 -1
  65. package/dist/sql-utils.d.mts.map +1 -1
  66. package/dist/statement-builders-vImtdfmM.mjs.map +1 -1
  67. package/dist/statement-builders.d.mts.map +1 -1
  68. package/dist/{tables-CWxZgD0H.mjs → tables-Vhh4k5yz.mjs} +2 -2
  69. package/dist/{tables-CWxZgD0H.mjs.map → tables-Vhh4k5yz.mjs.map} +1 -1
  70. package/dist/types-D-XIpzHA.d.mts.map +1 -1
  71. package/dist/types.d.mts +2 -2
  72. package/dist/types.d.mts.map +1 -1
  73. package/dist/types.mjs +1 -1
  74. package/package.json +17 -17
  75. package/src/core/migrations/issue-planner.ts +3 -3
  76. package/src/core/migrations/planner-strategies.ts +6 -6
  77. package/src/core/postgres-contract-serializer.ts +12 -12
  78. package/src/core/postgres-schema.ts +4 -4
  79. package/dist/issue-planner-OthDciOe.mjs.map +0 -1
  80. package/dist/postgres-contract-serializer-CrET5Ov0.mjs.map +0 -1
  81. package/dist/postgres-schema-CK82EuWq.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"planner-DZG1dsSW.mjs","names":[],"sources":["../src/core/migrations/verify-postgres-namespaces.ts","../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Resolves the live-database schema name for a given namespace\n * coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n * `planner-strategies.ts` so the verifier's projection and the\n * planner's projection always agree — Postgres-aware namespaces (the\n * production path) dispatch to `ddlSchemaName(storage)`, and bare\n * object payloads (used by some tests) fall back to the coordinate\n * itself.\n */\nfunction resolveDdlSchemaName(storage: SqlStorage, namespaceId: string): string {\n const namespace = storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/**\n * Reads the introspected list of schema names from the Postgres-flavoured\n * annotations slot on the schema IR. Defaults to the always-present\n * `public` schema when introspection did not populate the slot — a fresh\n * Postgres database always carries `public` (unless an operator dropped\n * it manually), so any verifier path that runs without an enriched\n * introspection still suppresses the redundant `CREATE SCHEMA \"public\"`.\n *\n * Production introspection (`PostgresControlAdapter.introspect`) is the\n * authoritative source: it queries `pg_namespace` and writes every\n * non-system schema into `annotations.pg.existingSchemas`. Tests that\n * want to assert against a richer initial state pass the slot\n * explicitly via the schema IR.\n */\nfunction existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {\n const annotations = (schema as { annotations?: { pg?: { existingSchemas?: unknown } } })\n .annotations;\n const slot = annotations?.pg?.existingSchemas;\n if (Array.isArray(slot)) {\n return slot.filter((s): s is string => typeof s === 'string');\n }\n return ['public'];\n}\n\n/**\n * Emits a `missing_schema` issue for every contract-declared Postgres\n * namespace whose live container does not yet exist.\n *\n * A namespace's live container is the schema returned by its\n * polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n * to their own id, the unbound singleton projects to `public` (sibling\n * present) or the framework sentinel (sibling absent). Issues are\n * emitted only when the resolved name is a real, creatable schema\n * (not the unbound sentinel) and is missing from the introspected\n * list. `public` is suppressed implicitly because the introspection\n * (or its sensible default) always carries it.\n *\n * Each emitted issue stamps `namespaceId` with the contract namespace\n * coordinate so the downstream `mapIssueToCall` re-resolves the DDL\n * schema name through the same polymorphic path — keeping the\n * coordinate, not the resolved name, as the issue's stable identity.\n */\nexport function verifyPostgresNamespacePresence(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIR;\n}): readonly SchemaIssue[] {\n const { contract, schema } = input;\n const existing = new Set(existingSchemasFromSchema(schema));\n const issues: SchemaIssue[] = [];\n const namespaceIds = Object.keys(contract.storage.namespaces).sort();\n for (const namespaceId of namespaceIds) {\n if (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n if (ddlName === UNBOUND_NAMESPACE_ID) continue;\n if (existing.has(ddlName)) continue;\n issues.push({\n kind: 'missing_schema',\n namespaceId,\n message: `Schema \"${ddlName}\" is missing from database`,\n });\n }\n return issues;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport {\n extractCodecControlHooks,\n planFieldEventOperations,\n plannerFailure,\n} from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport { readExistingEnumValues } from './enum-planning';\nimport { planIssues } from './issue-planner';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\nimport { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ninterface PlannerConfig {\n readonly defaultSchema: string;\n}\n\nconst DEFAULT_PLANNER_CONFIG: PlannerConfig = {\n defaultSchema: 'public',\n};\n\nexport function createPostgresMigrationPlanner(\n config: Partial<PlannerConfig> = {},\n): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner({\n ...DEFAULT_PLANNER_CONFIG,\n ...config,\n });\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | { readonly kind: 'success'; readonly plan: TypeScriptRenderablePostgresMigration }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n constructor(private readonly config: PlannerConfig) {}\n\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n /**\n * Contract space this plan applies to. Stamped onto the produced\n * {@link TypeScriptRenderablePostgresMigration.spaceId} so the runner keys\n * the marker row by the right space.\n */\n readonly spaceId: string;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(\n context: MigrationScaffoldContext,\n spaceId: string,\n ): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration(\n [],\n {\n from: context.fromHash,\n to: context.toHash,\n },\n spaceId,\n );\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName = options.schemaName ?? this.config.defaultSchema;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n const result = planIssues({\n issues: schemaIssues,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed\n // ordering is `structural → added → dropped → altered`, with\n // within-group sorting by `(tableName, fieldName)` so re-emits are\n // byte-stable. The hook fires only at the application emitter —\n // extension-space planning never reaches this helper.\n const fieldEventOps = planFieldEventOperations({\n priorContract: options.fromContract,\n newContract: options.contract,\n codecHooks,\n });\n // Codec-emitted calls already conform to `OpFactoryCall` — render +\n // toOp + importRequirements ride directly through the same emit path\n // as structural ops, no `RawSqlCall` wrap.\n const calls = [...result.value.calls, ...fieldEventOps];\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(\n calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n options.spaceId,\n ),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n resolveExistingEnumValues: (schema, enumType) =>\n readExistingEnumValues(schema, enumType.nativeType),\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n // Schema presence is a Postgres-specific concern (no equivalent in\n // SQLite / Mongo), so the issue emission lives in the target layer\n // rather than in the family verifier. Stitch it in here so a single\n // `SchemaIssue[]` flows through `planIssues` and the planner emits\n // CREATE SCHEMA in the dep bucket before any CreateTableCall.\n const namespaceIssues = verifyPostgresNamespacePresence({\n contract: options.contract,\n schema: options.schema,\n });\n if (namespaceIssues.length === 0) {\n return verifyResult.schema.issues;\n }\n return [...namespaceIssues, ...verifyResult.schema.issues];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,SAAS,qBAAqB,SAAqB,aAA6B;CAC9E,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,iBAAiB,UAAU,EAC7B,OAAO,UAAU,cAAc,QAAQ;CAEzC,OAAO;;;;;;;;;;;;;;;;AAiBT,SAAS,0BAA0B,QAAwC;CAGzE,MAAM,OAFe,OAClB,aACuB,IAAI;CAC9B,IAAI,MAAM,QAAQ,KAAK,EACrB,OAAO,KAAK,QAAQ,MAAmB,OAAO,MAAM,SAAS;CAE/D,OAAO,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;AAqBnB,SAAgB,gCAAgC,OAGrB;CACzB,MAAM,EAAE,UAAU,WAAW;CAC7B,MAAM,WAAW,IAAI,IAAI,0BAA0B,OAAO,CAAC;CAC3D,MAAM,SAAwB,EAAE;CAChC,MAAM,eAAe,OAAO,KAAK,SAAS,QAAQ,WAAW,CAAC,MAAM;CACpE,KAAK,MAAM,eAAe,cAAc;EACtC,IAAI,gBAAgB,sBAAsB;EAC1C,MAAM,UAAU,qBAAqB,SAAS,SAAS,YAAY;EACnE,IAAI,YAAY,sBAAsB;EACtC,IAAI,SAAS,IAAI,QAAQ,EAAE;EAC3B,OAAO,KAAK;GACV,MAAM;GACN;GACA,SAAS,WAAW,QAAQ;GAC7B,CAAC;;CAEJ,OAAO;;;;ACxCT,MAAM,yBAAwC,EAC5C,eAAe,UAChB;AAED,SAAgB,+BACd,SAAiC,EAAE,EACT;CAC1B,OAAO,IAAI,yBAAyB;EAClC,GAAG;EACH,GAAG;EACJ,CAAC;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;;CAGT,oBAA4B,SAA+D;EAIzF,MAAM,UAAU,QAAQ,OAAO;EAC/B,MAAM,SAAS,QAAQ,SAAS,WAAW,IAAI,QAAQ,SAAS,cAAc;EAY9E,MAAM,eAAe,gBAAgB;GAVnC,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GAChB;GACA,sCAAsB,IAAI,KAAK;GAC/B,qBAAqB,QAAQ;GAC7B,kBAAkB;GAClB,qBAAqB;GACrB,4BAA4B,QAAQ,aAClC,uBAAuB,QAAQ,SAAS,WAAW;GAEL,CAAC;EAMnD,MAAM,kBAAkB,gCAAgC;GACtD,UAAU,QAAQ;GAClB,QAAQ,QAAQ;GACjB,CAAC;EACF,IAAI,gBAAgB,WAAW,GAC7B,OAAO,aAAa,OAAO;EAE7B,OAAO,CAAC,GAAG,iBAAiB,GAAG,aAAa,OAAO,OAAO"}
1
+ {"version":3,"file":"planner-DlhK35aV.mjs","names":[],"sources":["../src/core/migrations/verify-postgres-namespaces.ts","../src/core/migrations/planner.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Resolves the live-database schema name for a given namespace\n * coordinate. Mirrors `resolveDdlSchemaForNamespace` in\n * `planner-strategies.ts` so the verifier's projection and the\n * planner's projection always agree — Postgres-aware namespaces (the\n * production path) dispatch to `ddlSchemaName(storage)`, and bare\n * object payloads (used by some tests) fall back to the coordinate\n * itself.\n */\nfunction resolveDdlSchemaName(storage: SqlStorage, namespaceId: string): string {\n const namespace = storage.namespaces[namespaceId];\n if (isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/**\n * Reads the introspected list of schema names from the Postgres-flavoured\n * annotations slot on the schema IR. Defaults to the always-present\n * `public` schema when introspection did not populate the slot — a fresh\n * Postgres database always carries `public` (unless an operator dropped\n * it manually), so any verifier path that runs without an enriched\n * introspection still suppresses the redundant `CREATE SCHEMA \"public\"`.\n *\n * Production introspection (`PostgresControlAdapter.introspect`) is the\n * authoritative source: it queries `pg_namespace` and writes every\n * non-system schema into `annotations.pg.existingSchemas`. Tests that\n * want to assert against a richer initial state pass the slot\n * explicitly via the schema IR.\n */\nfunction existingSchemasFromSchema(schema: SqlSchemaIR): readonly string[] {\n const annotations = (schema as { annotations?: { pg?: { existingSchemas?: unknown } } })\n .annotations;\n const slot = annotations?.pg?.existingSchemas;\n if (Array.isArray(slot)) {\n return slot.filter((s): s is string => typeof s === 'string');\n }\n return ['public'];\n}\n\n/**\n * Emits a `missing_schema` issue for every contract-declared Postgres\n * namespace whose live container does not yet exist.\n *\n * A namespace's live container is the schema returned by its\n * polymorphic `ddlSchemaName(storage)` method — named schemas resolve\n * to their own id, the unbound singleton projects to `public` (sibling\n * present) or the framework sentinel (sibling absent). Issues are\n * emitted only when the resolved name is a real, creatable schema\n * (not the unbound sentinel) and is missing from the introspected\n * list. `public` is suppressed implicitly because the introspection\n * (or its sensible default) always carries it.\n *\n * Each emitted issue stamps `namespaceId` with the contract namespace\n * coordinate so the downstream `mapIssueToCall` re-resolves the DDL\n * schema name through the same polymorphic path — keeping the\n * coordinate, not the resolved name, as the issue's stable identity.\n */\nexport function verifyPostgresNamespacePresence(input: {\n readonly contract: Contract<SqlStorage>;\n readonly schema: SqlSchemaIR;\n}): readonly SchemaIssue[] {\n const { contract, schema } = input;\n const existing = new Set(existingSchemasFromSchema(schema));\n const issues: SchemaIssue[] = [];\n const namespaceIds = Object.keys(contract.storage.namespaces).sort();\n for (const namespaceId of namespaceIds) {\n if (namespaceId === UNBOUND_NAMESPACE_ID) continue;\n const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);\n if (ddlName === UNBOUND_NAMESPACE_ID) continue;\n if (existing.has(ddlName)) continue;\n issues.push({\n kind: 'missing_schema',\n namespaceId,\n message: `Schema \"${ddlName}\" is missing from database`,\n });\n }\n return issues;\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport type {\n MigrationOperationPolicy,\n SqlMigrationPlannerPlanOptions,\n SqlPlannerFailureResult,\n} from '@prisma-next/family-sql/control';\nimport {\n extractCodecControlHooks,\n planFieldEventOperations,\n plannerFailure,\n} from '@prisma-next/family-sql/control';\nimport { verifySqlSchema } from '@prisma-next/family-sql/schema-verify';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n MigrationPlanner,\n MigrationPlanWithAuthoringSurface,\n MigrationScaffoldContext,\n SchemaIssue,\n} from '@prisma-next/framework-components/control';\nimport { parsePostgresDefault } from '../default-normalizer';\nimport { normalizeSchemaNativeType } from '../native-type-normalizer';\nimport { readExistingEnumValues } from './enum-planning';\nimport { planIssues } from './issue-planner';\nimport { TypeScriptRenderablePostgresMigration } from './planner-produced-postgres-migration';\nimport { postgresPlannerStrategies } from './planner-strategies';\nimport { verifyPostgresNamespacePresence } from './verify-postgres-namespaces';\n\ntype PlannerFrameworkComponents = SqlMigrationPlannerPlanOptions extends {\n readonly frameworkComponents: infer T;\n}\n ? T\n : ReadonlyArray<unknown>;\n\ntype PlannerOptionsWithComponents = SqlMigrationPlannerPlanOptions & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ntype VerifySqlSchemaOptionsWithComponents = Parameters<typeof verifySqlSchema>[0] & {\n readonly frameworkComponents: PlannerFrameworkComponents;\n};\n\ninterface PlannerConfig {\n readonly defaultSchema: string;\n}\n\nconst DEFAULT_PLANNER_CONFIG: PlannerConfig = {\n defaultSchema: 'public',\n};\n\nexport function createPostgresMigrationPlanner(\n config: Partial<PlannerConfig> = {},\n): PostgresMigrationPlanner {\n return new PostgresMigrationPlanner({\n ...DEFAULT_PLANNER_CONFIG,\n ...config,\n });\n}\n\n/**\n * Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose\n * success variant carries a `TypeScriptRenderablePostgresMigration` — a\n * migration object that both the CLI (via `renderTypeScript()`) and the\n * SQL-typed callers (via `operations`, `describe()`, etc.) consume\n * uniformly.\n */\nexport type PostgresPlanResult =\n | { readonly kind: 'success'; readonly plan: TypeScriptRenderablePostgresMigration }\n | SqlPlannerFailureResult;\n\n/**\n * Postgres migration planner — a thin wrapper over `planIssues`.\n *\n * `plan()` verifies the live schema against the target contract (producing\n * `SchemaIssue[]`) and delegates to `planIssues` with the unified\n * `postgresPlannerStrategies` list: enum-change, NOT-NULL backfill,\n * type-change, nullable-tightening, codec-hook storage types,\n * component-declared dependency installs, and shared-temp-default /\n * empty-table-guarded NOT-NULL add-column. The same strategy list runs for\n * `migration plan`, `db update`, and `db init`; behavior diverges purely on\n * `policy.allowedOperationClasses` (the data-safe strategies short-circuit\n * when `'data'` is excluded). The issue planner applies operation-class\n * policy gates and emits a single `PostgresOpFactoryCall[]` that drives both\n * the runtime-ops view (via `renderOps`) and the `renderTypeScript()`\n * authoring surface.\n */\nexport class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {\n constructor(private readonly config: PlannerConfig) {}\n\n plan(options: {\n readonly contract: unknown;\n readonly schema: unknown;\n readonly policy: MigrationOperationPolicy;\n /**\n * The \"from\" contract (state the planner assumes the database starts\n * at), or `null` for reconciliation flows. Only `migration plan` ever\n * supplies a non-null value; `db update` / `db init` reconcile against\n * the live schema and pass `null`. When present alongside the\n * `'data'` operation class, strategies that need from/to column-shape\n * comparisons (unsafe type change, nullability tightening) activate.\n *\n * Typed as the framework `Contract | null` to satisfy the\n * `MigrationPlanner` interface contract; `planSql` narrows to the SQL\n * shape via `SqlMigrationPlannerPlanOptions`. Used to populate\n * `describe().from` on the produced plan as\n * `fromContract?.storage.storageHash ?? null`.\n */\n readonly fromContract: Contract | null;\n readonly schemaName?: string;\n readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;\n /**\n * Contract space this plan applies to. Stamped onto the produced\n * {@link TypeScriptRenderablePostgresMigration.spaceId} so the runner keys\n * the marker row by the right space.\n */\n readonly spaceId: string;\n }): PostgresPlanResult {\n return this.planSql(options as SqlMigrationPlannerPlanOptions);\n }\n\n emptyMigration(\n context: MigrationScaffoldContext,\n spaceId: string,\n ): MigrationPlanWithAuthoringSurface {\n return new TypeScriptRenderablePostgresMigration(\n [],\n {\n from: context.fromHash,\n to: context.toHash,\n },\n spaceId,\n );\n }\n\n private planSql(options: SqlMigrationPlannerPlanOptions): PostgresPlanResult {\n const schemaName = options.schemaName ?? this.config.defaultSchema;\n const policyResult = this.ensureAdditivePolicy(options.policy);\n if (policyResult) {\n return policyResult;\n }\n\n const schemaIssues = this.collectSchemaIssues(options);\n const codecHooks = extractCodecControlHooks(options.frameworkComponents);\n const storageTypes = options.contract.storage.types ?? {};\n\n const result = planIssues({\n issues: schemaIssues,\n toContract: options.contract,\n // `fromContract` is only supplied by `migration plan`. It is `null` for\n // `db update` / `db init`, which means data-safety strategies needing\n // from/to comparisons (unsafe type change, nullable tightening) are\n // inapplicable there — reconciliation falls through to\n // `mapIssueToCall`'s direct destructive handlers.\n fromContract: options.fromContract,\n schemaName,\n codecHooks,\n storageTypes,\n schema: options.schema,\n policy: options.policy,\n frameworkComponents: options.frameworkComponents,\n strategies: postgresPlannerStrategies,\n });\n\n if (!result.ok) {\n return plannerFailure(result.failure);\n }\n\n // Inline `onFieldEvent`-emitted ops after structural DDL. The fixed\n // ordering is `structural → added → dropped → altered`, with\n // within-group sorting by `(tableName, fieldName)` so re-emits are\n // byte-stable. The hook fires only at the application emitter —\n // extension-space planning never reaches this helper.\n const fieldEventOps = planFieldEventOperations({\n priorContract: options.fromContract,\n newContract: options.contract,\n codecHooks,\n });\n // Codec-emitted calls already conform to `OpFactoryCall` — render +\n // toOp + importRequirements ride directly through the same emit path\n // as structural ops, no `RawSqlCall` wrap.\n const calls = [...result.value.calls, ...fieldEventOps];\n\n return Object.freeze({\n kind: 'success' as const,\n plan: new TypeScriptRenderablePostgresMigration(\n calls,\n {\n from: options.fromContract?.storage.storageHash ?? null,\n to: options.contract.storage.storageHash,\n },\n options.spaceId,\n ),\n });\n }\n\n private ensureAdditivePolicy(policy: MigrationOperationPolicy) {\n if (!policy.allowedOperationClasses.includes('additive')) {\n return plannerFailure([\n {\n kind: 'unsupportedOperation',\n summary: 'Migration planner requires additive operations be allowed',\n why: 'The planner requires the \"additive\" operation class to be allowed in the policy.',\n },\n ]);\n }\n return null;\n }\n\n private collectSchemaIssues(options: PlannerOptionsWithComponents): readonly SchemaIssue[] {\n // `db init` uses additive-only policy and intentionally ignores extra\n // schema objects. Any reconciliation-capable policy (widening or\n // destructive) must inspect extras to reconcile strict equality.\n const allowed = options.policy.allowedOperationClasses;\n const strict = allowed.includes('widening') || allowed.includes('destructive');\n const verifyOptions: VerifySqlSchemaOptionsWithComponents = {\n contract: options.contract,\n schema: options.schema,\n strict,\n typeMetadataRegistry: new Map(),\n frameworkComponents: options.frameworkComponents,\n normalizeDefault: parsePostgresDefault,\n normalizeNativeType: normalizeSchemaNativeType,\n resolveExistingEnumValues: (schema, enumType) =>\n readExistingEnumValues(schema, enumType.nativeType),\n };\n const verifyResult = verifySqlSchema(verifyOptions);\n // Schema presence is a Postgres-specific concern (no equivalent in\n // SQLite / Mongo), so the issue emission lives in the target layer\n // rather than in the family verifier. Stitch it in here so a single\n // `SchemaIssue[]` flows through `planIssues` and the planner emits\n // CREATE SCHEMA in the dep bucket before any CreateTableCall.\n const namespaceIssues = verifyPostgresNamespacePresence({\n contract: options.contract,\n schema: options.schema,\n });\n if (namespaceIssues.length === 0) {\n return verifyResult.schema.issues;\n }\n return [...namespaceIssues, ...verifyResult.schema.issues];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,SAAS,qBAAqB,SAAqB,aAA6B;CAC9E,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,iBAAiB,SAAS,GAC5B,OAAO,UAAU,cAAc,OA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tD,UAAU,QAAQ;GAClB,QAAQ,QAAQ;EAClB,CAAC;EACD,IAAI,gBAAgB,WAAW,GAC7B,OAAO,aAAa,OAAO;EAE7B,OAAO,CAAC,GAAG,iBAAiB,GAAG,aAAa,OAAO,MAAM;CAC3D;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-BewXAnsG.mjs";
2
- import { c as qualifyTableName, f as resolveColumnTypeMetadata } from "./planner-sql-checks-K-mTBJDi.mjs";
2
+ import { c as qualifyTableName, f as resolveColumnTypeMetadata } from "./planner-sql-checks-BDtJQ9WD.mjs";
3
3
  //#region src/core/migrations/planner-ddl-builders.ts
4
4
  function buildCreateTableSql(qualifiedTableName, table, codecHooks, storageTypes = {}) {
5
5
  const columnDefinitions = Object.entries(table.columns).map(([columnName, column]) => {
@@ -128,4 +128,4 @@ REFERENCES ${qualifyTableName(schemaName, foreignKey.target.tableName)} (${forei
128
128
  //#endregion
129
129
  export { buildForeignKeySql as a, buildCreateTableSql as i, buildColumnDefaultSql as n, renderDefaultLiteral as o, buildColumnTypeSql as r, buildAddColumnSql as t };
130
130
 
131
- //# sourceMappingURL=planner-ddl-builders-DYMuN0w1.mjs.map
131
+ //# sourceMappingURL=planner-ddl-builders--0TmW6Ey.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"planner-ddl-builders-DYMuN0w1.mjs","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n ForeignKey,\n PostgresEnumStorageEntry,\n ReferentialAction,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport type { PostgresColumnDefault } from '../types';\nimport { qualifyTableName } from './planner-sql-checks';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\nexport function buildCreateTableSql(\n qualifiedTableName: string,\n table: StorageTable,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const columnDefinitions = Object.entries(table.columns).map(\n ([columnName, column]: [string, StorageColumn]) => {\n const parts = [\n quoteIdentifier(columnName),\n buildColumnTypeSql(column, codecHooks, storageTypes),\n buildColumnDefaultSql(column.default, column),\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n },\n );\n\n const constraintDefinitions: string[] = [];\n if (table.primaryKey) {\n constraintDefinitions.push(\n `PRIMARY KEY (${table.primaryKey.columns.map(quoteIdentifier).join(', ')})`,\n );\n }\n\n const allDefinitions = [...columnDefinitions, ...constraintDefinitions];\n return `CREATE TABLE ${qualifiedTableName} (\\n ${allDefinitions.join(',\\n ')}\\n)`;\n}\n\n/**\n * Pattern for safe PostgreSQL type names.\n * Allows letters, digits, underscores, spaces (for \"double precision\", \"character varying\"),\n * and trailing [] for array types.\n */\nconst SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*(\\[\\])?$/;\n\nfunction assertSafeNativeType(nativeType: string): void {\n if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {\n throw new Error(\n `Unsafe native type name in contract: \"${nativeType}\". ` +\n 'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*(\\\\[\\\\])?$/',\n );\n }\n}\n\n/**\n * Sanity check against accidental SQL injection from malformed contract files.\n * Rejects semicolons, SQL comment tokens, and dollar-quoting.\n * Not a comprehensive security boundary — the contract is developer-authored.\n */\nfunction assertSafeDefaultExpression(expression: string): void {\n if (expression.includes(';') || /--|\\/\\*|\\$\\$|\\bSELECT\\b/i.test(expression)) {\n throw new Error(\n `Unsafe default expression in contract: \"${expression}\". ` +\n 'Default expressions must not contain semicolons, SQL comment tokens, dollar-quoting, or subqueries.',\n );\n }\n}\n\n/**\n * Renders the SQL type for a column in DDL context.\n *\n * @param allowPseudoTypes - When true (default), autoincrement integer columns\n * produce SERIAL/BIGSERIAL/SMALLSERIAL pseudo-types. Set to false for contexts\n * like ALTER COLUMN TYPE where pseudo-types are invalid.\n */\nexport function buildColumnTypeSql(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n allowPseudoTypes = true,\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (allowPseudoTypes) {\n const columnDefault = column.default;\n if (columnDefault?.kind === 'function' && columnDefault.expression === 'autoincrement()') {\n if (resolved.nativeType === 'int4' || resolved.nativeType === 'integer') {\n return 'SERIAL';\n }\n if (resolved.nativeType === 'int8' || resolved.nativeType === 'bigint') {\n return 'BIGSERIAL';\n }\n if (resolved.nativeType === 'int2' || resolved.nativeType === 'smallint') {\n return 'SMALLSERIAL';\n }\n }\n }\n\n const expanded = expandParameterizedTypeSql(resolved, codecHooks);\n if (expanded !== null) {\n return expanded;\n }\n\n if (column.typeRef) {\n return quoteIdentifier(resolved.nativeType);\n }\n\n assertSafeNativeType(resolved.nativeType);\n return resolved.nativeType;\n}\n\nfunction expandParameterizedTypeSql(\n column: Pick<StorageColumn, 'nativeType' | 'codecId' | 'typeParams'>,\n codecHooks: Map<string, CodecControlHooks>,\n): string | null {\n if (!column.typeParams) {\n return null;\n }\n\n if (!column.codecId) {\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" but has no codecId. ` +\n 'Ensure the column is associated with a codec.',\n );\n }\n\n const hooks = codecHooks.get(column.codecId);\n if (!hooks?.expandNativeType) {\n if (hooks?.planTypeOperations) {\n return null;\n }\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" ` +\n `but no expandNativeType hook is registered for codecId \"${column.codecId}\". ` +\n 'Ensure the extension providing this codec is included in extensionPacks.',\n );\n }\n\n const expanded = hooks.expandNativeType({\n nativeType: column.nativeType,\n codecId: column.codecId,\n typeParams: column.typeParams,\n });\n\n return expanded !== column.nativeType ? expanded : null;\n}\n\n/** Autoincrement columns use SERIAL types, so this returns empty for them. */\nexport function buildColumnDefaultSql(\n columnDefault: PostgresColumnDefault | undefined,\n column?: StorageColumn,\n): string {\n if (!columnDefault) {\n return '';\n }\n\n switch (columnDefault.kind) {\n case 'literal':\n return `DEFAULT ${renderDefaultLiteral(columnDefault.value, column)}`;\n case 'function': {\n if (columnDefault.expression === 'autoincrement()') {\n return '';\n }\n assertSafeDefaultExpression(columnDefault.expression);\n return `DEFAULT (${columnDefault.expression})`;\n }\n case 'sequence':\n return `DEFAULT nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`;\n }\n}\n\nexport function renderDefaultLiteral(value: unknown, column?: StorageColumn): string {\n const isJsonColumn = column?.nativeType === 'json' || column?.nativeType === 'jsonb';\n\n if (value instanceof Date) {\n return `'${escapeLiteral(value.toISOString())}'`;\n }\n if (typeof value === 'string') {\n return `'${escapeLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'NULL';\n }\n const json = JSON.stringify(value);\n if (isJsonColumn) {\n return `'${escapeLiteral(json)}'::${column.nativeType}`;\n }\n return `'${escapeLiteral(json)}'`;\n}\n\nexport function buildAddColumnSql(\n qualifiedTableName: string,\n columnName: string,\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n temporaryDefault?: string | null,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);\n const defaultSql =\n buildColumnDefaultSql(column.default, column) ||\n (temporaryDefault ? `DEFAULT ${temporaryDefault}` : '');\n const parts = [\n `ALTER TABLE ${qualifiedTableName}`,\n `ADD COLUMN ${quoteIdentifier(columnName)} ${typeSql}`,\n defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n}\n\nconst REFERENTIAL_ACTION_SQL: Record<ReferentialAction, string> = {\n noAction: 'NO ACTION',\n restrict: 'RESTRICT',\n cascade: 'CASCADE',\n setNull: 'SET NULL',\n setDefault: 'SET DEFAULT',\n};\n\nexport function buildForeignKeySql(\n schemaName: string,\n tableName: string,\n fkName: string,\n foreignKey: ForeignKey,\n): string {\n let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}\nADD CONSTRAINT ${quoteIdentifier(fkName)}\nFOREIGN KEY (${foreignKey.source.columns.map(quoteIdentifier).join(', ')})\nREFERENCES ${qualifyTableName(schemaName, foreignKey.target.tableName)} (${foreignKey.target.columns\n .map(quoteIdentifier)\n .join(', ')})`;\n\n if (foreignKey.onDelete !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[foreignKey.onDelete];\n if (!action) {\n throw new Error(`Unknown referential action for onDelete: ${String(foreignKey.onDelete)}`);\n }\n sql += `\\nON DELETE ${action}`;\n }\n if (foreignKey.onUpdate !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[foreignKey.onUpdate];\n if (!action) {\n throw new Error(`Unknown referential action for onUpdate: ${String(foreignKey.onUpdate)}`);\n }\n sql += `\\nON UPDATE ${action}`;\n }\n\n return sql;\n}\n"],"mappings":";;;AAcA,SAAgB,oBACd,oBACA,OACA,YACA,eAA+E,EAAE,EACzE;CACR,MAAM,oBAAoB,OAAO,QAAQ,MAAM,QAAQ,CAAC,KACrD,CAAC,YAAY,YAAqC;EAOjD,OANc;GACZ,gBAAgB,WAAW;GAC3B,mBAAmB,QAAQ,YAAY,aAAa;GACpD,sBAAsB,OAAO,SAAS,OAAO;GAC7C,OAAO,WAAW,KAAK;GACxB,CAAC,OAAO,QACG,CAAC,KAAK,IAAI;GAEzB;CAED,MAAM,wBAAkC,EAAE;CAC1C,IAAI,MAAM,YACR,sBAAsB,KACpB,gBAAgB,MAAM,WAAW,QAAQ,IAAI,gBAAgB,CAAC,KAAK,KAAK,CAAC,GAC1E;CAIH,OAAO,gBAAgB,mBAAmB,QAAQ,CAD1B,GAAG,mBAAmB,GAAG,sBACe,CA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AED,SAAgB,mBACd,YACA,WACA,QACA,YACQ;CACR,IAAI,MAAM,eAAe,iBAAiB,YAAY,UAAU,CAAC;iBAClD,gBAAgB,OAAO,CAAC;eAC1B,WAAW,OAAO,QAAQ,IAAI,gBAAgB,CAAC,KAAK,KAAK,CAAC;aAC5D,iBAAiB,YAAY,WAAW,OAAO,UAAU,CAAC,IAAI,WAAW,OAAO,QACxF,IAAI,gBAAgB,CACpB,KAAK,KAAK,CAAC;CAEd,IAAI,WAAW,aAAa,KAAA,GAAW;EACrC,MAAM,SAAS,uBAAuB,WAAW;EACjD,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,4CAA4C,OAAO,WAAW,SAAS,GAAG;EAE5F,OAAO,eAAe;;CAExB,IAAI,WAAW,aAAa,KAAA,GAAW;EACrC,MAAM,SAAS,uBAAuB,WAAW;EACjD,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,4CAA4C,OAAO,WAAW,SAAS,GAAG;EAE5F,OAAO,eAAe;;CAGxB,OAAO"}
1
+ {"version":3,"file":"planner-ddl-builders--0TmW6Ey.mjs","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n ForeignKey,\n PostgresEnumStorageEntry,\n ReferentialAction,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport type { PostgresColumnDefault } from '../types';\nimport { qualifyTableName } from './planner-sql-checks';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\nexport function buildCreateTableSql(\n qualifiedTableName: string,\n table: StorageTable,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const columnDefinitions = Object.entries(table.columns).map(\n ([columnName, column]: [string, StorageColumn]) => {\n const parts = [\n quoteIdentifier(columnName),\n buildColumnTypeSql(column, codecHooks, storageTypes),\n buildColumnDefaultSql(column.default, column),\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n },\n );\n\n const constraintDefinitions: string[] = [];\n if (table.primaryKey) {\n constraintDefinitions.push(\n `PRIMARY KEY (${table.primaryKey.columns.map(quoteIdentifier).join(', ')})`,\n );\n }\n\n const allDefinitions = [...columnDefinitions, ...constraintDefinitions];\n return `CREATE TABLE ${qualifiedTableName} (\\n ${allDefinitions.join(',\\n ')}\\n)`;\n}\n\n/**\n * Pattern for safe PostgreSQL type names.\n * Allows letters, digits, underscores, spaces (for \"double precision\", \"character varying\"),\n * and trailing [] for array types.\n */\nconst SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*(\\[\\])?$/;\n\nfunction assertSafeNativeType(nativeType: string): void {\n if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {\n throw new Error(\n `Unsafe native type name in contract: \"${nativeType}\". ` +\n 'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*(\\\\[\\\\])?$/',\n );\n }\n}\n\n/**\n * Sanity check against accidental SQL injection from malformed contract files.\n * Rejects semicolons, SQL comment tokens, and dollar-quoting.\n * Not a comprehensive security boundary — the contract is developer-authored.\n */\nfunction assertSafeDefaultExpression(expression: string): void {\n if (expression.includes(';') || /--|\\/\\*|\\$\\$|\\bSELECT\\b/i.test(expression)) {\n throw new Error(\n `Unsafe default expression in contract: \"${expression}\". ` +\n 'Default expressions must not contain semicolons, SQL comment tokens, dollar-quoting, or subqueries.',\n );\n }\n}\n\n/**\n * Renders the SQL type for a column in DDL context.\n *\n * @param allowPseudoTypes - When true (default), autoincrement integer columns\n * produce SERIAL/BIGSERIAL/SMALLSERIAL pseudo-types. Set to false for contexts\n * like ALTER COLUMN TYPE where pseudo-types are invalid.\n */\nexport function buildColumnTypeSql(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n allowPseudoTypes = true,\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (allowPseudoTypes) {\n const columnDefault = column.default;\n if (columnDefault?.kind === 'function' && columnDefault.expression === 'autoincrement()') {\n if (resolved.nativeType === 'int4' || resolved.nativeType === 'integer') {\n return 'SERIAL';\n }\n if (resolved.nativeType === 'int8' || resolved.nativeType === 'bigint') {\n return 'BIGSERIAL';\n }\n if (resolved.nativeType === 'int2' || resolved.nativeType === 'smallint') {\n return 'SMALLSERIAL';\n }\n }\n }\n\n const expanded = expandParameterizedTypeSql(resolved, codecHooks);\n if (expanded !== null) {\n return expanded;\n }\n\n if (column.typeRef) {\n return quoteIdentifier(resolved.nativeType);\n }\n\n assertSafeNativeType(resolved.nativeType);\n return resolved.nativeType;\n}\n\nfunction expandParameterizedTypeSql(\n column: Pick<StorageColumn, 'nativeType' | 'codecId' | 'typeParams'>,\n codecHooks: Map<string, CodecControlHooks>,\n): string | null {\n if (!column.typeParams) {\n return null;\n }\n\n if (!column.codecId) {\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" but has no codecId. ` +\n 'Ensure the column is associated with a codec.',\n );\n }\n\n const hooks = codecHooks.get(column.codecId);\n if (!hooks?.expandNativeType) {\n if (hooks?.planTypeOperations) {\n return null;\n }\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" ` +\n `but no expandNativeType hook is registered for codecId \"${column.codecId}\". ` +\n 'Ensure the extension providing this codec is included in extensionPacks.',\n );\n }\n\n const expanded = hooks.expandNativeType({\n nativeType: column.nativeType,\n codecId: column.codecId,\n typeParams: column.typeParams,\n });\n\n return expanded !== column.nativeType ? expanded : null;\n}\n\n/** Autoincrement columns use SERIAL types, so this returns empty for them. */\nexport function buildColumnDefaultSql(\n columnDefault: PostgresColumnDefault | undefined,\n column?: StorageColumn,\n): string {\n if (!columnDefault) {\n return '';\n }\n\n switch (columnDefault.kind) {\n case 'literal':\n return `DEFAULT ${renderDefaultLiteral(columnDefault.value, column)}`;\n case 'function': {\n if (columnDefault.expression === 'autoincrement()') {\n return '';\n }\n assertSafeDefaultExpression(columnDefault.expression);\n return `DEFAULT (${columnDefault.expression})`;\n }\n case 'sequence':\n return `DEFAULT nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`;\n }\n}\n\nexport function renderDefaultLiteral(value: unknown, column?: StorageColumn): string {\n const isJsonColumn = column?.nativeType === 'json' || column?.nativeType === 'jsonb';\n\n if (value instanceof Date) {\n return `'${escapeLiteral(value.toISOString())}'`;\n }\n if (typeof value === 'string') {\n return `'${escapeLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'NULL';\n }\n const json = JSON.stringify(value);\n if (isJsonColumn) {\n return `'${escapeLiteral(json)}'::${column.nativeType}`;\n }\n return `'${escapeLiteral(json)}'`;\n}\n\nexport function buildAddColumnSql(\n qualifiedTableName: string,\n columnName: string,\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n temporaryDefault?: string | null,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);\n const defaultSql =\n buildColumnDefaultSql(column.default, column) ||\n (temporaryDefault ? `DEFAULT ${temporaryDefault}` : '');\n const parts = [\n `ALTER TABLE ${qualifiedTableName}`,\n `ADD COLUMN ${quoteIdentifier(columnName)} ${typeSql}`,\n defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n}\n\nconst REFERENTIAL_ACTION_SQL: Record<ReferentialAction, string> = {\n noAction: 'NO ACTION',\n restrict: 'RESTRICT',\n cascade: 'CASCADE',\n setNull: 'SET NULL',\n setDefault: 'SET DEFAULT',\n};\n\nexport function buildForeignKeySql(\n schemaName: string,\n tableName: string,\n fkName: string,\n foreignKey: ForeignKey,\n): string {\n let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}\nADD CONSTRAINT ${quoteIdentifier(fkName)}\nFOREIGN KEY (${foreignKey.source.columns.map(quoteIdentifier).join(', ')})\nREFERENCES ${qualifyTableName(schemaName, foreignKey.target.tableName)} (${foreignKey.target.columns\n .map(quoteIdentifier)\n .join(', ')})`;\n\n if (foreignKey.onDelete !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[foreignKey.onDelete];\n if (!action) {\n throw new Error(`Unknown referential action for onDelete: ${String(foreignKey.onDelete)}`);\n }\n sql += `\\nON DELETE ${action}`;\n }\n if (foreignKey.onUpdate !== undefined) {\n const action = REFERENTIAL_ACTION_SQL[foreignKey.onUpdate];\n if (!action) {\n throw new Error(`Unknown referential action for onUpdate: ${String(foreignKey.onUpdate)}`);\n }\n sql += `\\nON UPDATE ${action}`;\n }\n\n return sql;\n}\n"],"mappings":";;;AAcA,SAAgB,oBACd,oBACA,OACA,YACA,eAA+E,CAAC,GACxE;CACR,MAAM,oBAAoB,OAAO,QAAQ,MAAM,OAAO,EAAE,KACrD,CAAC,YAAY,YAAqC;EAOjD,OANc;GACZ,gBAAgB,UAAU;GAC1B,mBAAmB,QAAQ,YAAY,YAAY;GACnD,sBAAsB,OAAO,SAAS,MAAM;GAC5C,OAAO,WAAW,KAAK;EACzB,EAAE,OAAO,OACE,EAAE,KAAK,GAAG;CACvB,CACF;CAEA,MAAM,wBAAkC,CAAC;CACzC,IAAI,MAAM,YACR,sBAAsB,KACpB,gBAAgB,MAAM,WAAW,QAAQ,IAAI,eAAe,EAAE,KAAK,IAAI,EAAE,EAC3E;CAIF,OAAO,gBAAgB,mBAAmB,QAAQ,CAD1B,GAAG,mBAAmB,GAAG,qBACc,EAAE,KAAK,OAAO,EAAE;AACjF;;;;;;AAOA,MAAM,2BAA2B;AAEjC,SAAS,qBAAqB,YAA0B;CACtD,IAAI,CAAC,yBAAyB,KAAK,UAAU,GAC3C,MAAM,IAAI,MACR,yCAAyC,WAAW,qEAEtD;AAEJ;;;;;;AAOA,SAAS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,UACA,UAAA,EAAY,UAAA"}
1
+ {"version":3,"file":"planner-ddl-builders.d.mts","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"mappings":";;;;;iBAcgB,mBAAA,CACd,kBAAA,UACA,KAAA,EAAO,YAAA,EACP,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,YAAA,GAAc,MAAA,SAAe,mBAAA,GAAsB,wBAAA;;AAJrD;;;;;;iBAkEgB,kBAAA,CACd,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,YAAA,GAAc,MAAA,SAAe,mBAAA,GAAsB,wBAAA,GACnD,gBAAA;;iBAqEc,qBAAA,CACd,aAAA,EAAe,qBAAA,cACf,MAAA,GAAS,aAAa;AAAA,iBAqBR,oBAAA,CAAqB,KAAA,WAAgB,MAAA,GAAS,aAAa;AAAA,iBAsB3D,iBAAA,CACd,kBAAA,UACA,UAAA,UACA,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,gBAAA,kBACA,YAAA,GAAc,MAAA,SAAe,mBAAA,GAAsB,wBAAA;AAAA,iBAuBrC,kBAAA,CACd,UAAA,UACA,SAAA,UACA,MAAA,UACA,UAAA,EAAY,UAAU"}
@@ -1,2 +1,2 @@
1
- import { a as buildForeignKeySql, i as buildCreateTableSql, n as buildColumnDefaultSql, o as renderDefaultLiteral, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-DYMuN0w1.mjs";
1
+ import { a as buildForeignKeySql, i as buildCreateTableSql, n as buildColumnDefaultSql, o as renderDefaultLiteral, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders--0TmW6Ey.mjs";
2
2
  export { buildAddColumnSql, buildColumnDefaultSql, buildColumnTypeSql, buildCreateTableSql, buildForeignKeySql, renderDefaultLiteral };
@@ -1 +1 @@
1
- {"version":3,"file":"planner-identity-values-ojX-6cPV.mjs","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresEnumType } from '../postgres-enum-type';\n\n/**\n * Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.\n * Checks codec hooks first (extensions can provide type-specific identity values),\n * then falls back to the built-in map.\n */\nexport function resolveIdentityValue(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string | null {\n const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;\n const referencedIsEnum =\n referencedType !== undefined && isPostgresEnumStorageEntry(referencedType);\n const referencedBinding = referencedIsEnum\n ? ((referencedType as PostgresEnumType).codecBinding ?? {\n codecId: (referencedType as PostgresEnumStorageEntry).codecId,\n typeParams: { values: (referencedType as PostgresEnumStorageEntry).values },\n })\n : undefined;\n const codecId =\n referencedBinding?.codecId ??\n (referencedType && !referencedIsEnum\n ? (referencedType as StorageTypeInstance).codecId\n : undefined) ??\n column.codecId;\n const nativeType = referencedType?.nativeType ?? column.nativeType;\n const typeParams =\n (referencedBinding?.typeParams as Record<string, unknown> | undefined) ??\n (referencedType && !referencedIsEnum\n ? (referencedType as StorageTypeInstance).typeParams\n : undefined) ??\n column.typeParams;\n\n if (codecId) {\n const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({\n nativeType,\n codecId,\n ...ifDefined('typeParams', typeParams),\n });\n if (hookDefault !== undefined) {\n return hookDefault;\n }\n }\n\n return buildBuiltinIdentityValue(nativeType, typeParams);\n}\n\n/**\n * Returns the built-in identity value (monoid neutral element) as a SQL literal for the given\n * PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.\n *\n * This is the planner's fallback when no codec hook provides a type-specific identity value.\n *\n * Returns null for unrecognized types (for example enums and extension-owned types without a\n * hook), which causes the planner to fall back to the empty-table precheck.\n *\n * @internal Exported for testing only.\n */\nexport function buildBuiltinIdentityValue(\n nativeType: string,\n typeParams?: Record<string, unknown>,\n): string | null {\n const normalizedNativeType = normalizeIdentityValueNativeType(nativeType);\n\n if (normalizedNativeType.endsWith('[]')) {\n return \"'{}'\";\n }\n\n switch (normalizedNativeType) {\n case 'text':\n case 'character':\n case 'bpchar':\n case 'character varying':\n case 'varchar':\n return \"''\";\n\n case 'int2':\n case 'int4':\n case 'int8':\n case 'integer':\n case 'bigint':\n case 'smallint':\n case 'float4':\n case 'float8':\n case 'real':\n case 'double precision':\n case 'numeric':\n case 'decimal':\n return '0';\n\n case 'bool':\n case 'boolean':\n return 'false';\n\n case 'uuid':\n return \"'00000000-0000-0000-0000-000000000000'\";\n\n case 'json':\n return \"'{}'::json\";\n case 'jsonb':\n return \"'{}'::jsonb\";\n\n case 'date':\n case 'timestamp':\n case 'timestamptz':\n case 'timestamp with time zone':\n case 'timestamp without time zone':\n return \"'epoch'\";\n\n case 'time':\n case 'time without time zone':\n return \"'00:00:00'\";\n case 'timetz':\n case 'time with time zone':\n return \"'00:00:00+00'\";\n\n case 'interval':\n return \"'0'\";\n\n case 'bytea':\n return \"''::bytea\";\n case 'tsvector':\n return \"''::tsvector\";\n\n case 'bit':\n return buildBitIdentityValue(typeParams);\n case 'bit varying':\n case 'varbit':\n return \"B''\";\n\n default:\n return null;\n }\n}\n\nfunction normalizeIdentityValueNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase().replace(/\\s+/g, ' ');\n}\n\nfunction buildBitIdentityValue(typeParams?: Record<string, unknown>): string | null {\n const length = typeParams?.['length'];\n if (length === undefined) {\n return \"B'0'\";\n }\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n return `B'${'0'.repeat(length)}'`;\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,qBACd,QACA,YACA,eAA+E,EAAE,EAClE;CAC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AK,SACH,OAAO;EACT,KAAK,YACH,OAAO;EAET,KAAK,OACH,OAAO,sBAAsB,WAAW;EAC1C,KAAK;EACL,KAAK,UACH,OAAO;EAET,SACE,OAAO;;;AAIb,SAAS,iCAAiC,YAA4B;CACpE,OAAO,WAAW,MAAM,CAAC,aAAa,CAAC,QAAQ,QAAQ,IAAI;;AAG7D,SAAS,sBAAsB,YAAqD;CAClF,MAAM,SAAS,aAAa;CAC5B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,IAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,OAAO,IAAI,UAAU,GACvE,OAAO;CAET,OAAO,KAAK,IAAI,OAAO,OAAO,CAAC"}
1
+ {"version":3,"file":"planner-identity-values-ojX-6cPV.mjs","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresEnumType } from '../postgres-enum-type';\n\n/**\n * Resolves the identity value (monoid neutral element) as a SQL literal for a column's type.\n * Checks codec hooks first (extensions can provide type-specific identity values),\n * then falls back to the built-in map.\n */\nexport function resolveIdentityValue(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string | null {\n const referencedType = column.typeRef ? storageTypes[column.typeRef] : undefined;\n const referencedIsEnum =\n referencedType !== undefined && isPostgresEnumStorageEntry(referencedType);\n const referencedBinding = referencedIsEnum\n ? ((referencedType as PostgresEnumType).codecBinding ?? {\n codecId: (referencedType as PostgresEnumStorageEntry).codecId,\n typeParams: { values: (referencedType as PostgresEnumStorageEntry).values },\n })\n : undefined;\n const codecId =\n referencedBinding?.codecId ??\n (referencedType && !referencedIsEnum\n ? (referencedType as StorageTypeInstance).codecId\n : undefined) ??\n column.codecId;\n const nativeType = referencedType?.nativeType ?? column.nativeType;\n const typeParams =\n (referencedBinding?.typeParams as Record<string, unknown> | undefined) ??\n (referencedType && !referencedIsEnum\n ? (referencedType as StorageTypeInstance).typeParams\n : undefined) ??\n column.typeParams;\n\n if (codecId) {\n const hookDefault = codecHooks.get(codecId)?.resolveIdentityValue?.({\n nativeType,\n codecId,\n ...ifDefined('typeParams', typeParams),\n });\n if (hookDefault !== undefined) {\n return hookDefault;\n }\n }\n\n return buildBuiltinIdentityValue(nativeType, typeParams);\n}\n\n/**\n * Returns the built-in identity value (monoid neutral element) as a SQL literal for the given\n * PostgreSQL native type — e.g. 0 for integers, '' for text, false for booleans.\n *\n * This is the planner's fallback when no codec hook provides a type-specific identity value.\n *\n * Returns null for unrecognized types (for example enums and extension-owned types without a\n * hook), which causes the planner to fall back to the empty-table precheck.\n *\n * @internal Exported for testing only.\n */\nexport function buildBuiltinIdentityValue(\n nativeType: string,\n typeParams?: Record<string, unknown>,\n): string | null {\n const normalizedNativeType = normalizeIdentityValueNativeType(nativeType);\n\n if (normalizedNativeType.endsWith('[]')) {\n return \"'{}'\";\n }\n\n switch (normalizedNativeType) {\n case 'text':\n case 'character':\n case 'bpchar':\n case 'character varying':\n case 'varchar':\n return \"''\";\n\n case 'int2':\n case 'int4':\n case 'int8':\n case 'integer':\n case 'bigint':\n case 'smallint':\n case 'float4':\n case 'float8':\n case 'real':\n case 'double precision':\n case 'numeric':\n case 'decimal':\n return '0';\n\n case 'bool':\n case 'boolean':\n return 'false';\n\n case 'uuid':\n return \"'00000000-0000-0000-0000-000000000000'\";\n\n case 'json':\n return \"'{}'::json\";\n case 'jsonb':\n return \"'{}'::jsonb\";\n\n case 'date':\n case 'timestamp':\n case 'timestamptz':\n case 'timestamp with time zone':\n case 'timestamp without time zone':\n return \"'epoch'\";\n\n case 'time':\n case 'time without time zone':\n return \"'00:00:00'\";\n case 'timetz':\n case 'time with time zone':\n return \"'00:00:00+00'\";\n\n case 'interval':\n return \"'0'\";\n\n case 'bytea':\n return \"''::bytea\";\n case 'tsvector':\n return \"''::tsvector\";\n\n case 'bit':\n return buildBitIdentityValue(typeParams);\n case 'bit varying':\n case 'varbit':\n return \"B''\";\n\n default:\n return null;\n }\n}\n\nfunction normalizeIdentityValueNativeType(nativeType: string): string {\n return nativeType.trim().toLowerCase().replace(/\\s+/g, ' ');\n}\n\nfunction buildBitIdentityValue(typeParams?: Record<string, unknown>): string | null {\n const length = typeParams?.['length'];\n if (length === undefined) {\n return \"B'0'\";\n }\n if (typeof length !== 'number' || !Number.isInteger(length) || length <= 0) {\n return null;\n }\n return `B'${'0'.repeat(length)}'`;\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,qBACd,QACA,YACA,eAA+E,CAAC,GACjE;CACf,MAAM,iBAAiB,OAAO,UAAU,aAAa,OAAO,WAAW,KAAA;CACvE,MAAM,mBACJ,mBAAmB,KAAA,KAAa,2BAA2B,cAAc;CAC3E,MAAM,oBAAoB,mBACpB,eAAoC,gBAAgB;EACpD,SAAU,eAA4C;EACtD,YAAY,EAAE,QAAS,eAA4C,OAAO;CAC5E,IACA,KAAA;CACJ,MAAM,UACJ,mBAAmB,YAClB,kBAAkB,CAAC,mBACf,eAAuC,UACxC,KAAA,MACJ,OAAO;CACT,MAAM,aAAa,gBAAgB,cAAc,OAAO;CACxD,MAAM,aACH,mBAAmB,eACnB,kBAAkB,CAAC,mBACf,eAAuC,aACxC,KAAA,MACJ,OAAO;CAET,IAAI,SAAS;EACX,MAAM,cAAc,WAAW,IAAI,OAAO,GAAG,uBAAuB;GAClE;GACA;GACA,GAAG,UAAU,cAAc,UAAU;EACvC,CAAC;EACD,IAAI,gBAAgB,KAAA,GAClB,OAAO;CAEX;CAEA,OAAO,0BAA0B,YAAY,UAAU;AACzD;;;;;;;;;;;;AAaA,SAAgB,0BACd,YACA,YACe;CACf,MAAM,uBAAuB,iCAAiC,UAAU;CAExE,IAAI,qBAAqB,SAAS,IAAI,GACpC,OAAO;CAGT,QAAQ,sBAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WACH,OAAO;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WACH,OAAO;EAET,KAAK;EACL,KAAK,WACH,OAAO;EAET,KAAK,QACH,OAAO;EAET,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO;EAET,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,+BACH,OAAO;EAET,KAAK;EACL,KAAK,0BACH,OAAO;EACT,KAAK;EACL,KAAK,uBACH,OAAO;EAET,KAAK,YACH,OAAO;EAET,KAAK,SACH,OAAO;EACT,KAAK,YACH,OAAO;EAET,KAAK,OACH,OAAO,sBAAsB,UAAU;EACzC,KAAK;EACL,KAAK,UACH,OAAO;EAET,SACE,OAAO;CACX;AACF;AAEA,SAAS,iCAAiC,YAA4B;CACpE,OAAO,WAAW,KAAK,EAAE,YAAY,EAAE,QAAQ,QAAQ,GAAG;AAC5D;AAEA,SAAS,sBAAsB,YAAqD;CAClF,MAAM,SAAS,aAAa;CAC5B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,IAAI,OAAO,WAAW,YAAY,CAAC,OAAO,UAAU,MAAM,KAAK,UAAU,GACvE,OAAO;CAET,OAAO,KAAK,IAAI,OAAO,MAAM,EAAE;AACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-identity-values.d.mts","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"mappings":";;;;;;;;;;;;;;;iBAoEgB,yBAAA,CACd,UAAA,UACA,UAAA,GAAa,MAAA"}
1
+ {"version":3,"file":"planner-identity-values.d.mts","names":[],"sources":["../src/core/migrations/planner-identity-values.ts"],"mappings":";;;;;;;;AAsEsC;;;;;;;iBAFtB,yBAAA,CACd,UAAA,UACA,UAAA,GAAa,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-produced-postgres-migration-TJWH2m_x.mjs","names":["#calls","#meta","#spaceId"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type {\n MigrationPlanWithAuthoringSurface,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly OpFactoryCall[];\n readonly #meta: MigrationMeta;\n readonly #spaceId: string;\n\n constructor(calls: readonly OpFactoryCall[], meta: MigrationMeta, spaceId: string) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n this.#spaceId = spaceId;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n /**\n * Contract space this planner-produced plan applies to. Threaded\n * from the planner options so the runner keys the marker row by\n * the right space when executing the plan.\n */\n get spaceId(): string {\n return this.#spaceId;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;AAuCA,IAAa,wCAAb,cACU,kBAEV;CACE;CACA;CACA;CAEA,YAAY,OAAiC,MAAqB,SAAiB;EACjF,OAAO;EACP,KAAKA,SAAS;EACd,KAAKC,QAAQ;EACb,KAAKC,WAAW;;CAGlB,IAAa,aAA4B;EACvC,OAAO,UAAU,KAAKF,OAAO;;CAG/B,WAAmC;EACjC,OAAO,KAAKC;;;;;;;CAQd,IAAI,UAAkB;EACpB,OAAO,KAAKC;;CAGd,mBAA2B;EACzB,OAAO,wBAAwB,KAAKF,QAAQ;GAC1C,MAAM,KAAKC,MAAM;GACjB,IAAI,KAAKA,MAAM;GACf,GAAG,UAAU,UAAU,KAAKA,MAAM,OAAO;GAC1C,CAAC"}
1
+ {"version":3,"file":"planner-produced-postgres-migration-TJWH2m_x.mjs","names":["#calls","#meta","#spaceId"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type {\n MigrationPlanWithAuthoringSurface,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly OpFactoryCall[];\n readonly #meta: MigrationMeta;\n readonly #spaceId: string;\n\n constructor(calls: readonly OpFactoryCall[], meta: MigrationMeta, spaceId: string) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n this.#spaceId = spaceId;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n /**\n * Contract space this planner-produced plan applies to. Threaded\n * from the planner options so the runner keys the marker row by\n * the right space when executing the plan.\n */\n get spaceId(): string {\n return this.#spaceId;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;AAuCA,IAAa,wCAAb,cACU,kBAEV;CACE;CACA;CACA;CAEA,YAAY,OAAiC,MAAqB,SAAiB;EACjF,MAAM;EACN,KAAKA,SAAS;EACd,KAAKC,QAAQ;EACb,KAAKC,WAAW;CAClB;CAEA,IAAa,aAA4B;EACvC,OAAO,UAAU,KAAKF,MAAM;CAC9B;CAEA,WAAmC;EACjC,OAAO,KAAKC;CACd;;;;;;CAOA,IAAI,UAAkB;EACpB,OAAO,KAAKC;CACd;CAEA,mBAA2B;EACzB,OAAO,wBAAwB,KAAKF,QAAQ;GAC1C,MAAM,KAAKC,MAAM;GACjB,IAAI,KAAKA,MAAM;GACf,GAAG,UAAU,UAAU,KAAKA,MAAM,MAAM;EAC1C,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-produced-postgres-migration-p-VKkCia.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"mappings":";;;;;;;KAqCK,EAAA,GAAK,yBAAA,CAA0B,yBAAA;AAAA,cAEvB,qCAAA,SACH,iBAAA,YACG,iCAAA;EAAA;cAMC,KAAA,WAAgB,aAAA,IAAiB,IAAA,EAAM,aAAA,EAAe,OAAA;EAAA,IAOrD,UAAA,CAAA,YAAuB,EAAA;EAI3B,QAAA,CAAA,GAAY,aAAA;EAAA;;;;;EAAA,IASjB,OAAA,CAAA;EAIJ,gBAAA,CAAA;AAAA"}
1
+ {"version":3,"file":"planner-produced-postgres-migration-p-VKkCia.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"mappings":";;;;;;;KAqCK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,cAEvB,qCAAA,SACH,iBAAA,YACG,iCAAA;EAAA;cAMC,KAAA,WAAgB,aAAA,IAAiB,IAAA,EAAM,aAAA,EAAe,OAAA;EAAA,IAOrD,UAAA,CAAA,YAAuB,EAAA;EAI3B,QAAA,CAAA,GAAY,aAAA;EAAA;;;;AAaL;EAbK,IASjB,OAAA,CAAA;EAIJ,gBAAA,CAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-schema-lookup-BGyukuzG.mjs","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { ForeignKey } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * Pre-computed lookup sets for a schema table's constraints.\n * Converts O(n*m) linear scans to O(1) Set lookups per constraint check.\n */\nexport interface SchemaTableLookup {\n readonly uniqueKeys: Set<string>;\n readonly indexKeys: Set<string>;\n readonly uniqueIndexKeys: Set<string>;\n readonly fkKeys: Set<string>;\n}\n\nexport function buildSchemaLookupMap(schema: SqlSchemaIR): ReadonlyMap<string, SchemaTableLookup> {\n const map = new Map<string, SchemaTableLookup>();\n for (const [tableName, table] of Object.entries(schema.tables)) {\n map.set(tableName, buildSchemaTableLookup(table));\n }\n return map;\n}\n\nfunction buildSchemaTableLookup(table: SqlSchemaIR['tables'][string]): SchemaTableLookup {\n const uniqueKeys = new Set(table.uniques.map((u) => u.columns.join(',')));\n const indexKeys = new Set(table.indexes.map((i) => i.columns.join(',')));\n const uniqueIndexKeys = new Set(\n table.indexes.filter((i) => i.unique).map((i) => i.columns.join(',')),\n );\n const fkKeys = new Set<string>();\n for (const fk of table.foreignKeys) {\n // Keys are JSON-encoded tuples so identifiers containing any character\n // (including the column-list comma or pipe characters) cannot collide\n // across structurally-distinct FKs. Unqualified keys are 3-tuples\n // (cols, table, refCols); qualified keys are 4-tuples\n // (cols, schema, table, refCols) — the arity difference makes the two\n // key shapes fundamentally non-collidable.\n fkKeys.add(JSON.stringify([fk.columns, fk.referencedTable, fk.referencedColumns]));\n if (fk.referencedSchema !== undefined) {\n fkKeys.add(\n JSON.stringify([fk.columns, fk.referencedSchema, fk.referencedTable, fk.referencedColumns]),\n );\n }\n }\n return { uniqueKeys, indexKeys, uniqueIndexKeys, fkKeys };\n}\n\nexport function hasUniqueConstraint(\n lookup: SchemaTableLookup,\n columns: readonly string[],\n): boolean {\n const key = columns.join(',');\n return lookup.uniqueKeys.has(key) || lookup.uniqueIndexKeys.has(key);\n}\n\nexport function hasIndex(lookup: SchemaTableLookup, columns: readonly string[]): boolean {\n const key = columns.join(',');\n return lookup.indexKeys.has(key) || lookup.uniqueKeys.has(key);\n}\n\nexport function hasForeignKey(lookup: SchemaTableLookup, fk: ForeignKey): boolean {\n // Mirror the encoding produced by buildSchemaTableLookup exactly:\n // unqualified 3-tuple for unbound-namespace FKs, qualified 4-tuple for\n // bound-namespace FKs.\n if (fk.target.namespaceId === UNBOUND_NAMESPACE_ID) {\n return lookup.fkKeys.has(\n JSON.stringify([fk.source.columns, fk.target.tableName, fk.target.columns]),\n );\n }\n return lookup.fkKeys.has(\n JSON.stringify([\n fk.source.columns,\n fk.target.namespaceId,\n fk.target.tableName,\n fk.target.columns,\n ]),\n );\n}\n"],"mappings":";;AAeA,SAAgB,qBAAqB,QAA6D;CAChG,MAAM,sBAAM,IAAI,KAAgC;CAChD,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,OAAO,EAC5D,IAAI,IAAI,WAAW,uBAAuB,MAAM,CAAC;CAEnD,OAAO;;AAGT,SAAS,uBAAuB,OAAyD;CACvF,MAAM,aAAa,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC;CACzE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC;CACxE,MAAM,kBAAkB,IAAI,IAC1B,MAAM,QAAQ,QAAQ,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,EAAE,QAAQ,KAAK,IAAI,CAAC,CACtE;CACD,MAAM,yBAAS,IAAI,KAAa;CAChC,KAAK,MAAM,MAAM,MAAM,aAAa;EAOlC,OAAO,IAAI,KAAK,UAAU;GAAC,GAAG;GAAS,GAAG;GAAiB,GAAG;GAAkB,CAAC,CAAC;EAClF,IAAI,GAAG,qBAAqB,KAAA,GAC1B,OAAO,IACL,KAAK,UAAU;GAAC,GAAG;GAAS,GAAG;GAAkB,GAAG;GAAiB,GAAG;GAAkB,CAAC,CAC5F;;CAGL,OAAO;EAAE;EAAY;EAAW;EAAiB;EAAQ;;AAG3D,SAAgB,oBACd,QACA,SACS;CACT,MAAM,MAAM,QAAQ,KAAK,IAAI;CAC7B,OAAO,OAAO,WAAW,IAAI,IAAI,IAAI,OAAO,gBAAgB,IAAI,IAAI;;AAGtE,SAAgB,SAAS,QAA2B,SAAqC;CACvF,MAAM,MAAM,QAAQ,KAAK,IAAI;CAC7B,OAAO,OAAO,UAAU,IAAI,IAAI,IAAI,OAAO,WAAW,IAAI,IAAI;;AAGhE,SAAgB,cAAc,QAA2B,IAAyB;CAIhF,IAAI,GAAG,OAAO,gBAAgB,sBAC5B,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EAAC,GAAG,OAAO;EAAS,GAAG,OAAO;EAAW,GAAG,OAAO;EAAQ,CAAC,CAC5E;CAEH,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EACb,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACX,CAAC,CACH"}
1
+ {"version":3,"file":"planner-schema-lookup-BGyukuzG.mjs","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { ForeignKey } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\n\n/**\n * Pre-computed lookup sets for a schema table's constraints.\n * Converts O(n*m) linear scans to O(1) Set lookups per constraint check.\n */\nexport interface SchemaTableLookup {\n readonly uniqueKeys: Set<string>;\n readonly indexKeys: Set<string>;\n readonly uniqueIndexKeys: Set<string>;\n readonly fkKeys: Set<string>;\n}\n\nexport function buildSchemaLookupMap(schema: SqlSchemaIR): ReadonlyMap<string, SchemaTableLookup> {\n const map = new Map<string, SchemaTableLookup>();\n for (const [tableName, table] of Object.entries(schema.tables)) {\n map.set(tableName, buildSchemaTableLookup(table));\n }\n return map;\n}\n\nfunction buildSchemaTableLookup(table: SqlSchemaIR['tables'][string]): SchemaTableLookup {\n const uniqueKeys = new Set(table.uniques.map((u) => u.columns.join(',')));\n const indexKeys = new Set(table.indexes.map((i) => i.columns.join(',')));\n const uniqueIndexKeys = new Set(\n table.indexes.filter((i) => i.unique).map((i) => i.columns.join(',')),\n );\n const fkKeys = new Set<string>();\n for (const fk of table.foreignKeys) {\n // Keys are JSON-encoded tuples so identifiers containing any character\n // (including the column-list comma or pipe characters) cannot collide\n // across structurally-distinct FKs. Unqualified keys are 3-tuples\n // (cols, table, refCols); qualified keys are 4-tuples\n // (cols, schema, table, refCols) — the arity difference makes the two\n // key shapes fundamentally non-collidable.\n fkKeys.add(JSON.stringify([fk.columns, fk.referencedTable, fk.referencedColumns]));\n if (fk.referencedSchema !== undefined) {\n fkKeys.add(\n JSON.stringify([fk.columns, fk.referencedSchema, fk.referencedTable, fk.referencedColumns]),\n );\n }\n }\n return { uniqueKeys, indexKeys, uniqueIndexKeys, fkKeys };\n}\n\nexport function hasUniqueConstraint(\n lookup: SchemaTableLookup,\n columns: readonly string[],\n): boolean {\n const key = columns.join(',');\n return lookup.uniqueKeys.has(key) || lookup.uniqueIndexKeys.has(key);\n}\n\nexport function hasIndex(lookup: SchemaTableLookup, columns: readonly string[]): boolean {\n const key = columns.join(',');\n return lookup.indexKeys.has(key) || lookup.uniqueKeys.has(key);\n}\n\nexport function hasForeignKey(lookup: SchemaTableLookup, fk: ForeignKey): boolean {\n // Mirror the encoding produced by buildSchemaTableLookup exactly:\n // unqualified 3-tuple for unbound-namespace FKs, qualified 4-tuple for\n // bound-namespace FKs.\n if (fk.target.namespaceId === UNBOUND_NAMESPACE_ID) {\n return lookup.fkKeys.has(\n JSON.stringify([fk.source.columns, fk.target.tableName, fk.target.columns]),\n );\n }\n return lookup.fkKeys.has(\n JSON.stringify([\n fk.source.columns,\n fk.target.namespaceId,\n fk.target.tableName,\n fk.target.columns,\n ]),\n );\n}\n"],"mappings":";;AAeA,SAAgB,qBAAqB,QAA6D;CAChG,MAAM,sBAAM,IAAI,IAA+B;CAC/C,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,MAAM,GAC3D,IAAI,IAAI,WAAW,uBAAuB,KAAK,CAAC;CAElD,OAAO;AACT;AAEA,SAAS,uBAAuB,OAAyD;CACvF,MAAM,aAAa,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC;CACxE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ,KAAK,MAAM,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC;CACvE,MAAM,kBAAkB,IAAI,IAC1B,MAAM,QAAQ,QAAQ,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,QAAQ,KAAK,GAAG,CAAC,CACtE;CACA,MAAM,yBAAS,IAAI,IAAY;CAC/B,KAAK,MAAM,MAAM,MAAM,aAAa;EAOlC,OAAO,IAAI,KAAK,UAAU;GAAC,GAAG;GAAS,GAAG;GAAiB,GAAG;EAAiB,CAAC,CAAC;EACjF,IAAI,GAAG,qBAAqB,KAAA,GAC1B,OAAO,IACL,KAAK,UAAU;GAAC,GAAG;GAAS,GAAG;GAAkB,GAAG;GAAiB,GAAG;EAAiB,CAAC,CAC5F;CAEJ;CACA,OAAO;EAAE;EAAY;EAAW;EAAiB;CAAO;AAC1D;AAEA,SAAgB,oBACd,QACA,SACS;CACT,MAAM,MAAM,QAAQ,KAAK,GAAG;CAC5B,OAAO,OAAO,WAAW,IAAI,GAAG,KAAK,OAAO,gBAAgB,IAAI,GAAG;AACrE;AAEA,SAAgB,SAAS,QAA2B,SAAqC;CACvF,MAAM,MAAM,QAAQ,KAAK,GAAG;CAC5B,OAAO,OAAO,UAAU,IAAI,GAAG,KAAK,OAAO,WAAW,IAAI,GAAG;AAC/D;AAEA,SAAgB,cAAc,QAA2B,IAAyB;CAIhF,IAAI,GAAG,OAAO,gBAAgB,sBAC5B,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EAAC,GAAG,OAAO;EAAS,GAAG,OAAO;EAAW,GAAG,OAAO;CAAO,CAAC,CAC5E;CAEF,OAAO,OAAO,OAAO,IACnB,KAAK,UAAU;EACb,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;CACZ,CAAC,CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-schema-lookup.d.mts","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"mappings":";;;;;;AAQA;;UAAiB,iBAAA;EAAA,SACN,UAAA,EAAY,GAAA;EAAA,SACZ,SAAA,EAAW,GAAA;EAAA,SACX,eAAA,EAAiB,GAAA;EAAA,SACjB,MAAA,EAAQ,GAAA;AAAA;AAAA,iBAGH,oBAAA,CAAqB,MAAA,EAAQ,WAAA,GAAc,WAAA,SAAoB,iBAAA;AAAA,iBAgC/D,mBAAA,CACd,MAAA,EAAQ,iBAAA,EACR,OAAA;AAAA,iBAMc,QAAA,CAAS,MAAA,EAAQ,iBAAA,EAAmB,OAAA;AAAA,iBAKpC,aAAA,CAAc,MAAA,EAAQ,iBAAA,EAAmB,EAAA,EAAI,UAAA"}
1
+ {"version":3,"file":"planner-schema-lookup.d.mts","names":[],"sources":["../src/core/migrations/planner-schema-lookup.ts"],"mappings":";;;;;;AAQA;;UAAiB,iBAAA;EAAA,SACN,UAAA,EAAY,GAAA;EAAA,SACZ,SAAA,EAAW,GAAA;EAAA,SACX,eAAA,EAAiB,GAAA;EAAA,SACjB,MAAA,EAAQ,GAAA;AAAA;AAAA,iBAGH,oBAAA,CAAqB,MAAA,EAAQ,WAAA,GAAc,WAAA,SAAoB,iBAAA;AAAA,iBAgC/D,mBAAA,CACd,MAAA,EAAQ,iBAAiB,EACzB,OAAA;AAAA,iBAMc,QAAA,CAAS,MAAA,EAAQ,iBAAiB,EAAE,OAAA;AAAA,iBAKpC,aAAA,CAAc,MAAA,EAAQ,iBAAA,EAAmB,EAAA,EAAI,UAAU"}
@@ -1,5 +1,5 @@
1
1
  import { i as quoteIdentifier, n as escapeLiteral } from "./sql-utils-BewXAnsG.mjs";
2
- import { i as postgresCreateNamespace } from "./postgres-schema-CK82EuWq.mjs";
2
+ import { i as postgresCreateNamespace } from "./postgres-schema-BL0RAvew.mjs";
3
3
  import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
4
4
  //#region src/core/migrations/planner-type-resolution.ts
5
5
  function resolveColumnTypeMetadata(column, storageTypes) {
@@ -258,4 +258,4 @@ function tableHasPrimaryKeyCheck(schema, table, exists, constraintName) {
258
258
  //#endregion
259
259
  export { columnNullabilityCheck as a, qualifyTableName as c, toRegclassLiteral as d, resolveColumnTypeMetadata as f, columnHasNoDefaultCheck as i, tableHasPrimaryKeyCheck as l, columnDefaultExistsCheck as n, columnTypeCheck as o, columnExistsCheck as r, constraintExistsCheck as s, buildExpectedFormatType as t, tableIsEmptyCheck as u };
260
260
 
261
- //# sourceMappingURL=planner-sql-checks-K-mTBJDi.mjs.map
261
+ //# sourceMappingURL=planner-sql-checks-BDtJQ9WD.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"planner-sql-checks-K-mTBJDi.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts","../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\n\nexport type ResolvedColumnTypeMetadata = Pick<\n StorageColumn,\n 'nativeType' | 'codecId' | 'typeParams'\n>;\n\nexport function resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n return column;\n }\n\n if (isPostgresEnumStorageEntry(referencedType)) {\n // Enum types are referenced by name (`quoteIdentifier(nativeType)`),\n // not via parameterised codec expansion. The structural shape\n // carries `codecId` as an enumerable property (mirroring the\n // codec-typed view); `typeParams` is intentionally omitted here so\n // `expandParameterizedTypeSql` does not try to look up a\n // (deliberately absent) `expandNativeType` hook for `pg/enum@*`.\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n };\n }\n\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n","import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n PostgresEnumStorageEntry,\n StorageColumn,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { postgresCreateNamespace } from '../postgres-schema';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\n/**\n * String-keyed entry points the migration ops use to render\n * schema-qualified DDL and catalog checks. The `schema` argument is\n * interpreted as a namespace coordinate: the framework `__unbound__`\n * sentinel resolves to the late-bound `PostgresUnboundSchema` singleton\n * (which elides the qualifier so `search_path` decides at runtime); any\n * other id materialises a `PostgresSchema(id)` whose qualifier is the\n * named schema. Helpers route through these `Namespace` concretions so\n * the unbound branch lives in the polymorphic override, not the call\n * site.\n */\nexport function qualifyTableName(schema: string, table: string): string {\n return postgresCreateNamespace({ id: schema }).qualifyTable(table);\n}\n\nexport function toRegclassLiteral(schema: string, name: string): string {\n return postgresCreateNamespace({ id: schema }).regclassLiteral(name);\n}\n\n/**\n * When `table` is omitted the check matches by name + schema across all tables.\n * Pass `table` to scope the check to a single table (prevents false matches on\n * identically-named constraints in different tables).\n */\nexport function constraintExistsCheck({\n constraintName,\n schema,\n table,\n exists = true,\n}: {\n constraintName: string;\n schema: string;\n table?: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n const tableFilter = table\n ? `AND c.conrelid = to_regclass(${namespace.regclassLiteral(table)})`\n : '';\n return `SELECT ${existsClause} (\n SELECT 1 FROM pg_constraint c\n JOIN pg_namespace n ON c.connamespace = n.oid\n WHERE c.conname = '${escapeLiteral(constraintName)}'\n AND n.nspname = ${namespace.schemaSqlExpression()}\n ${tableFilter}\n)`;\n}\n\nexport function columnExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? '' : 'NOT ';\n return `SELECT ${existsClause}EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n)`;\n}\n\nexport function columnNullabilityCheck({\n schema,\n table,\n column,\n nullable,\n}: {\n schema: string;\n table: string;\n column: string;\n nullable: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const expected = nullable ? 'YES' : 'NO';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND is_nullable = '${expected}'\n)`;\n}\n\nexport function tableIsEmptyCheck(qualifiedTableName: string): string {\n return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifiedTableName} LIMIT 1)`;\n}\n\nexport function columnHasNoDefaultCheck(opts: {\n schema: string;\n table: string;\n column: string;\n}): string {\n const namespace = postgresCreateNamespace({ id: opts.schema });\n return `SELECT NOT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(opts.table)}'\n AND column_name = '${escapeLiteral(opts.column)}'\n AND column_default IS NOT NULL\n)`;\n}\n\nconst FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string> = new Map([\n ['int2', 'smallint'],\n ['int4', 'integer'],\n ['int8', 'bigint'],\n ['float4', 'real'],\n ['float8', 'double precision'],\n ['bool', 'boolean'],\n ['timestamp', 'timestamp without time zone'],\n ['timestamptz', 'timestamp with time zone'],\n ['time', 'time without time zone'],\n ['timetz', 'time with time zone'],\n]);\n\nconst UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;\n\nconst POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([\n 'all',\n 'analyse',\n 'analyze',\n 'and',\n 'any',\n 'array',\n 'as',\n 'asc',\n 'asymmetric',\n 'authorization',\n 'between',\n 'binary',\n 'both',\n 'case',\n 'cast',\n 'check',\n 'collate',\n 'column',\n 'constraint',\n 'create',\n 'current_catalog',\n 'current_date',\n 'current_role',\n 'current_time',\n 'current_timestamp',\n 'current_user',\n 'default',\n 'deferrable',\n 'desc',\n 'distinct',\n 'do',\n 'else',\n 'end',\n 'except',\n 'false',\n 'fetch',\n 'for',\n 'foreign',\n 'freeze',\n 'from',\n 'full',\n 'grant',\n 'group',\n 'having',\n 'ilike',\n 'in',\n 'initially',\n 'inner',\n 'intersect',\n 'into',\n 'is',\n 'isnull',\n 'join',\n 'lateral',\n 'leading',\n 'left',\n 'like',\n 'limit',\n 'localtime',\n 'localtimestamp',\n 'natural',\n 'not',\n 'notnull',\n 'null',\n 'offset',\n 'on',\n 'only',\n 'or',\n 'order',\n 'outer',\n 'overlaps',\n 'placing',\n 'primary',\n 'references',\n 'right',\n 'select',\n 'session_user',\n 'similar',\n 'some',\n 'symmetric',\n 'table',\n 'then',\n 'to',\n 'trailing',\n 'true',\n 'union',\n 'unique',\n 'user',\n 'using',\n 'variadic',\n 'verbose',\n 'when',\n 'where',\n 'window',\n 'with',\n]);\n\nfunction formatUserDefinedTypeName(identifier: string): string {\n if (\n UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) &&\n !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)\n ) {\n return identifier;\n }\n\n return quoteIdentifier(identifier);\n}\n\nexport function buildExpectedFormatType(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (resolved.typeParams && resolved.codecId) {\n const hooks = codecHooks.get(resolved.codecId);\n if (hooks?.expandNativeType) {\n return hooks.expandNativeType({\n nativeType: resolved.nativeType,\n codecId: resolved.codecId,\n typeParams: resolved.typeParams,\n });\n }\n }\n\n if (column.typeRef) {\n return formatUserDefinedTypeName(resolved.nativeType);\n }\n\n return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;\n}\n\nexport function columnTypeCheck({\n schema,\n table,\n column,\n expectedType,\n}: {\n schema: string;\n table: string;\n column: string;\n expectedType: string;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n return `SELECT EXISTS (\n SELECT 1\n FROM pg_attribute a\n JOIN pg_class c ON c.oid = a.attrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND a.attname = '${escapeLiteral(column)}'\n AND format_type(a.atttypid, a.atttypmod) = '${escapeLiteral(expectedType)}'\n AND NOT a.attisdropped\n)`;\n}\n\nexport function columnDefaultExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const nullCheck = exists ? 'IS NOT NULL' : 'IS NULL';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND column_default ${nullCheck}\n)`;\n}\n\nexport function tableHasPrimaryKeyCheck(\n schema: string,\n table: string,\n exists: boolean,\n constraintName?: string,\n): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const comparison = exists ? '' : 'NOT ';\n const constraintFilter = constraintName\n ? `AND c2.relname = '${escapeLiteral(constraintName)}'`\n : '';\n return `SELECT ${comparison}EXISTS (\n SELECT 1\n FROM pg_index i\n JOIN pg_class c ON c.oid = i.indrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid\n WHERE n.nspname = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND i.indisprimary\n ${constraintFilter}\n)`;\n}\n"],"mappings":";;;;AAYA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,IAAI,2BAA2B,eAAe,EAO5C,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC5B;CAGH,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;EAC5B;;;;;;;;;;;;;;;ACrBH,SAAgB,iBAAiB,QAAgB,OAAuB;CACtE,OAAO,wBAAwB,EAAE,IAAI,QAAQ,CAAC,CAAC,aAAa,MAAM;;AAGpE,SAAgB,kBAAkB,QAAgB,MAAsB;CACtE,OAAO,wBAAwB,EAAE,IAAI,QAAQ,CAAC,CAAC,gBAAgB,KAAK;;;;;;;AAQtE,SAAgB,sBAAsB,EACpC,gBACA,Q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;CAClC,CAAC,UAAU,sBAAsB;CAClC,CAAC;AAEF,MAAM,uCAAuC;AAE7C,MAAM,qCAAqC,IAAI,IAAI;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAS,0BAA0B,YAA4B;CAC7D,IACE,qCAAqC,KAAK,WAAW,IACrD,CAAC,mCAAmC,IAAI,WAAW,EAEnD,OAAO;CAGT,OAAO,gBAAgB,WAAW;;AAGpC,SAAgB,wBACd,QACA,YACA,eAA+E,EAAE,EACzE;CACR,MAAM,WAAW,0BAA0B,QAAQ,aAAa;CAEhE,IAAI,SAAS,cAAc,SAAS,SAAS;EAC3C,MAAM,QAAQ,WAAW,IAAI,SAAS,QAAQ;EAC9C,IAAI,OAAO,kBACT,OAAO,MAAM,iBAAiB;GAC5B,YAAY,SAAS;GACrB,SAAS,SAAS;GAClB,YAAY,SAAS;GACtB,CAAC;;CAIN,IAAI,OAAO,SACT,OAAO,0BAA0B,SAAS,WAAW;CAGvD,OAAO,oBAAoB,IAAI,SAAS,WAAW,IAAI,SAAS;;AAGlE,SAAgB,gBAAgB,EAC9B,QACA,OACA,QACA,gBAMS;CAET,OAAO;;;;;sBADW,wBAAwB,EAAE,IAAI,QAAQ,CAM3B,CAAC,qBAAqB,CAAC;uBAC/B,cAAc,MAAM,CAAC;uBACrB,cAAc,OAAO,CAAC;kDACK,cAAc,aAAa,CAAC;;;;AAK9E,SAAgB,yBAAyB,EACvC,QACA,OACA,QACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,QAAQ,CAAC;CACzD,MAAM,YAAY,SAAS,gBAAgB;CAC3C,OAAO;;;yBAGgB,UAAU,qBAAqB,CAAC;wBACjC,cAAc,MAAM,CAAC;yBACpB,cAAc,OAAO,CAAC;yBACtB,UAAU;;;AAInC,SAAgB,wBACd,QACA,OACA,QACA,gBACQ;CACR,MAAM,YAAY,wBAAwB,EAAE,IAAI,QAAQ,CAAC;CACzD,MAAM,aAAa,SAAS,KAAK;CACjC,MAAM,mBAAmB,iBACrB,qBAAqB,cAAc,eAAe,CAAC,KACnD;CACJ,OAAO,UAAU,WAAW;;;;;;sBAMR,UAAU,qBAAqB,CAAC;uBAC/B,cAAc,MAAM,CAAC;;MAEtC,iBAAiB"}
1
+ {"version":3,"file":"planner-sql-checks-BDtJQ9WD.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts","../src/core/migrations/planner-sql-checks.ts"],"sourcesContent":["import {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\n\nexport type ResolvedColumnTypeMetadata = Pick<\n StorageColumn,\n 'nativeType' | 'codecId' | 'typeParams'\n>;\n\nexport function resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Readonly<Record<string, StorageTypeInstance | PostgresEnumStorageEntry>>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n return column;\n }\n\n if (isPostgresEnumStorageEntry(referencedType)) {\n // Enum types are referenced by name (`quoteIdentifier(nativeType)`),\n // not via parameterised codec expansion. The structural shape\n // carries `codecId` as an enumerable property (mirroring the\n // codec-typed view); `typeParams` is intentionally omitted here so\n // `expandParameterizedTypeSql` does not try to look up a\n // (deliberately absent) `expandNativeType` hook for `pg/enum@*`.\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n };\n }\n\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n","import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n PostgresEnumStorageEntry,\n StorageColumn,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { postgresCreateNamespace } from '../postgres-schema';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\n/**\n * String-keyed entry points the migration ops use to render\n * schema-qualified DDL and catalog checks. The `schema` argument is\n * interpreted as a namespace coordinate: the framework `__unbound__`\n * sentinel resolves to the late-bound `PostgresUnboundSchema` singleton\n * (which elides the qualifier so `search_path` decides at runtime); any\n * other id materialises a `PostgresSchema(id)` whose qualifier is the\n * named schema. Helpers route through these `Namespace` concretions so\n * the unbound branch lives in the polymorphic override, not the call\n * site.\n */\nexport function qualifyTableName(schema: string, table: string): string {\n return postgresCreateNamespace({ id: schema }).qualifyTable(table);\n}\n\nexport function toRegclassLiteral(schema: string, name: string): string {\n return postgresCreateNamespace({ id: schema }).regclassLiteral(name);\n}\n\n/**\n * When `table` is omitted the check matches by name + schema across all tables.\n * Pass `table` to scope the check to a single table (prevents false matches on\n * identically-named constraints in different tables).\n */\nexport function constraintExistsCheck({\n constraintName,\n schema,\n table,\n exists = true,\n}: {\n constraintName: string;\n schema: string;\n table?: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? 'EXISTS' : 'NOT EXISTS';\n const tableFilter = table\n ? `AND c.conrelid = to_regclass(${namespace.regclassLiteral(table)})`\n : '';\n return `SELECT ${existsClause} (\n SELECT 1 FROM pg_constraint c\n JOIN pg_namespace n ON c.connamespace = n.oid\n WHERE c.conname = '${escapeLiteral(constraintName)}'\n AND n.nspname = ${namespace.schemaSqlExpression()}\n ${tableFilter}\n)`;\n}\n\nexport function columnExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const existsClause = exists ? '' : 'NOT ';\n return `SELECT ${existsClause}EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n)`;\n}\n\nexport function columnNullabilityCheck({\n schema,\n table,\n column,\n nullable,\n}: {\n schema: string;\n table: string;\n column: string;\n nullable: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const expected = nullable ? 'YES' : 'NO';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND is_nullable = '${expected}'\n)`;\n}\n\nexport function tableIsEmptyCheck(qualifiedTableName: string): string {\n return `SELECT NOT EXISTS (SELECT 1 FROM ${qualifiedTableName} LIMIT 1)`;\n}\n\nexport function columnHasNoDefaultCheck(opts: {\n schema: string;\n table: string;\n column: string;\n}): string {\n const namespace = postgresCreateNamespace({ id: opts.schema });\n return `SELECT NOT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(opts.table)}'\n AND column_name = '${escapeLiteral(opts.column)}'\n AND column_default IS NOT NULL\n)`;\n}\n\nconst FORMAT_TYPE_DISPLAY: ReadonlyMap<string, string> = new Map([\n ['int2', 'smallint'],\n ['int4', 'integer'],\n ['int8', 'bigint'],\n ['float4', 'real'],\n ['float8', 'double precision'],\n ['bool', 'boolean'],\n ['timestamp', 'timestamp without time zone'],\n ['timestamptz', 'timestamp with time zone'],\n ['time', 'time without time zone'],\n ['timetz', 'time with time zone'],\n]);\n\nconst UNQUOTED_POSTGRES_IDENTIFIER_PATTERN = /^[a-z_][a-z0-9_$]*$/;\n\nconst POSTGRES_RESERVED_IDENTIFIER_WORDS = new Set([\n 'all',\n 'analyse',\n 'analyze',\n 'and',\n 'any',\n 'array',\n 'as',\n 'asc',\n 'asymmetric',\n 'authorization',\n 'between',\n 'binary',\n 'both',\n 'case',\n 'cast',\n 'check',\n 'collate',\n 'column',\n 'constraint',\n 'create',\n 'current_catalog',\n 'current_date',\n 'current_role',\n 'current_time',\n 'current_timestamp',\n 'current_user',\n 'default',\n 'deferrable',\n 'desc',\n 'distinct',\n 'do',\n 'else',\n 'end',\n 'except',\n 'false',\n 'fetch',\n 'for',\n 'foreign',\n 'freeze',\n 'from',\n 'full',\n 'grant',\n 'group',\n 'having',\n 'ilike',\n 'in',\n 'initially',\n 'inner',\n 'intersect',\n 'into',\n 'is',\n 'isnull',\n 'join',\n 'lateral',\n 'leading',\n 'left',\n 'like',\n 'limit',\n 'localtime',\n 'localtimestamp',\n 'natural',\n 'not',\n 'notnull',\n 'null',\n 'offset',\n 'on',\n 'only',\n 'or',\n 'order',\n 'outer',\n 'overlaps',\n 'placing',\n 'primary',\n 'references',\n 'right',\n 'select',\n 'session_user',\n 'similar',\n 'some',\n 'symmetric',\n 'table',\n 'then',\n 'to',\n 'trailing',\n 'true',\n 'union',\n 'unique',\n 'user',\n 'using',\n 'variadic',\n 'verbose',\n 'when',\n 'where',\n 'window',\n 'with',\n]);\n\nfunction formatUserDefinedTypeName(identifier: string): string {\n if (\n UNQUOTED_POSTGRES_IDENTIFIER_PATTERN.test(identifier) &&\n !POSTGRES_RESERVED_IDENTIFIER_WORDS.has(identifier)\n ) {\n return identifier;\n }\n\n return quoteIdentifier(identifier);\n}\n\nexport function buildExpectedFormatType(\n column: StorageColumn,\n codecHooks: Map<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (resolved.typeParams && resolved.codecId) {\n const hooks = codecHooks.get(resolved.codecId);\n if (hooks?.expandNativeType) {\n return hooks.expandNativeType({\n nativeType: resolved.nativeType,\n codecId: resolved.codecId,\n typeParams: resolved.typeParams,\n });\n }\n }\n\n if (column.typeRef) {\n return formatUserDefinedTypeName(resolved.nativeType);\n }\n\n return FORMAT_TYPE_DISPLAY.get(resolved.nativeType) ?? resolved.nativeType;\n}\n\nexport function columnTypeCheck({\n schema,\n table,\n column,\n expectedType,\n}: {\n schema: string;\n table: string;\n column: string;\n expectedType: string;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n return `SELECT EXISTS (\n SELECT 1\n FROM pg_attribute a\n JOIN pg_class c ON c.oid = a.attrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE n.nspname = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND a.attname = '${escapeLiteral(column)}'\n AND format_type(a.atttypid, a.atttypmod) = '${escapeLiteral(expectedType)}'\n AND NOT a.attisdropped\n)`;\n}\n\nexport function columnDefaultExistsCheck({\n schema,\n table,\n column,\n exists = true,\n}: {\n schema: string;\n table: string;\n column: string;\n exists?: boolean;\n}): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const nullCheck = exists ? 'IS NOT NULL' : 'IS NULL';\n return `SELECT EXISTS (\n SELECT 1\n FROM information_schema.columns\n WHERE table_schema = ${namespace.schemaSqlExpression()}\n AND table_name = '${escapeLiteral(table)}'\n AND column_name = '${escapeLiteral(column)}'\n AND column_default ${nullCheck}\n)`;\n}\n\nexport function tableHasPrimaryKeyCheck(\n schema: string,\n table: string,\n exists: boolean,\n constraintName?: string,\n): string {\n const namespace = postgresCreateNamespace({ id: schema });\n const comparison = exists ? '' : 'NOT ';\n const constraintFilter = constraintName\n ? `AND c2.relname = '${escapeLiteral(constraintName)}'`\n : '';\n return `SELECT ${comparison}EXISTS (\n SELECT 1\n FROM pg_index i\n JOIN pg_class c ON c.oid = i.indrelid\n JOIN pg_namespace n ON n.oid = c.relnamespace\n LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid\n WHERE n.nspname = ${namespace.schemaSqlExpression()}\n AND c.relname = '${escapeLiteral(table)}'\n AND i.indisprimary\n ${constraintFilter}\n)`;\n}\n"],"mappings":";;;;AAYA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,IAAI,2BAA2B,cAAc,GAO3C,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;CAC7B;CAGF,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;CAC7B;AACF;;;;;;;;;;;;;;ACtBA,SAAgB,iBAAiB,QAAgB,OAAuB;CACtE,OAAO,wBAAwB,EAAE,IAAI,OAAO,CAAC,EAAE,aAAa,KAAK;AACnE;AAEA,SAAgB,kBAAkB,QAAgB,MAAsB;CACtE,OAAO,wBAAwB,EAAE,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI;AACrE;;;;;;AAOA,SAAgB,sBAAsB,EACpC,gBACA,QACA,OACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CACxD,MAAM,eAAe,SAAS,WAAW;CACzC,MAAM,cAAc,QAChB,gCAAgC,UAAU,gBAAgB,KAAK,EAAE,KACjE;CACJ,OAAO,UAAU,aAAa;;;uBAGT,cAAc,cAAc,EAAE;oBACjC,UAAU,oBAAoB,EAAE;IAChD,YAAY;;AAEhB;AAEA,SAAgB,kBAAkB,EAChC,QACA,OACA,QACA,SAAS,QAMA;CACT,MAAM,YAAY,wBAAwB,EAAE,IAAI,OAAO,CAAC;CAExD,OAAO,UADc,SAAS,KAAK,OACL;;;yBAGP,UAAU,oBAAoB,EAAE;wBACjC,cAAc,KAA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,SAAS,KAAK;CACjC,MAAM,mBAAmB,iBACrB,qBAAqB,cAAc,cAAc,EAAE,KACnD;CACJ,OAAO,UAAU,WAAW;;;;;;sBAMR,UAAU,oBAAoB,EAAE;uBAC/B,cAAc,KAAK,EAAE;;MAEtC,iBAAiB;;AAEvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner-sql-checks.d.mts","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"mappings":";;;;;;AAqBA;;;;;AAIA;;;;iBAJgB,gBAAA,CAAiB,MAAA,UAAgB,KAAA;AAAA,iBAIjC,iBAAA,CAAkB,MAAA,UAAgB,IAAA;;;;;;iBASlC,qBAAA,CAAA;EACd,cAAA;EACA,MAAA;EACA,KAAA;EACA;AAAA;EAEA,cAAA;EACA,MAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,iBAgBc,iBAAA,CAAA;EACd,MAAA;EACA,KAAA;EACA,MAAA;EACA;AAAA;EAEA,MAAA;EACA,KAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,iBAac,sBAAA,CAAA;EACd,MAAA;EACA,KAAA;EACA,MAAA;EACA;AAAA;EAEA,MAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,iBAcc,iBAAA,CAAkB,kBAAA;AAAA,iBAIlB,uBAAA,CAAwB,IAAA;EACtC,MAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,iBAyIc,uBAAA,CACd,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,YAAA,GAAc,MAAA,SAAe,mBAAA,GAAsB,wBAAA;AAAA,iBAsErC,uBAAA,CACd,MAAA,UACA,KAAA,UACA,MAAA,WACA,cAAA"}
1
+ {"version":3,"file":"planner-sql-checks.d.mts","names":[],"sources":["../src/core/migrations/planner-sql-checks.ts"],"mappings":";;;;;;AAqBA;;;;AAA8D;AAI9D;;;;iBAJgB,gBAAA,CAAiB,MAAA,UAAgB,KAAa;AAAA,iBAI9C,iBAAA,CAAkB,MAAA,UAAgB,IAAY;;;;;;iBAS9C,qBAAA,CAAA;EACd,cAAA;EACA,MAAA;EACA,KAAA;EACA;AAAA;EAEA,cAAA;EACA,MAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,iBAgBc,iBAAA,CAAA;EACd,MAAA;EACA,KAAA;EACA,MAAA;EACA;AAAA;EAEA,MAAA;EACA,KAAA;EACA,MAAA;EACA,MAAA;AAAA;AAAA,iBAac,sBAAA,CAAA;EACd,MAAA;EACA,KAAA;EACA,MAAA;EACA;AAAA;EAEA,MAAA;EACA,KAAA;EACA,MAAA;EACA,QAAA;AAAA;AAAA,iBAcc,iBAAA,CAAkB,kBAA0B;AAAA,iBAI5C,uBAAA,CAAwB,IAAA;EACtC,MAAA;EACA,KAAA;EACA,MAAA;AAAA;AAAA,iBAyIc,uBAAA,CACd,MAAA,EAAQ,aAAA,EACR,UAAA,EAAY,GAAA,SAAY,iBAAA,GACxB,YAAA,GAAc,MAAA,SAAe,mBAAA,GAAsB,wBAAA;AAAA,iBAsErC,uBAAA,CACd,MAAA,UACA,KAAA,UACA,MAAA,WACA,cAAA"}
@@ -1,2 +1,2 @@
1
- import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, i as columnHasNoDefaultCheck, l as tableHasPrimaryKeyCheck, r as columnExistsCheck, s as constraintExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-K-mTBJDi.mjs";
1
+ import { a as columnNullabilityCheck, c as qualifyTableName, d as toRegclassLiteral, i as columnHasNoDefaultCheck, l as tableHasPrimaryKeyCheck, r as columnExistsCheck, s as constraintExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-BDtJQ9WD.mjs";
2
2
  export { buildExpectedFormatType, columnExistsCheck, columnHasNoDefaultCheck, columnNullabilityCheck, constraintExistsCheck, qualifyTableName, tableHasPrimaryKeyCheck, tableIsEmptyCheck, toRegclassLiteral };
@@ -1 +1 @@
1
- {"version":3,"file":"planner-target-details-CIj61DUj.d.mts","names":[],"sources":["../src/core/migrations/planner-target-details.ts"],"mappings":";KAEY,cAAA;AAAA,UAUK,yBAAA;EAAA,SACN,MAAA;EAAA,SACA,UAAA,EAAY,cAAA;EAAA,SACZ,IAAA;EAAA,SACA,KAAA;AAAA"}
1
+ {"version":3,"file":"planner-target-details-CIj61DUj.d.mts","names":[],"sources":["../src/core/migrations/planner-target-details.ts"],"mappings":";KAEY,cAAA;AAAA,UAUK,yBAAA;EAAA,SACN,MAAA;EAAA,SACA,UAAA,EAAY,cAAc;EAAA,SAC1B,IAAA;EAAA,SACA,KAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;UAyCU,aAAA;EAAA,SACC,aAAA;AAAA;AAAA,iBAOK,8BAAA,CACd,MAAA,GAAQ,OAAA,CAAQ,aAAA,IACf,wBAAA;;;;AAFH;;;;KAgBY,kBAAA;EAAA,SACG,IAAA;EAAA,SAA0B,IAAA,EAAM,qCAAA;AAAA,IAC3C,uBAAA;;;;;;;AAFJ;;;;;;;;;;cAoBa,wBAAA,YAAoC,gBAAA;EAAA,iBAClB,MAAA;cAAA,MAAA,EAAQ,aAAA;EAErC,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IAiBa;;;;;;;;;;;;;;IAAA,SAFrB,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IAFnC;;;;;IAAA,SAQA,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAWK,OAAA;EAAA,QA6DA,oBAAA;EAAA,QAaA,mBAAA;AAAA"}
1
+ {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;UAyCU,aAAA;EAAA,SACC,aAAa;AAAA;AAAA,iBAOR,8BAAA,CACd,MAAA,GAAQ,OAAA,CAAQ,aAAA,IACf,wBAAA;;;AATqB;AAOxB;;;;KAgBY,kBAAA;EAAA,SACG,IAAA;EAAA,SAA0B,IAAA,EAAM,qCAAA;AAAA,IAC3C,uBAAuB;;;;;;AAhBA;AAc3B;;;;;;;;;AAE2B;cAkBd,wBAAA,YAAoC,gBAAA;EAAA,iBAClB,MAAA;cAAA,MAAA,EAAQ,aAAA;EAErC,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IAiBa;;;;;;;;;;;;;;IAAA,SAFrB,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IAFnC;;;;;IAAA,SAQA,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAWK,OAAA;EAAA,QA6DA,oBAAA;EAAA,QAaA,mBAAA;AAAA"}
package/dist/planner.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createPostgresMigrationPlanner } from "./planner-DZG1dsSW.mjs";
1
+ import { t as createPostgresMigrationPlanner } from "./planner-DlhK35aV.mjs";
2
2
  export { createPostgresMigrationPlanner };
@@ -1,5 +1,5 @@
1
1
  import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-DLA2xV6B.mjs";
2
- import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-CK82EuWq.mjs";
2
+ import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-BL0RAvew.mjs";
3
3
  import { NamespaceBase, UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
4
4
  import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
5
5
  import { isAuthoringEntityTypeDescriptor } from "@prisma-next/framework-components/authoring";
@@ -45,14 +45,14 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
45
45
  }
46
46
  hydrateSqlNamespaceEntry(nsId, raw) {
47
47
  if (raw instanceof NamespaceBase) return raw;
48
- const { id, tables, types: hydratedNsTypes } = super.hydrateSqlNamespaceEntry(nsId, raw);
48
+ const { id, tables, enum: hydratedNsEnums } = super.hydrateSqlNamespaceEntry(nsId, raw);
49
49
  const emptyTables = Object.keys(tables).length === 0;
50
- const emptyTypes = !hydratedNsTypes || Object.keys(hydratedNsTypes).length === 0;
51
- if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyTypes) return PostgresSchema.unbound;
50
+ const emptyEnums = !hydratedNsEnums || Object.keys(hydratedNsEnums).length === 0;
51
+ if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyEnums) return PostgresSchema.unbound;
52
52
  return new PostgresSchema({
53
53
  id,
54
54
  tables,
55
- ...hydratedNsTypes !== void 0 ? { types: hydratedNsTypes } : {}
55
+ ...hydratedNsEnums !== void 0 ? { enum: hydratedNsEnums } : {}
56
56
  });
57
57
  }
58
58
  serializeContract(contract) {
@@ -61,12 +61,12 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
61
61
  for (const [nsId, ns] of Object.entries(storage.namespaces)) if (isPostgresSchema(ns)) namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);
62
62
  else {
63
63
  const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;
64
- const nsTypes = ns.types ?? {};
64
+ const nsEnums = ns.enum ?? {};
65
65
  namespacesJson[nsId] = {
66
66
  id: nsId,
67
67
  kind: isUnboundSlot ? "postgres-unbound-schema" : "postgres-schema",
68
68
  tables: Object.fromEntries(Object.entries(ns.tables).map(([tableName, table]) => [tableName, this.serializeJsonValue(table)])),
69
- types: Object.fromEntries(Object.entries(nsTypes).map(([typeName, entry]) => [typeName, this.serializeJsonValue(entry)]))
69
+ enum: Object.fromEntries(Object.entries(nsEnums).map(([typeName, entry]) => [typeName, this.serializeJsonValue(entry)]))
70
70
  };
71
71
  }
72
72
  const storageOut = {
@@ -86,13 +86,13 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
86
86
  serializePostgresNamespace(ns, isUnboundSlot) {
87
87
  const tablesOut = {};
88
88
  for (const [tableName, table] of Object.entries(ns.tables)) tablesOut[tableName] = this.serializeJsonValue(table);
89
- const typesOut = {};
90
- for (const [typeName, ty] of Object.entries(ns.types)) typesOut[typeName] = this.serializeJsonValue(ty);
89
+ const enumOut = {};
90
+ for (const [typeName, ty] of Object.entries(ns.enum)) enumOut[typeName] = this.serializeJsonValue(ty);
91
91
  return {
92
92
  id: ns.id,
93
93
  kind: isUnboundSlot ? "postgres-unbound-schema" : "postgres-schema",
94
94
  tables: tablesOut,
95
- types: typesOut
95
+ enum: enumOut
96
96
  };
97
97
  }
98
98
  serializeJsonValue(value) {
@@ -102,4 +102,4 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
102
102
  //#endregion
103
103
  export { PostgresContractSerializer as t };
104
104
 
105
- //# sourceMappingURL=postgres-contract-serializer-CrET5Ov0.mjs.map
105
+ //# sourceMappingURL=postgres-contract-serializer-CYct4Y7O.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-contract-serializer-CYct4Y7O.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type {\n SqlNamespaceTablesInput,\n SqlStorage,\n SqlStorageTypeEntry,\n StorageTable,\n} from '@prisma-next/sql-contract/types';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport type { Type } from 'arktype';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport type { PostgresEnumType } from './postgres-enum-type';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n typeof (output as AuthoringEntityTypeFactoryOutput).factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits the maps the\n * family base consumes — hydrators and validator-schema fragments, both\n * keyed by the descriptor's `discriminator`.\n */\nfunction collectEntityRegistryContributions(namespace: AuthoringEntityTypeNamespace): {\n readonly entityTypeRegistry: ReadonlyMap<string, SqlEntityHydrationFactory>;\n readonly validatorFragments: ReadonlyMap<string, Type<unknown>>;\n} {\n const entityTypeRegistry = new Map<string, SqlEntityHydrationFactory>();\n const validatorFragments = new Map<string, Type<unknown>>();\n const walk = (node: AuthoringEntityTypeNamespace): void => {\n for (const value of Object.values(node)) {\n if (isAuthoringEntityTypeDescriptor(value)) {\n if (isAuthoringEntityTypeFactoryOutput(value.output)) {\n const { factory } = value.output;\n entityTypeRegistry.set(\n value.discriminator,\n (raw) => factory(raw, POSTGRES_AUTHORING_CTX) as SqlStorageTypeEntry,\n );\n }\n if (value.validatorSchema !== undefined) {\n validatorFragments.set(value.discriminator, value.validatorSchema);\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return { entityTypeRegistry, validatorFragments };\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n const { entityTypeRegistry, validatorFragments } = collectEntityRegistryContributions(\n postgresAuthoringEntityTypes,\n );\n super(entityTypeRegistry, validatorFragments);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = super.hydrateSqlNamespaceEntry(nsId, raw) as {\n id: string;\n tables: Readonly<Record<string, StorageTable>>;\n enum?: Readonly<Record<string, PostgresEnumType>>;\n };\n const { id, tables, enum: hydratedNsEnums } = hydrated;\n\n const emptyTables = Object.keys(tables).length === 0;\n const emptyEnums = !hydratedNsEnums || Object.keys(hydratedNsEnums).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyEnums) {\n return PostgresSchema.unbound;\n }\n return new PostgresSchema({\n id,\n tables,\n ...(hydratedNsEnums !== undefined ? { enum: hydratedNsEnums } : {}),\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n // Family-level SqlNamespacePayload / SqlUnboundNamespace haven't\n // been promoted to a PostgresSchema instance yet (e.g. they came\n // straight from the TS builder, which uses the family-shared\n // SqlStorage constructor). Serialise them as postgres-schema /\n // postgres-unbound-schema so the round-trip through\n // deserializeContract hydrates them back into PostgresSchema\n // instances.\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n const nsEnums = (ns as { readonly enum?: Readonly<Record<string, unknown>> }).enum ?? {};\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n tables: Object.fromEntries(\n Object.entries(ns.tables).map(([tableName, table]) => [\n tableName,\n this.serializeJsonValue(table) as JsonObject,\n ]),\n ),\n enum: Object.fromEntries(\n Object.entries(nsEnums).map(([typeName, entry]) => [\n typeName,\n this.serializeJsonValue(entry) as JsonObject,\n ]),\n ),\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonValue(entry) as JsonObject;\n }\n storageOut['types'] = typesOut;\n }\n return {\n ...rest,\n storage: storageOut,\n } as unknown as JsonObject;\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.tables)) {\n tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;\n }\n const enumOut: Record<string, JsonObject> = {};\n for (const [typeName, ty] of Object.entries(ns.enum)) {\n enumOut[typeName] = this.serializeJsonValue(ty) as JsonObject;\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n tables: tablesOut,\n enum: enumOut,\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;AA4BA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,OAAQ,OAA4C,YAAY;AAEpE;;;;;;AAOA,SAAS,mCAAmC,WAG1C;CACA,MAAM,qCAAqB,IAAI,IAAuC;CACtE,MAAM,qCAAqB,IAAI,IAA2B;CAC1D,MAAM,QAAQ,SAA6C;EACzD,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GAAG;GACvC,IAAI,gCAAgC,KAAK,GAAG;IAC1C,IAAI,mCAAmC,MAAM,MAAM,GAAG;KACpD,MAAM,EAAE,YAAY,MAAM;KAC1B,mBAAmB,IACjB,MAAM,gBACL,QAAQ,QAAQ,KAAK,sBAAsB,CAC9C;IACF;IACA,IAAI,M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SACN,UAAA;EAAA,SACA,MAAA,EAAQ,OAAA;;;;;;;;;;WAUR,OAAA,SAAgB,gBAAA;cAEb,KAAA,EAAO,qBAAA,CAAsB,KAAA,EAAO,OAAA;EAAA,IAW5C,YAAA,CAAA;IAAA,SACO,OAAA,SAAgB,gBAAA;IAAA,SAChB,UAAA;MAAA,SAAuB,MAAA,EAAQ,OAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"file":"postgres-enum-type-CNhPTDhy.d.mts","names":[],"sources":["../src/core/postgres-enum-type.ts"],"mappings":";;;UAGiB,qBAAA;;AAAjB;;;;WASW,IAAA,EAAM,KAAA;EAPf;;;;;EAAA,SAaS,UAAA;EAAA,SACA,MAAA,EAAQ,OAAO;AAAA;AACzB;AAAA,cAGK,gBAAA;;;AAAgB;AAyBtB;;;;;;;;;;;;;;;;;;;;cAAa,gBAAA,+FAGH,OAAA;EAAA,SACU,IAAA;EAAA,SACT,IAAA,EAAM,KAAA;EAAA,SACN,UAAA;EAAA,SACA,MAAA,EAAQ,OAAA;;;;;;;;;;WAUR,OAAA,SAAgB,gBAAA;cAEb,KAAA,EAAO,qBAAA,CAAsB,KAAA,EAAO,OAAA;EAAA,IAW5C,YAAA,CAAA;IAAA,SACO,OAAA,SAAgB,gBAAA;IAAA,SAChB,UAAA;MAAA,SAAuB,MAAA,EAAQ,OAAA;IAAA;EAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-enum-type-DS-KLVRH.mjs","names":[],"sources":["../src/core/postgres-enum-type.ts"],"sourcesContent":["import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from '@prisma-next/sql-contract/types';\n\nexport interface PostgresEnumTypeInput<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> {\n /**\n * Contract-level enum name (e.g. `'Role'`). Used as the key in\n * `SqlStorage.types` and as the contract-facing identifier in\n * planner / verifier diagnostics.\n */\n readonly name: TName;\n /**\n * Postgres-side native type name created by `CREATE TYPE … AS ENUM`.\n * Defaults to `name` when not overridden via PSL `@map(...)` or the\n * TS authoring surface.\n */\n readonly nativeType?: string;\n readonly values: TValues;\n}\n\n/** Codec id used by Postgres enum-typed columns (text wire format). */\nconst PG_ENUM_CODEC_ID = 'pg/enum@1';\n\n/**\n * Postgres IR class for the `CREATE TYPE … AS ENUM` concept.\n *\n * Per Decision 18, enum is a target-only concept (Postgres alone today;\n * SQLite emulates via CHECK constraints). There is no family-layer\n * enum abstract — the abstract-earns-existence rule keeps the IR class\n * hierarchy minimal: this class extends `SqlNode` directly and is the\n * single concrete representation of the polymorphic `'postgres-enum'`\n * slot variant.\n *\n * Carries Postgres-specific resolution (`nativeType` defaults to\n * `name`; `values` is frozen at construction time). Constructor calls\n * `freezeNode(this)` per Decision 8 — the instance is fully immutable,\n * JSON-clean, and dispatchable on its enumerable `kind: 'postgres-enum'`\n * literal.\n *\n * The family-layer slot dispatch (verifier, planner, lowering, etc.)\n * narrows polymorphic `StorageType` entries via the `kind` literal\n * (e.g. `isPostgresEnumStorageEntry`) — SQL-domain code must not import\n * `target-postgres` directly (cross-domain layering rule). The\n * structural interface lives at the family layer for that purpose;\n * this class is the runtime concrete that satisfies it.\n */\nexport class PostgresEnumType<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> extends SqlNode {\n override readonly kind = 'postgres-enum' as const;\n readonly name: TName;\n readonly nativeType: string;\n readonly values: TValues;\n /**\n * Enumerable own property so the persisted JSON envelope carries\n * `codecId: 'pg/enum@1'` alongside `kind: 'postgres-enum'`. The\n * runtime path (`codecRefForStorageColumn`, `assertColumnCodecIntegrity`)\n * receives JSON-shaped contracts (e.g. inside a user-written\n * `migration.ts` that loads `endContract` from `end-contract.json`)\n * and reads `codecId` directly from the envelope rather than\n * dispatching through the prototype-only `codecBinding` accessor.\n */\n readonly codecId: typeof PG_ENUM_CODEC_ID = PG_ENUM_CODEC_ID;\n\n constructor(input: PostgresEnumTypeInput<TName, TValues>) {\n super();\n this.name = input.name;\n this.nativeType = input.nativeType ?? input.name;\n // `Object.freeze` returns `Readonly<string[]>`, widening past the\n // `TValues` literal tuple. Cast preserves the caller-supplied\n // tuple shape so inferred contract types retain literal narrowing.\n this.values = Object.freeze([...input.values] as unknown as TValues);\n freezeNode(this);\n }\n\n get codecBinding(): {\n readonly codecId: typeof PG_ENUM_CODEC_ID;\n readonly typeParams: { readonly values: TValues };\n } {\n return { codecId: PG_ENUM_CODEC_ID, typeParams: { values: this.values } };\n }\n}\n"],"mappings":";;;;AAuBA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;AAyBzB,IAAa,mBAAb,cAGU,QAAQ;CAChB,OAAyB;CACzB;CACA;CACA;;;;;;;;;;CAUA,UAA4C;CAE5C,YAAY,OAA8C;EACxD,OAAO;EACP,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa,MAAM,cAAc,MAAM;EAI5C,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,OAAO,CAAuB;EACpE,WAAW,KAAK;;CAGlB,IAAI,eAGF;EACA,OAAO;GAAE,SAAS;GAAkB,YAAY,EAAE,QAAQ,KAAK,QAAQ;GAAE"}
1
+ {"version":3,"file":"postgres-enum-type-DS-KLVRH.mjs","names":[],"sources":["../src/core/postgres-enum-type.ts"],"sourcesContent":["import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from '@prisma-next/sql-contract/types';\n\nexport interface PostgresEnumTypeInput<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> {\n /**\n * Contract-level enum name (e.g. `'Role'`). Used as the key in\n * `SqlStorage.types` and as the contract-facing identifier in\n * planner / verifier diagnostics.\n */\n readonly name: TName;\n /**\n * Postgres-side native type name created by `CREATE TYPE … AS ENUM`.\n * Defaults to `name` when not overridden via PSL `@map(...)` or the\n * TS authoring surface.\n */\n readonly nativeType?: string;\n readonly values: TValues;\n}\n\n/** Codec id used by Postgres enum-typed columns (text wire format). */\nconst PG_ENUM_CODEC_ID = 'pg/enum@1';\n\n/**\n * Postgres IR class for the `CREATE TYPE … AS ENUM` concept.\n *\n * Per Decision 18, enum is a target-only concept (Postgres alone today;\n * SQLite emulates via CHECK constraints). There is no family-layer\n * enum abstract — the abstract-earns-existence rule keeps the IR class\n * hierarchy minimal: this class extends `SqlNode` directly and is the\n * single concrete representation of the polymorphic `'postgres-enum'`\n * slot variant.\n *\n * Carries Postgres-specific resolution (`nativeType` defaults to\n * `name`; `values` is frozen at construction time). Constructor calls\n * `freezeNode(this)` per Decision 8 — the instance is fully immutable,\n * JSON-clean, and dispatchable on its enumerable `kind: 'postgres-enum'`\n * literal.\n *\n * The family-layer slot dispatch (verifier, planner, lowering, etc.)\n * narrows polymorphic `StorageType` entries via the `kind` literal\n * (e.g. `isPostgresEnumStorageEntry`) — SQL-domain code must not import\n * `target-postgres` directly (cross-domain layering rule). The\n * structural interface lives at the family layer for that purpose;\n * this class is the runtime concrete that satisfies it.\n */\nexport class PostgresEnumType<\n TName extends string = string,\n TValues extends readonly string[] = readonly string[],\n> extends SqlNode {\n override readonly kind = 'postgres-enum' as const;\n readonly name: TName;\n readonly nativeType: string;\n readonly values: TValues;\n /**\n * Enumerable own property so the persisted JSON envelope carries\n * `codecId: 'pg/enum@1'` alongside `kind: 'postgres-enum'`. The\n * runtime path (`codecRefForStorageColumn`, `assertColumnCodecIntegrity`)\n * receives JSON-shaped contracts (e.g. inside a user-written\n * `migration.ts` that loads `endContract` from `end-contract.json`)\n * and reads `codecId` directly from the envelope rather than\n * dispatching through the prototype-only `codecBinding` accessor.\n */\n readonly codecId: typeof PG_ENUM_CODEC_ID = PG_ENUM_CODEC_ID;\n\n constructor(input: PostgresEnumTypeInput<TName, TValues>) {\n super();\n this.name = input.name;\n this.nativeType = input.nativeType ?? input.name;\n // `Object.freeze` returns `Readonly<string[]>`, widening past the\n // `TValues` literal tuple. Cast preserves the caller-supplied\n // tuple shape so inferred contract types retain literal narrowing.\n this.values = Object.freeze([...input.values] as unknown as TValues);\n freezeNode(this);\n }\n\n get codecBinding(): {\n readonly codecId: typeof PG_ENUM_CODEC_ID;\n readonly typeParams: { readonly values: TValues };\n } {\n return { codecId: PG_ENUM_CODEC_ID, typeParams: { values: this.values } };\n }\n}\n"],"mappings":";;;;AAuBA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;AAyBzB,IAAa,mBAAb,cAGU,QAAQ;CAChB,OAAyB;CACzB;CACA;CACA;;;;;;;;;;CAUA,UAA4C;CAE5C,YAAY,OAA8C;EACxD,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,aAAa,MAAM,cAAc,MAAM;EAI5C,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,MAAM,CAAuB;EACnE,WAAW,IAAI;CACjB;CAEA,IAAI,eAGF;EACA,OAAO;GAAE,SAAS;GAAkB,YAAY,EAAE,QAAQ,KAAK,OAAO;EAAE;CAC1E;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-migration-uADmx0dW.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,MAAM;EAIZ,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,MAAM,GAC5B,KAAA;;;;;;;CAQN,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,oCAAoC;EAE5C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,eAAe"}
1
+ {"version":3,"file":"postgres-migration-uADmx0dW.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;AACF"}
@@ -27,12 +27,12 @@ var PostgresSchema = class extends NamespaceBase {
27
27
  static unbound;
28
28
  id;
29
29
  tables;
30
- types;
30
+ enum;
31
31
  constructor(input) {
32
32
  super();
33
33
  this.id = input.id;
34
34
  this.tables = Object.freeze(Object.fromEntries(Object.entries(input.tables ?? {}).map(([name, t]) => [name, t instanceof StorageTable ? t : new StorageTable(t)])));
35
- this.types = Object.freeze(Object.fromEntries(Object.entries(input.types ?? {}).map(([name, ty]) => [name, ty instanceof PostgresEnumType ? ty : new PostgresEnumType(ty)])));
35
+ this.enum = Object.freeze(Object.fromEntries(Object.entries(input.enum ?? {}).map(([name, ty]) => [name, ty instanceof PostgresEnumType ? ty : new PostgresEnumType(ty)])));
36
36
  Object.defineProperty(this, "kind", {
37
37
  value: "schema",
38
38
  writable: false,
@@ -165,4 +165,4 @@ function postgresCreateNamespace(input) {
165
165
  //#endregion
166
166
  export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
167
167
 
168
- //# sourceMappingURL=postgres-schema-CK82EuWq.mjs.map
168
+ //# sourceMappingURL=postgres-schema-BL0RAvew.mjs.map