@prisma/orm-target-postgres 0.16.0-dev.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/adapter-CWvVo0PV.d.mts +22 -0
- package/dist/adapter-CWvVo0PV.d.mts.map +1 -0
- package/dist/adapter-DhqcO3YO-jzwDVcCv.mjs +70 -0
- package/dist/adapter-DhqcO3YO-jzwDVcCv.mjs.map +1 -0
- package/dist/adapter.d.mts +12 -0
- package/dist/adapter.mjs +7 -0
- package/dist/adapter__adapter.d.mts +2 -0
- package/dist/adapter__adapter.mjs +2 -0
- package/dist/adapter__column-types.d.mts +2 -0
- package/dist/adapter__column-types.mjs +2 -0
- package/dist/adapter__control.d.mts +5 -0
- package/dist/adapter__control.mjs +441 -0
- package/dist/adapter__control.mjs.map +1 -0
- package/dist/adapter__operation-types.d.mts +2 -0
- package/dist/adapter__operation-types.mjs +1 -0
- package/dist/adapter__runtime.d.mts +2 -0
- package/dist/adapter__runtime.mjs +38 -0
- package/dist/adapter__runtime.mjs.map +1 -0
- package/dist/adapter__types.d.mts +4 -0
- package/dist/adapter__types.mjs +1 -0
- package/dist/authoring-03FwIL2k-kPjZAp3s.mjs +757 -0
- package/dist/authoring-03FwIL2k-kPjZAp3s.mjs.map +1 -0
- package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts +34 -0
- package/dist/canonicalize-CQlxSR4D-MnrT5gtW.d.mts.map +1 -0
- package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs +59 -0
- package/dist/canonicalize-CrN3u_xM-D4MrOqcB.mjs.map +1 -0
- package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts +37 -0
- package/dist/codec-descriptor-Bec_zukr-BfvtUqhm.d.mts.map +1 -0
- package/dist/codec-descriptor-Bg-_412t.d.mts +1 -0
- package/dist/codec-descriptor-CB6x0xEu-C-Zn2IEz.mjs +135 -0
- package/dist/codec-descriptor-CB6x0xEu-C-Zn2IEz.mjs.map +1 -0
- package/dist/codec-ids-CsOU3xDv-mPI0INiF.d.mts +33 -0
- package/dist/codec-ids-CsOU3xDv-mPI0INiF.d.mts.map +1 -0
- package/dist/codec-ids-fgafMLR7.d.mts +1 -0
- package/dist/codec-ids-tX7Svtz--BuOfRaVU.mjs +33 -0
- package/dist/codec-ids-tX7Svtz--BuOfRaVU.mjs.map +1 -0
- package/dist/codec-types-BHwY9Ff-.d.mts +2 -0
- package/dist/codec-types-mWhnDEAf-CAQzGFnF.d.mts +82 -0
- package/dist/codec-types-mWhnDEAf-CAQzGFnF.d.mts.map +1 -0
- package/dist/codecs-CBl0nD44-CaWPc1bd.mjs +1486 -0
- package/dist/codecs-CBl0nD44-CaWPc1bd.mjs.map +1 -0
- package/dist/codecs-CHIVTNZs.mjs +15 -0
- package/dist/codecs-CHIVTNZs.mjs.map +1 -0
- package/dist/codecs-Cvqvb9pV-Cdc51FKY.d.mts +589 -0
- package/dist/codecs-Cvqvb9pV-Cdc51FKY.d.mts.map +1 -0
- package/dist/codecs-DBn-uIv-.d.mts +15 -0
- package/dist/codecs-DBn-uIv-.d.mts.map +1 -0
- package/dist/column-types-BH-MU6uU.d.mts +108 -0
- package/dist/column-types-BH-MU6uU.d.mts.map +1 -0
- package/dist/column-types-CwAyCgp2.mjs +126 -0
- package/dist/column-types-CwAyCgp2.mjs.map +1 -0
- package/dist/contract-free-BZUS18FU.mjs +118 -0
- package/dist/contract-free-BZUS18FU.mjs.map +1 -0
- package/dist/contract-free-DzpGxLfb.d.mts +258 -0
- package/dist/contract-free-DzpGxLfb.d.mts.map +1 -0
- package/dist/control-2F195jJk.d.mts +11 -0
- package/dist/control-2F195jJk.d.mts.map +1 -0
- package/dist/control-6WFTtLAM.mjs +60 -0
- package/dist/control-6WFTtLAM.mjs.map +1 -0
- package/dist/control-B-FTbEnE.d.mts +22 -0
- package/dist/control-B-FTbEnE.d.mts.map +1 -0
- package/dist/control-D85zv_aY.d.mts +199 -0
- package/dist/control-D85zv_aY.d.mts.map +1 -0
- package/dist/control-DRMWptiJ.mjs +1355 -0
- package/dist/control-DRMWptiJ.mjs.map +1 -0
- package/dist/control-adapter-B9t0g7Pf-HrCxlM65.mjs +1901 -0
- package/dist/control-adapter-B9t0g7Pf-HrCxlM65.mjs.map +1 -0
- package/dist/control-policy-Cl3RRSPg-CT3QGpR3.mjs +1257 -0
- package/dist/control-policy-Cl3RRSPg-CT3QGpR3.mjs.map +1 -0
- package/dist/data-transform-BSM7TQpE.d.mts +1 -0
- package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs +53 -0
- package/dist/data-transform-ChZzy2dP-CxVCat_8.mjs.map +1 -0
- package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts +38 -0
- package/dist/data-transform-Ck5FbyNO-BNE7QlAo.d.mts.map +1 -0
- package/dist/ddl-B4Rh8ntj.d.mts +1 -0
- package/dist/ddl-BdP4q3KY-Duef4uHw.mjs +395 -0
- package/dist/ddl-BdP4q3KY-Duef4uHw.mjs.map +1 -0
- package/dist/default-normalizer-B36TOul4.d.mts +31 -0
- package/dist/default-normalizer-B36TOul4.d.mts.map +1 -0
- package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs +253 -0
- package/dist/default-normalizer-Ba5ZebHM-isV86rjy.mjs.map +1 -0
- package/dist/descriptor-meta-2IlVC6_d-DnV00Qd_.mjs +351 -0
- package/dist/descriptor-meta-2IlVC6_d-DnV00Qd_.mjs.map +1 -0
- package/dist/descriptor-meta-DnHabAS3-C53XXPQw.mjs +28 -0
- package/dist/descriptor-meta-DnHabAS3-C53XXPQw.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs +13 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD-B_m_Ha8r.mjs.map +1 -0
- package/dist/diff-database-schema-BfRs2vrG-D2o4KII0.mjs +390 -0
- package/dist/diff-database-schema-BfRs2vrG-D2o4KII0.mjs.map +1 -0
- package/dist/diff-database-schema-DsoNznGC.d.mts +38 -0
- package/dist/diff-database-schema-DsoNznGC.d.mts.map +1 -0
- package/dist/driver.d.mts +3 -0
- package/dist/driver.mjs +2 -0
- package/dist/driver__control.d.mts +2 -0
- package/dist/driver__control.mjs +2 -0
- package/dist/driver__runtime.d.mts +2 -0
- package/dist/driver__runtime.mjs +597 -0
- package/dist/driver__runtime.mjs.map +1 -0
- package/dist/errors-DCcVX4j1.d.mts +32 -0
- package/dist/errors-DCcVX4j1.d.mts.map +1 -0
- package/dist/errors-kYxOQjdD-D4T3rbVp.mjs +39 -0
- package/dist/errors-kYxOQjdD-D4T3rbVp.mjs.map +1 -0
- package/dist/issue-planner-jkY6p-Ca.d.mts +105 -0
- package/dist/issue-planner-jkY6p-Ca.d.mts.map +1 -0
- package/dist/migration-CBSAPE8S.d.mts +25 -0
- package/dist/migration-CBSAPE8S.d.mts.map +1 -0
- package/dist/migration-PTHAY9Cv.mjs +21 -0
- package/dist/migration-PTHAY9Cv.mjs.map +1 -0
- package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86-Cpp8PTxD.mjs.map +1 -0
- package/dist/native-type-normalizer-DqJlOTeX.d.mts +19 -0
- package/dist/native-type-normalizer-DqJlOTeX.d.mts.map +1 -0
- package/dist/native-type-normalizer-yvd3tqv-.mjs +38 -0
- package/dist/native-type-normalizer-yvd3tqv-.mjs.map +1 -0
- package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts +235 -0
- package/dist/nodes-BU-V-aZA-RqwPH68u.d.mts.map +1 -0
- package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs +255 -0
- package/dist/nodes-DAvDJLvJ-BBdvFXNa.mjs.map +1 -0
- package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs +121 -0
- package/dist/normalize-error-CNjgVO71-CLlZ3CuJ.mjs.map +1 -0
- package/dist/op-factory-call-DifL68KT-Bo6pxs-R.mjs +2009 -0
- package/dist/op-factory-call-DifL68KT-Bo6pxs-R.mjs.map +1 -0
- package/dist/op-factory-call-FEA5mnWH.d.mts +1 -0
- package/dist/op-factory-call-jd4cgfjA-CyNT4YVn.d.mts +521 -0
- package/dist/op-factory-call-jd4cgfjA-CyNT4YVn.d.mts.map +1 -0
- package/dist/operation-types-BfRocNI8.d.mts +22 -0
- package/dist/operation-types-BfRocNI8.d.mts.map +1 -0
- package/dist/pack-DFM4tmob.d.mts +610 -0
- package/dist/pack-DFM4tmob.d.mts.map +1 -0
- package/dist/planner-Bmje9ii8-B99fEsNM.mjs +588 -0
- package/dist/planner-Bmje9ii8-B99fEsNM.mjs.map +1 -0
- package/dist/planner-DL4Bh5Nk.d.mts +163 -0
- package/dist/planner-DL4Bh5Nk.d.mts.map +1 -0
- package/dist/planner-ddl-builders-CbfICQfm-CxYiLrhX.mjs +102 -0
- package/dist/planner-ddl-builders-CbfICQfm-CxYiLrhX.mjs.map +1 -0
- package/dist/planner-ddl-builders-ijp60-JO.d.mts +19 -0
- package/dist/planner-ddl-builders-ijp60-JO.d.mts.map +1 -0
- package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs +90 -0
- package/dist/planner-identity-values-BmHn5C6U-BYBbUAyR.mjs.map +1 -0
- package/dist/planner-identity-values-TfEhnoWa.d.mts +25 -0
- package/dist/planner-identity-values-TfEhnoWa.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration-B0PQLLUb-qsS6cQqX.d.mts +25 -0
- package/dist/planner-produced-postgres-migration-B0PQLLUb-qsS6cQqX.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration-C3GPZWeC.d.mts +1 -0
- package/dist/planner-produced-postgres-migration-Cicg2sXg-Ck9iDxGI.mjs +47 -0
- package/dist/planner-produced-postgres-migration-Cicg2sXg-Ck9iDxGI.mjs.map +1 -0
- package/dist/planner-schema-lookup-C4DHAddq.d.mts +21 -0
- package/dist/planner-schema-lookup-C4DHAddq.d.mts.map +1 -0
- package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs +57 -0
- package/dist/planner-schema-lookup-kMIVP2y--CdO4VlnF.mjs.map +1 -0
- package/dist/planner-sql-checks-CFgbRTJw.d.mts +20 -0
- package/dist/planner-sql-checks-CFgbRTJw.d.mts.map +1 -0
- package/dist/planner-sql-checks-DRc_78n8-C9nHOrvU.mjs +152 -0
- package/dist/planner-sql-checks-DRc_78n8-C9nHOrvU.mjs.map +1 -0
- package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts +12 -0
- package/dist/planner-target-details-HkP4RrRO-_xPQVPF0.d.mts.map +1 -0
- package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs +15 -0
- package/dist/planner-type-resolution-Bt2f_q-F-C4T6YTae.mjs.map +1 -0
- package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts +36 -0
- package/dist/postgres-contract-view-2OP5JnXl-D2fpy4-8.d.mts.map +1 -0
- package/dist/postgres-contract-view-FdLX7dV9-Cat1VKV9.mjs +144 -0
- package/dist/postgres-contract-view-FdLX7dV9-Cat1VKV9.mjs.map +1 -0
- package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts +285 -0
- package/dist/postgres-database-schema-node-CyfpHXDr-BqyozkQE.d.mts.map +1 -0
- package/dist/postgres-migration-CDJj7CvD-Bsqs_fVo.d.mts +260 -0
- package/dist/postgres-migration-CDJj7CvD-Bsqs_fVo.d.mts.map +1 -0
- package/dist/postgres-migration-CJshdIZn-DYYjgdD0.mjs +201 -0
- package/dist/postgres-migration-CJshdIZn-DYYjgdD0.mjs.map +1 -0
- package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs +45 -0
- package/dist/postgres-native-enum-CdP3b_-R-Cgz9KEKx.mjs.map +1 -0
- package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts +61 -0
- package/dist/postgres-rls-policy-CnDxf3z9-C3LIHAIG.d.mts.map +1 -0
- package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs +204 -0
- package/dist/postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs.map +1 -0
- package/dist/postgres-schema-KSzLDONj-CsXGoY8b.mjs +421 -0
- package/dist/postgres-schema-KSzLDONj-CsXGoY8b.mjs.map +1 -0
- package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts +269 -0
- package/dist/postgres-schema-Xsjt3RKO-Buv2X8ai.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs +212 -0
- package/dist/postgres-table-schema-node-BBkitBQh-DT1T5VWU.mjs.map +1 -0
- package/dist/render-ops-DPwhZt2W.d.mts +11 -0
- package/dist/render-ops-DPwhZt2W.d.mts.map +1 -0
- package/dist/render-ops-DxzTxSsv-Bz85uUHk.mjs +34 -0
- package/dist/render-ops-DxzTxSsv-Bz85uUHk.mjs.map +1 -0
- package/dist/render-typescript-6sCFvMBh.d.mts +21 -0
- package/dist/render-typescript-6sCFvMBh.d.mts.map +1 -0
- package/dist/render-typescript-Cw3lFO28-Cx0lXWmv.mjs +117 -0
- package/dist/render-typescript-Cw3lFO28-Cx0lXWmv.mjs.map +1 -0
- package/dist/resolve-ddl-schema-CxqlLW47-0GiHRziS.mjs +22 -0
- package/dist/resolve-ddl-schema-CxqlLW47-0GiHRziS.mjs.map +1 -0
- package/dist/runtime-BbSRVwdd.d.mts +12 -0
- package/dist/runtime-BbSRVwdd.d.mts.map +1 -0
- package/dist/runtime-CDewySU9.d.mts +55 -0
- package/dist/runtime-CDewySU9.d.mts.map +1 -0
- package/dist/runtime-_TfO66h5.d.mts +32 -0
- package/dist/runtime-_TfO66h5.d.mts.map +1 -0
- package/dist/schema-ir-annotations-DuuYh0gl.d.mts +15 -0
- package/dist/schema-ir-annotations-DuuYh0gl.d.mts.map +1 -0
- package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts +30 -0
- package/dist/schema-node-kinds-qlnURWJy-Bo30pwTM.d.mts.map +1 -0
- package/dist/sql-utils-BnBlQxyh-DaX9Nb7Z.mjs +90 -0
- package/dist/sql-utils-BnBlQxyh-DaX9Nb7Z.mjs.map +1 -0
- package/dist/sql-utils-DW6fkczF.d.mts +62 -0
- package/dist/sql-utils-DW6fkczF.d.mts.map +1 -0
- package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts +15 -0
- package/dist/table-source-ikHOZmhD-DriY1Lcr.d.mts.map +1 -0
- package/dist/target.d.mts +47 -0
- package/dist/target.mjs +34 -0
- package/dist/target__codec-descriptor.d.mts +3 -0
- package/dist/target__codec-descriptor.mjs +2 -0
- package/dist/target__codec-ids.d.mts +3 -0
- package/dist/target__codec-ids.mjs +2 -0
- package/dist/target__codec-types.d.mts +4 -0
- package/dist/target__codec-types.mjs +1 -0
- package/dist/target__codecs.d.mts +3 -0
- package/dist/target__codecs.mjs +3 -0
- package/dist/target__contract-free.d.mts +3 -0
- package/dist/target__contract-free.mjs +4 -0
- package/dist/target__control.d.mts +2 -0
- package/dist/target__control.mjs +2 -0
- package/dist/target__data-transform.d.mts +3 -0
- package/dist/target__data-transform.mjs +2 -0
- package/dist/target__ddl.d.mts +4 -0
- package/dist/target__ddl.mjs +2 -0
- package/dist/target__default-normalizer.d.mts +2 -0
- package/dist/target__default-normalizer.mjs +2 -0
- package/dist/target__diff-database-schema.d.mts +2 -0
- package/dist/target__diff-database-schema.mjs +2 -0
- package/dist/target__errors.d.mts +2 -0
- package/dist/target__errors.mjs +2 -0
- package/dist/target__issue-planner.d.mts +2 -0
- package/dist/target__issue-planner.mjs +2 -0
- package/dist/target__migration.d.mts +4 -0
- package/dist/target__migration.mjs +5 -0
- package/dist/target__native-type-normalizer.d.mts +2 -0
- package/dist/target__native-type-normalizer.mjs +2 -0
- package/dist/target__op-factory-call.d.mts +3 -0
- package/dist/target__op-factory-call.mjs +2 -0
- package/dist/target__pack.d.mts +2 -0
- package/dist/target__pack.mjs +2 -0
- package/dist/target__planner-ddl-builders.d.mts +2 -0
- package/dist/target__planner-ddl-builders.mjs +2 -0
- package/dist/target__planner-identity-values.d.mts +2 -0
- package/dist/target__planner-identity-values.mjs +2 -0
- package/dist/target__planner-produced-postgres-migration.d.mts +3 -0
- package/dist/target__planner-produced-postgres-migration.mjs +2 -0
- package/dist/target__planner-schema-lookup.d.mts +2 -0
- package/dist/target__planner-schema-lookup.mjs +2 -0
- package/dist/target__planner-sql-checks.d.mts +2 -0
- package/dist/target__planner-sql-checks.mjs +2 -0
- package/dist/target__planner-target-details.d.mts +2 -0
- package/dist/target__planner-target-details.mjs +1 -0
- package/dist/target__planner.d.mts +2 -0
- package/dist/target__planner.mjs +3 -0
- package/dist/target__render-ops.d.mts +2 -0
- package/dist/target__render-ops.mjs +2 -0
- package/dist/target__render-typescript.d.mts +2 -0
- package/dist/target__render-typescript.mjs +2 -0
- package/dist/target__rls-canonicalize.d.mts +2 -0
- package/dist/target__rls-canonicalize.mjs +2 -0
- package/dist/target__runtime.d.mts +3 -0
- package/dist/target__runtime.mjs +23 -0
- package/dist/target__runtime.mjs.map +1 -0
- package/dist/target__schema-ir-annotations.d.mts +2 -0
- package/dist/target__schema-ir-annotations.mjs +2 -0
- package/dist/target__sql-utils.d.mts +2 -0
- package/dist/target__sql-utils.mjs +2 -0
- package/dist/target__types.d.mts +7 -0
- package/dist/target__types.mjs +5 -0
- package/dist/types-CkryN1AS-6MNZLjLY.d.mts +27 -0
- package/dist/types-CkryN1AS-6MNZLjLY.d.mts.map +1 -0
- package/dist/types-Cp_Jf2tk.d.mts +1 -0
- package/dist/types-ue6jkJyF-BQJzjx1P.d.mts +10 -0
- package/dist/types-ue6jkJyF-BQJzjx1P.d.mts.map +1 -0
- package/dist/types-xa86TkcV.d.mts +32 -0
- package/dist/types-xa86TkcV.d.mts.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86-Cpp8PTxD.mjs";
|
|
2
|
+
import { d as isPostgresSchema, i as PostgresRlsPolicy } from "./postgres-schema-KSzLDONj-CsXGoY8b.mjs";
|
|
3
|
+
import { n as PostgresNamespaceSchemaNode, r as PostgresPolicySchemaNode, t as PostgresDatabaseSchemaNode } from "./postgres-role-schema-node-B8Z5i5D--PObwlU2Z.mjs";
|
|
4
|
+
import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-CxqlLW47-0GiHRziS.mjs";
|
|
5
|
+
import { A as RenamePostgresRlsPolicyCall, T as DropPostgresRlsPolicyCall, k as RenameIndexCall, p as CreatePostgresRlsPolicyCall } from "./op-factory-call-DifL68KT-Bo6pxs-R.mjs";
|
|
6
|
+
import { a as planIssues, c as renderPostgresSuppression, d as resolvePostgresNodeIssueControlPolicySubject, f as resolvePostgresNodeIssueCreationFactoryName, i as issueSchemaName, l as resolveNamespaceIdForDdlSchema, n as conflictForDisallowedCall, o as postgresNodeStorageCoordinate, r as issueNode, s as postgresPlannerStrategies, t as coalesceSubtreeIssues, u as resolvePostgresCallControlPolicySubject } from "./control-policy-Cl3RRSPg-CT3QGpR3.mjs";
|
|
7
|
+
import { t as buildPostgresPlanDiff } from "./diff-database-schema-BfRs2vrG-D2o4KII0.mjs";
|
|
8
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-Cicg2sXg-Ck9iDxGI.mjs";
|
|
9
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
10
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
11
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
12
|
+
import { namingOf, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
13
|
+
import { issueOutcome } from "@prisma/orm-framework/components/control";
|
|
14
|
+
import { controlPolicyForCall, extractCodecControlHooks, partitionCallsByControlPolicy, partitionIssuesByControlPolicy, planFieldEventOperations, plannerFailure } from "@prisma/orm-family-sql/family/control";
|
|
15
|
+
import { SqlIndexIR } from "@prisma/orm-family-sql/schema-ir/types";
|
|
16
|
+
//#region ../../../3-targets/3-targets/postgres/dist/planner-Bmje9ii8.mjs
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the live-database schema name for a given namespace
|
|
19
|
+
* coordinate. Mirrors `resolveDdlSchemaForNamespace` in
|
|
20
|
+
* `planner-strategies.ts` so the verifier's projection and the
|
|
21
|
+
* planner's projection always agree — Postgres-aware namespaces (the
|
|
22
|
+
* production path) dispatch to `ddlSchemaName(storage)`, and bare
|
|
23
|
+
* object payloads (used by some tests) fall back to the coordinate
|
|
24
|
+
* itself.
|
|
25
|
+
*/
|
|
26
|
+
function resolveDdlSchemaName(storage, namespaceId) {
|
|
27
|
+
const namespace = storage.namespaces[namespaceId];
|
|
28
|
+
if (isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
|
|
29
|
+
return namespaceId;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the introspected list of schema names from the database-root schema
|
|
33
|
+
* node. `existingSchemas` is database-level, so it lives on the
|
|
34
|
+
* `PostgresDatabaseSchemaNode` root — not on the per-schema namespace nodes.
|
|
35
|
+
*
|
|
36
|
+
* Defaults to the always-present `public` schema when the node is not the
|
|
37
|
+
* database root — a fresh Postgres database always carries `public` (unless an
|
|
38
|
+
* operator dropped it manually), so any verifier path that runs without an
|
|
39
|
+
* enriched introspection still suppresses the redundant `CREATE SCHEMA
|
|
40
|
+
* "public"`.
|
|
41
|
+
*
|
|
42
|
+
* Production introspection (`PostgresControlAdapter.introspect`) is the
|
|
43
|
+
* authoritative source: it queries `pg_namespace` and sets `existingSchemas`
|
|
44
|
+
* on the returned root. Tests that want to assert against a richer initial
|
|
45
|
+
* state construct a `PostgresDatabaseSchemaNode` explicitly.
|
|
46
|
+
*/
|
|
47
|
+
function existingSchemasFromSchema(schema) {
|
|
48
|
+
if (PostgresDatabaseSchemaNode.is(schema)) return schema.existingSchemas;
|
|
49
|
+
return [DEFAULT_NAMESPACE_ID];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Emits a `postgres-namespace` `not-found` diff issue for every
|
|
53
|
+
* contract-declared Postgres namespace whose live container does not yet
|
|
54
|
+
* exist. The planner prepends these (node-typed, synthesized) to the
|
|
55
|
+
* relational diff issues so a multi-schema plan emits `CREATE SCHEMA`
|
|
56
|
+
* before the tables that need it — a planner-only concern (verify already
|
|
57
|
+
* rejects via the `not-found` table issues a missing schema already
|
|
58
|
+
* produces), so this is not part of the shared diff.
|
|
59
|
+
*
|
|
60
|
+
* A namespace's live container is the schema returned by its
|
|
61
|
+
* polymorphic `ddlSchemaName(storage)` method — named schemas resolve
|
|
62
|
+
* to their own id; the unbound singleton returns `UNBOUND_NAMESPACE_ID`
|
|
63
|
+
* and is skipped explicitly (late-bound namespaces have no fixed DDL
|
|
64
|
+
* schema). Issues are emitted only when the resolved name is a real,
|
|
65
|
+
* creatable schema (not the unbound sentinel) and is missing from the
|
|
66
|
+
* introspected list. `public` is suppressed implicitly because the
|
|
67
|
+
* introspection (or its sensible default) always carries it.
|
|
68
|
+
*
|
|
69
|
+
* Each emitted issue's path is `['database', ddlName]` — an ancestor of
|
|
70
|
+
* every table path under that schema, so it must never be run through
|
|
71
|
+
* `coalesceSubtreeIssues` alongside the table diff (it would swallow the
|
|
72
|
+
* table-level `not-found` issues that drive `CREATE TABLE`); the planner
|
|
73
|
+
* adds these AFTER coalescing the relational issues, and they are not
|
|
74
|
+
* subject to sibling-space ownership scoping (mirrors the retired
|
|
75
|
+
* coordinate walk, which prepended namespace issues after that filter).
|
|
76
|
+
*/
|
|
77
|
+
function verifyPostgresNamespacePresence(input) {
|
|
78
|
+
const { contract, schema } = input;
|
|
79
|
+
const existing = new Set(existingSchemasFromSchema(schema));
|
|
80
|
+
const issues = [];
|
|
81
|
+
const namespaceIds = Object.keys(contract.storage.namespaces).sort();
|
|
82
|
+
for (const namespaceId of namespaceIds) {
|
|
83
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) continue;
|
|
84
|
+
const ddlName = resolveDdlSchemaName(contract.storage, namespaceId);
|
|
85
|
+
if (ddlName === UNBOUND_NAMESPACE_ID) continue;
|
|
86
|
+
if (existing.has(ddlName)) continue;
|
|
87
|
+
const namespace = new PostgresNamespaceSchemaNode({
|
|
88
|
+
schemaName: ddlName,
|
|
89
|
+
tables: {}
|
|
90
|
+
});
|
|
91
|
+
issues.push({
|
|
92
|
+
path: ["database", ddlName],
|
|
93
|
+
expected: namespace
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return issues;
|
|
97
|
+
}
|
|
98
|
+
function createPostgresMigrationPlanner(lowerer) {
|
|
99
|
+
return new PostgresMigrationPlanner(lowerer);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Postgres migration planner — a thin wrapper over `planIssues`.
|
|
103
|
+
*
|
|
104
|
+
* `plan()` diffs the target contract against the live schema via the one
|
|
105
|
+
* differ (`buildPostgresPlanDiff`, producing node-typed `SchemaDiffIssue[]`)
|
|
106
|
+
* and delegates to `planIssues` with the unified `postgresPlannerStrategies`
|
|
107
|
+
* list: NOT-NULL backfill, type-change, nullable-tightening, codec-hook
|
|
108
|
+
* storage types, component-declared dependency installs, and
|
|
109
|
+
* shared-temp-default / empty-table-guarded NOT-NULL add-column. The same
|
|
110
|
+
* strategy list runs for `migration plan`, `db update`, and `db init`;
|
|
111
|
+
* behavior diverges purely on `policy.allowedOperationClasses` (the
|
|
112
|
+
* data-safe strategies short-circuit when `'data'` is excluded). The issue
|
|
113
|
+
* planner applies operation-class policy gates and emits a single
|
|
114
|
+
* `PostgresOpFactoryCall[]` that drives both the runtime-ops view (via
|
|
115
|
+
* `renderOps`) and the `renderTypeScript()` authoring surface. RLS policy
|
|
116
|
+
* drift (the structural half of the same one-differ tree) is handled
|
|
117
|
+
* separately via `planPostgresSchemaDiff`.
|
|
118
|
+
*/
|
|
119
|
+
var PostgresMigrationPlanner = class {
|
|
120
|
+
#lowerer;
|
|
121
|
+
constructor(lowerer) {
|
|
122
|
+
this.#lowerer = lowerer;
|
|
123
|
+
}
|
|
124
|
+
plan(options) {
|
|
125
|
+
return this.planSql(options);
|
|
126
|
+
}
|
|
127
|
+
emptyMigration(context, spaceId) {
|
|
128
|
+
return new TypeScriptRenderablePostgresMigration([], {
|
|
129
|
+
from: context.fromHash,
|
|
130
|
+
to: context.toHash
|
|
131
|
+
}, spaceId, context.snapshotsImportPath, this.#lowerer);
|
|
132
|
+
}
|
|
133
|
+
planSql(options) {
|
|
134
|
+
const schemaName = options.schemaName ?? Object.keys(options.contract.storage.namespaces).find((id) => id !== UNBOUND_NAMESPACE_ID) ?? UNBOUND_NAMESPACE_ID;
|
|
135
|
+
const policyResult = this.ensureAdditivePolicy(options.policy);
|
|
136
|
+
if (policyResult) return policyResult;
|
|
137
|
+
PostgresDatabaseSchemaNode.assert(options.schema);
|
|
138
|
+
const { issues: rawIssues } = buildPostgresPlanDiff({
|
|
139
|
+
contract: options.contract,
|
|
140
|
+
actualSchema: options.schema,
|
|
141
|
+
frameworkComponents: options.frameworkComponents
|
|
142
|
+
});
|
|
143
|
+
const policyDiffIssues = rawIssues.filter((issue) => isPolicyDiffIssue(issue));
|
|
144
|
+
const relationalDiffIssues = rawIssues.filter((issue) => !isPolicyDiffIssue(issue));
|
|
145
|
+
const strict = options.policy.allowedOperationClasses.includes("widening") || options.policy.allowedOperationClasses.includes("destructive");
|
|
146
|
+
const owned = retainUnownedExtras(coalesceSubtreeIssues(relationalDiffIssues), options.ownership, options.contract);
|
|
147
|
+
const gated = strict ? owned : owned.filter((issue) => issueOutcome(issue) !== "not-expected");
|
|
148
|
+
const schemaIssues = [...verifyPostgresNamespacePresence({
|
|
149
|
+
contract: options.contract,
|
|
150
|
+
schema: options.schema
|
|
151
|
+
}), ...gated];
|
|
152
|
+
const indexRenames = this.pairIndexRenames(options, schemaIssues);
|
|
153
|
+
const plannableIssues = indexRenames.consumed.size === 0 ? schemaIssues : schemaIssues.filter((issue) => !indexRenames.consumed.has(issue));
|
|
154
|
+
const codecHooks = extractCodecControlHooks(options.frameworkComponents);
|
|
155
|
+
const storageTypes = options.contract.storage.types ?? {};
|
|
156
|
+
const relationalSchema = relationalNamespaceNode(options.schema, schemaName);
|
|
157
|
+
const issuePartition = partitionIssuesByControlPolicy({
|
|
158
|
+
issues: plannableIssues,
|
|
159
|
+
contract: options.contract,
|
|
160
|
+
resolveControlPolicySubject: (issue) => resolvePostgresNodeIssueControlPolicySubject(issue, options.contract),
|
|
161
|
+
resolveCreationFactoryName: resolvePostgresNodeIssueCreationFactoryName
|
|
162
|
+
});
|
|
163
|
+
const result = planIssues({
|
|
164
|
+
issues: issuePartition.plannable,
|
|
165
|
+
toContract: options.contract,
|
|
166
|
+
fromContract: options.fromContract,
|
|
167
|
+
schemaName,
|
|
168
|
+
codecHooks,
|
|
169
|
+
storageTypes,
|
|
170
|
+
...ifDefined("schema", relationalSchema),
|
|
171
|
+
policy: options.policy,
|
|
172
|
+
frameworkComponents: options.frameworkComponents,
|
|
173
|
+
strategies: postgresPlannerStrategies
|
|
174
|
+
});
|
|
175
|
+
const schemaDiff = this.planPostgresSchemaDiff(options, policyDiffIssues);
|
|
176
|
+
if (!result.ok || schemaDiff.conflicts.length > 0) return plannerFailure([...result.ok ? [] : result.failure, ...schemaDiff.conflicts]);
|
|
177
|
+
const indexRenamePartition = partitionCallsByControlPolicy({
|
|
178
|
+
calls: indexRenames.calls,
|
|
179
|
+
contract: options.contract,
|
|
180
|
+
resolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),
|
|
181
|
+
resolveFactoryName: (call) => call.factoryName
|
|
182
|
+
});
|
|
183
|
+
const schemaDiffPartition = partitionCallsByControlPolicy({
|
|
184
|
+
calls: schemaDiff.calls,
|
|
185
|
+
contract: options.contract,
|
|
186
|
+
resolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),
|
|
187
|
+
resolveFactoryName: (call) => call.factoryName
|
|
188
|
+
});
|
|
189
|
+
const fieldEventPartition = partitionCallsByControlPolicy({
|
|
190
|
+
calls: blindCast(planFieldEventOperations({
|
|
191
|
+
priorContract: options.fromContract,
|
|
192
|
+
newContract: options.contract,
|
|
193
|
+
codecHooks
|
|
194
|
+
})),
|
|
195
|
+
contract: options.contract,
|
|
196
|
+
resolveControlPolicySubject: (call) => resolvePostgresCallControlPolicySubject(call, options.contract),
|
|
197
|
+
resolveFactoryName: (call) => call.factoryName
|
|
198
|
+
});
|
|
199
|
+
const calls = [
|
|
200
|
+
...result.value.calls,
|
|
201
|
+
...indexRenamePartition.kept,
|
|
202
|
+
...schemaDiffPartition.kept,
|
|
203
|
+
...fieldEventPartition.kept
|
|
204
|
+
];
|
|
205
|
+
const seenWarnings = /* @__PURE__ */ new Set();
|
|
206
|
+
const warnings = [
|
|
207
|
+
...issuePartition.suppressions,
|
|
208
|
+
...indexRenamePartition.suppressions,
|
|
209
|
+
...schemaDiff.suppressions,
|
|
210
|
+
...schemaDiffPartition.suppressions,
|
|
211
|
+
...fieldEventPartition.suppressions
|
|
212
|
+
].map((record) => renderPostgresSuppression(record, options.contract)).filter((warning) => {
|
|
213
|
+
const key = JSON.stringify(warning);
|
|
214
|
+
if (seenWarnings.has(key)) return false;
|
|
215
|
+
seenWarnings.add(key);
|
|
216
|
+
return true;
|
|
217
|
+
});
|
|
218
|
+
return Object.freeze({
|
|
219
|
+
kind: "success",
|
|
220
|
+
plan: new TypeScriptRenderablePostgresMigration(calls, {
|
|
221
|
+
from: options.fromContract?.storage.storageHash ?? null,
|
|
222
|
+
to: options.contract.storage.storageHash
|
|
223
|
+
}, options.spaceId, options.snapshotsImportPath, this.#lowerer),
|
|
224
|
+
...warnings.length > 0 ? { warnings: Object.freeze(warnings) } : {}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Rename post-pass for indexes, per `(schema, table)`, widening-only,
|
|
229
|
+
* deterministic by sorted names — the same structure as the policy pass
|
|
230
|
+
* below (which stays untouched: policies pair by hash only).
|
|
231
|
+
*
|
|
232
|
+
* Hash pairing (prefix-only renames): extras whose live names parse as
|
|
233
|
+
* wire names, grouped by `(schema, table, hash)`; missing nodes iterated
|
|
234
|
+
* in sorted-name order consume the sorted-name-first candidate.
|
|
235
|
+
*
|
|
236
|
+
* Content pairing (exact→wire convergence), after hash pairing has
|
|
237
|
+
* consumed its matches: the remaining wire-named-missing nodes
|
|
238
|
+
* (`prefix` defined) against the remaining extras of any name shape,
|
|
239
|
+
* paired iff content-equal (columns ordered-strict both-defined-or-
|
|
240
|
+
* both-undefined, `unique`/`type` strict, `options` loose, bodies
|
|
241
|
+
* byte-equal).
|
|
242
|
+
*
|
|
243
|
+
* Leftovers proceed as create/drop exactly as before; without the
|
|
244
|
+
* widening allowance the pass is skipped and pairing degrades to the
|
|
245
|
+
* additive half, like the policy pass.
|
|
246
|
+
*/
|
|
247
|
+
pairIndexRenames(options, issues) {
|
|
248
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
249
|
+
const calls = [];
|
|
250
|
+
if (!options.policy.allowedOperationClasses.includes("widening")) return {
|
|
251
|
+
calls,
|
|
252
|
+
consumed
|
|
253
|
+
};
|
|
254
|
+
const missing = [];
|
|
255
|
+
const extra = [];
|
|
256
|
+
for (const issue of issues) {
|
|
257
|
+
const node = issueNode(issue);
|
|
258
|
+
if (node === void 0 || !SqlIndexIR.is(node)) continue;
|
|
259
|
+
const ddlSchema = issue.path[1];
|
|
260
|
+
const tableName = issue.path[2];
|
|
261
|
+
if (ddlSchema === void 0 || tableName === void 0) continue;
|
|
262
|
+
if (issueOutcome(issue) === "not-found") missing.push({
|
|
263
|
+
issue,
|
|
264
|
+
node,
|
|
265
|
+
ddlSchema,
|
|
266
|
+
tableName
|
|
267
|
+
});
|
|
268
|
+
else if (issueOutcome(issue) === "not-expected") extra.push({
|
|
269
|
+
issue,
|
|
270
|
+
node,
|
|
271
|
+
ddlSchema,
|
|
272
|
+
tableName
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (missing.length === 0 || extra.length === 0) return {
|
|
276
|
+
calls,
|
|
277
|
+
consumed
|
|
278
|
+
};
|
|
279
|
+
const byName = (a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0;
|
|
280
|
+
const emissionSchema = (ddlSchema) => resolveNamespaceIdForDdlSchema(options.contract, ddlSchema) === UNBOUND_NAMESPACE_ID ? UNBOUND_NAMESPACE_ID : ddlSchema;
|
|
281
|
+
const pairingKey = (finding, hash) => JSON.stringify([
|
|
282
|
+
finding.ddlSchema,
|
|
283
|
+
finding.tableName,
|
|
284
|
+
hash
|
|
285
|
+
]);
|
|
286
|
+
const rename = (missingFinding, candidate) => {
|
|
287
|
+
consumed.add(missingFinding.issue);
|
|
288
|
+
consumed.add(candidate.issue);
|
|
289
|
+
calls.push(new RenameIndexCall(emissionSchema(missingFinding.ddlSchema), missingFinding.tableName, candidate.node.name, missingFinding.node.name));
|
|
290
|
+
};
|
|
291
|
+
const sortedMissing = [...missing].sort(byName);
|
|
292
|
+
const extrasByHash = /* @__PURE__ */ new Map();
|
|
293
|
+
for (const finding of extra) {
|
|
294
|
+
const parsed = parseWireName(finding.node.name);
|
|
295
|
+
if (parsed === void 0) continue;
|
|
296
|
+
const key = pairingKey(finding, parsed.hash);
|
|
297
|
+
const group = extrasByHash.get(key) ?? [];
|
|
298
|
+
group.push(finding);
|
|
299
|
+
extrasByHash.set(key, group);
|
|
300
|
+
}
|
|
301
|
+
for (const group of extrasByHash.values()) group.sort(byName);
|
|
302
|
+
for (const missingFinding of sortedMissing) {
|
|
303
|
+
const parsed = parseWireName(missingFinding.node.name);
|
|
304
|
+
if (parsed === void 0) continue;
|
|
305
|
+
const candidate = extrasByHash.get(pairingKey(missingFinding, parsed.hash))?.shift();
|
|
306
|
+
if (candidate === void 0) continue;
|
|
307
|
+
rename(missingFinding, candidate);
|
|
308
|
+
}
|
|
309
|
+
const sortedExtras = [...extra].sort(byName);
|
|
310
|
+
for (const missingFinding of sortedMissing) {
|
|
311
|
+
if (consumed.has(missingFinding.issue)) continue;
|
|
312
|
+
if (missingFinding.node.prefix === void 0) continue;
|
|
313
|
+
const candidate = sortedExtras.find((extraFinding) => !consumed.has(extraFinding.issue) && extraFinding.ddlSchema === missingFinding.ddlSchema && extraFinding.tableName === missingFinding.tableName && missingFinding.node.contentEquals(extraFinding.node, {
|
|
314
|
+
columnPresence: "matching",
|
|
315
|
+
bodies: "verbatim"
|
|
316
|
+
}));
|
|
317
|
+
if (candidate === void 0) continue;
|
|
318
|
+
rename(missingFinding, candidate);
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
calls,
|
|
322
|
+
consumed
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Maps the RLS policy findings of the one combined tree diff
|
|
327
|
+
* (`buildPostgresPlanDiff`, already ownership-filtered) into
|
|
328
|
+
* `CREATE POLICY` / `DROP POLICY` / `ALTER POLICY … RENAME TO` ops — a
|
|
329
|
+
* `not-equal` finding (an exact-named policy whose content drifted)
|
|
330
|
+
* becomes drop + create, or a disallowed-call conflict when the policy
|
|
331
|
+
* forbids the destructive drop. It
|
|
332
|
+
* does not re-diff — it consumes exactly the policy-node subset of the
|
|
333
|
+
* shared diff's issues. Enablement is NOT decided here: `ENABLE`/`DISABLE
|
|
334
|
+
* ROW LEVEL SECURITY` derive from the table's marker-driven `rlsEnabled`
|
|
335
|
+
* attribute diff on the relational side.
|
|
336
|
+
*
|
|
337
|
+
* Rename post-pass (the index pass's structure): hash pairing pairs a
|
|
338
|
+
* `not-found` and a `not-expected` policy on the SAME table whose
|
|
339
|
+
* wire-name content hashes match but prefixes differ (prefix-only rename);
|
|
340
|
+
* content pairing then pairs remaining wire-named-missing policies against remaining
|
|
341
|
+
* extras of any name shape by verbatim content (the node-owned `contentEquals` —
|
|
342
|
+
* exact→wire adoption). Multi-candidate groups pair deterministically
|
|
343
|
+
* by sorted name; leftovers proceed as create/drop; an exact-named
|
|
344
|
+
* missing policy never content-pairs.
|
|
345
|
+
*
|
|
346
|
+
* The pairing runs only when the policy allows `widening` (rename's
|
|
347
|
+
* class). Without it (db-init's additive-only set), pairing degrades
|
|
348
|
+
* deliberately to the additive half: the new name is CREATEd and the old
|
|
349
|
+
* policy survives live until a widening/destructive-allowed plan runs —
|
|
350
|
+
* emitting an ungated widening rename would only fail at the runner's
|
|
351
|
+
* class re-enforcement.
|
|
352
|
+
*/
|
|
353
|
+
planPostgresSchemaDiff(options, filteredDiffIssues) {
|
|
354
|
+
const allowsDestructive = options.policy.allowedOperationClasses.includes("destructive");
|
|
355
|
+
const allowsWidening = options.policy.allowedOperationClasses.includes("widening");
|
|
356
|
+
const missing = [];
|
|
357
|
+
const extra = [];
|
|
358
|
+
const changed = [];
|
|
359
|
+
for (const issue of filteredDiffIssues) if (issueOutcome(issue) === "not-equal") {
|
|
360
|
+
const expected = issue.expected;
|
|
361
|
+
PostgresPolicySchemaNode.assert(expected);
|
|
362
|
+
changed.push({
|
|
363
|
+
node: expected,
|
|
364
|
+
schemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)
|
|
365
|
+
});
|
|
366
|
+
} else if (issueOutcome(issue) === "not-found") {
|
|
367
|
+
const expected = issue.expected;
|
|
368
|
+
PostgresPolicySchemaNode.assert(expected);
|
|
369
|
+
missing.push({
|
|
370
|
+
node: expected,
|
|
371
|
+
schemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, expected.namespaceId)
|
|
372
|
+
});
|
|
373
|
+
} else if (issueOutcome(issue) === "not-expected") {
|
|
374
|
+
const actual = issue.actual;
|
|
375
|
+
PostgresPolicySchemaNode.assert(actual);
|
|
376
|
+
extra.push({
|
|
377
|
+
node: actual,
|
|
378
|
+
schemaForTable: resolveDdlSchemaForNamespaceStorage(options.contract.storage, actual.namespaceId)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
const calls = [];
|
|
382
|
+
const conflicts = [];
|
|
383
|
+
const suppressions = [];
|
|
384
|
+
const renamedExtras = /* @__PURE__ */ new Set();
|
|
385
|
+
const renamedMissing = /* @__PURE__ */ new Set();
|
|
386
|
+
const pairingKey = (finding, hash) => JSON.stringify([
|
|
387
|
+
finding.schemaForTable,
|
|
388
|
+
finding.node.tableName,
|
|
389
|
+
hash
|
|
390
|
+
]);
|
|
391
|
+
if (allowsWidening) {
|
|
392
|
+
const extrasByGroup = /* @__PURE__ */ new Map();
|
|
393
|
+
for (const finding of extra) {
|
|
394
|
+
const parsed = parseWireName(finding.node.name);
|
|
395
|
+
if (parsed === void 0) continue;
|
|
396
|
+
const key = pairingKey(finding, parsed.hash);
|
|
397
|
+
const group = extrasByGroup.get(key) ?? [];
|
|
398
|
+
group.push(finding);
|
|
399
|
+
extrasByGroup.set(key, group);
|
|
400
|
+
}
|
|
401
|
+
for (const group of extrasByGroup.values()) group.sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);
|
|
402
|
+
const sortedMissing = [...missing].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);
|
|
403
|
+
for (const missingFinding of sortedMissing) {
|
|
404
|
+
const parsed = parseWireName(missingFinding.node.name);
|
|
405
|
+
if (parsed === void 0) continue;
|
|
406
|
+
const candidate = extrasByGroup.get(pairingKey(missingFinding, parsed.hash))?.shift();
|
|
407
|
+
if (candidate === void 0) continue;
|
|
408
|
+
renamedExtras.add(candidate);
|
|
409
|
+
renamedMissing.add(missingFinding);
|
|
410
|
+
calls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));
|
|
411
|
+
}
|
|
412
|
+
const sortedExtras = [...extra].sort((a, b) => a.node.name < b.node.name ? -1 : a.node.name > b.node.name ? 1 : 0);
|
|
413
|
+
for (const missingFinding of sortedMissing) {
|
|
414
|
+
if (renamedMissing.has(missingFinding)) continue;
|
|
415
|
+
if (missingFinding.node.prefix === void 0) continue;
|
|
416
|
+
const candidate = sortedExtras.find((extraFinding) => !renamedExtras.has(extraFinding) && extraFinding.schemaForTable === missingFinding.schemaForTable && extraFinding.node.tableName === missingFinding.node.tableName && missingFinding.node.contentEquals(extraFinding.node));
|
|
417
|
+
if (candidate === void 0) continue;
|
|
418
|
+
renamedExtras.add(candidate);
|
|
419
|
+
renamedMissing.add(missingFinding);
|
|
420
|
+
calls.push(new RenamePostgresRlsPolicyCall(missingFinding.schemaForTable, missingFinding.node.tableName, candidate.node.name, missingFinding.node.name));
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (const finding of changed) {
|
|
424
|
+
const replacement = {
|
|
425
|
+
drop: new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name),
|
|
426
|
+
create: new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node))
|
|
427
|
+
};
|
|
428
|
+
const graded = gradePolicyReplacement(replacement, options.contract, options.policy.allowedOperationClasses);
|
|
429
|
+
if (graded.disposition === "suppress") {
|
|
430
|
+
suppressions.push(graded.record);
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (graded.disposition === "conflict") {
|
|
434
|
+
conflicts.push(graded.conflict);
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
calls.push(replacement.drop);
|
|
438
|
+
calls.push(replacement.create);
|
|
439
|
+
}
|
|
440
|
+
for (const finding of missing) {
|
|
441
|
+
if (renamedMissing.has(finding)) continue;
|
|
442
|
+
calls.push(new CreatePostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, policyNodeToContractPolicy(finding.node)));
|
|
443
|
+
}
|
|
444
|
+
if (allowsDestructive) for (const finding of extra) {
|
|
445
|
+
if (renamedExtras.has(finding)) continue;
|
|
446
|
+
calls.push(new DropPostgresRlsPolicyCall(finding.schemaForTable, finding.node.tableName, finding.node.name));
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
calls,
|
|
450
|
+
conflicts,
|
|
451
|
+
suppressions
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
ensureAdditivePolicy(policy) {
|
|
455
|
+
if (!policy.allowedOperationClasses.includes("additive")) return plannerFailure([{
|
|
456
|
+
kind: "unsupportedOperation",
|
|
457
|
+
summary: "Migration planner requires additive operations be allowed",
|
|
458
|
+
why: "The planner requires the \"additive\" operation class to be allowed in the policy."
|
|
459
|
+
}]);
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* A diff issue whose node is an RLS policy — the structural half of the one
|
|
465
|
+
* combined tree diff, routed to `planPostgresSchemaDiff` instead of
|
|
466
|
+
* `planIssues`.
|
|
467
|
+
*/
|
|
468
|
+
function isPolicyDiffIssue(issue) {
|
|
469
|
+
const node = issue.expected ?? issue.actual;
|
|
470
|
+
return node !== void 0 && PostgresPolicySchemaNode.is(node);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Drops a `not-expected` issue when it is a whole extra storage entity (a table
|
|
474
|
+
* or a native enum) that some space in the composition owns. Each such node
|
|
475
|
+
* yields its own storage coordinate (see {@link postgresNodeStorageCoordinate}),
|
|
476
|
+
* so `declaresEntity` answers over the whole composition on one uniform
|
|
477
|
+
* coordinate: a positive answer means a sibling owns this entity here — leave
|
|
478
|
+
* it; a negative answer means a genuine orphan — drop it. A node with no storage
|
|
479
|
+
* coordinate (a namespace, or a deeper column/constraint drift on an owned
|
|
480
|
+
* table) is this space's own and is always kept. No oracle ⇒ keep everything.
|
|
481
|
+
*/
|
|
482
|
+
function retainUnownedExtras(issues, ownership, contract) {
|
|
483
|
+
if (ownership === void 0) return issues;
|
|
484
|
+
return issues.filter((issue) => {
|
|
485
|
+
if (issueOutcome(issue) !== "not-expected") return true;
|
|
486
|
+
const node = issueNode(issue);
|
|
487
|
+
if (node === void 0) return true;
|
|
488
|
+
const coordinate = postgresNodeStorageCoordinate(node);
|
|
489
|
+
if (coordinate === void 0) return true;
|
|
490
|
+
const ddlSchemaName = issueSchemaName(issue);
|
|
491
|
+
if (ddlSchemaName === void 0) return true;
|
|
492
|
+
const namespaceId = resolveNamespaceIdForDdlSchema(contract, ddlSchemaName);
|
|
493
|
+
return !ownership.declaresEntity({
|
|
494
|
+
namespaceId,
|
|
495
|
+
...coordinate
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Returns the one namespace node the relational strategy layer probes for
|
|
501
|
+
* live-table existence and reads codec-hook context off — the namespace
|
|
502
|
+
* matching the planner's resolved schema name, or the first namespace when
|
|
503
|
+
* none matches. `undefined` when the tree has no namespaces, so the strategy
|
|
504
|
+
* context uses its empty-schema default.
|
|
505
|
+
*
|
|
506
|
+
* The relational strategies key tables by bare name, so they can only probe one
|
|
507
|
+
* namespace at a time; probing across every namespace at once is future work.
|
|
508
|
+
*
|
|
509
|
+
* Returns the real `PostgresNamespaceSchemaNode` reference rather than a
|
|
510
|
+
* projection: `storageTypePlanCallStrategy` hands this same value to codec
|
|
511
|
+
* `planTypeOperations` hooks as `schema`, and hooks read the Postgres-specific
|
|
512
|
+
* `nativeEnums` field off it (via `PostgresNamespaceSchemaNode.is`) to decide
|
|
513
|
+
* whether a native enum type already exists — a projection that only copies
|
|
514
|
+
* `tables` would silently drop that signal. `StrategyContext.schema`'s
|
|
515
|
+
* declared type (`SqlSchemaIR`, shared with SQLite's flat shape) doesn't
|
|
516
|
+
* capture this, so the return is `blindCast` the same way `namespaceSchemaNodes`
|
|
517
|
+
* in the family's relational walk already treats a namespace node as a
|
|
518
|
+
* structurally-`SqlSchemaIR`-shaped value.
|
|
519
|
+
*/
|
|
520
|
+
function relationalNamespaceNode(schema, schemaName) {
|
|
521
|
+
const namespaceNodes = Object.values(schema.namespaces);
|
|
522
|
+
const namespaceNode = namespaceNodes.find((node) => node.schemaName === schemaName) ?? namespaceNodes[0];
|
|
523
|
+
if (namespaceNode === void 0) return void 0;
|
|
524
|
+
return blindCast(namespaceNode);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Grades a {@link PolicyReplacement} as one unit against the table's
|
|
528
|
+
* control policy, BEFORE the pair becomes calls or a conflict. This runs
|
|
529
|
+
* ahead of `partitionCallsByControlPolicy`, which later re-grades the
|
|
530
|
+
* surviving calls per-call — a no-op here, since only managed units
|
|
531
|
+
* survive this grading.
|
|
532
|
+
*
|
|
533
|
+
* A replacement is deliberately STRICTER than the shared
|
|
534
|
+
* `callAllowedUnderControlPolicy` rule: `tolerated` permits whole-object
|
|
535
|
+
* creation, but a replacement's create is the second half of a repair of
|
|
536
|
+
* an existing object, not a new object — so ANY non-managed control
|
|
537
|
+
* (external, observed, tolerated) suppresses the whole unit. Drift on an
|
|
538
|
+
* object the plan does not manage is reported, never repaired; the
|
|
539
|
+
* suppression subject names the drifted policy (`rlsPolicy`) so the
|
|
540
|
+
* report says which policy drifted, matching the conflict path's
|
|
541
|
+
* `location.rlsPolicy`.
|
|
542
|
+
*/
|
|
543
|
+
function gradePolicyReplacement(replacement, contract, allowedOperationClasses) {
|
|
544
|
+
const subject = resolvePostgresCallControlPolicySubject(replacement.drop, contract);
|
|
545
|
+
const controlPolicy = controlPolicyForCall(subject, contract.defaultControlPolicy);
|
|
546
|
+
if (controlPolicy !== "managed") return {
|
|
547
|
+
disposition: "suppress",
|
|
548
|
+
record: {
|
|
549
|
+
subject: subject === void 0 ? void 0 : {
|
|
550
|
+
...subject,
|
|
551
|
+
rlsPolicy: replacement.drop.policyName
|
|
552
|
+
},
|
|
553
|
+
policy: controlPolicy,
|
|
554
|
+
factoryName: void 0,
|
|
555
|
+
createsNewObject: false
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
if (!allowedOperationClasses.includes("destructive")) return {
|
|
559
|
+
disposition: "conflict",
|
|
560
|
+
conflict: conflictForDisallowedCall(replacement.drop, allowedOperationClasses)
|
|
561
|
+
};
|
|
562
|
+
return { disposition: "plan" };
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Rebuilds the `PostgresRlsPolicy` contract entity `CreatePostgresRlsPolicyCall`
|
|
566
|
+
* carries (its `renderTypeScript`/`createRlsPolicy` paths serialize the whole
|
|
567
|
+
* entity, `namespaceId` included). This reconstructs rather than looking the
|
|
568
|
+
* original up in the contract on purpose: the diff node's `namespaceId` is the
|
|
569
|
+
* *resolved DDL schema* (set when the expected tree was built), which is the
|
|
570
|
+
* value the emitted op must carry; the contract-stored entity holds the raw,
|
|
571
|
+
* pre-resolution coordinate, so a lookup would change the migration output.
|
|
572
|
+
*/
|
|
573
|
+
function policyNodeToContractPolicy(node) {
|
|
574
|
+
return new PostgresRlsPolicy({
|
|
575
|
+
naming: namingOf(node.name, node.prefix),
|
|
576
|
+
tableName: node.tableName,
|
|
577
|
+
namespaceId: node.namespaceId,
|
|
578
|
+
operation: node.operation,
|
|
579
|
+
roles: [...node.roles],
|
|
580
|
+
using: node.using,
|
|
581
|
+
withCheck: node.withCheck,
|
|
582
|
+
permissive: node.permissive
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
//#endregion
|
|
586
|
+
export { createPostgresMigrationPlanner as t };
|
|
587
|
+
|
|
588
|
+
//# sourceMappingURL=planner-Bmje9ii8-B99fEsNM.mjs.map
|