@prisma/orm-target-postgres 8.0.0-rc.14-dev.11 → 8.0.0-rc.14-dev.13

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 (94) hide show
  1. package/dist/{adapter-Bb_FFDea-Bnp9ew_B.mjs → adapter-Bb_FFDea-DyyfToJz.mjs} +2 -2
  2. package/dist/{adapter-Bb_FFDea-Bnp9ew_B.mjs.map → adapter-Bb_FFDea-DyyfToJz.mjs.map} +1 -1
  3. package/dist/adapter.mjs +2 -2
  4. package/dist/adapter__adapter.mjs +1 -1
  5. package/dist/adapter__control.mjs +3 -3
  6. package/dist/adapter__runtime.mjs +2 -2
  7. package/dist/{authoring-2oKPEpBv-DfCFpeuD.mjs → authoring-DULm2ZZP-DgykBF-F.mjs} +4 -4
  8. package/dist/{authoring-2oKPEpBv-DfCFpeuD.mjs.map → authoring-DULm2ZZP-DgykBF-F.mjs.map} +1 -1
  9. package/dist/{contract-free-B2-ZWT2L.mjs → contract-free-C0GQe4X_.mjs} +3 -3
  10. package/dist/{contract-free-B2-ZWT2L.mjs.map → contract-free-C0GQe4X_.mjs.map} +1 -1
  11. package/dist/{control-D5Vb1l8F.mjs → control-BMhsfqMy.mjs} +13 -25
  12. package/dist/control-BMhsfqMy.mjs.map +1 -0
  13. package/dist/{control-CUzQZfhu.d.mts → control-D7_yfEfH.d.mts} +5 -2
  14. package/dist/{control-CUzQZfhu.d.mts.map → control-D7_yfEfH.d.mts.map} +1 -1
  15. package/dist/{control-adapter-C6kz--Q4-CAryb7mj.mjs → control-adapter-C6kz--Q4-BBli0l1k.mjs} +4 -4
  16. package/dist/{control-adapter-C6kz--Q4-CAryb7mj.mjs.map → control-adapter-C6kz--Q4-BBli0l1k.mjs.map} +1 -1
  17. package/dist/{control-policy-API5I4jr-ivEvCf_e.mjs → control-policy-CThlWQ8k-m3CT6KpR.mjs} +28 -15
  18. package/dist/control-policy-CThlWQ8k-m3CT6KpR.mjs.map +1 -0
  19. package/dist/{ddl-BEslwyjE-CzNPjhh1.mjs → ddl-C6M0Hkbe-BSSauy2X.mjs} +3 -3
  20. package/dist/{ddl-BEslwyjE-CzNPjhh1.mjs.map → ddl-C6M0Hkbe-BSSauy2X.mjs.map} +1 -1
  21. package/dist/{descriptor-meta-B1rbY3IE-I1ec-I6j.mjs → descriptor-meta-JJJwM3Gl-BcH0pYOV.mjs} +4 -4
  22. package/dist/{descriptor-meta-B1rbY3IE-I1ec-I6j.mjs.map → descriptor-meta-JJJwM3Gl-BcH0pYOV.mjs.map} +1 -1
  23. package/dist/{diff-database-schema-MymRFpdQ-CyY82tmS.mjs → diff-database-schema-Bp0uC68P-NxeVJERq.mjs} +7 -7
  24. package/dist/{diff-database-schema-MymRFpdQ-CyY82tmS.mjs.map → diff-database-schema-Bp0uC68P-NxeVJERq.mjs.map} +1 -1
  25. package/dist/{infer-psl-contract-CsDvYcvN-CMQR2WNf.mjs → infer-psl-contract-ChPangpl-CxL4__yw.mjs} +5 -5
  26. package/dist/{infer-psl-contract-CsDvYcvN-CMQR2WNf.mjs.map → infer-psl-contract-ChPangpl-CxL4__yw.mjs.map} +1 -1
  27. package/dist/{issue-planner-C4iR-Ik-.d.mts → issue-planner-WWpJ3gOQ.d.mts} +2 -2
  28. package/dist/{issue-planner-C4iR-Ik-.d.mts.map → issue-planner-WWpJ3gOQ.d.mts.map} +1 -1
  29. package/dist/{migration-BTiY0PPC.d.mts → migration-DwqTcQ5d.d.mts} +3 -3
  30. package/dist/{migration-BTiY0PPC.d.mts.map → migration-DwqTcQ5d.d.mts.map} +1 -1
  31. package/dist/migration-PTHAY9Cv.mjs.map +1 -1
  32. package/dist/{op-factory-call-VLJFI-b_-Du23HNYc.d.mts → op-factory-call-CmhDgfov-BjHdIpND.d.mts} +24 -7
  33. package/dist/op-factory-call-CmhDgfov-BjHdIpND.d.mts.map +1 -0
  34. package/dist/{op-factory-call-uRJcYmJG-Bpyq2pCt.mjs → op-factory-call-DYkz28kP-4BmpSB4B.mjs} +81 -18
  35. package/dist/op-factory-call-DYkz28kP-4BmpSB4B.mjs.map +1 -0
  36. package/dist/op-factory-call-DbjizP4b.d.mts +1 -0
  37. package/dist/{planner-Bp89yaJS-4TV82o0Y.mjs → planner-B_ILQa75-CoVpbzCr.mjs} +32 -214
  38. package/dist/planner-B_ILQa75-CoVpbzCr.mjs.map +1 -0
  39. package/dist/{planner-SLaWpf7q.d.mts → planner-fD25Vk53.d.mts} +2 -41
  40. package/dist/{planner-SLaWpf7q.d.mts.map → planner-fD25Vk53.d.mts.map} +1 -1
  41. package/dist/{planner-produced-postgres-migration-D7vODJo4-BoaNLGvs.mjs → planner-produced-postgres-migration-BQFrdLuE-CeyZeWPJ.mjs} +3 -3
  42. package/dist/{planner-produced-postgres-migration-D7vODJo4-BoaNLGvs.mjs.map → planner-produced-postgres-migration-BQFrdLuE-CeyZeWPJ.mjs.map} +1 -1
  43. package/dist/{planner-produced-postgres-migration-CoOcn-b9-8kOq82_P.d.mts → planner-produced-postgres-migration-CMGC3vS6-CGdYLZFB.d.mts} +3 -3
  44. package/dist/planner-produced-postgres-migration-CMGC3vS6-CGdYLZFB.d.mts.map +1 -0
  45. package/dist/planner-produced-postgres-migration-DJFPEI7l.d.mts +1 -0
  46. package/dist/{planner-sql-checks-ZMXeCK6W-D1VMBywZ.mjs → planner-sql-checks-Bxz8yvg8-Bj6jGClB.mjs} +3 -3
  47. package/dist/{planner-sql-checks-ZMXeCK6W-D1VMBywZ.mjs.map → planner-sql-checks-Bxz8yvg8-Bj6jGClB.mjs.map} +1 -1
  48. package/dist/{postgres-contract-view-CUWYe586-CHykrpRs.mjs → postgres-contract-view-BEp5ikai-BmYXd1MR.mjs} +4 -4
  49. package/dist/{postgres-contract-view-CUWYe586-CHykrpRs.mjs.map → postgres-contract-view-BEp5ikai-BmYXd1MR.mjs.map} +1 -1
  50. package/dist/postgres-migration-DWtr5s00-CSlA4I1U.mjs +569 -0
  51. package/dist/postgres-migration-DWtr5s00-CSlA4I1U.mjs.map +1 -0
  52. package/dist/{postgres-migration-B03W06rR-DTB0R3cj.d.mts → postgres-migration-vpMSrXLQ-CJ72Zey3.d.mts} +19 -3
  53. package/dist/postgres-migration-vpMSrXLQ-CJ72Zey3.d.mts.map +1 -0
  54. package/dist/{postgres-schema-yugFGBdS-5cY1PCmb.mjs → postgres-schema-C8slJGZo-CFGUyJPt.mjs} +3 -3
  55. package/dist/{postgres-schema-yugFGBdS-5cY1PCmb.mjs.map → postgres-schema-C8slJGZo-CFGUyJPt.mjs.map} +1 -1
  56. package/dist/{prisma7-binding-D8_eGy5l.mjs → prisma7-binding-Cajs2zo2.mjs} +5 -5
  57. package/dist/{prisma7-binding-D8_eGy5l.mjs.map → prisma7-binding-Cajs2zo2.mjs.map} +1 -1
  58. package/dist/{resolve-ddl-schema-euaYYSHi-DM7kyWEw.mjs → resolve-ddl-schema-Bq4m2dD9-DrlUipYU.mjs} +3 -3
  59. package/dist/{resolve-ddl-schema-euaYYSHi-DM7kyWEw.mjs.map → resolve-ddl-schema-Bq4m2dD9-DrlUipYU.mjs.map} +1 -1
  60. package/dist/target.d.mts +10 -10
  61. package/dist/target.mjs +17 -17
  62. package/dist/target__contract-free.mjs +3 -3
  63. package/dist/target__control.d.mts +1 -1
  64. package/dist/target__control.mjs +3 -2
  65. package/dist/target__diff-database-schema.mjs +1 -1
  66. package/dist/target__issue-planner.d.mts +1 -1
  67. package/dist/target__issue-planner.mjs +1 -1
  68. package/dist/target__migration.d.mts +2 -2
  69. package/dist/target__migration.mjs +2 -2
  70. package/dist/target__op-factory-call.d.mts +3 -3
  71. package/dist/target__op-factory-call.mjs +2 -2
  72. package/dist/target__pack.mjs +1 -1
  73. package/dist/target__planner-produced-postgres-migration.d.mts +2 -2
  74. package/dist/target__planner-produced-postgres-migration.mjs +1 -1
  75. package/dist/target__planner-sql-checks.mjs +1 -1
  76. package/dist/target__planner.d.mts +1 -1
  77. package/dist/target__planner.mjs +2 -2
  78. package/dist/target__prisma7-binding.mjs +1 -1
  79. package/dist/target__runtime.mjs +2 -2
  80. package/dist/target__runtime.mjs.map +1 -1
  81. package/dist/target__schema-ir-annotations.mjs +1 -1
  82. package/dist/target__types.mjs +1 -1
  83. package/package.json +9 -9
  84. package/dist/control-D5Vb1l8F.mjs.map +0 -1
  85. package/dist/control-policy-API5I4jr-ivEvCf_e.mjs.map +0 -1
  86. package/dist/op-factory-call-Bi1XxJEv.d.mts +0 -1
  87. package/dist/op-factory-call-VLJFI-b_-Du23HNYc.d.mts.map +0 -1
  88. package/dist/op-factory-call-uRJcYmJG-Bpyq2pCt.mjs.map +0 -1
  89. package/dist/planner-Bp89yaJS-4TV82o0Y.mjs.map +0 -1
  90. package/dist/planner-produced-postgres-migration-Bi_Otmtx.d.mts +0 -1
  91. package/dist/planner-produced-postgres-migration-CoOcn-b9-8kOq82_P.d.mts.map +0 -1
  92. package/dist/postgres-migration-B03W06rR-DTB0R3cj.d.mts.map +0 -1
  93. package/dist/postgres-migration-DMTY4p1--KjAAFSJ_.mjs +0 -223
  94. package/dist/postgres-migration-DMTY4p1--KjAAFSJ_.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-contract-view-CUWYe586-CHykrpRs.mjs","names":[],"sources":["../../../../3-targets/3-targets/postgres/dist/postgres-contract-view-CUWYe586.mjs"],"sourcesContent":["import { S as PG_TEXT_CODEC_ID, _ as PG_INT_CODEC_ID } from \"./codec-ids-Cb0yO-IS.mjs\";\nimport { n as postgresAuthoringEntityTypes } from \"./authoring-2oKPEpBv.mjs\";\nimport { a as nativeEnumEntityKind, c as roleEntityKind, o as policyEntityKind, s as rlsEnablementEntityKind, t as PostgresSchema } from \"./postgres-schema-yugFGBdS.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { isAuthoringEntityTypeDescriptor } from \"@internal/framework-components/authoring\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { buildSqlSchemaQualifiedView } from \"@internal/sql-contract/contract-view\";\nimport { createPreserveEmptyPredicate } from \"@internal/contract/hashing-utils\";\nimport { SqlContractSerializerBase } from \"@internal/family-sql/ir\";\nimport { sqlContractCanonicalizationHooks } from \"@internal/sql-contract/canonicalization-hooks\";\n//#region src/core/postgres-contract-serializer.ts\nconst POSTGRES_AUTHORING_CTX = {\n\tfamily: \"sql\",\n\ttarget: \"postgres\",\n\tenumInferenceCodecs: {\n\t\ttext: PG_TEXT_CODEC_ID,\n\t\tint: PG_INT_CODEC_ID\n\t}\n};\nfunction isAuthoringEntityTypeFactoryOutput(output) {\n\treturn typeof output === \"object\" && output !== null && \"factory\" in output && typeof output.factory === \"function\";\n}\n/**\n* Walks a pack's entity-type namespace tree and emits hydration factories\n* keyed by the descriptor's `discriminator`. Used for `storage.types`\n* (codec-triple hydration). Namespace entries hydration dispatches by\n* entries key, not discriminator — handled by `hydrateNamespaceEntities`.\n*/\nfunction collectStorageTypesHydrators(namespace) {\n\tconst registry = /* @__PURE__ */ new Map();\n\tconst walk = (node) => {\n\t\tfor (const value of Object.values(node)) {\n\t\t\tif (isAuthoringEntityTypeDescriptor(value)) {\n\t\t\t\tif (isAuthoringEntityTypeFactoryOutput(value.output)) {\n\t\t\t\t\tconst { factory } = value.output;\n\t\t\t\t\tregistry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof value === \"object\" && value !== null) walk(value);\n\t\t}\n\t};\n\twalk(namespace);\n\treturn registry;\n}\n/**\n* The canonicalization walk drops a field whose value equals its type's\n* default, which for a required field of an entity kind means the emitted\n* contract fails that kind's own schema on the next read (a RESTRICTIVE\n* policy's `permissive: false` is the live case). The set of fields that must\n* survive is therefore the required keys of the registered entity kinds —\n* read off the schemas rather than listed by hand, so a kind that gains a\n* required field is covered the day it gains one.\n*/\nfunction requiredEntityFieldsSurviveDefaults(kinds) {\n\treturn createPreserveEmptyPredicate(kinds.flatMap((kind) => requiredKeysOf(kind.schema).map((key) => [\n\t\t\"storage\",\n\t\t\"namespaces\",\n\t\t\"*\",\n\t\t\"entries\",\n\t\tkind.kind,\n\t\t\"*\",\n\t\tkey\n\t])));\n}\nfunction isSchemaPropList(value) {\n\treturn Array.isArray(value) && value.every((prop) => prop !== null && (typeof prop === \"object\" || typeof prop === \"function\") && \"kind\" in prop && \"key\" in prop);\n}\nfunction requiredKeysOf(schema) {\n\tconst props = \"props\" in schema ? schema.props : void 0;\n\tif (!isSchemaPropList(props)) throw new InternalError(\"entity-kind schema does not expose arktype object props; the required-field preserve set cannot be derived\");\n\treturn props.flatMap((prop) => prop.kind === \"required\" && typeof prop.key === \"string\" ? [prop.key] : []);\n}\nvar PostgresContractSerializer = class extends SqlContractSerializerBase {\n\tshouldPreserveEmpty;\n\tconstructor(extraPackEntityKinds = []) {\n\t\tconst storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n\t\tconst entityKinds = [\n\t\t\tpolicyEntityKind,\n\t\t\troleEntityKind,\n\t\t\trlsEnablementEntityKind,\n\t\t\tnativeEnumEntityKind,\n\t\t\t...extraPackEntityKinds\n\t\t];\n\t\tsuper(storageTypesHydrators, entityKinds);\n\t\tconst preserveRequired = requiredEntityFieldsSurviveDefaults(entityKinds);\n\t\tthis.shouldPreserveEmpty = (path) => preserveRequired(path) || sqlContractCanonicalizationHooks.shouldPreserveEmpty(path);\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\tconst { id, entries } = blindCast(super.hydrateSqlNamespaceEntry(nsId, raw));\n\t\tconst allSlotsEmpty = Object.values(entries).every((slot) => slot === void 0 || Object.keys(slot).length === 0);\n\t\tif (id === UNBOUND_NAMESPACE_ID && allSlotsEmpty) return PostgresSchema.unbound;\n\t\tconst valueSetSlot = entries[\"valueSet\"];\n\t\tconst hasValueSets = valueSetSlot !== void 0 && Object.keys(valueSetSlot).length > 0;\n\t\treturn new PostgresSchema({\n\t\t\tid,\n\t\t\tentries: {\n\t\t\t\t...entries,\n\t\t\t\ttable: entries[\"table\"] ?? {},\n\t\t\t\t...hasValueSets ? { valueSet: valueSetSlot } : {}\n\t\t\t}\n\t\t});\n\t}\n\tserializeContract(contract) {\n\t\tconst { storage, ...rest } = contract;\n\t\tconst namespacesJson = {};\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) {\n\t\t\tconst isUnboundSlot = ns.id === UNBOUND_NAMESPACE_ID;\n\t\t\tnamespacesJson[nsId] = {\n\t\t\t\tid: ns.id,\n\t\t\t\tkind: isUnboundSlot ? \"postgres-unbound-schema\" : \"postgres-schema\",\n\t\t\t\tentries: this.serializeNamespaceEntries(ns.entries)\n\t\t\t};\n\t\t}\n\t\tconst storageOut = {\n\t\t\tstorageHash: String(storage.storageHash),\n\t\t\tnamespaces: namespacesJson\n\t\t};\n\t\tif (storage.types !== void 0) {\n\t\t\tconst typesOut = {};\n\t\t\tfor (const [name, entry] of Object.entries(storage.types)) typesOut[name] = this.serializeJsonObject(entry);\n\t\t\tstorageOut[\"types\"] = typesOut;\n\t\t}\n\t\treturn blindCast({\n\t\t\t...rest,\n\t\t\tstorage: storageOut\n\t\t});\n\t}\n};\n//#endregion\n//#region src/core/postgres-contract-view.ts\nconst PostgresContractView = {\n\t/** Wrap an already-deserialized Postgres contract in a schema-qualified view. */\n\tfrom(contract) {\n\t\treturn buildSqlSchemaQualifiedView(contract);\n\t},\n\t/** Deserialize a Postgres contract JSON envelope and wrap it in a view. */\n\tfromJson(json) {\n\t\treturn buildSqlSchemaQualifiedView(new PostgresContractSerializer().deserializeContract(json));\n\t}\n};\n//#endregion\nexport { PostgresContractSerializer as n, PostgresContractView as t };\n\n//# sourceMappingURL=postgres-contract-view-CUWYe586.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,yBAAyB;CAC9B,QAAQ;CACR,QAAQ;CACR,qBAAqB;EACpB,MAAM;EACN,KAAK;CACN;AACD;AACA,SAA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AoB,KAAK;GAC1G,WAAW,WAAW;EACvB;EACA,OAAO,UAAU;GAChB,GAAG;GACH,SAAS;EACV,CAAC;CACF;AACD;AAGA,MAAM,uBAAuB;;CAE5B,KAAK,UAAU;EACd,OAAO,4BAA4B,QAAQ;CAC5C;;CAEA,SAAS,MAAM;EACd,OAAO,4BAA4B,IAAI,2BAA2B,CAAC,CAAC,oBAAoB,IAAI,CAAC;CAC9F;AACD"}
