@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,2009 @@
|
|
|
1
|
+
import { n as postgresError } from "./errors-kYxOQjdD-D4T3rbVp.mjs";
|
|
2
|
+
import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86-Cpp8PTxD.mjs";
|
|
3
|
+
import { a as validateEnumValueLength, i as quoteQualifiedName, r as quoteIdentifier, t as escapeLiteral } from "./sql-utils-BnBlQxyh-DaX9Nb7Z.mjs";
|
|
4
|
+
import { C as nativeEnumValueExistsAst, D as tableExistsAst, E as rlsPolicyExistsAst, O as tableIsEmptyAst, S as nativeEnumTypeExistsAst, T as rlsEnabledAst, _ as dropIndex$1, a as columnDefaultAst, b as extensionExistsAst, c as columnTypeAst, d as createPolicy, f as createSchema, g as dropDefaultAction, h as disableRowLevelSecurity$1, i as alterTable, l as constraintExistsAst, m as createType, n as alterIndexRename, o as columnExistsAst, p as createTable, r as alterPolicyRename, s as columnNullabilityAst, t as addColumnAction, u as createIndex$1, v as dropPolicy, w as noNullValuesAst, x as indexExistsAst, y as dropType } from "./ddl-BdP4q3KY-Duef4uHw.mjs";
|
|
5
|
+
import { n as qualifyTableName } from "./planner-sql-checks-DRc_78n8-C9nHOrvU.mjs";
|
|
6
|
+
import { n as buildColumnTypeSql } from "./planner-ddl-builders-CbfICQfm-CxYiLrhX.mjs";
|
|
7
|
+
import { FunctionColumnDefault, LiteralColumnDefault } from "@prisma/orm-family-sql/relational-core/ast";
|
|
8
|
+
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
9
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
10
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
11
|
+
import { namingOf } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
12
|
+
import { col } from "@prisma/orm-family-sql/relational-core/contract-free";
|
|
13
|
+
import { InternalError, assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
14
|
+
import { errorUnfilledPlaceholder } from "@prisma/orm-framework/errors/migration";
|
|
15
|
+
import { TsExpression, jsonToTsSource } from "@prisma/orm-framework/ts-render";
|
|
16
|
+
import { REFERENTIAL_ACTION_SQL } from "@prisma/orm-family-sql/contract/referential-action-sql";
|
|
17
|
+
//#region ../../../3-targets/3-targets/postgres/dist/op-factory-call-DifL68KT.mjs
|
|
18
|
+
/**
|
|
19
|
+
* Maps a planner schema name to the contract-free DDL builder's optional
|
|
20
|
+
* `schema` field: the unbound sentinel becomes `undefined` (the builder omits
|
|
21
|
+
* the schema qualifier), every other name passes through.
|
|
22
|
+
*/
|
|
23
|
+
function boundSchema(schemaName) {
|
|
24
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
25
|
+
}
|
|
26
|
+
function step(description, sql, params) {
|
|
27
|
+
return {
|
|
28
|
+
description,
|
|
29
|
+
sql,
|
|
30
|
+
...ifDefined("params", params)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function targetDetails(objectType, name, schema, table) {
|
|
34
|
+
return {
|
|
35
|
+
id: "postgres",
|
|
36
|
+
details: {
|
|
37
|
+
schema,
|
|
38
|
+
objectType,
|
|
39
|
+
name,
|
|
40
|
+
...ifDefined("table", table)
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function columnExistsSteps(lowerer, options) {
|
|
45
|
+
const checks = columnExistsAst(options);
|
|
46
|
+
return {
|
|
47
|
+
present: await lowerer.lowerToExecuteRequest(checks.columnPresent()),
|
|
48
|
+
absent: await lowerer.lowerToExecuteRequest(checks.columnAbsent())
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function dropColumn(schemaName, tableName, columnName, lowerer) {
|
|
52
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
53
|
+
const { present, absent } = await columnExistsSteps(lowerer, {
|
|
54
|
+
schema: schemaName,
|
|
55
|
+
table: tableName,
|
|
56
|
+
column: columnName
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
id: `dropColumn.${tableName}.${columnName}`,
|
|
60
|
+
label: `Drop column "${columnName}" from "${tableName}"`,
|
|
61
|
+
operationClass: "destructive",
|
|
62
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
63
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
64
|
+
execute: [step(`drop column "${columnName}"`, `ALTER TABLE ${qualified} DROP COLUMN ${quoteIdentifier(columnName)}`)],
|
|
65
|
+
postcheck: [step(`verify column "${columnName}" does not exist`, absent.sql, absent.params)]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `qualifiedTargetType` is the new column type as it appears in the
|
|
70
|
+
* `ALTER COLUMN TYPE` clause (schema-qualified for user-defined types, raw
|
|
71
|
+
* native name for built-ins). `formatTypeExpected` is the unqualified
|
|
72
|
+
* `format_type` form used in the postcheck. `rawTargetTypeForLabel` is the
|
|
73
|
+
* string appearing in the human-readable label (typically `toType` when
|
|
74
|
+
* explicit, else the column's native type).
|
|
75
|
+
*/
|
|
76
|
+
async function alterColumnType(schemaName, tableName, columnName, options, lowerer) {
|
|
77
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
78
|
+
const usingClause = options.using ? ` USING ${options.using}` : ` USING ${quoteIdentifier(columnName)}::${options.qualifiedTargetType}`;
|
|
79
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
80
|
+
schema: schemaName,
|
|
81
|
+
table: tableName,
|
|
82
|
+
column: columnName
|
|
83
|
+
});
|
|
84
|
+
const typeCheck = await lowerer.lowerToExecuteRequest(columnTypeAst({
|
|
85
|
+
schema: schemaName,
|
|
86
|
+
table: tableName,
|
|
87
|
+
column: columnName,
|
|
88
|
+
expectedType: options.formatTypeExpected
|
|
89
|
+
}));
|
|
90
|
+
return {
|
|
91
|
+
id: `alterType.${tableName}.${columnName}`,
|
|
92
|
+
label: `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`,
|
|
93
|
+
operationClass: "destructive",
|
|
94
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
95
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
96
|
+
execute: [step(`alter type of "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} TYPE ${options.qualifiedTargetType}${usingClause}`)],
|
|
97
|
+
postcheck: [step(`verify column "${columnName}" has type "${options.formatTypeExpected}"`, typeCheck.sql, typeCheck.params)],
|
|
98
|
+
meta: { warning: "TABLE_REWRITE" }
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function setNotNull(schemaName, tableName, columnName, lowerer) {
|
|
102
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
103
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
104
|
+
schema: schemaName,
|
|
105
|
+
table: tableName,
|
|
106
|
+
column: columnName
|
|
107
|
+
});
|
|
108
|
+
const noNulls = await lowerer.lowerToExecuteRequest(noNullValuesAst({
|
|
109
|
+
schema: schemaName,
|
|
110
|
+
table: tableName,
|
|
111
|
+
column: columnName
|
|
112
|
+
}));
|
|
113
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
114
|
+
schema: schemaName,
|
|
115
|
+
table: tableName,
|
|
116
|
+
column: columnName,
|
|
117
|
+
nullable: false
|
|
118
|
+
}));
|
|
119
|
+
return {
|
|
120
|
+
id: `alterNullability.setNotNull.${tableName}.${columnName}`,
|
|
121
|
+
label: `Set NOT NULL on "${tableName}"."${columnName}"`,
|
|
122
|
+
operationClass: "destructive",
|
|
123
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
124
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params), step(`ensure no NULL values in "${columnName}"`, noNulls.sql, noNulls.params)],
|
|
125
|
+
execute: [step(`set NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET NOT NULL`)],
|
|
126
|
+
postcheck: [step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function dropNotNull(schemaName, tableName, columnName, lowerer) {
|
|
130
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
131
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
132
|
+
schema: schemaName,
|
|
133
|
+
table: tableName,
|
|
134
|
+
column: columnName
|
|
135
|
+
});
|
|
136
|
+
const nullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
137
|
+
schema: schemaName,
|
|
138
|
+
table: tableName,
|
|
139
|
+
column: columnName,
|
|
140
|
+
nullable: true
|
|
141
|
+
}));
|
|
142
|
+
return {
|
|
143
|
+
id: `alterNullability.dropNotNull.${tableName}.${columnName}`,
|
|
144
|
+
label: `Drop NOT NULL on "${tableName}"."${columnName}"`,
|
|
145
|
+
operationClass: "widening",
|
|
146
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
147
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
148
|
+
execute: [step(`drop NOT NULL on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} DROP NOT NULL`)],
|
|
149
|
+
postcheck: [step(`verify column "${columnName}" is nullable`, nullable.sql, nullable.params)]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* `defaultSql` is the full `DEFAULT …` clause as produced by
|
|
154
|
+
* `buildColumnDefaultSql` — e.g. `"DEFAULT 42"`,
|
|
155
|
+
* `"DEFAULT (CURRENT_TIMESTAMP)"`, or `"DEFAULT nextval('seq'::regclass)"`.
|
|
156
|
+
*
|
|
157
|
+
* `operationClass` defaults to `'additive'` (setting a default on a column
|
|
158
|
+
* that currently has none). The reconciliation planner passes `'widening'`
|
|
159
|
+
* when the column already has a different default — policy enforcement
|
|
160
|
+
* treats that as a widening change rather than an additive one.
|
|
161
|
+
*/
|
|
162
|
+
async function setDefault(schemaName, tableName, columnName, defaultSql, lowerer, operationClass = "additive") {
|
|
163
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
164
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
165
|
+
schema: schemaName,
|
|
166
|
+
table: tableName,
|
|
167
|
+
column: columnName
|
|
168
|
+
});
|
|
169
|
+
const hasDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
170
|
+
schema: schemaName,
|
|
171
|
+
table: tableName,
|
|
172
|
+
column: columnName
|
|
173
|
+
}).defaultPresent());
|
|
174
|
+
return {
|
|
175
|
+
id: `setDefault.${tableName}.${columnName}`,
|
|
176
|
+
label: `Set default on "${tableName}"."${columnName}"`,
|
|
177
|
+
operationClass,
|
|
178
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
179
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
180
|
+
execute: [step(`set default on "${columnName}"`, `ALTER TABLE ${qualified} ALTER COLUMN ${quoteIdentifier(columnName)} SET ${defaultSql}`)],
|
|
181
|
+
postcheck: [step(`verify column "${columnName}" has a default`, hasDefault.sql, hasDefault.params)]
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async function dropDefault(schemaName, tableName, columnName, lowerer) {
|
|
185
|
+
const { present } = await columnExistsSteps(lowerer, {
|
|
186
|
+
schema: schemaName,
|
|
187
|
+
table: tableName,
|
|
188
|
+
column: columnName
|
|
189
|
+
});
|
|
190
|
+
const dropDefaultExec = await lowerer.lowerToExecuteRequest(alterTable({
|
|
191
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
192
|
+
table: tableName,
|
|
193
|
+
actions: [dropDefaultAction(columnName)]
|
|
194
|
+
}));
|
|
195
|
+
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
196
|
+
schema: schemaName,
|
|
197
|
+
table: tableName,
|
|
198
|
+
column: columnName
|
|
199
|
+
}).defaultAbsent());
|
|
200
|
+
return {
|
|
201
|
+
id: `dropDefault.${tableName}.${columnName}`,
|
|
202
|
+
label: `Drop default on "${tableName}"."${columnName}"`,
|
|
203
|
+
operationClass: "destructive",
|
|
204
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
205
|
+
precheck: [step(`ensure column "${columnName}" exists`, present.sql, present.params)],
|
|
206
|
+
execute: [step(`drop default on "${columnName}"`, dropDefaultExec.sql)],
|
|
207
|
+
postcheck: [step(`verify column "${columnName}" has no default`, noDefault.sql, noDefault.params)]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Builds the op for adding a NOT NULL column (no contract default) to a
|
|
212
|
+
* non-empty table. Prechecks assert the column is absent and the table is
|
|
213
|
+
* empty; the execute step lowers the typed `AddColumn` DDL node through the
|
|
214
|
+
* adapter; postchecks assert the column exists and is NOT NULL.
|
|
215
|
+
*/
|
|
216
|
+
async function addNotNullColumnDirect(schemaName, tableName, column, lowerer) {
|
|
217
|
+
const columnName = column.name;
|
|
218
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
219
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
220
|
+
table: tableName,
|
|
221
|
+
actions: [addColumnAction(column)]
|
|
222
|
+
}));
|
|
223
|
+
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
224
|
+
schema: schemaName,
|
|
225
|
+
table: tableName,
|
|
226
|
+
column: columnName
|
|
227
|
+
}).columnAbsent());
|
|
228
|
+
const tableEmpty = await lowerer.lowerToExecuteRequest(tableIsEmptyAst(schemaName, tableName));
|
|
229
|
+
const present = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
230
|
+
schema: schemaName,
|
|
231
|
+
table: tableName,
|
|
232
|
+
column: columnName
|
|
233
|
+
}).columnPresent());
|
|
234
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
235
|
+
schema: schemaName,
|
|
236
|
+
table: tableName,
|
|
237
|
+
column: columnName,
|
|
238
|
+
nullable: false
|
|
239
|
+
}));
|
|
240
|
+
return {
|
|
241
|
+
id: `column.${tableName}.${columnName}`,
|
|
242
|
+
label: `Add column ${columnName} to ${tableName}`,
|
|
243
|
+
summary: `Adds column ${columnName} to table ${tableName}`,
|
|
244
|
+
operationClass: "additive",
|
|
245
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
246
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params), step(`ensure table "${tableName}" is empty before adding NOT NULL column without default`, tableEmpty.sql, tableEmpty.params)],
|
|
247
|
+
execute: [step(`add column "${columnName}"`, addColumn.sql)],
|
|
248
|
+
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params), step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params)]
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function constraintCheckSteps(lowerer, options) {
|
|
252
|
+
const checks = constraintExistsAst(options);
|
|
253
|
+
return {
|
|
254
|
+
absent: await lowerer.lowerToExecuteRequest(checks.constraintAbsent()),
|
|
255
|
+
present: await lowerer.lowerToExecuteRequest(checks.constraintPresent())
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function renderForeignKeySql(schemaName, tableName, fk) {
|
|
259
|
+
let sql = `ALTER TABLE ${qualifyTableName(schemaName, tableName)}
|
|
260
|
+
ADD CONSTRAINT ${quoteIdentifier(fk.name)}
|
|
261
|
+
FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(", ")})
|
|
262
|
+
REFERENCES ${qualifyTableName(fk.references.schema, fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(", ")})`;
|
|
263
|
+
if (fk.onDelete !== void 0) {
|
|
264
|
+
const action = REFERENTIAL_ACTION_SQL[fk.onDelete];
|
|
265
|
+
if (!action) throw new InternalError(`Unknown referential action for onDelete: ${String(fk.onDelete)}`);
|
|
266
|
+
sql += `\nON DELETE ${action}`;
|
|
267
|
+
}
|
|
268
|
+
if (fk.onUpdate !== void 0) {
|
|
269
|
+
const action = REFERENTIAL_ACTION_SQL[fk.onUpdate];
|
|
270
|
+
if (!action) throw new InternalError(`Unknown referential action for onUpdate: ${String(fk.onUpdate)}`);
|
|
271
|
+
sql += `\nON UPDATE ${action}`;
|
|
272
|
+
}
|
|
273
|
+
return sql;
|
|
274
|
+
}
|
|
275
|
+
async function addPrimaryKey(schemaName, tableName, constraintName, columns, lowerer) {
|
|
276
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
277
|
+
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
278
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
279
|
+
constraintName,
|
|
280
|
+
schema: schemaName,
|
|
281
|
+
table: tableName
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
id: `primaryKey.${tableName}.${constraintName}`,
|
|
285
|
+
label: `Add primary key on "${tableName}"`,
|
|
286
|
+
operationClass: "additive",
|
|
287
|
+
target: targetDetails("primaryKey", constraintName, schemaName, tableName),
|
|
288
|
+
precheck: [step(`ensure primary key "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
289
|
+
execute: [step(`add primary key "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} PRIMARY KEY (${columnList})`)],
|
|
290
|
+
postcheck: [step(`verify primary key "${constraintName}" exists`, present.sql, present.params)]
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
async function addUnique(schemaName, tableName, constraintName, columns, lowerer) {
|
|
294
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
295
|
+
const columnList = columns.map(quoteIdentifier).join(", ");
|
|
296
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
297
|
+
constraintName,
|
|
298
|
+
schema: schemaName,
|
|
299
|
+
table: tableName
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
id: `unique.${tableName}.${constraintName}`,
|
|
303
|
+
label: `Add unique constraint on "${tableName}" (${columns.join(", ")})`,
|
|
304
|
+
operationClass: "additive",
|
|
305
|
+
target: targetDetails("unique", constraintName, schemaName, tableName),
|
|
306
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
307
|
+
execute: [step(`add unique constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} UNIQUE (${columnList})`)],
|
|
308
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async function addForeignKey(schemaName, tableName, fk, lowerer) {
|
|
312
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
313
|
+
constraintName: fk.name,
|
|
314
|
+
schema: schemaName,
|
|
315
|
+
table: tableName
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
id: `foreignKey.${tableName}.${fk.name}`,
|
|
319
|
+
label: `Add foreign key "${fk.name}" on "${tableName}"`,
|
|
320
|
+
operationClass: "additive",
|
|
321
|
+
target: targetDetails("foreignKey", fk.name, schemaName, tableName),
|
|
322
|
+
precheck: [step(`ensure FK "${fk.name}" does not exist`, absent.sql, absent.params)],
|
|
323
|
+
execute: [step(`add FK "${fk.name}"`, renderForeignKeySql(schemaName, tableName, fk))],
|
|
324
|
+
postcheck: [step(`verify FK "${fk.name}" exists`, present.sql, present.params)]
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
async function addCheckConstraint(schemaName, tableName, constraintName, column, values, lowerer) {
|
|
328
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
329
|
+
const valueList = values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
|
|
330
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
331
|
+
constraintName,
|
|
332
|
+
schema: schemaName,
|
|
333
|
+
table: tableName
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
id: `checkConstraint.${tableName}.${constraintName}`,
|
|
337
|
+
label: `Add check constraint "${constraintName}" on "${tableName}"."${column}"`,
|
|
338
|
+
operationClass: "additive",
|
|
339
|
+
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
340
|
+
precheck: [step(`ensure constraint "${constraintName}" does not exist`, absent.sql, absent.params)],
|
|
341
|
+
execute: [step(`add check constraint "${constraintName}"`, `ALTER TABLE ${qualified} ADD CONSTRAINT ${quoteIdentifier(constraintName)} CHECK (${quoteIdentifier(column)} IN (${valueList}))`)],
|
|
342
|
+
postcheck: [step(`verify constraint "${constraintName}" exists`, present.sql, present.params)]
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
async function dropCheckConstraint(schemaName, tableName, constraintName, lowerer) {
|
|
346
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
347
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
348
|
+
constraintName,
|
|
349
|
+
schema: schemaName,
|
|
350
|
+
table: tableName
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
id: `dropCheckConstraint.${tableName}.${constraintName}`,
|
|
354
|
+
label: `Drop check constraint "${constraintName}" on "${tableName}"`,
|
|
355
|
+
operationClass: "destructive",
|
|
356
|
+
target: targetDetails("checkConstraint", constraintName, schemaName, tableName),
|
|
357
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
358
|
+
execute: [step(`drop check constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
359
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* `kind` feeds the operation's `target.details.objectType`. Descriptor-flow
|
|
364
|
+
* does not carry kind information in its drop-constraint descriptor, so the
|
|
365
|
+
* default is `'unique'`. The reconciliation planner passes the correct kind
|
|
366
|
+
* (`'foreignKey'`, `'primaryKey'`, or `'unique'`) based on the diff issue
|
|
367
|
+
* that produced the drop.
|
|
368
|
+
*/
|
|
369
|
+
async function dropConstraint(schemaName, tableName, constraintName, lowerer, kind = "unique") {
|
|
370
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
371
|
+
const { absent, present } = await constraintCheckSteps(lowerer, {
|
|
372
|
+
constraintName,
|
|
373
|
+
schema: schemaName,
|
|
374
|
+
table: tableName
|
|
375
|
+
});
|
|
376
|
+
return {
|
|
377
|
+
id: `dropConstraint.${tableName}.${constraintName}`,
|
|
378
|
+
label: `Drop constraint "${constraintName}" on "${tableName}"`,
|
|
379
|
+
operationClass: "destructive",
|
|
380
|
+
target: targetDetails(kind, constraintName, schemaName, tableName),
|
|
381
|
+
precheck: [step(`ensure constraint "${constraintName}" exists`, present.sql, present.params)],
|
|
382
|
+
execute: [step(`drop constraint "${constraintName}"`, `ALTER TABLE ${qualified} DROP CONSTRAINT ${quoteIdentifier(constraintName)}`)],
|
|
383
|
+
postcheck: [step(`verify constraint "${constraintName}" does not exist`, absent.sql, absent.params)]
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function createExtension(extensionName) {
|
|
387
|
+
return {
|
|
388
|
+
id: `extension.${extensionName}`,
|
|
389
|
+
label: `Create extension "${extensionName}"`,
|
|
390
|
+
operationClass: "additive",
|
|
391
|
+
target: { id: "postgres" },
|
|
392
|
+
precheck: [],
|
|
393
|
+
execute: [step(`Create extension "${extensionName}"`, `CREATE EXTENSION IF NOT EXISTS ${quoteIdentifier(extensionName)}`)],
|
|
394
|
+
postcheck: []
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Install a Postgres extension as the baseline op for an extension-pack
|
|
399
|
+
* contract space. Layered on top of {@link createExtension}: stamps an
|
|
400
|
+
* `invariantId` (required so the per-space marker records the install),
|
|
401
|
+
* scopes the op `id` under a caller-chosen namespace (e.g. `pgvector.`),
|
|
402
|
+
* and emits pre- and postcheck SQL probing `pg_extension`. The richer
|
|
403
|
+
* shape lets the runner's idempotency probe skip the install on re-run
|
|
404
|
+
* (postcheck-pre-satisfied) without firing the precheck.
|
|
405
|
+
*
|
|
406
|
+
* Use this for hand-rolled baseline migrations in contract-space
|
|
407
|
+
* extension packages (e.g. `extension-pgvector`, `extension-paradedb`);
|
|
408
|
+
* use the bare {@link createExtension} for planner-emitted ops where the
|
|
409
|
+
* caller already controls idempotency through the surrounding plan.
|
|
410
|
+
*/
|
|
411
|
+
async function installExtension(options, lowerer) {
|
|
412
|
+
const { extensionName, invariantId, id } = options;
|
|
413
|
+
const label = options.label ?? `Enable extension "${extensionName}"`;
|
|
414
|
+
const checks = extensionExistsAst(extensionName);
|
|
415
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.extensionAbsent());
|
|
416
|
+
const present = await lowerer.lowerToExecuteRequest(checks.extensionPresent());
|
|
417
|
+
return {
|
|
418
|
+
id,
|
|
419
|
+
label,
|
|
420
|
+
operationClass: "additive",
|
|
421
|
+
invariantId,
|
|
422
|
+
target: {
|
|
423
|
+
id: "postgres",
|
|
424
|
+
details: {
|
|
425
|
+
schema: DEFAULT_NAMESPACE_ID,
|
|
426
|
+
objectType: "dependency",
|
|
427
|
+
name: extensionName
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
precheck: [step(`verify extension "${extensionName}" is not already enabled`, absent.sql, absent.params)],
|
|
431
|
+
execute: [step(`create extension "${extensionName}"`, `CREATE EXTENSION IF NOT EXISTS ${extensionName}`)],
|
|
432
|
+
postcheck: [step(`confirm extension "${extensionName}" is enabled`, present.sql, present.params)]
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
async function indexExistsSteps(lowerer, schemaName, indexName) {
|
|
436
|
+
const checks = indexExistsAst(schemaName, indexName);
|
|
437
|
+
return {
|
|
438
|
+
present: await lowerer.lowerToExecuteRequest(checks.indexPresent()),
|
|
439
|
+
absent: await lowerer.lowerToExecuteRequest(checks.indexAbsent())
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/** An unbound-namespace object renders unqualified: the DDL node takes no schema. */
|
|
443
|
+
function ddlSchemaOf(schemaName) {
|
|
444
|
+
return schemaName === UNBOUND_NAMESPACE_ID ? void 0 : schemaName;
|
|
445
|
+
}
|
|
446
|
+
async function createIndex(schemaName, tableName, indexName, elements, lowerer, extras) {
|
|
447
|
+
const ddlNode = createIndex$1({
|
|
448
|
+
schema: ddlSchemaOf(schemaName),
|
|
449
|
+
table: tableName,
|
|
450
|
+
name: indexName,
|
|
451
|
+
unique: extras?.unique === true,
|
|
452
|
+
elements,
|
|
453
|
+
type: extras?.type,
|
|
454
|
+
options: extras?.options,
|
|
455
|
+
where: extras?.where
|
|
456
|
+
});
|
|
457
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
458
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
459
|
+
return {
|
|
460
|
+
id: `index.${tableName}.${indexName}`,
|
|
461
|
+
label: `Create index "${indexName}" on "${tableName}"`,
|
|
462
|
+
operationClass: "additive",
|
|
463
|
+
target: targetDetails("index", indexName, schemaName, tableName),
|
|
464
|
+
precheck: [step(`ensure index "${indexName}" does not exist`, absent.sql, absent.params)],
|
|
465
|
+
execute: [step(`create index "${indexName}"`, execute.sql, execute.params)],
|
|
466
|
+
postcheck: [step(`verify index "${indexName}" exists`, present.sql, present.params)]
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* `ALTER INDEX … RENAME TO`. `widening` for the same typology reason as the
|
|
471
|
+
* RLS policy rename: a rename is neither additive creation nor destructive,
|
|
472
|
+
* and the class vocabulary has no neutral middle class — it is NOT that a
|
|
473
|
+
* rename widens anything.
|
|
474
|
+
*/
|
|
475
|
+
async function renameIndex(schemaName, tableName, fromName, toName, lowerer) {
|
|
476
|
+
const fromChecks = indexExistsAst(schemaName, fromName);
|
|
477
|
+
const toChecks = indexExistsAst(schemaName, toName);
|
|
478
|
+
const fromPresent = await lowerer.lowerToExecuteRequest(fromChecks.indexPresent());
|
|
479
|
+
const toAbsent = await lowerer.lowerToExecuteRequest(toChecks.indexAbsent());
|
|
480
|
+
const toPresent = await lowerer.lowerToExecuteRequest(toChecks.indexPresent());
|
|
481
|
+
const ddlNode = alterIndexRename({
|
|
482
|
+
schema: ddlSchemaOf(schemaName),
|
|
483
|
+
from: fromName,
|
|
484
|
+
to: toName
|
|
485
|
+
});
|
|
486
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
487
|
+
return {
|
|
488
|
+
id: `index.${schemaName}.${tableName}.${fromName}.rename`,
|
|
489
|
+
label: `Rename index "${fromName}" to "${toName}" on "${tableName}"`,
|
|
490
|
+
operationClass: "widening",
|
|
491
|
+
target: targetDetails("index", toName, schemaName, tableName),
|
|
492
|
+
precheck: [step(`ensure index "${fromName}" exists`, fromPresent.sql, fromPresent.params), step(`ensure index "${toName}" does not exist`, toAbsent.sql, toAbsent.params)],
|
|
493
|
+
execute: [step(`rename index "${fromName}" to "${toName}"`, execute.sql, execute.params)],
|
|
494
|
+
postcheck: [step(`verify index "${toName}" exists`, toPresent.sql, toPresent.params)]
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
async function dropIndex(schemaName, tableName, indexName, lowerer) {
|
|
498
|
+
const ddlNode = dropIndex$1({
|
|
499
|
+
schema: ddlSchemaOf(schemaName),
|
|
500
|
+
name: indexName
|
|
501
|
+
});
|
|
502
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
503
|
+
const { present, absent } = await indexExistsSteps(lowerer, schemaName, indexName);
|
|
504
|
+
return {
|
|
505
|
+
id: `dropIndex.${tableName}.${indexName}`,
|
|
506
|
+
label: `Drop index "${indexName}"`,
|
|
507
|
+
operationClass: "destructive",
|
|
508
|
+
target: targetDetails("index", indexName, schemaName, tableName),
|
|
509
|
+
precheck: [step(`ensure index "${indexName}" exists`, present.sql, present.params)],
|
|
510
|
+
execute: [step(`drop index "${indexName}"`, execute.sql, execute.params)],
|
|
511
|
+
postcheck: [step(`verify index "${indexName}" does not exist`, absent.sql, absent.params)]
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* `CREATE TYPE <qualified> AS ENUM (…)` for a managed native enum, built as a
|
|
516
|
+
* typed DDL node and lowered by the control adapter (the type name is quoted,
|
|
517
|
+
* member values render as escaped string literals in declaration order —
|
|
518
|
+
* Postgres enum sort order is semantic). `boundSchema` maps the unbound sentinel
|
|
519
|
+
* to an absent schema so the type name renders unqualified and the connection's
|
|
520
|
+
* `search_path` resolves the schema at runtime.
|
|
521
|
+
*/
|
|
522
|
+
async function createNativeEnumType(schemaName, typeName, members, lowerer) {
|
|
523
|
+
for (const member of members) validateEnumValueLength(member, typeName);
|
|
524
|
+
const ddlNode = createType({
|
|
525
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
526
|
+
name: typeName,
|
|
527
|
+
values: members
|
|
528
|
+
});
|
|
529
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
530
|
+
return {
|
|
531
|
+
id: `createNativeEnumType.${typeName}`,
|
|
532
|
+
label: `Create enum type "${typeName}"`,
|
|
533
|
+
operationClass: "additive",
|
|
534
|
+
target: targetDetails("type", typeName, schemaName),
|
|
535
|
+
precheck: [],
|
|
536
|
+
execute: [step(`create enum type "${typeName}"`, statement.sql, statement.params)],
|
|
537
|
+
postcheck: []
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
/** `DROP TYPE <qualified>` for an unclaimed managed native enum, via typed DDL. */
|
|
541
|
+
async function dropNativeEnumType(schemaName, typeName, lowerer) {
|
|
542
|
+
const ddlNode = dropType({
|
|
543
|
+
...ifDefined("schema", boundSchema(schemaName)),
|
|
544
|
+
name: typeName
|
|
545
|
+
});
|
|
546
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
547
|
+
return {
|
|
548
|
+
id: `dropNativeEnumType.${typeName}`,
|
|
549
|
+
label: `Drop enum type "${typeName}"`,
|
|
550
|
+
operationClass: "destructive",
|
|
551
|
+
target: targetDetails("type", typeName, schemaName),
|
|
552
|
+
precheck: [],
|
|
553
|
+
execute: [step(`drop enum type "${typeName}"`, statement.sql, statement.params)],
|
|
554
|
+
postcheck: []
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const PLAIN_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
558
|
+
function validateRoleName(role) {
|
|
559
|
+
if (!PLAIN_IDENTIFIER.test(role)) throw postgresError("CONTRACT.ROLE_INVALID", `Invalid role name ${JSON.stringify(role)}: role names must be plain SQL identifiers matching ^[A-Za-z_][A-Za-z0-9_$]*$`, { meta: {
|
|
560
|
+
role,
|
|
561
|
+
reason: "not-a-plain-identifier"
|
|
562
|
+
} });
|
|
563
|
+
return role;
|
|
564
|
+
}
|
|
565
|
+
async function createRlsPolicy(schemaName, tableName, policy, lowerer) {
|
|
566
|
+
const validatedRoles = policy.roles.map(validateRoleName);
|
|
567
|
+
const ddlNode = createPolicy({
|
|
568
|
+
schema: schemaName,
|
|
569
|
+
table: tableName,
|
|
570
|
+
name: policy.name,
|
|
571
|
+
permissive: policy.permissive,
|
|
572
|
+
operation: policy.operation,
|
|
573
|
+
roles: validatedRoles,
|
|
574
|
+
...ifDefined("using", policy.using),
|
|
575
|
+
...ifDefined("withCheck", policy.withCheck)
|
|
576
|
+
});
|
|
577
|
+
const checks = rlsPolicyExistsAst({
|
|
578
|
+
schema: schemaName,
|
|
579
|
+
table: tableName,
|
|
580
|
+
policyName: policy.name
|
|
581
|
+
});
|
|
582
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
583
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
584
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
585
|
+
return {
|
|
586
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policy.name}`,
|
|
587
|
+
label: `Create RLS policy "${policy.name}" on "${tableName}"`,
|
|
588
|
+
operationClass: "additive",
|
|
589
|
+
target: targetDetails("rlsPolicy", policy.name, schemaName, tableName),
|
|
590
|
+
precheck: [step(`ensure RLS policy "${policy.name}" does not exist`, absent.sql, absent.params)],
|
|
591
|
+
execute: [step(`create RLS policy "${policy.name}"`, execute.sql, execute.params)],
|
|
592
|
+
postcheck: [step(`verify RLS policy "${policy.name}" exists`, present.sql, present.params)]
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
async function dropRlsPolicy(schemaName, tableName, policyName, lowerer) {
|
|
596
|
+
const ddlNode = dropPolicy({
|
|
597
|
+
schema: schemaName,
|
|
598
|
+
table: tableName,
|
|
599
|
+
name: policyName
|
|
600
|
+
});
|
|
601
|
+
const checks = rlsPolicyExistsAst({
|
|
602
|
+
schema: schemaName,
|
|
603
|
+
table: tableName,
|
|
604
|
+
policyName
|
|
605
|
+
});
|
|
606
|
+
const present = await lowerer.lowerToExecuteRequest(checks.policyPresent());
|
|
607
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
608
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.policyAbsent());
|
|
609
|
+
return {
|
|
610
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${policyName}.drop`,
|
|
611
|
+
label: `Drop RLS policy "${policyName}" on "${tableName}"`,
|
|
612
|
+
operationClass: "destructive",
|
|
613
|
+
target: targetDetails("rlsPolicy", policyName, schemaName, tableName),
|
|
614
|
+
precheck: [step(`ensure RLS policy "${policyName}" exists`, present.sql, present.params)],
|
|
615
|
+
execute: [step(`drop RLS policy "${policyName}"`, execute.sql, execute.params)],
|
|
616
|
+
postcheck: [step(`verify RLS policy "${policyName}" is absent`, absent.sql, absent.params)]
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
async function enableRowLevelSecurity(schemaName, tableName, lowerer) {
|
|
620
|
+
const checks = rlsEnabledAst(schemaName, tableName);
|
|
621
|
+
const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
|
|
622
|
+
const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
|
|
623
|
+
return {
|
|
624
|
+
id: `rowLevelSecurity.${schemaName}.${tableName}`,
|
|
625
|
+
label: `Enable row-level security on "${tableName}"`,
|
|
626
|
+
operationClass: "additive",
|
|
627
|
+
target: targetDetails("rowLevelSecurity", tableName, schemaName),
|
|
628
|
+
precheck: [step(`check RLS is not already enabled on "${tableName}"`, disabled.sql, disabled.params)],
|
|
629
|
+
execute: [step(`enable row-level security on "${tableName}"`, `ALTER TABLE ${qualifyTableName(schemaName, tableName)} ENABLE ROW LEVEL SECURITY`)],
|
|
630
|
+
postcheck: [step(`verify row-level security is enabled on "${tableName}"`, enabled.sql, enabled.params)]
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
async function disableRowLevelSecurity(schemaName, tableName, lowerer) {
|
|
634
|
+
const ddlNode = disableRowLevelSecurity$1({
|
|
635
|
+
schema: schemaName,
|
|
636
|
+
table: tableName
|
|
637
|
+
});
|
|
638
|
+
const checks = rlsEnabledAst(schemaName, tableName);
|
|
639
|
+
const enabled = await lowerer.lowerToExecuteRequest(checks.rlsEnabled());
|
|
640
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
641
|
+
const disabled = await lowerer.lowerToExecuteRequest(checks.rlsDisabled());
|
|
642
|
+
return {
|
|
643
|
+
id: `rowLevelSecurity.${schemaName}.${tableName}.disable`,
|
|
644
|
+
label: `Disable row-level security on "${tableName}"`,
|
|
645
|
+
operationClass: "destructive",
|
|
646
|
+
target: targetDetails("rowLevelSecurity", tableName, schemaName),
|
|
647
|
+
precheck: [step(`check RLS is currently enabled on "${tableName}"`, enabled.sql, enabled.params)],
|
|
648
|
+
execute: [step(`disable row-level security on "${tableName}"`, execute.sql, execute.params)],
|
|
649
|
+
postcheck: [step(`verify row-level security is disabled on "${tableName}"`, disabled.sql, disabled.params)]
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
async function renameRlsPolicy(schemaName, tableName, oldPolicyName, newPolicyName, lowerer) {
|
|
653
|
+
const ddlNode = alterPolicyRename({
|
|
654
|
+
schema: schemaName,
|
|
655
|
+
table: tableName,
|
|
656
|
+
name: oldPolicyName,
|
|
657
|
+
newName: newPolicyName
|
|
658
|
+
});
|
|
659
|
+
const oldChecks = rlsPolicyExistsAst({
|
|
660
|
+
schema: schemaName,
|
|
661
|
+
table: tableName,
|
|
662
|
+
policyName: oldPolicyName
|
|
663
|
+
});
|
|
664
|
+
const newChecks = rlsPolicyExistsAst({
|
|
665
|
+
schema: schemaName,
|
|
666
|
+
table: tableName,
|
|
667
|
+
policyName: newPolicyName
|
|
668
|
+
});
|
|
669
|
+
const oldPresent = await lowerer.lowerToExecuteRequest(oldChecks.policyPresent());
|
|
670
|
+
const execute = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
671
|
+
const newPresent = await lowerer.lowerToExecuteRequest(newChecks.policyPresent());
|
|
672
|
+
return {
|
|
673
|
+
id: `rlsPolicy.${schemaName}.${tableName}.${oldPolicyName}.rename`,
|
|
674
|
+
label: `Rename RLS policy "${oldPolicyName}" to "${newPolicyName}" on "${tableName}"`,
|
|
675
|
+
operationClass: "widening",
|
|
676
|
+
target: targetDetails("rlsPolicy", newPolicyName, schemaName, tableName),
|
|
677
|
+
precheck: [step(`ensure RLS policy "${oldPolicyName}" exists`, oldPresent.sql, oldPresent.params)],
|
|
678
|
+
execute: [step(`rename RLS policy "${oldPolicyName}" to "${newPolicyName}"`, execute.sql, execute.params)],
|
|
679
|
+
postcheck: [step(`verify RLS policy "${newPolicyName}" exists`, newPresent.sql, newPresent.params)]
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
async function dropTable(schemaName, tableName, lowerer) {
|
|
683
|
+
const qualified = qualifyTableName(schemaName, tableName);
|
|
684
|
+
const checks = tableExistsAst(schemaName, tableName);
|
|
685
|
+
const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
|
|
686
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
|
|
687
|
+
return {
|
|
688
|
+
id: `dropTable.${tableName}`,
|
|
689
|
+
label: `Drop table "${tableName}"`,
|
|
690
|
+
operationClass: "destructive",
|
|
691
|
+
target: targetDetails("table", tableName, schemaName),
|
|
692
|
+
precheck: [step(`ensure table "${tableName}" exists`, present.sql, present.params)],
|
|
693
|
+
execute: [step(`drop table "${tableName}"`, `DROP TABLE ${qualified}`)],
|
|
694
|
+
postcheck: [step(`verify table "${tableName}" does not exist`, absent.sql, absent.params)]
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function buildTargetDetails(objectType, name, schema, table) {
|
|
698
|
+
return {
|
|
699
|
+
schema,
|
|
700
|
+
objectType,
|
|
701
|
+
name,
|
|
702
|
+
...ifDefined("table", table)
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function buildAddColumnOperationIdentity(schema, tableName, columnName) {
|
|
706
|
+
return {
|
|
707
|
+
id: `column.${tableName}.${columnName}`,
|
|
708
|
+
label: `Add column ${columnName} to ${tableName}`,
|
|
709
|
+
summary: `Adds column ${columnName} to table ${tableName}`,
|
|
710
|
+
target: {
|
|
711
|
+
id: "postgres",
|
|
712
|
+
details: buildTargetDetails("table", tableName, schema)
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
async function buildAddNotNullColumnWithTemporaryDefaultOperation(options) {
|
|
717
|
+
const { schema, tableName, columnName, column, codecHooks, storageTypes, temporaryDefault, lowerer } = options;
|
|
718
|
+
const ddlColumn = col(columnName, buildColumnTypeSql(column, codecHooks, storageTypes), {
|
|
719
|
+
notNull: true,
|
|
720
|
+
default: new FunctionColumnDefault(temporaryDefault)
|
|
721
|
+
});
|
|
722
|
+
const addColumn = await lowerer.lowerToExecuteRequest(alterTable({
|
|
723
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
724
|
+
table: tableName,
|
|
725
|
+
actions: [addColumnAction(ddlColumn)]
|
|
726
|
+
}));
|
|
727
|
+
const dropTempDefault = await lowerer.lowerToExecuteRequest(alterTable({
|
|
728
|
+
...ifDefined("schema", boundSchema(schema)),
|
|
729
|
+
table: tableName,
|
|
730
|
+
actions: [dropDefaultAction(columnName)]
|
|
731
|
+
}));
|
|
732
|
+
const absent = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
733
|
+
schema,
|
|
734
|
+
table: tableName,
|
|
735
|
+
column: columnName
|
|
736
|
+
}).columnAbsent());
|
|
737
|
+
const present = await lowerer.lowerToExecuteRequest(columnExistsAst({
|
|
738
|
+
schema,
|
|
739
|
+
table: tableName,
|
|
740
|
+
column: columnName
|
|
741
|
+
}).columnPresent());
|
|
742
|
+
const notNullable = await lowerer.lowerToExecuteRequest(columnNullabilityAst({
|
|
743
|
+
schema,
|
|
744
|
+
table: tableName,
|
|
745
|
+
column: columnName,
|
|
746
|
+
nullable: false
|
|
747
|
+
}));
|
|
748
|
+
const noDefault = await lowerer.lowerToExecuteRequest(columnDefaultAst({
|
|
749
|
+
schema,
|
|
750
|
+
table: tableName,
|
|
751
|
+
column: columnName
|
|
752
|
+
}).noDefault());
|
|
753
|
+
return {
|
|
754
|
+
...buildAddColumnOperationIdentity(schema, tableName, columnName),
|
|
755
|
+
operationClass: "additive",
|
|
756
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
757
|
+
execute: [{
|
|
758
|
+
description: `add column "${columnName}"`,
|
|
759
|
+
sql: addColumn.sql
|
|
760
|
+
}, {
|
|
761
|
+
description: `drop temporary default from column "${columnName}"`,
|
|
762
|
+
sql: dropTempDefault.sql
|
|
763
|
+
}],
|
|
764
|
+
postcheck: [
|
|
765
|
+
step(`verify column "${columnName}" exists`, present.sql, present.params),
|
|
766
|
+
step(`verify column "${columnName}" is NOT NULL`, notNullable.sql, notNullable.params),
|
|
767
|
+
step(`verify column "${columnName}" has no default after temporary default removal`, noDefault.sql, noDefault.params)
|
|
768
|
+
]
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Postgres migration IR: one concrete `*Call` class per pure factory under
|
|
773
|
+
* `operations/`, plus a shared `PostgresOpFactoryCallNode` abstract base.
|
|
774
|
+
*
|
|
775
|
+
* Every call class carries the literal arguments its backing factory would
|
|
776
|
+
* receive, computes a human-readable `label` in its constructor, and
|
|
777
|
+
* implements two polymorphic hooks:
|
|
778
|
+
*
|
|
779
|
+
* - `toOp()` — converts the IR node to a runtime
|
|
780
|
+
* `SqlMigrationPlanOperation` by delegating to the matching pure factory
|
|
781
|
+
* under `operations/`. `DataTransformCall.toOp()` always throws
|
|
782
|
+
* `MIGRATION.UNFILLED_PLACEHOLDER` because a planner-generated data transform is an
|
|
783
|
+
* unfilled authoring stub by construction.
|
|
784
|
+
* - `renderTypeScript()` / `importRequirements()` — inherited from
|
|
785
|
+
* `TsExpression`. Used by `renderCallsToTypeScript` to emit the call as
|
|
786
|
+
* a TypeScript expression inside the scaffolded `migration.ts`.
|
|
787
|
+
*
|
|
788
|
+
* The abstract base and all concrete classes are package-private. External
|
|
789
|
+
* consumers see only the framework-level `OpFactoryCall` interface and the
|
|
790
|
+
* `PostgresOpFactoryCall` union.
|
|
791
|
+
*/
|
|
792
|
+
const POSTGRES_MIGRATION_FACADE = "@internal/postgres/migration";
|
|
793
|
+
var PostgresOpFactoryCallNode = class extends TsExpression {
|
|
794
|
+
importRequirements() {
|
|
795
|
+
return [{
|
|
796
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
797
|
+
symbol: this.factoryName
|
|
798
|
+
}];
|
|
799
|
+
}
|
|
800
|
+
freeze() {
|
|
801
|
+
Object.freeze(this);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
function postgresDefaultToDdlColumnDefault(columnDefault) {
|
|
805
|
+
if (!columnDefault) return void 0;
|
|
806
|
+
switch (columnDefault.kind) {
|
|
807
|
+
case "literal": return new LiteralColumnDefault(columnDefault.value);
|
|
808
|
+
case "function":
|
|
809
|
+
if (columnDefault.expression === "autoincrement()") return void 0;
|
|
810
|
+
return new FunctionColumnDefault(columnDefault.expression);
|
|
811
|
+
case "sequence": return new FunctionColumnDefault(`nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`);
|
|
812
|
+
default: {
|
|
813
|
+
const exhaustive = columnDefault;
|
|
814
|
+
return assertNever(exhaustive, `postgresDefaultToDdlColumnDefault: unhandled kind "${blindCast(exhaustive).kind}"`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
function renderDdlColumnDefault(def) {
|
|
819
|
+
if (!def) return "";
|
|
820
|
+
if (def.kind === "literal") return `lit(${jsonToTsSource(def.value)})`;
|
|
821
|
+
return `fn(${jsonToTsSource(def.expression)})`;
|
|
822
|
+
}
|
|
823
|
+
function renderDdlColumnAsTsCall(col) {
|
|
824
|
+
const opts = [];
|
|
825
|
+
if (col.notNull) opts.push("notNull: true");
|
|
826
|
+
if (col.primaryKey) opts.push("primaryKey: true");
|
|
827
|
+
if (col.default) opts.push(`default: ${renderDdlColumnDefault(col.default)}`);
|
|
828
|
+
if (col.codecRef) opts.push(`codecRef: ${jsonToTsSource(col.codecRef)}`);
|
|
829
|
+
const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
|
|
830
|
+
return `col(${jsonToTsSource(col.name)}, ${jsonToTsSource(col.type)}${optsStr})`;
|
|
831
|
+
}
|
|
832
|
+
function renderDdlConstraintAsTsCall(constraint) {
|
|
833
|
+
switch (constraint.kind) {
|
|
834
|
+
case "primary-key": {
|
|
835
|
+
const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
|
|
836
|
+
return `primaryKey(${jsonToTsSource(constraint.columns)}${nameOpt})`;
|
|
837
|
+
}
|
|
838
|
+
case "foreign-key": {
|
|
839
|
+
const opts = [];
|
|
840
|
+
if (constraint.name) opts.push(`name: ${jsonToTsSource(constraint.name)}`);
|
|
841
|
+
if (constraint.onDelete) opts.push(`onDelete: ${jsonToTsSource(constraint.onDelete)}`);
|
|
842
|
+
if (constraint.onUpdate) opts.push(`onUpdate: ${jsonToTsSource(constraint.onUpdate)}`);
|
|
843
|
+
const optsStr = opts.length > 0 ? `, { ${opts.join(", ")} }` : "";
|
|
844
|
+
return `foreignKey(${jsonToTsSource(constraint.columns)}, ${jsonToTsSource(constraint.refTable)}, ${jsonToTsSource(constraint.refColumns)}${optsStr})`;
|
|
845
|
+
}
|
|
846
|
+
case "unique": {
|
|
847
|
+
const nameOpt = constraint.name ? `, { name: ${jsonToTsSource(constraint.name)} }` : "";
|
|
848
|
+
return `unique(${jsonToTsSource(constraint.columns)}${nameOpt})`;
|
|
849
|
+
}
|
|
850
|
+
case "check-expression": return `checkExpression(${jsonToTsSource(constraint.name)}, ${jsonToTsSource(constraint.expression)})`;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
function needsColOrConstraintImport(columns) {
|
|
854
|
+
return columns.length > 0;
|
|
855
|
+
}
|
|
856
|
+
function constraintImportSymbols(constraints) {
|
|
857
|
+
if (!constraints || constraints.length === 0) return [];
|
|
858
|
+
const symbols = /* @__PURE__ */ new Set();
|
|
859
|
+
for (const c of constraints) if (c.kind === "primary-key") symbols.add("primaryKey");
|
|
860
|
+
else if (c.kind === "foreign-key") symbols.add("foreignKey");
|
|
861
|
+
else if (c.kind === "unique") symbols.add("unique");
|
|
862
|
+
else if (c.kind === "check-expression") symbols.add("checkExpression");
|
|
863
|
+
return [...symbols];
|
|
864
|
+
}
|
|
865
|
+
function defaultImportSymbols(columns) {
|
|
866
|
+
const symbols = /* @__PURE__ */ new Set();
|
|
867
|
+
for (const col of columns) if (col.default?.kind === "literal") symbols.add("lit");
|
|
868
|
+
else if (col.default?.kind === "function") symbols.add("fn");
|
|
869
|
+
return [...symbols];
|
|
870
|
+
}
|
|
871
|
+
var CreateTableCall = class extends PostgresOpFactoryCallNode {
|
|
872
|
+
factoryName = "createTable";
|
|
873
|
+
operationClass = "additive";
|
|
874
|
+
schemaName;
|
|
875
|
+
tableName;
|
|
876
|
+
columns;
|
|
877
|
+
constraints;
|
|
878
|
+
label;
|
|
879
|
+
constructor(schemaName, tableName, columns, constraints) {
|
|
880
|
+
super();
|
|
881
|
+
this.schemaName = schemaName;
|
|
882
|
+
this.tableName = tableName;
|
|
883
|
+
this.columns = Object.freeze([...columns]);
|
|
884
|
+
this.constraints = constraints ? Object.freeze([...constraints]) : void 0;
|
|
885
|
+
this.label = `Create table "${tableName}"`;
|
|
886
|
+
this.freeze();
|
|
887
|
+
}
|
|
888
|
+
async toOp(lowerer) {
|
|
889
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateTableCall" } });
|
|
890
|
+
const ddlNode = createTable({
|
|
891
|
+
...ifDefined("schema", boundSchema(this.schemaName)),
|
|
892
|
+
table: this.tableName,
|
|
893
|
+
columns: this.columns,
|
|
894
|
+
...ifDefined("constraints", this.constraints)
|
|
895
|
+
});
|
|
896
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
897
|
+
const schemaName = this.schemaName;
|
|
898
|
+
const tableName = this.tableName;
|
|
899
|
+
const checks = tableExistsAst(schemaName, tableName);
|
|
900
|
+
const absent = await lowerer.lowerToExecuteRequest(checks.tableAbsent());
|
|
901
|
+
const present = await lowerer.lowerToExecuteRequest(checks.tablePresent());
|
|
902
|
+
return {
|
|
903
|
+
id: `table.${tableName}`,
|
|
904
|
+
label: `Create table "${tableName}"`,
|
|
905
|
+
summary: `Creates table "${tableName}"`,
|
|
906
|
+
operationClass: "additive",
|
|
907
|
+
target: targetDetails("table", tableName, schemaName),
|
|
908
|
+
precheck: [step(`ensure table "${tableName}" does not exist`, absent.sql, absent.params)],
|
|
909
|
+
execute: [{
|
|
910
|
+
description: `create table "${tableName}"`,
|
|
911
|
+
sql: statement.sql,
|
|
912
|
+
params: statement.params ?? []
|
|
913
|
+
}],
|
|
914
|
+
postcheck: [step(`verify table "${tableName}" exists`, present.sql, present.params)]
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
renderTypeScript() {
|
|
918
|
+
const columnsList = this.columns.map(renderDdlColumnAsTsCall).join(", ");
|
|
919
|
+
const constraintsList = this.constraints ? this.constraints.map(renderDdlConstraintAsTsCall).join(", ") : void 0;
|
|
920
|
+
const opts = [];
|
|
921
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
922
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
923
|
+
opts.push(`columns: [${columnsList}]`);
|
|
924
|
+
if (constraintsList) opts.push(`constraints: [${constraintsList}]`);
|
|
925
|
+
return `this.createTable({ ${opts.join(", ")} })`;
|
|
926
|
+
}
|
|
927
|
+
importRequirements() {
|
|
928
|
+
const req = [];
|
|
929
|
+
if (needsColOrConstraintImport(this.columns)) {
|
|
930
|
+
req.push({
|
|
931
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
932
|
+
symbol: "col"
|
|
933
|
+
});
|
|
934
|
+
for (const sym of defaultImportSymbols(this.columns)) req.push({
|
|
935
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
936
|
+
symbol: sym
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
for (const sym of constraintImportSymbols(this.constraints)) req.push({
|
|
940
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
941
|
+
symbol: sym
|
|
942
|
+
});
|
|
943
|
+
return req;
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
var DropTableCall = class extends PostgresOpFactoryCallNode {
|
|
947
|
+
factoryName = "dropTable";
|
|
948
|
+
operationClass = "destructive";
|
|
949
|
+
schemaName;
|
|
950
|
+
tableName;
|
|
951
|
+
label;
|
|
952
|
+
constructor(schemaName, tableName) {
|
|
953
|
+
super();
|
|
954
|
+
this.schemaName = schemaName;
|
|
955
|
+
this.tableName = tableName;
|
|
956
|
+
this.label = `Drop table "${tableName}"`;
|
|
957
|
+
this.freeze();
|
|
958
|
+
}
|
|
959
|
+
async toOp(lowerer) {
|
|
960
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropTableCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropTableCall" } });
|
|
961
|
+
return dropTable(this.schemaName, this.tableName, lowerer);
|
|
962
|
+
}
|
|
963
|
+
renderTypeScript() {
|
|
964
|
+
const opts = [];
|
|
965
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
966
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
967
|
+
return `this.dropTable({ ${opts.join(", ")} })`;
|
|
968
|
+
}
|
|
969
|
+
importRequirements() {
|
|
970
|
+
return [];
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
var AddColumnCall = class extends PostgresOpFactoryCallNode {
|
|
974
|
+
factoryName = "addColumn";
|
|
975
|
+
operationClass = "additive";
|
|
976
|
+
schemaName;
|
|
977
|
+
tableName;
|
|
978
|
+
column;
|
|
979
|
+
label;
|
|
980
|
+
constructor(schemaName, tableName, column) {
|
|
981
|
+
super();
|
|
982
|
+
this.schemaName = schemaName;
|
|
983
|
+
this.tableName = tableName;
|
|
984
|
+
this.column = column;
|
|
985
|
+
this.label = `Add column "${column.name}" to "${tableName}"`;
|
|
986
|
+
this.freeze();
|
|
987
|
+
}
|
|
988
|
+
async toOp(lowerer) {
|
|
989
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddColumnCall.toOp: a DDL lowerer is required on the Postgres planner path (column "${this.column.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddColumnCall" } });
|
|
990
|
+
const ddlNode = alterTable({
|
|
991
|
+
...ifDefined("schema", boundSchema(this.schemaName)),
|
|
992
|
+
table: this.tableName,
|
|
993
|
+
actions: [addColumnAction(this.column)]
|
|
994
|
+
});
|
|
995
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
996
|
+
const schemaName = this.schemaName;
|
|
997
|
+
const tableName = this.tableName;
|
|
998
|
+
const columnName = this.column.name;
|
|
999
|
+
const colChecks = columnExistsAst({
|
|
1000
|
+
schema: schemaName,
|
|
1001
|
+
table: tableName,
|
|
1002
|
+
column: columnName
|
|
1003
|
+
});
|
|
1004
|
+
const absent = await lowerer.lowerToExecuteRequest(colChecks.columnAbsent());
|
|
1005
|
+
const present = await lowerer.lowerToExecuteRequest(colChecks.columnPresent());
|
|
1006
|
+
return {
|
|
1007
|
+
id: `column.${schemaName}.${tableName}.${columnName}`,
|
|
1008
|
+
label: `Add column "${columnName}" to "${tableName}"`,
|
|
1009
|
+
operationClass: "additive",
|
|
1010
|
+
target: targetDetails("column", columnName, schemaName, tableName),
|
|
1011
|
+
precheck: [step(`ensure column "${columnName}" is missing`, absent.sql, absent.params)],
|
|
1012
|
+
execute: [step(`add column "${columnName}"`, statement.sql)],
|
|
1013
|
+
postcheck: [step(`verify column "${columnName}" exists`, present.sql, present.params)]
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
renderTypeScript() {
|
|
1017
|
+
const opts = [];
|
|
1018
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1019
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1020
|
+
opts.push(`column: ${renderDdlColumnAsTsCall(this.column)}`);
|
|
1021
|
+
return `this.addColumn({ ${opts.join(", ")} })`;
|
|
1022
|
+
}
|
|
1023
|
+
importRequirements() {
|
|
1024
|
+
const req = [{
|
|
1025
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
1026
|
+
symbol: "col"
|
|
1027
|
+
}];
|
|
1028
|
+
for (const sym of defaultImportSymbols([this.column])) req.push({
|
|
1029
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
1030
|
+
symbol: sym
|
|
1031
|
+
});
|
|
1032
|
+
return req;
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
var DropColumnCall = class extends PostgresOpFactoryCallNode {
|
|
1036
|
+
factoryName = "dropColumn";
|
|
1037
|
+
operationClass = "destructive";
|
|
1038
|
+
schemaName;
|
|
1039
|
+
tableName;
|
|
1040
|
+
columnName;
|
|
1041
|
+
label;
|
|
1042
|
+
constructor(schemaName, tableName, columnName) {
|
|
1043
|
+
super();
|
|
1044
|
+
this.schemaName = schemaName;
|
|
1045
|
+
this.tableName = tableName;
|
|
1046
|
+
this.columnName = columnName;
|
|
1047
|
+
this.label = `Drop column "${columnName}" from "${tableName}"`;
|
|
1048
|
+
this.freeze();
|
|
1049
|
+
}
|
|
1050
|
+
async toOp(lowerer) {
|
|
1051
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropColumnCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropColumnCall" } });
|
|
1052
|
+
return dropColumn(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
1053
|
+
}
|
|
1054
|
+
renderTypeScript() {
|
|
1055
|
+
const opts = [];
|
|
1056
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1057
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1058
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1059
|
+
return `this.dropColumn({ ${opts.join(", ")} })`;
|
|
1060
|
+
}
|
|
1061
|
+
importRequirements() {
|
|
1062
|
+
return [];
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var AlterColumnTypeCall = class extends PostgresOpFactoryCallNode {
|
|
1066
|
+
factoryName = "alterColumnType";
|
|
1067
|
+
operationClass = "destructive";
|
|
1068
|
+
schemaName;
|
|
1069
|
+
tableName;
|
|
1070
|
+
columnName;
|
|
1071
|
+
options;
|
|
1072
|
+
label;
|
|
1073
|
+
constructor(schemaName, tableName, columnName, options) {
|
|
1074
|
+
super();
|
|
1075
|
+
this.schemaName = schemaName;
|
|
1076
|
+
this.tableName = tableName;
|
|
1077
|
+
this.columnName = columnName;
|
|
1078
|
+
this.options = options;
|
|
1079
|
+
this.label = `Alter type of "${tableName}"."${columnName}" to ${options.rawTargetTypeForLabel}`;
|
|
1080
|
+
this.freeze();
|
|
1081
|
+
}
|
|
1082
|
+
async toOp(lowerer) {
|
|
1083
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AlterColumnTypeCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AlterColumnTypeCall" } });
|
|
1084
|
+
return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options, lowerer);
|
|
1085
|
+
}
|
|
1086
|
+
renderTypeScript() {
|
|
1087
|
+
const opts = [];
|
|
1088
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1089
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1090
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1091
|
+
opts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
1092
|
+
return `this.alterColumnType({ ${opts.join(", ")} })`;
|
|
1093
|
+
}
|
|
1094
|
+
importRequirements() {
|
|
1095
|
+
return [];
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
var SetNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
1099
|
+
factoryName = "setNotNull";
|
|
1100
|
+
operationClass = "destructive";
|
|
1101
|
+
schemaName;
|
|
1102
|
+
tableName;
|
|
1103
|
+
columnName;
|
|
1104
|
+
label;
|
|
1105
|
+
constructor(schemaName, tableName, columnName) {
|
|
1106
|
+
super();
|
|
1107
|
+
this.schemaName = schemaName;
|
|
1108
|
+
this.tableName = tableName;
|
|
1109
|
+
this.columnName = columnName;
|
|
1110
|
+
this.label = `Set NOT NULL on "${tableName}"."${columnName}"`;
|
|
1111
|
+
this.freeze();
|
|
1112
|
+
}
|
|
1113
|
+
async toOp(lowerer) {
|
|
1114
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `SetNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "SetNotNullCall" } });
|
|
1115
|
+
return setNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
1116
|
+
}
|
|
1117
|
+
renderTypeScript() {
|
|
1118
|
+
const opts = [];
|
|
1119
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1120
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1121
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1122
|
+
return `this.setNotNull({ ${opts.join(", ")} })`;
|
|
1123
|
+
}
|
|
1124
|
+
importRequirements() {
|
|
1125
|
+
return [];
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
var DropNotNullCall = class extends PostgresOpFactoryCallNode {
|
|
1129
|
+
factoryName = "dropNotNull";
|
|
1130
|
+
operationClass = "widening";
|
|
1131
|
+
schemaName;
|
|
1132
|
+
tableName;
|
|
1133
|
+
columnName;
|
|
1134
|
+
label;
|
|
1135
|
+
constructor(schemaName, tableName, columnName) {
|
|
1136
|
+
super();
|
|
1137
|
+
this.schemaName = schemaName;
|
|
1138
|
+
this.tableName = tableName;
|
|
1139
|
+
this.columnName = columnName;
|
|
1140
|
+
this.label = `Drop NOT NULL on "${tableName}"."${columnName}"`;
|
|
1141
|
+
this.freeze();
|
|
1142
|
+
}
|
|
1143
|
+
async toOp(lowerer) {
|
|
1144
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropNotNullCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropNotNullCall" } });
|
|
1145
|
+
return dropNotNull(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
1146
|
+
}
|
|
1147
|
+
renderTypeScript() {
|
|
1148
|
+
const opts = [];
|
|
1149
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1150
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1151
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1152
|
+
return `this.dropNotNull({ ${opts.join(", ")} })`;
|
|
1153
|
+
}
|
|
1154
|
+
importRequirements() {
|
|
1155
|
+
return [];
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
var SetDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
1159
|
+
factoryName = "setDefault";
|
|
1160
|
+
operationClass;
|
|
1161
|
+
schemaName;
|
|
1162
|
+
tableName;
|
|
1163
|
+
columnName;
|
|
1164
|
+
defaultSql;
|
|
1165
|
+
label;
|
|
1166
|
+
constructor(schemaName, tableName, columnName, defaultSql, operationClass = "additive") {
|
|
1167
|
+
super();
|
|
1168
|
+
this.schemaName = schemaName;
|
|
1169
|
+
this.tableName = tableName;
|
|
1170
|
+
this.columnName = columnName;
|
|
1171
|
+
this.defaultSql = defaultSql;
|
|
1172
|
+
this.operationClass = operationClass;
|
|
1173
|
+
this.label = `Set default on "${tableName}"."${columnName}"`;
|
|
1174
|
+
this.freeze();
|
|
1175
|
+
}
|
|
1176
|
+
async toOp(lowerer) {
|
|
1177
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `SetDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "SetDefaultCall" } });
|
|
1178
|
+
return setDefault(this.schemaName, this.tableName, this.columnName, this.defaultSql, lowerer, this.operationClass);
|
|
1179
|
+
}
|
|
1180
|
+
renderTypeScript() {
|
|
1181
|
+
const opts = [];
|
|
1182
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1183
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1184
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1185
|
+
opts.push(`defaultSql: ${jsonToTsSource(this.defaultSql)}`);
|
|
1186
|
+
if (this.operationClass !== "additive") opts.push(`operationClass: ${jsonToTsSource(this.operationClass)}`);
|
|
1187
|
+
return `this.setDefault({ ${opts.join(", ")} })`;
|
|
1188
|
+
}
|
|
1189
|
+
importRequirements() {
|
|
1190
|
+
return [];
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
var DropDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
1194
|
+
factoryName = "dropDefault";
|
|
1195
|
+
operationClass = "destructive";
|
|
1196
|
+
schemaName;
|
|
1197
|
+
tableName;
|
|
1198
|
+
columnName;
|
|
1199
|
+
label;
|
|
1200
|
+
constructor(schemaName, tableName, columnName) {
|
|
1201
|
+
super();
|
|
1202
|
+
this.schemaName = schemaName;
|
|
1203
|
+
this.tableName = tableName;
|
|
1204
|
+
this.columnName = columnName;
|
|
1205
|
+
this.label = `Drop default on "${tableName}"."${columnName}"`;
|
|
1206
|
+
this.freeze();
|
|
1207
|
+
}
|
|
1208
|
+
async toOp(lowerer) {
|
|
1209
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropDefaultCall" } });
|
|
1210
|
+
return dropDefault(this.schemaName, this.tableName, this.columnName, lowerer);
|
|
1211
|
+
}
|
|
1212
|
+
renderTypeScript() {
|
|
1213
|
+
const opts = [];
|
|
1214
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1215
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1216
|
+
opts.push(`column: ${jsonToTsSource(this.columnName)}`);
|
|
1217
|
+
return `this.dropDefault({ ${opts.join(", ")} })`;
|
|
1218
|
+
}
|
|
1219
|
+
importRequirements() {
|
|
1220
|
+
return [];
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
/**
|
|
1224
|
+
* Planner-internal call for adding a NOT NULL column (no contract default) to
|
|
1225
|
+
* a table that must be empty at migration time. Carries the typed `DdlColumn`
|
|
1226
|
+
* and lowers it to an ADD COLUMN execute step via the adapter at `toOp` time.
|
|
1227
|
+
*
|
|
1228
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1229
|
+
* planner, never hand-written by migration authors.
|
|
1230
|
+
*/
|
|
1231
|
+
var AddNotNullColumnDirectCall = class extends PostgresOpFactoryCallNode {
|
|
1232
|
+
factoryName = "rawSql";
|
|
1233
|
+
operationClass = "additive";
|
|
1234
|
+
schemaName;
|
|
1235
|
+
tableName;
|
|
1236
|
+
columnName;
|
|
1237
|
+
column;
|
|
1238
|
+
label;
|
|
1239
|
+
constructor(schemaName, tableName, columnName, column) {
|
|
1240
|
+
super();
|
|
1241
|
+
this.schemaName = schemaName;
|
|
1242
|
+
this.tableName = tableName;
|
|
1243
|
+
this.columnName = columnName;
|
|
1244
|
+
this.column = column;
|
|
1245
|
+
this.label = `Add column ${columnName} to ${tableName}`;
|
|
1246
|
+
this.freeze();
|
|
1247
|
+
}
|
|
1248
|
+
async toOp(lowerer) {
|
|
1249
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNotNullColumnDirectCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNotNullColumnDirectCall" } });
|
|
1250
|
+
return addNotNullColumnDirect(this.schemaName, this.tableName, this.column, lowerer);
|
|
1251
|
+
}
|
|
1252
|
+
renderTypeScript() {
|
|
1253
|
+
return `rawSql(${jsonToTsSource({
|
|
1254
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1255
|
+
label: this.label,
|
|
1256
|
+
operationClass: "additive"
|
|
1257
|
+
})})`;
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
/**
|
|
1261
|
+
* Planner-internal call for adding a NOT NULL column (no contract default)
|
|
1262
|
+
* using a temporary default value for non-empty tables. Carries all parameters
|
|
1263
|
+
* needed for `buildAddNotNullColumnWithTemporaryDefaultOperation`; both the
|
|
1264
|
+
* typed ADD COLUMN execute step and the pre/postchecks are lowered via the
|
|
1265
|
+
* adapter at `toOp` time.
|
|
1266
|
+
*
|
|
1267
|
+
* No authored `PostgresMigration` method: this call is only emitted by the
|
|
1268
|
+
* planner, never hand-written by migration authors.
|
|
1269
|
+
*/
|
|
1270
|
+
var AddNotNullColumnWithTempDefaultCall = class extends PostgresOpFactoryCallNode {
|
|
1271
|
+
factoryName = "rawSql";
|
|
1272
|
+
operationClass = "additive";
|
|
1273
|
+
schemaName;
|
|
1274
|
+
tableName;
|
|
1275
|
+
columnName;
|
|
1276
|
+
column;
|
|
1277
|
+
codecHooks;
|
|
1278
|
+
storageTypes;
|
|
1279
|
+
temporaryDefault;
|
|
1280
|
+
label;
|
|
1281
|
+
constructor(options) {
|
|
1282
|
+
super();
|
|
1283
|
+
this.schemaName = options.schemaName;
|
|
1284
|
+
this.tableName = options.tableName;
|
|
1285
|
+
this.columnName = options.columnName;
|
|
1286
|
+
this.column = options.column;
|
|
1287
|
+
this.codecHooks = options.codecHooks;
|
|
1288
|
+
this.storageTypes = options.storageTypes;
|
|
1289
|
+
this.temporaryDefault = options.temporaryDefault;
|
|
1290
|
+
this.label = `Add column ${options.columnName} to ${options.tableName}`;
|
|
1291
|
+
this.freeze();
|
|
1292
|
+
}
|
|
1293
|
+
async toOp(lowerer) {
|
|
1294
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNotNullColumnWithTempDefaultCall.toOp: a lowerer is required on the Postgres planner path (column "${this.columnName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNotNullColumnWithTempDefaultCall" } });
|
|
1295
|
+
return buildAddNotNullColumnWithTemporaryDefaultOperation({
|
|
1296
|
+
schema: this.schemaName,
|
|
1297
|
+
tableName: this.tableName,
|
|
1298
|
+
columnName: this.columnName,
|
|
1299
|
+
column: this.column,
|
|
1300
|
+
codecHooks: this.codecHooks,
|
|
1301
|
+
storageTypes: this.storageTypes,
|
|
1302
|
+
temporaryDefault: this.temporaryDefault,
|
|
1303
|
+
lowerer
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
renderTypeScript() {
|
|
1307
|
+
return `rawSql(${jsonToTsSource({
|
|
1308
|
+
id: `column.${this.tableName}.${this.columnName}`,
|
|
1309
|
+
label: this.label,
|
|
1310
|
+
operationClass: "additive"
|
|
1311
|
+
})})`;
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
function constraintCallOptions(schemaName, tableName, constraintName) {
|
|
1315
|
+
const opts = [];
|
|
1316
|
+
if (schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(schemaName)}`);
|
|
1317
|
+
opts.push(`table: ${jsonToTsSource(tableName)}`);
|
|
1318
|
+
opts.push(`constraint: ${jsonToTsSource(constraintName)}`);
|
|
1319
|
+
return opts.join(", ");
|
|
1320
|
+
}
|
|
1321
|
+
var AddPrimaryKeyCall = class extends PostgresOpFactoryCallNode {
|
|
1322
|
+
factoryName = "addPrimaryKey";
|
|
1323
|
+
operationClass = "additive";
|
|
1324
|
+
schemaName;
|
|
1325
|
+
tableName;
|
|
1326
|
+
constraintName;
|
|
1327
|
+
columns;
|
|
1328
|
+
label;
|
|
1329
|
+
constructor(schemaName, tableName, constraintName, columns) {
|
|
1330
|
+
super();
|
|
1331
|
+
this.schemaName = schemaName;
|
|
1332
|
+
this.tableName = tableName;
|
|
1333
|
+
this.constraintName = constraintName;
|
|
1334
|
+
this.columns = columns;
|
|
1335
|
+
this.label = `Add primary key on "${tableName}"`;
|
|
1336
|
+
this.freeze();
|
|
1337
|
+
}
|
|
1338
|
+
async toOp(lowerer) {
|
|
1339
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddPrimaryKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddPrimaryKeyCall" } });
|
|
1340
|
+
return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
1341
|
+
}
|
|
1342
|
+
renderTypeScript() {
|
|
1343
|
+
return `this.addPrimaryKey({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1344
|
+
}
|
|
1345
|
+
importRequirements() {
|
|
1346
|
+
return [];
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
var AddUniqueCall = class extends PostgresOpFactoryCallNode {
|
|
1350
|
+
factoryName = "addUnique";
|
|
1351
|
+
operationClass = "additive";
|
|
1352
|
+
schemaName;
|
|
1353
|
+
tableName;
|
|
1354
|
+
constraintName;
|
|
1355
|
+
columns;
|
|
1356
|
+
label;
|
|
1357
|
+
constructor(schemaName, tableName, constraintName, columns) {
|
|
1358
|
+
super();
|
|
1359
|
+
this.schemaName = schemaName;
|
|
1360
|
+
this.tableName = tableName;
|
|
1361
|
+
this.constraintName = constraintName;
|
|
1362
|
+
this.columns = columns;
|
|
1363
|
+
this.label = `Add unique constraint on "${tableName}" (${columns.join(", ")})`;
|
|
1364
|
+
this.freeze();
|
|
1365
|
+
}
|
|
1366
|
+
async toOp(lowerer) {
|
|
1367
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddUniqueCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddUniqueCall" } });
|
|
1368
|
+
return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns, lowerer);
|
|
1369
|
+
}
|
|
1370
|
+
renderTypeScript() {
|
|
1371
|
+
return `this.addUnique({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, columns: ${jsonToTsSource(this.columns)} })`;
|
|
1372
|
+
}
|
|
1373
|
+
importRequirements() {
|
|
1374
|
+
return [];
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
var AddForeignKeyCall = class extends PostgresOpFactoryCallNode {
|
|
1378
|
+
factoryName = "addForeignKey";
|
|
1379
|
+
operationClass = "additive";
|
|
1380
|
+
schemaName;
|
|
1381
|
+
tableName;
|
|
1382
|
+
fk;
|
|
1383
|
+
label;
|
|
1384
|
+
constructor(schemaName, tableName, fk) {
|
|
1385
|
+
super();
|
|
1386
|
+
this.schemaName = schemaName;
|
|
1387
|
+
this.tableName = tableName;
|
|
1388
|
+
this.fk = fk;
|
|
1389
|
+
this.label = `Add foreign key "${fk.name}" on "${tableName}"`;
|
|
1390
|
+
this.freeze();
|
|
1391
|
+
}
|
|
1392
|
+
async toOp(lowerer) {
|
|
1393
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddForeignKeyCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.fk.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddForeignKeyCall" } });
|
|
1394
|
+
return addForeignKey(this.schemaName, this.tableName, this.fk, lowerer);
|
|
1395
|
+
}
|
|
1396
|
+
renderTypeScript() {
|
|
1397
|
+
const opts = [];
|
|
1398
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1399
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1400
|
+
opts.push(`foreignKey: ${jsonToTsSource(this.fk)}`);
|
|
1401
|
+
return `this.addForeignKey({ ${opts.join(", ")} })`;
|
|
1402
|
+
}
|
|
1403
|
+
importRequirements() {
|
|
1404
|
+
return [];
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
var DropConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
1408
|
+
factoryName = "dropConstraint";
|
|
1409
|
+
operationClass = "destructive";
|
|
1410
|
+
schemaName;
|
|
1411
|
+
tableName;
|
|
1412
|
+
constraintName;
|
|
1413
|
+
kind;
|
|
1414
|
+
label;
|
|
1415
|
+
constructor(schemaName, tableName, constraintName, kind = "unique") {
|
|
1416
|
+
super();
|
|
1417
|
+
this.schemaName = schemaName;
|
|
1418
|
+
this.tableName = tableName;
|
|
1419
|
+
this.constraintName = constraintName;
|
|
1420
|
+
this.kind = kind;
|
|
1421
|
+
this.label = `Drop constraint "${constraintName}" on "${tableName}"`;
|
|
1422
|
+
this.freeze();
|
|
1423
|
+
}
|
|
1424
|
+
async toOp(lowerer) {
|
|
1425
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropConstraintCall" } });
|
|
1426
|
+
return dropConstraint(this.schemaName, this.tableName, this.constraintName, lowerer, this.kind);
|
|
1427
|
+
}
|
|
1428
|
+
renderTypeScript() {
|
|
1429
|
+
const opts = [constraintCallOptions(this.schemaName, this.tableName, this.constraintName)];
|
|
1430
|
+
if (this.kind !== "unique") opts.push(`kind: ${jsonToTsSource(this.kind)}`);
|
|
1431
|
+
return `this.dropConstraint({ ${opts.join(", ")} })`;
|
|
1432
|
+
}
|
|
1433
|
+
importRequirements() {
|
|
1434
|
+
return [];
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
var AddCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
1438
|
+
factoryName = "addCheckConstraint";
|
|
1439
|
+
operationClass = "additive";
|
|
1440
|
+
schemaName;
|
|
1441
|
+
tableName;
|
|
1442
|
+
constraintName;
|
|
1443
|
+
column;
|
|
1444
|
+
values;
|
|
1445
|
+
label;
|
|
1446
|
+
constructor(schemaName, tableName, constraintName, column, values) {
|
|
1447
|
+
super();
|
|
1448
|
+
this.schemaName = schemaName;
|
|
1449
|
+
this.tableName = tableName;
|
|
1450
|
+
this.constraintName = constraintName;
|
|
1451
|
+
this.column = column;
|
|
1452
|
+
this.values = values;
|
|
1453
|
+
this.label = `Add check constraint "${constraintName}" on "${tableName}"."${column}"`;
|
|
1454
|
+
this.freeze();
|
|
1455
|
+
}
|
|
1456
|
+
async toOp(lowerer) {
|
|
1457
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddCheckConstraintCall" } });
|
|
1458
|
+
return addCheckConstraint(this.schemaName, this.tableName, this.constraintName, this.column, this.values, lowerer);
|
|
1459
|
+
}
|
|
1460
|
+
renderTypeScript() {
|
|
1461
|
+
return `this.addCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)}, column: ${jsonToTsSource(this.column)}, values: ${jsonToTsSource(this.values)} })`;
|
|
1462
|
+
}
|
|
1463
|
+
importRequirements() {
|
|
1464
|
+
return [];
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
var DropCheckConstraintCall = class extends PostgresOpFactoryCallNode {
|
|
1468
|
+
factoryName = "dropCheckConstraint";
|
|
1469
|
+
operationClass = "destructive";
|
|
1470
|
+
schemaName;
|
|
1471
|
+
tableName;
|
|
1472
|
+
constraintName;
|
|
1473
|
+
label;
|
|
1474
|
+
constructor(schemaName, tableName, constraintName) {
|
|
1475
|
+
super();
|
|
1476
|
+
this.schemaName = schemaName;
|
|
1477
|
+
this.tableName = tableName;
|
|
1478
|
+
this.constraintName = constraintName;
|
|
1479
|
+
this.label = `Drop check constraint "${constraintName}" on "${tableName}"`;
|
|
1480
|
+
this.freeze();
|
|
1481
|
+
}
|
|
1482
|
+
async toOp(lowerer) {
|
|
1483
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropCheckConstraintCall.toOp: a lowerer is required on the Postgres planner path (constraint "${this.constraintName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropCheckConstraintCall" } });
|
|
1484
|
+
return dropCheckConstraint(this.schemaName, this.tableName, this.constraintName, lowerer);
|
|
1485
|
+
}
|
|
1486
|
+
renderTypeScript() {
|
|
1487
|
+
return `this.dropCheckConstraint({ ${constraintCallOptions(this.schemaName, this.tableName, this.constraintName)} })`;
|
|
1488
|
+
}
|
|
1489
|
+
importRequirements() {
|
|
1490
|
+
return [];
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
var CreateIndexCall = class extends PostgresOpFactoryCallNode {
|
|
1494
|
+
factoryName = "createIndex";
|
|
1495
|
+
operationClass = "additive";
|
|
1496
|
+
schemaName;
|
|
1497
|
+
tableName;
|
|
1498
|
+
indexName;
|
|
1499
|
+
/** Column tuple when the index is column-based; absent for expression indexes. */
|
|
1500
|
+
columns;
|
|
1501
|
+
/** Opaque whole element list when the index is expression-based. */
|
|
1502
|
+
expression;
|
|
1503
|
+
indexType;
|
|
1504
|
+
options;
|
|
1505
|
+
where;
|
|
1506
|
+
unique;
|
|
1507
|
+
label;
|
|
1508
|
+
constructor(schemaName, tableName, indexName, elements, extras) {
|
|
1509
|
+
super();
|
|
1510
|
+
this.schemaName = schemaName;
|
|
1511
|
+
this.tableName = tableName;
|
|
1512
|
+
this.indexName = indexName;
|
|
1513
|
+
this.columns = "columns" in elements ? elements.columns : void 0;
|
|
1514
|
+
this.expression = "expression" in elements ? elements.expression : void 0;
|
|
1515
|
+
this.indexType = extras?.type;
|
|
1516
|
+
this.options = extras?.options;
|
|
1517
|
+
this.where = extras?.where;
|
|
1518
|
+
this.unique = extras?.unique === true;
|
|
1519
|
+
this.label = `Create index "${indexName}" on "${tableName}"`;
|
|
1520
|
+
this.freeze();
|
|
1521
|
+
}
|
|
1522
|
+
async toOp(lowerer) {
|
|
1523
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateIndexCall" } });
|
|
1524
|
+
const extras = {};
|
|
1525
|
+
if (this.indexType !== void 0) extras.type = this.indexType;
|
|
1526
|
+
if (this.options !== void 0) extras.options = this.options;
|
|
1527
|
+
if (this.where !== void 0) extras.where = this.where;
|
|
1528
|
+
if (this.unique) extras.unique = true;
|
|
1529
|
+
return createIndex(this.schemaName, this.tableName, this.indexName, this.columns !== void 0 ? { columns: this.columns } : { expression: this.expression ?? "" }, lowerer, extras);
|
|
1530
|
+
}
|
|
1531
|
+
renderTypeScript() {
|
|
1532
|
+
const opts = [];
|
|
1533
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1534
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1535
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1536
|
+
if (this.columns !== void 0) opts.push(`columns: ${jsonToTsSource(this.columns)}`);
|
|
1537
|
+
else opts.push(`expression: ${jsonToTsSource(this.expression ?? "")}`);
|
|
1538
|
+
if (this.indexType !== void 0 || this.options !== void 0 || this.where !== void 0 || this.unique) {
|
|
1539
|
+
const extrasParts = [];
|
|
1540
|
+
if (this.indexType !== void 0) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);
|
|
1541
|
+
if (this.options !== void 0) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);
|
|
1542
|
+
if (this.where !== void 0) extrasParts.push(`where: ${jsonToTsSource(this.where)}`);
|
|
1543
|
+
if (this.unique) extrasParts.push("unique: true");
|
|
1544
|
+
opts.push(`extras: { ${extrasParts.join(", ")} }`);
|
|
1545
|
+
}
|
|
1546
|
+
return `this.createIndex({ ${opts.join(", ")} })`;
|
|
1547
|
+
}
|
|
1548
|
+
importRequirements() {
|
|
1549
|
+
return [];
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
var RenameIndexCall = class extends PostgresOpFactoryCallNode {
|
|
1553
|
+
factoryName = "renameIndex";
|
|
1554
|
+
operationClass = "widening";
|
|
1555
|
+
schemaName;
|
|
1556
|
+
tableName;
|
|
1557
|
+
oldIndexName;
|
|
1558
|
+
newIndexName;
|
|
1559
|
+
label;
|
|
1560
|
+
constructor(schemaName, tableName, oldIndexName, newIndexName) {
|
|
1561
|
+
super();
|
|
1562
|
+
this.schemaName = schemaName;
|
|
1563
|
+
this.tableName = tableName;
|
|
1564
|
+
this.oldIndexName = oldIndexName;
|
|
1565
|
+
this.newIndexName = newIndexName;
|
|
1566
|
+
this.label = `Rename index "${oldIndexName}" to "${newIndexName}" on "${tableName}"`;
|
|
1567
|
+
this.freeze();
|
|
1568
|
+
}
|
|
1569
|
+
async toOp(lowerer) {
|
|
1570
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `RenameIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.oldIndexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "RenameIndexCall" } });
|
|
1571
|
+
return renameIndex(this.schemaName, this.tableName, this.oldIndexName, this.newIndexName, lowerer);
|
|
1572
|
+
}
|
|
1573
|
+
renderTypeScript() {
|
|
1574
|
+
const opts = [];
|
|
1575
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1576
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1577
|
+
opts.push(`from: ${jsonToTsSource(this.oldIndexName)}`);
|
|
1578
|
+
opts.push(`to: ${jsonToTsSource(this.newIndexName)}`);
|
|
1579
|
+
return `this.renameIndex({ ${opts.join(", ")} })`;
|
|
1580
|
+
}
|
|
1581
|
+
importRequirements() {
|
|
1582
|
+
return [];
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
var DropIndexCall = class extends PostgresOpFactoryCallNode {
|
|
1586
|
+
factoryName = "dropIndex";
|
|
1587
|
+
operationClass = "destructive";
|
|
1588
|
+
schemaName;
|
|
1589
|
+
tableName;
|
|
1590
|
+
indexName;
|
|
1591
|
+
label;
|
|
1592
|
+
constructor(schemaName, tableName, indexName) {
|
|
1593
|
+
super();
|
|
1594
|
+
this.schemaName = schemaName;
|
|
1595
|
+
this.tableName = tableName;
|
|
1596
|
+
this.indexName = indexName;
|
|
1597
|
+
this.label = `Drop index "${indexName}"`;
|
|
1598
|
+
this.freeze();
|
|
1599
|
+
}
|
|
1600
|
+
async toOp(lowerer) {
|
|
1601
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropIndexCall.toOp: a lowerer is required on the Postgres planner path (index "${this.indexName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropIndexCall" } });
|
|
1602
|
+
return dropIndex(this.schemaName, this.tableName, this.indexName, lowerer);
|
|
1603
|
+
}
|
|
1604
|
+
renderTypeScript() {
|
|
1605
|
+
const opts = [];
|
|
1606
|
+
if (this.schemaName !== UNBOUND_NAMESPACE_ID) opts.push(`schema: ${jsonToTsSource(this.schemaName)}`);
|
|
1607
|
+
opts.push(`table: ${jsonToTsSource(this.tableName)}`);
|
|
1608
|
+
opts.push(`index: ${jsonToTsSource(this.indexName)}`);
|
|
1609
|
+
return `this.dropIndex({ ${opts.join(", ")} })`;
|
|
1610
|
+
}
|
|
1611
|
+
importRequirements() {
|
|
1612
|
+
return [];
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
/**
|
|
1616
|
+
* Laundered pre-built operation.
|
|
1617
|
+
*
|
|
1618
|
+
* Wraps an already-materialized `SqlMigrationPlanOperation` — typically one
|
|
1619
|
+
* produced by a SQL-family method or a codec control hook — so the planner
|
|
1620
|
+
* can carry it alongside IR nodes without reverse-engineering it into a
|
|
1621
|
+
* structured call class. Doubles as the user-facing escape hatch for raw
|
|
1622
|
+
* migrations: authors can pass a full op shape to `rawSql({...})`.
|
|
1623
|
+
*
|
|
1624
|
+
* `toOp()` returns the stored op unchanged. `renderTypeScript()` emits
|
|
1625
|
+
* `rawSql({...})` with the op serialized as a JSON literal — round-tripping
|
|
1626
|
+
* requires every field on the op to be JSON-serializable (no closures).
|
|
1627
|
+
*/
|
|
1628
|
+
var RawSqlCall = class extends PostgresOpFactoryCallNode {
|
|
1629
|
+
factoryName = "rawSql";
|
|
1630
|
+
operationClass;
|
|
1631
|
+
label;
|
|
1632
|
+
op;
|
|
1633
|
+
constructor(op) {
|
|
1634
|
+
super();
|
|
1635
|
+
this.op = op;
|
|
1636
|
+
this.label = op.label;
|
|
1637
|
+
this.operationClass = op.operationClass;
|
|
1638
|
+
this.freeze();
|
|
1639
|
+
}
|
|
1640
|
+
toOp() {
|
|
1641
|
+
return this.op;
|
|
1642
|
+
}
|
|
1643
|
+
renderTypeScript() {
|
|
1644
|
+
return `rawSql(${jsonToTsSource(this.op)})`;
|
|
1645
|
+
}
|
|
1646
|
+
};
|
|
1647
|
+
var CreateExtensionCall = class extends PostgresOpFactoryCallNode {
|
|
1648
|
+
factoryName = "createExtension";
|
|
1649
|
+
operationClass = "additive";
|
|
1650
|
+
extensionName;
|
|
1651
|
+
label;
|
|
1652
|
+
constructor(extensionName) {
|
|
1653
|
+
super();
|
|
1654
|
+
this.extensionName = extensionName;
|
|
1655
|
+
this.label = `Create extension "${extensionName}"`;
|
|
1656
|
+
this.freeze();
|
|
1657
|
+
}
|
|
1658
|
+
toOp() {
|
|
1659
|
+
return createExtension(this.extensionName);
|
|
1660
|
+
}
|
|
1661
|
+
renderTypeScript() {
|
|
1662
|
+
return `createExtension(${jsonToTsSource(this.extensionName)})`;
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
var CreateSchemaCall = class extends PostgresOpFactoryCallNode {
|
|
1666
|
+
factoryName = "createSchema";
|
|
1667
|
+
operationClass = "additive";
|
|
1668
|
+
schemaName;
|
|
1669
|
+
label;
|
|
1670
|
+
constructor(schemaName) {
|
|
1671
|
+
super();
|
|
1672
|
+
this.schemaName = schemaName;
|
|
1673
|
+
this.label = `Create schema "${schemaName}"`;
|
|
1674
|
+
this.freeze();
|
|
1675
|
+
}
|
|
1676
|
+
async toOp(lowerer) {
|
|
1677
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateSchemaCall" } });
|
|
1678
|
+
const ddlNode = createSchema({
|
|
1679
|
+
schema: this.schemaName,
|
|
1680
|
+
ifNotExists: true
|
|
1681
|
+
});
|
|
1682
|
+
const statement = await lowerer.lowerToExecuteRequest(ddlNode);
|
|
1683
|
+
const schemaName = this.schemaName;
|
|
1684
|
+
return {
|
|
1685
|
+
id: `schema.${schemaName}`,
|
|
1686
|
+
label: `Create schema "${schemaName}"`,
|
|
1687
|
+
operationClass: "additive",
|
|
1688
|
+
target: { id: "postgres" },
|
|
1689
|
+
precheck: [],
|
|
1690
|
+
execute: [{
|
|
1691
|
+
description: `Create schema "${schemaName}"`,
|
|
1692
|
+
sql: statement.sql,
|
|
1693
|
+
params: statement.params ?? []
|
|
1694
|
+
}],
|
|
1695
|
+
postcheck: []
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
renderTypeScript() {
|
|
1699
|
+
return `this.createSchema({ schema: ${jsonToTsSource(this.schemaName)} })`;
|
|
1700
|
+
}
|
|
1701
|
+
importRequirements() {
|
|
1702
|
+
return [];
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
var CreateNativeEnumTypeCall = class extends PostgresOpFactoryCallNode {
|
|
1706
|
+
factoryName = "createNativeEnumType";
|
|
1707
|
+
operationClass = "additive";
|
|
1708
|
+
schemaName;
|
|
1709
|
+
typeName;
|
|
1710
|
+
members;
|
|
1711
|
+
label;
|
|
1712
|
+
constructor(schemaName, typeName, members) {
|
|
1713
|
+
super();
|
|
1714
|
+
this.schemaName = schemaName;
|
|
1715
|
+
this.typeName = typeName;
|
|
1716
|
+
this.members = Object.freeze([...members]);
|
|
1717
|
+
this.label = `Create enum type "${typeName}"`;
|
|
1718
|
+
this.freeze();
|
|
1719
|
+
}
|
|
1720
|
+
async toOp(lowerer) {
|
|
1721
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreateNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreateNativeEnumTypeCall" } });
|
|
1722
|
+
return createNativeEnumType(this.schemaName, this.typeName, this.members, lowerer);
|
|
1723
|
+
}
|
|
1724
|
+
renderTypeScript() {
|
|
1725
|
+
return `this.createNativeEnumType({ ${[
|
|
1726
|
+
`schema: ${jsonToTsSource(this.schemaName)}`,
|
|
1727
|
+
`typeName: ${jsonToTsSource(this.typeName)}`,
|
|
1728
|
+
`members: ${jsonToTsSource(this.members)}`
|
|
1729
|
+
].join(", ")} })`;
|
|
1730
|
+
}
|
|
1731
|
+
importRequirements() {
|
|
1732
|
+
return [];
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
var DropNativeEnumTypeCall = class extends PostgresOpFactoryCallNode {
|
|
1736
|
+
factoryName = "dropNativeEnumType";
|
|
1737
|
+
operationClass = "destructive";
|
|
1738
|
+
schemaName;
|
|
1739
|
+
typeName;
|
|
1740
|
+
label;
|
|
1741
|
+
constructor(schemaName, typeName) {
|
|
1742
|
+
super();
|
|
1743
|
+
this.schemaName = schemaName;
|
|
1744
|
+
this.typeName = typeName;
|
|
1745
|
+
this.label = `Drop enum type "${typeName}"`;
|
|
1746
|
+
this.freeze();
|
|
1747
|
+
}
|
|
1748
|
+
async toOp(lowerer) {
|
|
1749
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropNativeEnumTypeCall.toOp: a DDL lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropNativeEnumTypeCall" } });
|
|
1750
|
+
return dropNativeEnumType(this.schemaName, this.typeName, lowerer);
|
|
1751
|
+
}
|
|
1752
|
+
renderTypeScript() {
|
|
1753
|
+
return `this.dropNativeEnumType({ ${[`schema: ${jsonToTsSource(this.schemaName)}`, `typeName: ${jsonToTsSource(this.typeName)}`].join(", ")} })`;
|
|
1754
|
+
}
|
|
1755
|
+
importRequirements() {
|
|
1756
|
+
return [];
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
/** Schema-qualified, quoted enum type name — unqualified when `schemaName` is the unbound sentinel, matching `boundSchema`'s DDL-node convention. */
|
|
1760
|
+
function qualifiedNativeEnumTypeName(schemaName, typeName) {
|
|
1761
|
+
const bound = boundSchema(schemaName);
|
|
1762
|
+
return quoteQualifiedName(bound === void 0 ? typeName : `${bound}.${typeName}`);
|
|
1763
|
+
}
|
|
1764
|
+
const ADD_VALUE_TRANSACTION_CAVEAT = "A newly added enum value cannot be used until the transaction that adds it commits, so a migration that both appends a value and uses it in the same step will fail at apply.";
|
|
1765
|
+
/**
|
|
1766
|
+
* `ALTER TYPE <qualified> ADD VALUE '<value>'` for a suffix-appended member on
|
|
1767
|
+
* a managed native enum. Built directly as SQL text (qualified via
|
|
1768
|
+
* `quoteQualifiedName`, the value escaped via `escapeLiteral`) rather than a
|
|
1769
|
+
* typed DDL node — mirrors how `enableRowLevelSecurity` renders its execute
|
|
1770
|
+
* step, since no DDL-AST node exists for this statement. Prechecks/postchecks
|
|
1771
|
+
* are still typed catalog queries lowered through the control adapter.
|
|
1772
|
+
* `validateEnumValueLength` runs at construction, so an over-length value
|
|
1773
|
+
* fails before planning produces a call.
|
|
1774
|
+
*/
|
|
1775
|
+
var AddNativeEnumValueCall = class extends PostgresOpFactoryCallNode {
|
|
1776
|
+
factoryName = "addNativeEnumValue";
|
|
1777
|
+
operationClass = "additive";
|
|
1778
|
+
schemaName;
|
|
1779
|
+
typeName;
|
|
1780
|
+
value;
|
|
1781
|
+
label;
|
|
1782
|
+
summary;
|
|
1783
|
+
constructor(schemaName, typeName, value) {
|
|
1784
|
+
super();
|
|
1785
|
+
validateEnumValueLength(value, typeName);
|
|
1786
|
+
this.schemaName = schemaName;
|
|
1787
|
+
this.typeName = typeName;
|
|
1788
|
+
this.value = value;
|
|
1789
|
+
this.label = `Add value "${value}" to enum type "${typeName}"`;
|
|
1790
|
+
this.summary = `Adds value "${value}" to enum type "${typeName}". ${ADD_VALUE_TRANSACTION_CAVEAT}`;
|
|
1791
|
+
this.freeze();
|
|
1792
|
+
}
|
|
1793
|
+
async toOp(lowerer) {
|
|
1794
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `AddNativeEnumValueCall.toOp: a lowerer is required on the Postgres planner path (type "${this.typeName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "AddNativeEnumValueCall" } });
|
|
1795
|
+
const { schemaName, typeName, value } = this;
|
|
1796
|
+
const typeChecks = nativeEnumTypeExistsAst(schemaName, typeName);
|
|
1797
|
+
const valueChecks = nativeEnumValueExistsAst({
|
|
1798
|
+
schema: schemaName,
|
|
1799
|
+
typeName,
|
|
1800
|
+
value
|
|
1801
|
+
});
|
|
1802
|
+
const typePresent = await lowerer.lowerToExecuteRequest(typeChecks.typePresent());
|
|
1803
|
+
const valueAbsent = await lowerer.lowerToExecuteRequest(valueChecks.valueAbsent());
|
|
1804
|
+
const valuePresent = await lowerer.lowerToExecuteRequest(valueChecks.valuePresent());
|
|
1805
|
+
const qualifiedType = qualifiedNativeEnumTypeName(schemaName, typeName);
|
|
1806
|
+
return {
|
|
1807
|
+
id: `addNativeEnumValue.${typeName}.${value}`,
|
|
1808
|
+
label: this.label,
|
|
1809
|
+
summary: this.summary,
|
|
1810
|
+
operationClass: "additive",
|
|
1811
|
+
target: targetDetails("type", typeName, schemaName),
|
|
1812
|
+
precheck: [step(`ensure enum type "${typeName}" exists`, typePresent.sql, typePresent.params), step(`ensure value "${value}" is absent from enum type "${typeName}"`, valueAbsent.sql, valueAbsent.params)],
|
|
1813
|
+
execute: [step(`add value "${value}" to enum type "${typeName}"`, `ALTER TYPE ${qualifiedType} ADD VALUE '${escapeLiteral(value)}'`)],
|
|
1814
|
+
postcheck: [step(`verify value "${value}" exists on enum type "${typeName}"`, valuePresent.sql, valuePresent.params)]
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
renderTypeScript() {
|
|
1818
|
+
return `this.addNativeEnumValue({ ${[
|
|
1819
|
+
`schema: ${jsonToTsSource(this.schemaName)}`,
|
|
1820
|
+
`typeName: ${jsonToTsSource(this.typeName)}`,
|
|
1821
|
+
`value: ${jsonToTsSource(this.value)}`
|
|
1822
|
+
].join(", ")} })`;
|
|
1823
|
+
}
|
|
1824
|
+
importRequirements() {
|
|
1825
|
+
return [];
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
/**
|
|
1829
|
+
* A planner-generated data-transform stub. `checkSlot` and `runSlot` name
|
|
1830
|
+
* the unfilled authoring slots that the rendered `migration.ts` will expose
|
|
1831
|
+
* to the user via `placeholder("…")` calls. `toOp()` always throws
|
|
1832
|
+
* `MIGRATION.UNFILLED_PLACEHOLDER`: the planner cannot lower a stubbed transform to a runtime
|
|
1833
|
+
* op — the user must fill the rendered `migration.ts` and re-emit.
|
|
1834
|
+
*/
|
|
1835
|
+
var DataTransformCall = class extends PostgresOpFactoryCallNode {
|
|
1836
|
+
factoryName = "dataTransform";
|
|
1837
|
+
operationClass;
|
|
1838
|
+
label;
|
|
1839
|
+
checkSlot;
|
|
1840
|
+
runSlot;
|
|
1841
|
+
constructor(label, checkSlot, runSlot, operationClass = "data") {
|
|
1842
|
+
super();
|
|
1843
|
+
this.label = label;
|
|
1844
|
+
this.checkSlot = checkSlot;
|
|
1845
|
+
this.runSlot = runSlot;
|
|
1846
|
+
this.operationClass = operationClass;
|
|
1847
|
+
this.freeze();
|
|
1848
|
+
}
|
|
1849
|
+
toOp() {
|
|
1850
|
+
throw errorUnfilledPlaceholder(this.label);
|
|
1851
|
+
}
|
|
1852
|
+
renderTypeScript() {
|
|
1853
|
+
return [
|
|
1854
|
+
`this.dataTransform(endContract, ${jsonToTsSource(this.label)}, {`,
|
|
1855
|
+
` check: () => placeholder(${jsonToTsSource(this.checkSlot)}),`,
|
|
1856
|
+
` run: () => placeholder(${jsonToTsSource(this.runSlot)}),`,
|
|
1857
|
+
"})"
|
|
1858
|
+
].join("\n");
|
|
1859
|
+
}
|
|
1860
|
+
importRequirements() {
|
|
1861
|
+
return [{
|
|
1862
|
+
moduleSpecifier: POSTGRES_MIGRATION_FACADE,
|
|
1863
|
+
symbol: "placeholder"
|
|
1864
|
+
}];
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
var CreatePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1868
|
+
factoryName = "createRlsPolicy";
|
|
1869
|
+
operationClass = "additive";
|
|
1870
|
+
schemaName;
|
|
1871
|
+
tableName;
|
|
1872
|
+
policy;
|
|
1873
|
+
label;
|
|
1874
|
+
constructor(schemaName, tableName, policy) {
|
|
1875
|
+
super();
|
|
1876
|
+
this.schemaName = schemaName;
|
|
1877
|
+
this.tableName = tableName;
|
|
1878
|
+
this.policy = policy;
|
|
1879
|
+
this.label = `Create RLS policy "${policy.name}" on "${tableName}"`;
|
|
1880
|
+
this.freeze();
|
|
1881
|
+
}
|
|
1882
|
+
async toOp(lowerer) {
|
|
1883
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `CreatePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policy.name}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "CreatePostgresRlsPolicyCall" } });
|
|
1884
|
+
return createRlsPolicy(this.schemaName, this.tableName, this.policy, lowerer);
|
|
1885
|
+
}
|
|
1886
|
+
renderTypeScript() {
|
|
1887
|
+
const p = this.policy;
|
|
1888
|
+
const input = {
|
|
1889
|
+
naming: namingOf(p.name, p.prefix),
|
|
1890
|
+
tableName: p.tableName,
|
|
1891
|
+
namespaceId: p.namespaceId,
|
|
1892
|
+
operation: p.operation,
|
|
1893
|
+
roles: p.roles,
|
|
1894
|
+
...ifDefined("using", p.using),
|
|
1895
|
+
...ifDefined("withCheck", p.withCheck),
|
|
1896
|
+
permissive: p.permissive
|
|
1897
|
+
};
|
|
1898
|
+
return `this.createRlsPolicy({ schema: ${jsonToTsSource(this.schemaName)}, table: ${jsonToTsSource(this.tableName)}, policy: ${jsonToTsSource(input)} })`;
|
|
1899
|
+
}
|
|
1900
|
+
importRequirements() {
|
|
1901
|
+
return [];
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
var DropPostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1905
|
+
factoryName = "dropRlsPolicy";
|
|
1906
|
+
operationClass = "destructive";
|
|
1907
|
+
schemaName;
|
|
1908
|
+
tableName;
|
|
1909
|
+
policyName;
|
|
1910
|
+
label;
|
|
1911
|
+
constructor(schemaName, tableName, policyName) {
|
|
1912
|
+
super();
|
|
1913
|
+
this.schemaName = schemaName;
|
|
1914
|
+
this.tableName = tableName;
|
|
1915
|
+
this.policyName = policyName;
|
|
1916
|
+
this.label = `Drop RLS policy "${policyName}" on "${tableName}"`;
|
|
1917
|
+
this.freeze();
|
|
1918
|
+
}
|
|
1919
|
+
async toOp(lowerer) {
|
|
1920
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DropPostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.policyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DropPostgresRlsPolicyCall" } });
|
|
1921
|
+
return dropRlsPolicy(this.schemaName, this.tableName, this.policyName, lowerer);
|
|
1922
|
+
}
|
|
1923
|
+
renderTypeScript() {
|
|
1924
|
+
return `this.dropRlsPolicy({ schema: ${jsonToTsSource(this.schemaName)}, table: ${jsonToTsSource(this.tableName)}, policy: ${jsonToTsSource(this.policyName)} })`;
|
|
1925
|
+
}
|
|
1926
|
+
importRequirements() {
|
|
1927
|
+
return [];
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
var EnableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
|
|
1931
|
+
factoryName = "enableRowLevelSecurity";
|
|
1932
|
+
operationClass = "additive";
|
|
1933
|
+
schemaName;
|
|
1934
|
+
tableName;
|
|
1935
|
+
label;
|
|
1936
|
+
constructor(schemaName, tableName) {
|
|
1937
|
+
super();
|
|
1938
|
+
this.schemaName = schemaName;
|
|
1939
|
+
this.tableName = tableName;
|
|
1940
|
+
this.label = `Enable row-level security on "${tableName}"`;
|
|
1941
|
+
this.freeze();
|
|
1942
|
+
}
|
|
1943
|
+
async toOp(lowerer) {
|
|
1944
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `EnableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "EnableRowLevelSecurityCall" } });
|
|
1945
|
+
return enableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
|
|
1946
|
+
}
|
|
1947
|
+
renderTypeScript() {
|
|
1948
|
+
return `this.enableRowLevelSecurity({ schema: ${jsonToTsSource(this.schemaName)}, table: ${jsonToTsSource(this.tableName)} })`;
|
|
1949
|
+
}
|
|
1950
|
+
importRequirements() {
|
|
1951
|
+
return [];
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
var DisableRowLevelSecurityCall = class extends PostgresOpFactoryCallNode {
|
|
1955
|
+
factoryName = "disableRowLevelSecurity";
|
|
1956
|
+
operationClass = "destructive";
|
|
1957
|
+
schemaName;
|
|
1958
|
+
tableName;
|
|
1959
|
+
label;
|
|
1960
|
+
constructor(schemaName, tableName) {
|
|
1961
|
+
super();
|
|
1962
|
+
this.schemaName = schemaName;
|
|
1963
|
+
this.tableName = tableName;
|
|
1964
|
+
this.label = `Disable row-level security on "${tableName}"`;
|
|
1965
|
+
this.freeze();
|
|
1966
|
+
}
|
|
1967
|
+
async toOp(lowerer) {
|
|
1968
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `DisableRowLevelSecurityCall.toOp: a lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "DisableRowLevelSecurityCall" } });
|
|
1969
|
+
return disableRowLevelSecurity(this.schemaName, this.tableName, lowerer);
|
|
1970
|
+
}
|
|
1971
|
+
renderTypeScript() {
|
|
1972
|
+
return `this.disableRowLevelSecurity({ schema: ${jsonToTsSource(this.schemaName)}, table: ${jsonToTsSource(this.tableName)} })`;
|
|
1973
|
+
}
|
|
1974
|
+
importRequirements() {
|
|
1975
|
+
return [];
|
|
1976
|
+
}
|
|
1977
|
+
};
|
|
1978
|
+
var RenamePostgresRlsPolicyCall = class extends PostgresOpFactoryCallNode {
|
|
1979
|
+
factoryName = "renameRlsPolicy";
|
|
1980
|
+
operationClass = "widening";
|
|
1981
|
+
schemaName;
|
|
1982
|
+
tableName;
|
|
1983
|
+
oldPolicyName;
|
|
1984
|
+
newPolicyName;
|
|
1985
|
+
label;
|
|
1986
|
+
constructor(schemaName, tableName, oldPolicyName, newPolicyName) {
|
|
1987
|
+
super();
|
|
1988
|
+
this.schemaName = schemaName;
|
|
1989
|
+
this.tableName = tableName;
|
|
1990
|
+
this.oldPolicyName = oldPolicyName;
|
|
1991
|
+
this.newPolicyName = newPolicyName;
|
|
1992
|
+
this.label = `Rename RLS policy "${oldPolicyName}" to "${newPolicyName}" on "${tableName}"`;
|
|
1993
|
+
this.freeze();
|
|
1994
|
+
}
|
|
1995
|
+
async toOp(lowerer) {
|
|
1996
|
+
if (lowerer === void 0) throw postgresError("MIGRATION.POSTGRES_CONTROL_STACK_MISSING", `RenamePostgresRlsPolicyCall.toOp: a lowerer is required on the Postgres planner path (policy "${this.oldPolicyName}" on table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`, { meta: { factory: "RenamePostgresRlsPolicyCall" } });
|
|
1997
|
+
return renameRlsPolicy(this.schemaName, this.tableName, this.oldPolicyName, this.newPolicyName, lowerer);
|
|
1998
|
+
}
|
|
1999
|
+
renderTypeScript() {
|
|
2000
|
+
return `this.renameRlsPolicy({ schema: ${jsonToTsSource(this.schemaName)}, table: ${jsonToTsSource(this.tableName)}, from: ${jsonToTsSource(this.oldPolicyName)}, to: ${jsonToTsSource(this.newPolicyName)} })`;
|
|
2001
|
+
}
|
|
2002
|
+
importRequirements() {
|
|
2003
|
+
return [];
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
//#endregion
|
|
2007
|
+
export { RenamePostgresRlsPolicyCall as A, DropNativeEnumTypeCall as C, EnableRowLevelSecurityCall as D, DropTableCall as E, installExtension as F, postgresDefaultToDdlColumnDefault as I, SetNotNullCall as M, buildTargetDetails as N, RawSqlCall as O, createExtension as P, DropIndexCall as S, DropPostgresRlsPolicyCall as T, DisableRowLevelSecurityCall as _, AddNotNullColumnDirectCall as a, DropConstraintCall as b, AddUniqueCall as c, CreateIndexCall as d, CreateNativeEnumTypeCall as f, DataTransformCall as g, CreateTableCall as h, AddNativeEnumValueCall as i, SetDefaultCall as j, RenameIndexCall as k, AlterColumnTypeCall as l, CreateSchemaCall as m, AddColumnCall as n, AddNotNullColumnWithTempDefaultCall as o, CreatePostgresRlsPolicyCall as p, AddForeignKeyCall as r, AddPrimaryKeyCall as s, AddCheckConstraintCall as t, CreateExtensionCall as u, DropCheckConstraintCall as v, DropNotNullCall as w, DropDefaultCall as x, DropColumnCall as y };
|
|
2008
|
+
|
|
2009
|
+
//# sourceMappingURL=op-factory-call-DifL68KT-Bo6pxs-R.mjs.map
|