1
+ {"version":3,"file":"postgres-contract-view-BEp5ikai-BmYXd1MR.mjs","names":[],"sources":["../../../../3-targets/3-targets/postgres/dist/postgres-contract-view-BEp5ikai.mjs"],"sourcesContent":["import { S as PG_TEXT_CODEC_ID, _ as PG_INT_CODEC_ID } from \"./codec-ids-Cb0yO-IS.mjs\";\nimport { n as postgresAuthoringEntityTypes } from \"./authoring-DULm2ZZP.mjs\";\nimport { a as nativeEnumEntityKind, c as roleEntityKind, o as policyEntityKind, s as rlsEnablementEntityKind, t as PostgresSchema } from \"./postgres-schema-C8slJGZo.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { UNBOUND_NAMESPACE_ID } from \"@internal/framework-components/ir\";\nimport { isAuthoringEntityTypeDescriptor } from \"@internal/framework-components/authoring\";\nimport { InternalError } from \"@internal/utils/internal-error\";\nimport { buildSqlSchemaQualifiedView } from \"@internal/sql-contract/contract-view\";\nimport { createPreserveEmptyPredicate } from \"@internal/contract/hashing-utils\";\nimport { SqlContractSerializerBase } from \"@internal/family-sql/ir\";\nimport { sqlContractCanonicalizationHooks } from \"@internal/sql-contract/canonicalization-hooks\";\n//#region src/core/postgres-contract-serializer.ts\nconst POSTGRES_AUTHORING_CTX = {\n\tfamily: \"sql\",\n\ttarget: \"postgres\",\n\tenumInferenceCodecs: {\n\t\ttext: PG_TEXT_CODEC_ID,\n\t\tint: PG_INT_CODEC_ID\n\t}\n};\nfunction isAuthoringEntityTypeFactoryOutput(output) {\n\treturn typeof output === \"object\" && output !== null && \"factory\" in output && typeof output.factory === \"function\";\n}\n/**\n* Walks a pack's entity-type namespace tree and emits hydration factories\n* keyed by the descriptor's `discriminator`. Used for `storage.types`\n* (codec-triple hydration). Namespace entries hydration dispatches by\n* entries key, not discriminator — handled by `hydrateNamespaceEntities`.\n*/\nfunction collectStorageTypesHydrators(namespace) {\n\tconst registry = /* @__PURE__ */ new Map();\n\tconst walk = (node) => {\n\t\tfor (const value of Object.values(node)) {\n\t\t\tif (isAuthoringEntityTypeDescriptor(value)) {\n\t\t\t\tif (isAuthoringEntityTypeFactoryOutput(value.output)) {\n\t\t\t\t\tconst { factory } = value.output;\n\t\t\t\t\tregistry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof value === \"object\" && value !== null) walk(value);\n\t\t}\n\t};\n\twalk(namespace);\n\treturn registry;\n}\n/**\n* The canonicalization walk drops a field whose value equals its type's\n* default, which for a required field of an entity kind means the emitted\n* contract fails that kind's own schema on the next read (a RESTRICTIVE\n* policy's `permissive: false` is the live case). The set of fields that must\n* survive is therefore the required keys of the registered entity kinds —\n* read off the schemas rather than listed by hand, so a kind that gains a\n* required field is covered the day it gains one.\n*/\nfunction requiredEntityFieldsSurviveDefaults(kinds) {\n\treturn createPreserveEmptyPredicate(kinds.flatMap((kind) => requiredKeysOf(kind.schema).map((key) => [\n\t\t\"storage\",\n\t\t\"namespaces\",\n\t\t\"*\",\n\t\t\"entries\",\n\t\tkind.kind,\n\t\t\"*\",\n\t\tkey\n\t])));\n}\nfunction isSchemaPropList(value) {\n\treturn Array.isArray(value) && value.every((prop) => prop !== null && (typeof prop === \"object\" || typeof prop === \"function\") && \"kind\" in prop && \"key\" in prop);\n}\nfunction requiredKeysOf(schema) {\n\tconst props = \"props\" in schema ? schema.props : void 0;\n\tif (!isSchemaPropList(props)) throw new InternalError(\"entity-kind schema does not expose arktype object props; the required-field preserve set cannot be derived\");\n\treturn props.flatMap((prop) => prop.kind === \"required\" && typeof prop.key === \"string\" ? [prop.key] : []);\n}\nvar PostgresContractSerializer = class extends SqlContractSerializerBase {\n\tshouldPreserveEmpty;\n\tconstructor(extraPackEntityKinds = []) {\n\t\tconst storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n\t\tconst entityKinds = [\n\t\t\tpolicyEntityKind,\n\t\t\troleEntityKind,\n\t\t\trlsEnablementEntityKind,\n\t\t\tnativeEnumEntityKind,\n\t\t\t...extraPackEntityKinds\n\t\t];\n\t\tsuper(storageTypesHydrators, entityKinds);\n\t\tconst preserveRequired = requiredEntityFieldsSurviveDefaults(entityKinds);\n\t\tthis.shouldPreserveEmpty = (path) => preserveRequired(path) || sqlContractCanonicalizationHooks.shouldPreserveEmpty(path);\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\tconst { id, entries } = blindCast(super.hydrateSqlNamespaceEntry(nsId, raw));\n\t\tconst allSlotsEmpty = Object.values(entries).every((slot) => slot === void 0 || Object.keys(slot).length === 0);\n\t\tif (id === UNBOUND_NAMESPACE_ID && allSlotsEmpty) return PostgresSchema.unbound;\n\t\tconst valueSetSlot = entries[\"valueSet\"];\n\t\tconst hasValueSets = valueSetSlot !== void 0 && Object.keys(valueSetSlot).length > 0;\n\t\treturn new PostgresSchema({\n\t\t\tid,\n\t\t\tentries: {\n\t\t\t\t...entries,\n\t\t\t\ttable: entries[\"table\"] ?? {},\n\t\t\t\t...hasValueSets ? { valueSet: valueSetSlot } : {}\n\t\t\t}\n\t\t});\n\t}\n\tserializeContract(contract) {\n\t\tconst { storage, ...rest } = contract;\n\t\tconst namespacesJson = {};\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) {\n\t\t\tconst isUnboundSlot = ns.id === UNBOUND_NAMESPACE_ID;\n\t\t\tnamespacesJson[nsId] = {\n\t\t\t\tid: ns.id,\n\t\t\t\tkind: isUnboundSlot ? \"postgres-unbound-schema\" : \"postgres-schema\",\n\t\t\t\tentries: this.serializeNamespaceEntries(ns.entries)\n\t\t\t};\n\t\t}\n\t\tconst storageOut = {\n\t\t\tstorageHash: String(storage.storageHash),\n\t\t\tnamespaces: namespacesJson\n\t\t};\n\t\tif (storage.types !== void 0) {\n\t\t\tconst typesOut = {};\n\t\t\tfor (const [name, entry] of Object.entries(storage.types)) typesOut[name] = this.serializeJsonObject(entry);\n\t\t\tstorageOut[\"types\"] = typesOut;\n\t\t}\n\t\treturn blindCast({\n\t\t\t...rest,\n\t\t\tstorage: storageOut\n\t\t});\n\t}\n};\n//#endregion\n//#region src/core/postgres-contract-view.ts\nconst PostgresContractView = {\n\t/** Wrap an already-deserialized Postgres contract in a schema-qualified view. */\n\tfrom(contract) {\n\t\treturn buildSqlSchemaQualifiedView(contract);\n\t},\n\t/** Deserialize a Postgres contract JSON envelope and wrap it in a view. */\n\tfromJson(json) {\n\t\treturn buildSqlSchemaQualifiedView(new PostgresContractSerializer().deserializeContract(json));\n\t}\n};\n//#endregion\nexport { PostgresContractSerializer as n, PostgresContractView as t };\n\n//# sourceMappingURL=postgres-contract-view-BEp5ikai.mjs.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,yBAAyB;CAC9B,QAAQ;CACR,QAAQ;CACR,qBAAqB;EACpB,MAAM;EACN,KAAK;CACN;AACD;AACA,SAAS,mCAAmC,QAAQ;CACnD,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,aAAa,UAAU,OAAO,OAAO,YAAY;AAC1G;;;;;;;AAOA,SAAS,6BAA6B,WAAW;CAChD,MAAM,2BAA2B,IAAI,IAAI;CACzC,MAAM,QAAQ,SAAS;EACtB,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GAAG;GACxC,IAAI,gCAAgC,KAAK,GAAG;IAC3C,IAAI,mCAAmC,MAAM,MAAM,GAAG;KACrD,MAAM,EAAE,YAAY,MAAM;KAC1B,SAAS,IAAI,MAAM,gBAAgB,QAAQ,QAAQ,KAAK,sBAAsB,CAAC;IAChF;IACA;GACD;GACA,IAAI,O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AwB,eAAe,OAAO,eAAe;EACxE,MAAM,eAAe,QAAQ;EAC7B,MAAM,eAAe,iBAAiB,KAAK,KAAK,OAAO,KAAK,YAAY,CAAC,CAAC,SAAS;EACnF,OAAO,IAAI,eAAe;GACzB;GACA,SAAS;IACR,GAAG;IACH,OAAO,QAAQ,YAAY,CAAC;IAC5B,GAAG,eAAe,EAAE,UAAU,aAAa,IAAI,CAAC;GACjD;EACD,CAAC;CACF;CACA,kBAAkB,UAAU;EAC3B,MAAM,EAAE,SAAS,GAAG,SAAS;EAC7B,MAAM,iBAAiB,CAAC;EACxB,KAAK,MAAM,CAAC,MAAM,OAAO,OAAO,QAAQ,QAAQ,UAAU,GAAG;GAC5D,MAAM,gBAAgB,GAAG,OAAO;GAChC,eAAe,QAAQ;IACtB,IAAI,GAAG;IACP,MAAM,gBAAgB,4BAA4B;IAClD,SAAS,KAAK,0BAA0B,GAAG,OAAO;GACnD;EACD;EACA,MAAM,aAAa;GAClB,aAAa,OAAO,QAAQ,WAAW;GACvC,YAAY;EACb;EACA,IAAI,QAAQ,UAAU,KAAK,GAAG;GAC7B,MAAM,WAAW,CAAC;GAClB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,KAAK,GAAG,SAAS,QAAQ,KAAK,oBAAoB,KAAK;GAC1G,WAAW,WAAW;EACvB;EACA,OAAO,UAAU;GAChB,GAAG;GACH,SAAS;EACV,CAAC;CACF;AACD;AAGA,MAAM,uBAAuB;;CAE5B,KAAK,UAAU;EACd,OAAO,4BAA4B,QAAQ;CAC5C;;CAEA,SAAS,MAAM;EACd,OAAO,4BAA4B,IAAI,2BAA2B,CAAC,CAAC,oBAAoB,IAAI,CAAC;CAC9F;AACD"}
@@ -0,0 +1,569 @@
1
+ import { t as errorPostgresMigrationStackMissing } from "./errors-DYyzTYzE-39CV_aMo.mjs";
2
+ import { i as PostgresRlsPolicy, n as PostgresRlsEnablement } from "./postgres-schema-C8slJGZo-CFGUyJPt.mjs";
3
+ import { n as postgresResolveDefault } from "./default-normalizer-Cb7nWBUa-DXchlOUk.mjs";
4
+ import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-Bq4m2dD9-DrlUipYU.mjs";
5
+ import { i as renderDefaultLiteral } from "./planner-ddl-builders-DSpQVbIm-Y4SbsU-O.mjs";
6
+ import { A as RenameIndexCall, C as DropNativeEnumTypeCall, D as EnableRowLevelSecurityCall, E as DropTableCall, M as RenameTableCall, N as SetDefaultCall, P as SetNotNullCall, R as installExtension, S as DropIndexCall, T as DropPostgresRlsPolicyCall, _ as DisableRowLevelSecurityCall, b as DropConstraintCall, c as AddUniqueCall, d as CreateIndexCall, f as CreateNativeEnumTypeCall, h as CreateTableCall, i as AddNativeEnumValueCall, j as RenamePostgresRlsPolicyCall, k as RenameConstraintCall, l as AlterColumnTypeCall, m as CreateSchemaCall, n as AddColumnCall, p as CreatePostgresRlsPolicyCall, r as AddForeignKeyCall, s as AddPrimaryKeyCall, t as AddCheckConstraintCall, v as DropCheckConstraintCall, w as DropNotNullCall, x as DropDefaultCall, y as DropColumnCall } from "./op-factory-call-DYkz28kP-4BmpSB4B.mjs";
7
+ import { a as defaultUniqueName, f as resolveNamespaceIdForDdlSchema, i as defaultPrimaryKeyName, o as issueNode, r as defaultForeignKeyName } from "./control-policy-CThlWQ8k-m3CT6KpR.mjs";
8
+ import { n as buildPostgresPlanDiff, r as contractToPostgresDatabaseSchemaNode, t as buildPostgresNativeTypeExpander } from "./diff-database-schema-Bp0uC68P-NxeVJERq.mjs";
9
+ import { n as PostgresContractView } from "./postgres-contract-view-BEp5ikai-BmYXd1MR.mjs";
10
+ import { t as dataTransform } from "./data-transform-Bo32KRbq-BLn1_UG-.mjs";
11
+ import { blindCast } from "@prisma/orm-framework/utils/casts";
12
+ import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
13
+ import { issueOutcome } from "@prisma/orm-framework/components/control";
14
+ import { namingOf, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
15
+ import { assertDefined } from "@prisma/orm-framework/utils/assertions";
16
+ import { ifDefined } from "@prisma/orm-framework/utils/defined";
17
+ import { applyTableRename, buildDataTypeResolver } from "@prisma/orm-family-sql/family/control";
18
+ import { SqlCheckConstraintIR, SqlIndexIR } from "@prisma/orm-family-sql/schema-ir/types";
19
+ import { errorMigrationOperationOptionRemoved } from "@prisma/orm-framework/errors/migration";
20
+ import { Migration } from "@prisma/orm-family-sql/family/migration";
21
+ import { MigrationContractViews } from "@prisma/orm-toolchain/migration-tools/migration";
22
+ //#region ../../../3-targets/3-targets/postgres/dist/postgres-migration-DWtr5s00.mjs
23
+ /**
24
+ * Rename post-pass for indexes, per `(schema, table)`, widening-only,
25
+ * deterministic by sorted names — the same structure as the policy pass
26
+ * below (which stays untouched: policies pair by hash only).
27
+ *
28
+ * Hash pairing (prefix-only renames): extras whose live names parse as
29
+ * wire names, grouped by `(schema, table, hash)`; missing nodes iterated
30
+ * in sorted-name order consume the sorted-name-first candidate.
31
+ *
32
+ * Content pairing (exact→wire convergence), after hash pairing has
33
+ * consumed its matches: the remaining wire-named-missing nodes
34
+ * (`prefix` defined) against the remaining extras of any name shape,
35
+ * paired iff content-equal (columns ordered-strict both-defined-or-
36
+ * both-undefined, `unique`/`type` strict, `options` loose, bodies
37
+ * byte-equal).
38
+ *
39
+ * Leftovers proceed as create/drop exactly as before; without the
40
+ * widening allowance the pass is skipped and pairing degrades to the
41
+ * additive half, like the policy pass.
42
+ */
43
+ function pairIndexRenames(options, issues) {
44
+ const consumed = /* @__PURE__ */ new Set();
45
+ const calls = [];
46
+ if (!options.policy.allowedOperationClasses.includes("widening")) return {
47
+ calls,
48
+ consumed
49
+ };
50
+ const missing = [];
51
+ const extra = [];
52
+ for (const issue of issues) {
53
+ const node = issueNode(issue);
54
+ if (node === void 0 || !SqlIndexIR.is(node)) continue;
55
+ const ddlSchema = issue.path[1];
56
+ const tableName = issue.path[2];
57
+ if (ddlSchema === void 0 || tableName === void 0) continue;
58
+ if (issueOutcome(issue) === "not-found") missing.push({
59
+ issue,
60
+ node,
61
+ ddlSchema,
62
+ tableName
63
+ });
64
+ else if (issueOutcome(issue) === "not-expected") extra.push({
65
+ issue,
66
+ node,
67
+ ddlSchema,
68
+ tableName
69
+ });
70
+ }
71
+ if (missing.length === 0 || extra.length === 0) return {
72
+ calls,
73
+ consumed
74
+ };
75
+ const byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;
76
+ const emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;
77
+ const pairingKey = (finding, hash) => JSON.stringify([
78
+ finding.ddlSchema,
79
+ finding.tableName,
80
+ hash
81
+ ]);
82
+ const rename = (missingFinding, candidate) => {
83
+ consumed.add(missingFinding.issue);
84
+ consumed.add(candidate.issue);
85
+ calls.push(new RenameIndexCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));
86
+ };
87
+ const sortedMissing = [...missing].sort(byName);
88
+ const extrasByHash = /* @__PURE__ */ new Map();
89
+ for (const finding of extra) {
90
+ const parsed = parseWireName(finding.node.name);
91
+ if (parsed === void 0) continue;
92
+ const key = pairingKey(finding, parsed.hash);
93
+ const group = extrasByHash.get(key) ?? [];
94
+ group.push(finding);
95
+ extrasByHash.set(key, group);
96
+ }
97
+ for (const group of extrasByHash.values()) group.sort(byName);
98
+ for (const missingFinding of sortedMissing) {
99
+ const parsed = parseWireName(missingFinding.node.name);
100
+ if (parsed === void 0) continue;
101
+ const candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();
102
+ if (candidate === void 0) continue;
103
+ rename(missingFinding, candidate);
104
+ }
105
+ const sortedExtras = [...extra].sort(byName);
106
+ for (const missingFinding of sortedMissing) {
107
+ if (consumed.has(missingFinding.issue)) continue;
108
+ if (missingFinding.node.prefix === void 0) continue;
109
+ const candidate = sortedExtras.find((extraFinding) => !consumed.has(extraFinding.issue) && extraFinding.ddlSchema === missingFinding.ddlSchema && extraFinding.tableName === missingFinding.tableName && missingFinding.node.contentEquals(extraFinding.node, {
110
+ columnPresence: "matching",
111
+ bodies: "verbatim"
112
+ }));
113
+ if (candidate === void 0) continue;
114
+ rename(missingFinding, candidate);
115
+ }
116
+ return {
117
+ calls,
118
+ consumed
119
+ };
120
+ }
121
+ /**
122
+ * Check-constraint rename post-pass: a `not-found` and a `not-expected`
123
+ * check on the same table whose wire-name content hashes match but whose
124
+ * prefixes differ is a prefix-only rename, and collapses into one
125
+ * `ALTER TABLE … RENAME CONSTRAINT`.
126
+ *
127
+ * This is the index pass's hash-pairing phase and nothing else. There is
128
+ * deliberately no content-pairing phase: a live check body is whatever
129
+ * Postgres reprinted, so it never byte-matches the authored text, and
130
+ * pairing an exact-named live check by content would bless whatever
131
+ * predicate is actually live. Adoption of an old exact-named check stays
132
+ * drop + add.
133
+ *
134
+ * Runs only when the policy allows `widening` (rename's class). Without it
135
+ * the pass no-ops and the pair degrades to the slice-1 behavior: an add,
136
+ * plus a drop when `destructive` is allowed too.
137
+ */
138
+ function pairCheckRenames(options, issues) {
139
+ const consumed = /* @__PURE__ */ new Set();
140
+ const calls = [];
141
+ if (!options.policy.allowedOperationClasses.includes("widening")) return {
142
+ calls,
143
+ consumed
144
+ };
145
+ const missing = [];
146
+ const extra = [];
147
+ for (const issue of issues) {
148
+ const node = issueNode(issue);
149
+ if (node === void 0 || !SqlCheckConstraintIR.is(node)) continue;
150
+ const ddlSchema = issue.path[1];
151
+ const tableName = issue.path[2];
152
+ if (ddlSchema === void 0 || tableName === void 0) continue;
153
+ if (issueOutcome(issue) === "not-found") missing.push({
154
+ issue,
155
+ node,
156
+ ddlSchema,
157
+ tableName
158
+ });
159
+ else if (issueOutcome(issue) === "not-expected") extra.push({
160
+ issue,
161
+ node,
162
+ ddlSchema,
163
+ tableName
164
+ });
165
+ }
166
+ if (missing.length === 0 || extra.length === 0) return {
167
+ calls,
168
+ consumed
169
+ };
170
+ const byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;
171
+ const emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;
172
+ const pairingKey = (finding, hash) => JSON.stringify([
173
+ finding.ddlSchema,
174
+ finding.tableName,
175
+ hash
176
+ ]);
177
+ const sortedMissing = [...missing].sort(byName);
178
+ const extrasByHash = /* @__PURE__ */ new Map();
179
+ for (const finding of extra) {
180
+ const parsed = parseWireName(finding.node.name);
181
+ if (parsed === void 0) continue;
182
+ const key = pairingKey(finding, parsed.hash);
183
+ const group = extrasByHash.get(key) ?? [];
184
+ group.push(finding);
185
+ extrasByHash.set(key, group);
186
+ }
187
+ for (const group of extrasByHash.values()) group.sort(byName);
188
+ for (const missingFinding of sortedMissing) {
189
+ const parsed = parseWireName(missingFinding.node.name);
190
+ if (parsed === void 0) continue;
191
+ const candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();
192
+ if (candidate === void 0) continue;
193
+ consumed.add(missingFinding.issue);
194
+ consumed.add(candidate.issue);
195
+ calls.push(new RenameConstraintCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, "checkConstraint", candidate.node.name, missingFinding.node.name));
196
+ }
197
+ return {
198
+ calls,
199
+ consumed
200
+ };
201
+ }
202
+ function postgresRenderDefault(def, column) {
203
+ if (def.kind === "function") return def.expression;
204
+ return renderDefaultLiteral(def.value, column);
205
+ }
206
+ /**
207
+ * The Postgres schema tree a contract describes, as the planner's "from" side:
208
+ * the target descriptor's `migrations.contractToSchema` hook and the trees
209
+ * `renameTable` compares to find its companion renames both go through here,
210
+ * so they are built with the same expander, default renderer, default resolver
211
+ * and data type resolver.
212
+ */
213
+ function postgresContractToSchema(contract, frameworkComponents) {
214
+ const expander = buildPostgresNativeTypeExpander(frameworkComponents);
215
+ return contractToPostgresDatabaseSchemaNode(blindCast(contract), {
216
+ annotationNamespace: "pg",
217
+ expandNativeType: expander,
218
+ renderDefault: postgresRenderDefault,
219
+ resolveDefault: postgresResolveDefault,
220
+ ...ifDefined("dataTypeOf", buildDataTypeResolver(frameworkComponents))
221
+ });
222
+ }
223
+ function renamedMarker(marker, rename) {
224
+ if (!(marker instanceof PostgresRlsEnablement) || marker.tableName !== rename.from) return marker;
225
+ return new PostgresRlsEnablement({
226
+ tableName: rename.to,
227
+ namespaceId: marker.namespaceId
228
+ });
229
+ }
230
+ function renamedPolicy(policy, rename) {
231
+ if (!(policy instanceof PostgresRlsPolicy) || policy.tableName !== rename.from) return policy;
232
+ return new PostgresRlsPolicy({
233
+ naming: namingOf(policy.name, policy.prefix),
234
+ tableName: rename.to,
235
+ namespaceId: policy.namespaceId,
236
+ operation: policy.operation,
237
+ roles: policy.roles,
238
+ using: policy.using,
239
+ withCheck: policy.withCheck,
240
+ permissive: policy.permissive
241
+ });
242
+ }
243
+ /**
244
+ * Moves the RLS marker and the policies of a renamed table onto its new name. The marker is keyed by table name; policies are keyed by their own name and only their `tableName` changes. Policy names do not derive from the table name, so none is renamed.
245
+ */
246
+ function renameRlsReferences(entries, rename) {
247
+ const markers = entries["rls"];
248
+ const policies = entries["policy"];
249
+ return {
250
+ ...entries,
251
+ ...markers === void 0 ? {} : { rls: Object.fromEntries(Object.entries(markers).map(([tableName, marker]) => [tableName === rename.from ? rename.to : tableName, renamedMarker(marker, rename)])) },
252
+ ...policies === void 0 ? {} : { policy: Object.fromEntries(Object.entries(policies).map(([name, policy]) => [name, renamedPolicy(policy, rename)])) }
253
+ };
254
+ }
255
+ /** The constraint of the next table the diff pairs with `node` and finds unchanged, as the diff compares them. */
256
+ function unchangedIn(node, nextNodes) {
257
+ return nextNodes.find((next) => next.id === node.id && next.isEqualTo(node));
258
+ }
259
+ /**
260
+ * The constraint renames that follow a table rename. A primary key, unique constraint or foreign key the start contract left unnamed carries a name derived from the old table name. When the end contract keeps the same constraint unchanged, it is renamed to the name the end contract gives it explicitly, or otherwise to the name derived from the new table name. A constraint the end contract changes is not renamed, so it keeps its name in the database. A constraint the start contract named keeps its name. Indexes and checks are not handled here: their wire names pair by content hash in the index and check rename passes.
261
+ */
262
+ function constraintRenamesForTableRename(input) {
263
+ const { schemaName, from, to, previous, next } = input;
264
+ const rename = (kind, oldName, unchanged, derivedName) => {
265
+ if (unchanged === void 0) return [];
266
+ const newName = unchanged.name ?? derivedName;
267
+ return oldName === newName ? [] : [new RenameConstraintCall(schemaName, to, kind, oldName, newName)];
268
+ };
269
+ const primaryKey = previous.primaryKey !== void 0 && previous.primaryKey.name === void 0 ? rename("primaryKey", defaultPrimaryKeyName(from), unchangedIn(previous.primaryKey, next.primaryKey === void 0 ? [] : [next.primaryKey]), defaultPrimaryKeyName(to)) : [];
270
+ const uniques = previous.uniques.filter((unique) => unique.name === void 0).flatMap((unique) => rename("unique", defaultUniqueName(from, unique.columns), unchangedIn(unique, next.uniques), defaultUniqueName(to, unique.columns)));
271
+ const foreignKeys = previous.foreignKeys.filter((fk) => fk.name === void 0).flatMap((fk) => rename("foreignKey", defaultForeignKeyName(from, fk.columns), unchangedIn(fk, next.foreignKeys), defaultForeignKeyName(to, fk.columns)));
272
+ return [
273
+ ...primaryKey,
274
+ ...uniques,
275
+ ...foreignKeys
276
+ ];
277
+ }
278
+ const RENAME_POLICY = { allowedOperationClasses: ["widening"] };
279
+ function emissionSchemaForNamespace(contract, namespaceId) {
280
+ return namespaceId === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : resolveDdlSchemaForNamespaceStorage(contract.storage, namespaceId);
281
+ }
282
+ function renamedTableNode(schema, contract, rename) {
283
+ const ddlSchema = resolveDdlSchemaForNamespaceStorage(contract.storage, rename.namespaceId);
284
+ const table = Object.values(schema.namespaces).find((namespace) => namespace.schemaName === ddlSchema)?.tables[rename.to];
285
+ assertDefined(table, `a resolved rename names table "${rename.to}" in schema "${ddlSchema}"`);
286
+ return table;
287
+ }
288
+ /**
289
+ * The calls a migration's `renameTable` emits: the table rename, then a rename of each primary key, unique constraint and foreign key the start contract left unnamed, and of each wire-named index and check whose prefix derives from the table name. Only objects the end contract leaves otherwise unchanged are renamed; an unchanged constraint takes the end contract's explicit name if it has one. Throws `MIGRATION.TABLE_RENAME_UNMATCHED` when the start contract lacks the table or the end contract lacks the new name.
290
+ */
291
+ function postgresTableRenameCalls(input) {
292
+ const applied = applyTableRename({
293
+ startContract: input.startContract,
294
+ endContract: input.endContract,
295
+ rename: input.rename,
296
+ renameTableReferences: renameRlsReferences
297
+ });
298
+ if (!applied.ok) throw applied.failure;
299
+ const { rename } = applied.value;
300
+ const contract = input.endContract;
301
+ const schemaName = emissionSchemaForNamespace(contract, rename.namespaceId);
302
+ const previousSchema = postgresContractToSchema(applied.value.contract, input.frameworkComponents);
303
+ const nextSchema = postgresContractToSchema(contract, input.frameworkComponents);
304
+ const { issues } = buildPostgresPlanDiff({
305
+ contract,
306
+ actualSchema: previousSchema,
307
+ frameworkComponents: input.frameworkComponents
308
+ });
309
+ const onRenamedTable = (call) => call.schemaName === schemaName && call.tableName === rename.to;
310
+ const pairing = {
311
+ contract,
312
+ policy: RENAME_POLICY
313
+ };
314
+ return [
315
+ new RenameTableCall(schemaName, rename.from, rename.to),
316
+ ...constraintRenamesForTableRename({
317
+ schemaName,
318
+ from: rename.from,
319
+ to: rename.to,
320
+ previous: renamedTableNode(previousSchema, contract, rename),
321
+ next: renamedTableNode(nextSchema, contract, rename)
322
+ }),
323
+ ...pairIndexRenames(pairing, issues).calls.filter(onRenamedTable),
324
+ ...pairCheckRenames(pairing, issues).calls.filter(onRenamedTable)
325
+ ];
326
+ }
327
+ /**
328
+ * Target-owned base class for Postgres migrations.
329
+ *
330
+ * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the
331
+ * abstract `targetId` to the Postgres target-id string literal, so both
332
+ * user-authored migrations and renderer-generated scaffolds (the output of
333
+ * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without
334
+ * redeclaring target-local identity.
335
+ *
336
+ * Mirrors `MongoMigration` in `@internal/family-mongo`: the renderer
337
+ * emits `extends Migration` against a facade re-export of this class
338
+ * from `@internal/postgres/migration`, keeping the authoring surface
339
+ * target-scoped rather than family-scoped.
340
+ *
341
+ * The constructor materializes a single Postgres `SqlControlAdapter` from
342
+ * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`
343
+ * instance method forwards to the free `dataTransform` factory with that
344
+ * stored adapter, so user migrations can write `this.dataTransform(...)`
345
+ * without threading the adapter through every call.
346
+ *
347
+ * Every method requires an explicit `schema`. Postgres migrations name their
348
+ * schema deliberately — there is no default and no `search_path`-relative
349
+ * option. A migration that left the schema unspecified would resolve against
350
+ * whatever `search_path` the connection happened to carry, and that ambiguity
351
+ * is an antipattern in a migration. (The unbound/unspecified namespace concept
352
+ * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
353
+ */
354
+ var PostgresMigration = class extends Migration {
355
+ targetId = "postgres";
356
+ /**
357
+ * Materialized Postgres control adapter, created once per migration
358
+ * instance from the injected stack. `undefined` only when the migration
359
+ * was instantiated without a stack (test fixtures); `controlAdapterFor`
360
+ * throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING in that case to surface the misuse.
361
+ */
362
+ controlAdapter;
363
+ #endView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
364
+ #startView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
365
+ constructor(stack) {
366
+ super(stack);
367
+ this.controlAdapter = stack?.adapter ? blindCast(stack.adapter.create(stack)) : void 0;
368
+ }
369
+ frameworkComponents() {
370
+ const stack = this.stack;
371
+ if (stack === void 0) return [];
372
+ return [
373
+ stack.target,
374
+ ...stack.adapter === void 0 ? [] : [stack.adapter],
375
+ ...stack.extensions
376
+ ];
377
+ }
378
+ /**
379
+ * Returns the materialized control adapter, or throws a MIGRATION.POSTGRES_CONTROL_STACK_MISSING naming
380
+ * `operation` when the migration was constructed without a `ControlStack`.
381
+ * Single home for the null-check that every DDL/DML method shares.
382
+ */
383
+ controlAdapterFor(operation) {
384
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing(operation);
385
+ return this.controlAdapter;
386
+ }
387
+ /**
388
+ * The typed, schema-qualified Postgres view over this migration's end-state
389
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
390
+ * if no `endContractJson` was provided.
391
+ */
392
+ get endContract() {
393
+ return this.#endView.endContract;
394
+ }
395
+ /**
396
+ * The typed Postgres view over this migration's start-state contract, or
397
+ * `null` for a baseline migration (no `startContractJson`).
398
+ */
399
+ get startContract() {
400
+ return this.#startView.startContract;
401
+ }
402
+ /**
403
+ * Instance-method wrapper around the free `dataTransform` factory that
404
+ * supplies the stored control adapter. Authors call this from inside
405
+ * `get operations()`; the adapter argument is hidden from the call site.
406
+ */
407
+ dataTransform(contract, name, options) {
408
+ return dataTransform(contract, name, options, this.controlAdapterFor("dataTransform"));
409
+ }
410
+ /**
411
+ * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
412
+ * the supplied options and lowers it through the stored control adapter.
413
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
414
+ */
415
+ createTable(options) {
416
+ return new CreateTableCall(options.schema, options.table, options.columns, options.constraints).toOp(this.controlAdapterFor("createTable"));
417
+ }
418
+ /**
419
+ * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
420
+ * the supplied options and lowers it through the stored control adapter.
421
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
422
+ */
423
+ createSchema(options) {
424
+ return new CreateSchemaCall(options.schema).toOp(this.controlAdapterFor("createSchema"));
425
+ }
426
+ /**
427
+ * Emit a `CREATE TYPE ... AS ENUM (...)` migration operation for a managed
428
+ * native enum. Builds a typed DDL node and lowers it through the stored
429
+ * control adapter (members render in declaration order). Throws if no adapter
430
+ * is present.
431
+ */
432
+ createNativeEnumType(options) {
433
+ return new CreateNativeEnumTypeCall(options.schema, options.typeName, options.members).toOp(this.controlAdapterFor("createNativeEnumType"));
434
+ }
435
+ /**
436
+ * Emit a `DROP TYPE` migration operation for a managed native enum, lowered
437
+ * through the stored control adapter. Throws if no adapter is present.
438
+ */
439
+ dropNativeEnumType(options) {
440
+ return new DropNativeEnumTypeCall(options.schema, options.typeName).toOp(this.controlAdapterFor("dropNativeEnumType"));
441
+ }
442
+ /**
443
+ * Emit an `ALTER TYPE ... ADD VALUE` migration operation appending one
444
+ * member to a managed native enum, lowered through the stored control
445
+ * adapter. Throws if no adapter is present. Every appended value is its
446
+ * own operation — call this once per value to append more than one.
447
+ */
448
+ addNativeEnumValue(options) {
449
+ return new AddNativeEnumValueCall(options.schema, options.typeName, options.value).toOp(this.controlAdapterFor("addNativeEnumValue"));
450
+ }
451
+ addColumn(options) {
452
+ return new AddColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("addColumn"));
453
+ }
454
+ addPrimaryKey(options) {
455
+ return new AddPrimaryKeyCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapterFor("addPrimaryKey"));
456
+ }
457
+ addUnique(options) {
458
+ return new AddUniqueCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapterFor("addUnique"));
459
+ }
460
+ addForeignKey(options) {
461
+ return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(this.controlAdapterFor("addForeignKey"));
462
+ }
463
+ addCheckConstraint(options) {
464
+ return new AddCheckConstraintCall(options.schema, options.table, options.constraint, options.expression).toOp(this.controlAdapterFor("addCheckConstraint"));
465
+ }
466
+ renameCheckConstraint(options) {
467
+ return this.renameConstraint({
468
+ ...options,
469
+ kind: "checkConstraint"
470
+ });
471
+ }
472
+ renameConstraint(options) {
473
+ return new RenameConstraintCall(options.schema ?? UNBOUND_NAMESPACE_ID, options.table, options.kind, options.from, options.to).toOp(this.controlAdapterFor("renameConstraint"));
474
+ }
475
+ dropCheckConstraint(options) {
476
+ return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(this.controlAdapterFor("dropCheckConstraint"));
477
+ }
478
+ dropConstraint(options) {
479
+ return new DropConstraintCall(options.schema, options.table, options.constraint, options.kind ?? "unique").toOp(this.controlAdapterFor("dropConstraint"));
480
+ }
481
+ /**
482
+ * Emit the operations that rename a table: the table rename, then a rename of each primary key, unique constraint, foreign key, index and check whose name was derived from the old table name, read from this migration's start and end contracts. Spread the result into `operations`: `...this.renameTable({ table: 'userProfile', to: 'UserProfile' })`. `schema` names the table's namespace when more than one declares the table. Throws `MIGRATION.TABLE_RENAME_UNMATCHED` when the start contract lacks the table or the end contract lacks the new name.
483
+ */
484
+ renameTable(options) {
485
+ const adapter = this.controlAdapterFor("renameTable");
486
+ return postgresTableRenameCalls({
487
+ startContract: this.startContract,
488
+ endContract: this.endContract,
489
+ rename: {
490
+ namespaceId: options.schema,
491
+ from: options.table,
492
+ to: options.to
493
+ },
494
+ frameworkComponents: this.frameworkComponents()
495
+ }).map(async (call) => call.toOp(adapter));
496
+ }
497
+ dropTable(options) {
498
+ return new DropTableCall(options.schema, options.table).toOp(this.controlAdapterFor("dropTable"));
499
+ }
500
+ dropColumn(options) {
501
+ return new DropColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropColumn"));
502
+ }
503
+ alterColumnType(options) {
504
+ return new AlterColumnTypeCall(options.schema, options.table, options.column, options.options).toOp(this.controlAdapterFor("alterColumnType"));
505
+ }
506
+ setNotNull(options) {
507
+ return new SetNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("setNotNull"));
508
+ }
509
+ dropNotNull(options) {
510
+ return new DropNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropNotNull"));
511
+ }
512
+ setDefault(options) {
513
+ refuseEarlierSetDefaultOptions(options);
514
+ return new SetDefaultCall(options.schema, options.table, options.column, options.operationClass).toOp(this.controlAdapterFor("setDefault"));
515
+ }
516
+ dropDefault(options) {
517
+ return new DropDefaultCall(options.schema, options.table, options.column).toOp(this.controlAdapterFor("dropDefault"));
518
+ }
519
+ createIndex(options) {
520
+ return new CreateIndexCall(options.schema, options.table, options.index, options.columns !== void 0 ? { columns: options.columns } : { expression: options.expression }, options.extras).toOp(this.controlAdapterFor("createIndex"));
521
+ }
522
+ renameIndex(options) {
523
+ return new RenameIndexCall(options.schema, options.table, options.from, options.to).toOp(this.controlAdapterFor("renameIndex"));
524
+ }
525
+ dropIndex(options) {
526
+ return new DropIndexCall(options.schema, options.table, options.index).toOp(this.controlAdapterFor("dropIndex"));
527
+ }
528
+ installExtension(options) {
529
+ return installExtension(options, this.controlAdapterFor("installExtension"));
530
+ }
531
+ enableRowLevelSecurity(options) {
532
+ return new EnableRowLevelSecurityCall(options.schema, options.table).toOp(this.controlAdapterFor("enableRowLevelSecurity"));
533
+ }
534
+ disableRowLevelSecurity(options) {
535
+ return new DisableRowLevelSecurityCall(options.schema, options.table).toOp(this.controlAdapterFor("disableRowLevelSecurity"));
536
+ }
537
+ createRlsPolicy(options) {
538
+ return new CreatePostgresRlsPolicyCall(options.schema, options.table, new PostgresRlsPolicy({
539
+ ...options.policy,
540
+ using: options.policy.using,
541
+ withCheck: options.policy.withCheck
542
+ })).toOp(this.controlAdapterFor("createRlsPolicy"));
543
+ }
544
+ dropRlsPolicy(options) {
545
+ return new DropPostgresRlsPolicyCall(options.schema, options.table, options.policy).toOp(this.controlAdapterFor("dropRlsPolicy"));
546
+ }
547
+ renameRlsPolicy(options) {
548
+ return new RenamePostgresRlsPolicyCall(options.schema, options.table, options.from, options.to).toOp(this.controlAdapterFor("renameRlsPolicy"));
549
+ }
550
+ };
551
+ /**
552
+ * `setDefault` options an earlier version wrote carry the column's name in `column` and its default as SQL text in `defaultSql`.
553
+ */
554
+ function refuseEarlierSetDefaultOptions(options) {
555
+ const column = options.column;
556
+ const columnIsName = typeof column === "string";
557
+ if (!columnIsName && !Object.hasOwn(options, "defaultSql")) return;
558
+ throw errorMigrationOperationOptionRemoved({
559
+ operation: "setDefault",
560
+ option: "defaultSql",
561
+ subject: `column ${JSON.stringify(columnIsName ? column : options.column.name)} of table ${JSON.stringify(options.table)}`,
562
+ rewrite: "Pass the column as `col(name, type, { default, codecRef })`, with its default written as `lit(value)` or `fn(expression)`, in place of its name and `defaultSql`.",
563
+ upgradeEntry: "migration-ts-column-defaults"
564
+ });
565
+ }
566
+ //#endregion
567
+ export { postgresContractToSchema as a, pairIndexRenames as i, emissionSchemaForNamespace as n, postgresRenderDefault as o, pairCheckRenames as r, PostgresMigration as t };
568
+
569
+ //# sourceMappingURL=postgres-migration-DWtr5s00-CSlA4I1U.mjs.map