@prisma/orm-toolchain 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 +28 -0
- package/dist/aggregate-B4mhR4Sk.mjs +1012 -0
- package/dist/aggregate-B4mhR4Sk.mjs.map +1 -0
- package/dist/aggregate-BflrjWPO.d.mts +803 -0
- package/dist/aggregate-BflrjWPO.d.mts.map +1 -0
- package/dist/bin__prisma-next.mjs +800 -0
- package/dist/bin__prisma-next.mjs.map +1 -0
- package/dist/cli-telemetry.d.mts +367 -0
- package/dist/cli-telemetry.d.mts.map +1 -0
- package/dist/cli-telemetry.mjs +48 -0
- package/dist/cli-telemetry.mjs.map +1 -0
- package/dist/cli-telemetry__sender.d.mts +1 -0
- package/dist/cli-telemetry__sender.mjs +1 -0
- package/dist/cli.d.mts +31 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +180 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/cli__commands__contract-emit.d.mts +2 -0
- package/dist/cli__commands__contract-emit.mjs +2 -0
- package/dist/cli__commands__contract-infer.d.mts +7 -0
- package/dist/cli__commands__contract-infer.d.mts.map +1 -0
- package/dist/cli__commands__contract-infer.mjs +2 -0
- package/dist/cli__commands__db-init.d.mts +7 -0
- package/dist/cli__commands__db-init.d.mts.map +1 -0
- package/dist/cli__commands__db-init.mjs +2 -0
- package/dist/cli__commands__db-schema.d.mts +7 -0
- package/dist/cli__commands__db-schema.d.mts.map +1 -0
- package/dist/cli__commands__db-schema.mjs +2 -0
- package/dist/cli__commands__db-sign.d.mts +7 -0
- package/dist/cli__commands__db-sign.d.mts.map +1 -0
- package/dist/cli__commands__db-sign.mjs +2 -0
- package/dist/cli__commands__db-update.d.mts +7 -0
- package/dist/cli__commands__db-update.d.mts.map +1 -0
- package/dist/cli__commands__db-update.mjs +2 -0
- package/dist/cli__commands__db-verify.d.mts +7 -0
- package/dist/cli__commands__db-verify.d.mts.map +1 -0
- package/dist/cli__commands__db-verify.mjs +2 -0
- package/dist/cli__commands__migrate.d.mts +66 -0
- package/dist/cli__commands__migrate.d.mts.map +1 -0
- package/dist/cli__commands__migrate.mjs +2 -0
- package/dist/cli__commands__migration-check.d.mts +64 -0
- package/dist/cli__commands__migration-check.d.mts.map +1 -0
- package/dist/cli__commands__migration-check.mjs +3 -0
- package/dist/cli__commands__migration-graph.d.mts +36 -0
- package/dist/cli__commands__migration-graph.d.mts.map +1 -0
- package/dist/cli__commands__migration-graph.mjs +2 -0
- package/dist/cli__commands__migration-list.d.mts +79 -0
- package/dist/cli__commands__migration-list.d.mts.map +1 -0
- package/dist/cli__commands__migration-list.mjs +2 -0
- package/dist/cli__commands__migration-log.d.mts +20 -0
- package/dist/cli__commands__migration-log.d.mts.map +1 -0
- package/dist/cli__commands__migration-log.mjs +2 -0
- package/dist/cli__commands__migration-new.d.mts +7 -0
- package/dist/cli__commands__migration-new.d.mts.map +1 -0
- package/dist/cli__commands__migration-new.mjs +2 -0
- package/dist/cli__commands__migration-plan.d.mts +79 -0
- package/dist/cli__commands__migration-plan.d.mts.map +1 -0
- package/dist/cli__commands__migration-plan.mjs +2 -0
- package/dist/cli__commands__migration-show.d.mts +27 -0
- package/dist/cli__commands__migration-show.d.mts.map +1 -0
- package/dist/cli__commands__migration-show.mjs +2 -0
- package/dist/cli__commands__migration-status.d.mts +55 -0
- package/dist/cli__commands__migration-status.d.mts.map +1 -0
- package/dist/cli__commands__migration-status.mjs +3 -0
- package/dist/cli__commands__ref.d.mts +34 -0
- package/dist/cli__commands__ref.d.mts.map +1 -0
- package/dist/cli__commands__ref.mjs +2 -0
- package/dist/cli__commands__telemetry.d.mts +7 -0
- package/dist/cli__commands__telemetry.d.mts.map +1 -0
- package/dist/cli__commands__telemetry.mjs +2 -0
- package/dist/cli__config-types.d.mts +2 -0
- package/dist/cli__config-types.mjs +2 -0
- package/dist/cli__control-api.d.mts +141 -0
- package/dist/cli__control-api.d.mts.map +1 -0
- package/dist/cli__control-api.mjs +4 -0
- package/dist/cli__init-output.d.mts +37 -0
- package/dist/cli__init-output.d.mts.map +1 -0
- package/dist/cli__init-output.mjs +2 -0
- package/dist/cli__migration-cli.d.mts +79 -0
- package/dist/cli__migration-cli.d.mts.map +1 -0
- package/dist/cli__migration-cli.mjs +407 -0
- package/dist/cli__migration-cli.mjs.map +1 -0
- package/dist/client-75qrAPqf-DZAVUxFa.mjs +1606 -0
- package/dist/client-75qrAPqf-DZAVUxFa.mjs.map +1 -0
- package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs +1671 -0
- package/dist/command-helpers-CAoXqAY9-DWUBcTXM.mjs.map +1 -0
- package/dist/config-loader.d.mts +18 -0
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +2 -0
- package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs +10 -0
- package/dist/constants-CM-w38DQ-Cz_EXbOc.mjs.map +1 -0
- package/dist/constants-Dkcn8Qu4.d.mts +10 -0
- package/dist/constants-Dkcn8Qu4.d.mts.map +1 -0
- package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs +36 -0
- package/dist/contract-at-errors-BX7w-p19-SxA8eaV2.mjs.map +1 -0
- package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs +148 -0
- package/dist/contract-emit-0hSjbuxp-BBOKldTZ.mjs.map +1 -0
- package/dist/contract-emit-B65_UiFn.d.mts +7 -0
- package/dist/contract-emit-B65_UiFn.d.mts.map +1 -0
- package/dist/contract-emit-B6odMoem-CK3diBPk.mjs +359 -0
- package/dist/contract-emit-B6odMoem-CK3diBPk.mjs.map +1 -0
- package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs +56 -0
- package/dist/contract-enrichment-DrMvvY2A-DxNGeF4d.mjs.map +1 -0
- package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs +73 -0
- package/dist/contract-infer-BnkqpftN-DVM2eKJ3.mjs.map +1 -0
- package/dist/contract-snapshot-store-CbqynbtE.d.mts +28 -0
- package/dist/contract-snapshot-store-CbqynbtE.d.mts.map +1 -0
- package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs +118 -0
- package/dist/contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs.map +1 -0
- package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs +302 -0
- package/dist/contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs.map +1 -0
- package/dist/db-init-Vbkb_TKZ.mjs +153 -0
- package/dist/db-init-Vbkb_TKZ.mjs.map +1 -0
- package/dist/db-schema-ClQCu3xY.mjs +47 -0
- package/dist/db-schema-ClQCu3xY.mjs.map +1 -0
- package/dist/db-sign-jjXDgQ1u.mjs +175 -0
- package/dist/db-sign-jjXDgQ1u.mjs.map +1 -0
- package/dist/db-update-BQlrqtDD.mjs +183 -0
- package/dist/db-update-BQlrqtDD.mjs.map +1 -0
- package/dist/db-verify-CKPsRFrj-3udprZQD.mjs +396 -0
- package/dist/db-verify-CKPsRFrj-3udprZQD.mjs.map +1 -0
- package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs +334 -0
- package/dist/domain-type-generation-DAn9y5d2-BgoT5uKI.mjs.map +1 -0
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts +63 -0
- package/dist/domain-type-generation-PkAb39ob-Ct8AGqow.d.mts.map +1 -0
- package/dist/emitter.d.mts +75 -0
- package/dist/emitter.d.mts.map +1 -0
- package/dist/emitter.mjs +3 -0
- package/dist/emitter__domain-type-generation.d.mts +2 -0
- package/dist/emitter__domain-type-generation.mjs +2 -0
- package/dist/emitter__type-expression-safety.d.mts +6 -0
- package/dist/emitter__type-expression-safety.d.mts.map +1 -0
- package/dist/emitter__type-expression-safety.mjs +2 -0
- package/dist/errors--qsXZUtL.d.mts +72 -0
- package/dist/errors--qsXZUtL.d.mts.map +1 -0
- package/dist/errors-IpZm1Skp-BH495dRd.mjs +378 -0
- package/dist/errors-IpZm1Skp-BH495dRd.mjs.map +1 -0
- package/dist/exports-BN0vFTxG.mjs +276 -0
- package/dist/exports-BN0vFTxG.mjs.map +1 -0
- package/dist/exports-B_xhKZmC.mjs +1436 -0
- package/dist/exports-B_xhKZmC.mjs.map +1 -0
- package/dist/exports-D3-NwrMA-CadaBGQ3.mjs +154 -0
- package/dist/exports-D3-NwrMA-CadaBGQ3.mjs.map +1 -0
- package/dist/exports-Dl2aGAk7.mjs +119 -0
- package/dist/exports-Dl2aGAk7.mjs.map +1 -0
- package/dist/format-ByDm2goZ-DKLyhNHo.mjs +101 -0
- package/dist/format-ByDm2goZ-DKLyhNHo.mjs.map +1 -0
- package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs +58 -0
- package/dist/framework-components-CjshQKHA-Dlp6Leo5.mjs.map +1 -0
- package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts +35 -0
- package/dist/global-flags-BpoOYtNZ-CHZD3fud.d.mts.map +1 -0
- package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts +28 -0
- package/dist/graph-bDjJ4GL9-BhFevsJS.d.mts.map +1 -0
- package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs +14 -0
- package/dist/graph-membership-DW6nnbyQ-Bp2KcVwR.mjs.map +1 -0
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs +64 -0
- package/dist/hash-DH8hl5Rq-BpM2t3Nu.mjs.map +1 -0
- package/dist/hash-XZYYKJ-i.d.mts +53 -0
- package/dist/hash-XZYYKJ-i.d.mts.map +1 -0
- package/dist/import-roots-B6CtsWXb.d.mts +119 -0
- package/dist/import-roots-B6CtsWXb.d.mts.map +1 -0
- package/dist/import-roots-NDOIEDVj.mjs +217 -0
- package/dist/import-roots-NDOIEDVj.mjs.map +1 -0
- package/dist/init-DHctXAI9-DSlaaYXN.mjs +2186 -0
- package/dist/init-DHctXAI9-DSlaaYXN.mjs.map +1 -0
- package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs +91 -0
- package/dist/inspect-live-schema-CnwYTRZ0-BErPHMni.mjs.map +1 -0
- package/dist/invariants-B5wLrgQS.d.mts +39 -0
- package/dist/invariants-B5wLrgQS.d.mts.map +1 -0
- package/dist/invariants-lXzy6txi-DAoP4nTE.mjs +57 -0
- package/dist/invariants-lXzy6txi-DAoP4nTE.mjs.map +1 -0
- package/dist/io-C8TdyBKt-DloEBi70.mjs +313 -0
- package/dist/io-C8TdyBKt-DloEBi70.mjs.map +1 -0
- package/dist/io-DYfeLJxR.d.mts +1 -0
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts +125 -0
- package/dist/io-sr4CO9_t-C3eV_kn-.d.mts.map +1 -0
- package/dist/ledger-origin-BGRN77Oy.d.mts +6 -0
- package/dist/ledger-origin-BGRN77Oy.d.mts.map +1 -0
- package/dist/ledger-origin-D7PN4Fon.mjs +9 -0
- package/dist/ledger-origin-D7PN4Fon.mjs.map +1 -0
- package/dist/metadata-2nbOAGsV-uYNeq2Cp.d.mts +2 -0
- package/dist/metadata-BtscDay2.d.mts +1 -0
- package/dist/migrate-Cb_iv264.mjs +500 -0
- package/dist/migrate-Cb_iv264.mjs.map +1 -0
- package/dist/migration-B2ljMJim.d.mts +155 -0
- package/dist/migration-B2ljMJim.d.mts.map +1 -0
- package/dist/migration-BuUmO7It.mjs +209 -0
- package/dist/migration-BuUmO7It.mjs.map +1 -0
- package/dist/migration-check-CcG-fB8r-CDs5C9vt.mjs +597 -0
- package/dist/migration-check-CcG-fB8r-CDs5C9vt.mjs.map +1 -0
- package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs +103 -0
- package/dist/migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs.map +1 -0
- package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs +500 -0
- package/dist/migration-graph-CBf9ORe7-B4xAF8GN.mjs.map +1 -0
- package/dist/migration-graph-DkoCC0Qy.mjs +185 -0
- package/dist/migration-graph-DkoCC0Qy.mjs.map +1 -0
- package/dist/migration-graph-Dqndu0i5.d.mts +9 -0
- package/dist/migration-graph-Dqndu0i5.d.mts.map +1 -0
- package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs +1945 -0
- package/dist/migration-graph-command-render-BKrg6BPv-BP8Pfj4J.mjs.map +1 -0
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts +124 -0
- package/dist/migration-graph-tarTxJ99-BrGBANeE.d.mts.map +1 -0
- package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs +228 -0
- package/dist/migration-list-BFBeo1_X-c0kqYokL.mjs.map +1 -0
- package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs +220 -0
- package/dist/migration-log-CS5IWcNq-BQ-32Low.mjs.map +1 -0
- package/dist/migration-new-BurCjyaQ.mjs +168 -0
- package/dist/migration-new-BurCjyaQ.mjs.map +1 -0
- package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs +38 -0
- package/dist/migration-path-target-D3Sj55PI-BICblCuk.mjs.map +1 -0
- package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs +759 -0
- package/dist/migration-plan-q_L84PN1-BWE0LTH6.mjs.map +1 -0
- package/dist/migration-show-Bx5I5aW9.mjs +171 -0
- package/dist/migration-show-Bx5I5aW9.mjs.map +1 -0
- package/dist/migration-status-CFlzlRmu-DewBN8Ys.mjs +444 -0
- package/dist/migration-status-CFlzlRmu-DewBN8Ys.mjs.map +1 -0
- package/dist/migration-tools.d.mts +23 -0
- package/dist/migration-tools.mjs +17 -0
- package/dist/migration-tools__aggregate.d.mts +2 -0
- package/dist/migration-tools__aggregate.mjs +2 -0
- package/dist/migration-tools__constants.d.mts +2 -0
- package/dist/migration-tools__constants.mjs +2 -0
- package/dist/migration-tools__contract-snapshot-store.d.mts +2 -0
- package/dist/migration-tools__contract-snapshot-store.mjs +2 -0
- package/dist/migration-tools__errors.d.mts +2 -0
- package/dist/migration-tools__errors.mjs +2 -0
- package/dist/migration-tools__graph.d.mts +2 -0
- package/dist/migration-tools__graph.mjs +1 -0
- package/dist/migration-tools__hash.d.mts +2 -0
- package/dist/migration-tools__hash.mjs +2 -0
- package/dist/migration-tools__invariants.d.mts +2 -0
- package/dist/migration-tools__invariants.mjs +2 -0
- package/dist/migration-tools__io.d.mts +3 -0
- package/dist/migration-tools__io.mjs +2 -0
- package/dist/migration-tools__ledger-origin.d.mts +2 -0
- package/dist/migration-tools__ledger-origin.mjs +2 -0
- package/dist/migration-tools__metadata.d.mts +3 -0
- package/dist/migration-tools__metadata.mjs +1 -0
- package/dist/migration-tools__migration-graph.d.mts +3 -0
- package/dist/migration-tools__migration-graph.mjs +3 -0
- package/dist/migration-tools__migration-ts.d.mts +2 -0
- package/dist/migration-tools__migration-ts.mjs +2 -0
- package/dist/migration-tools__migration.d.mts +2 -0
- package/dist/migration-tools__migration.mjs +2 -0
- package/dist/migration-tools__package.d.mts +3 -0
- package/dist/migration-tools__package.mjs +1 -0
- package/dist/migration-tools__ref-resolution.d.mts +2 -0
- package/dist/migration-tools__ref-resolution.mjs +2 -0
- package/dist/migration-tools__refs.d.mts +2 -0
- package/dist/migration-tools__refs.mjs +2 -0
- package/dist/migration-tools__spaces.d.mts +3 -0
- package/dist/migration-tools__spaces.mjs +3 -0
- package/dist/migration-ts-CNaAtK8C.d.mts +38 -0
- package/dist/migration-ts-CNaAtK8C.d.mts.map +1 -0
- package/dist/migration-ts-FyF55c4M.mjs +67 -0
- package/dist/migration-ts-FyF55c4M.mjs.map +1 -0
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +13 -0
- package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +1 -0
- package/dist/output-DWNYqZGc-D2sRgLAm.mjs +109 -0
- package/dist/output-DWNYqZGc-D2sRgLAm.mjs.map +1 -0
- package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts +21 -0
- package/dist/package-CfWiDNrr-ZR4HM_Iz.d.mts.map +1 -0
- package/dist/package-N9PPdFV_.d.mts +3 -0
- package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs +43 -0
- package/dist/progress-adapter-CjAeTxY_-BXYSd1eY.mjs.map +1 -0
- package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs +99 -0
- package/dist/project-import-root-CpwLCDLY-DkVwAnWj.mjs.map +1 -0
- package/dist/publish-surface.d.mts +3 -0
- package/dist/publish-surface.mjs +3 -0
- package/dist/publish-surface__import-roots.d.mts +2 -0
- package/dist/publish-surface__import-roots.mjs +2 -0
- package/dist/publish-surface__shells.d.mts +2 -0
- package/dist/publish-surface__shells.mjs +2 -0
- package/dist/quick-reference-mongo.md +114 -0
- package/dist/quick-reference-postgres.md +93 -0
- package/dist/readme-mongo.md +35 -0
- package/dist/readme-postgres.md +34 -0
- package/dist/ref-B6cTthTi.mjs +171 -0
- package/dist/ref-B6cTthTi.mjs.map +1 -0
- package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs +57 -0
- package/dist/ref-advancement-CSPMoQs3-fEipZrdu.mjs.map +1 -0
- package/dist/ref-resolution-BjJBWPjX.mjs +250 -0
- package/dist/ref-resolution-BjJBWPjX.mjs.map +1 -0
- package/dist/ref-resolution-COGOSL57.d.mts +127 -0
- package/dist/ref-resolution-COGOSL57.d.mts.map +1 -0
- package/dist/refs-BDbB9BRB-D6Za3Q49.mjs +241 -0
- package/dist/refs-BDbB9BRB-D6Za3Q49.mjs.map +1 -0
- package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts +43 -0
- package/dist/refs-BNCUu58Y-BIso5Jfg.d.mts.map +1 -0
- package/dist/schemas-CeGMYFYX-h3OcU__O.d.mts +192 -0
- package/dist/schemas-CeGMYFYX-h3OcU__O.d.mts.map +1 -0
- package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs +112 -0
- package/dist/schemas-KhXMzNA_-CzZ7GFX_.mjs.map +1 -0
- package/dist/shells-BenrJHp2.mjs +602 -0
- package/dist/shells-BenrJHp2.mjs.map +1 -0
- package/dist/shells-COHV_Ozf.d.mts +135 -0
- package/dist/shells-COHV_Ozf.d.mts.map +1 -0
- package/dist/spaces-C27bA-xc.mjs +267 -0
- package/dist/spaces-C27bA-xc.mjs.map +1 -0
- package/dist/spaces-DxFj5y8l.d.mts +415 -0
- package/dist/spaces-DxFj5y8l.d.mts.map +1 -0
- package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs +120 -0
- package/dist/telemetry-CmbCa3Ld-CmE5zcIG.mjs.map +1 -0
- package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts +133 -0
- package/dist/terminal-ui-BN4QOsm5-Bf3pim46.d.mts.map +1 -0
- package/dist/type-expression-safety-CgHTWypx.mjs +8 -0
- package/dist/type-expression-safety-CgHTWypx.mjs.map +1 -0
- package/dist/types-DZWEs4si-D8UlyJI0.d.mts +893 -0
- package/dist/types-DZWEs4si-D8UlyJI0.d.mts.map +1 -0
- package/dist/verify-DnVNjc5C-BGdsblBK.mjs +283 -0
- package/dist/verify-DnVNjc5C-BGdsblBK.mjs.map +1 -0
- package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs +252 -0
- package/dist/verify-contract-spaces-BZDcJsuA-De8v4Z4T.mjs.map +1 -0
- package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts +136 -0
- package/dist/verify-contract-spaces-Cc1u_wJo-BilPJS2S.d.mts.map +1 -0
- package/dist/vite-plugin-contract-emit.d.mts +54 -0
- package/dist/vite-plugin-contract-emit.d.mts.map +1 -0
- package/dist/vite-plugin-contract-emit.mjs +303 -0
- package/dist/vite-plugin-contract-emit.mjs.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-init-Vbkb_TKZ.mjs","names":["errorRuntime","CliStructuredError"],"sources":["../../../../1-framework/3-tooling/cli/dist/commands/db-init.mjs"],"sourcesContent":["import { B as errorContractValidationFailed, C as formatMigrationApplyOutput, F as CliStructuredError, T as formatMigrationPlanOutput, X as errorMigrationPlanningFailed, _ as createTerminalUI, c as sanitizeErrorMessage, ct as errorUnexpected, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, lt as mapMigrationToolsError, nt as errorRunnerFailed, rt as errorRuntime, s as resolveMigrationPaths, u as setCommandExamples, w as formatMigrationJson, y as handleResult } from \"../command-helpers-CAoXqAY9.mjs\";\nimport { n as prepareMigrationContext, t as addMigrationCommandOptions } from \"../migration-command-scaffold-BCuoeAki.mjs\";\nimport { i as readContractIR, n as computeRefAdvancementName, t as buildRefAdvancementFields } from \"../ref-advancement-CSPMoQs3.mjs\";\nimport { Command } from \"commander\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { notOk, ok } from \"@internal/utils/result\";\nimport { assertNever } from \"@internal/utils/internal-error\";\nimport { isStructuredError } from \"@internal/utils/structured-error\";\nimport { MigrationToolsError } from \"@internal/migration-tools/errors\";\n//#region src/commands/db-init.ts\n/**\n* Maps a DbInitFailure to a CliStructuredError for consistent error handling.\n*/\nfunction mapDbInitFailure(failure) {\n\tif (failure.code === \"PLANNING_FAILED\") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });\n\tif (failure.code === \"MIGRATION.MARKER_ORIGIN_MISMATCH\") {\n\t\tconst mismatchParts = [];\n\t\tif (failure.marker?.storageHash !== failure.destination?.storageHash && failure.marker?.storageHash && failure.destination?.storageHash) mismatchParts.push(`storageHash (marker: ${failure.marker.storageHash}, destination: ${failure.destination.storageHash})`);\n\t\tif (failure.marker?.profileHash !== failure.destination?.profileHash && failure.marker?.profileHash && failure.destination?.profileHash) mismatchParts.push(`profileHash (marker: ${failure.marker.profileHash}, destination: ${failure.destination.profileHash})`);\n\t\treturn errorRuntime(`Existing database signature does not match plan destination.${mismatchParts.length > 0 ? ` Mismatch in ${mismatchParts.join(\" and \")}.` : \"\"}`, {\n\t\t\twhy: \"Database has an existing signature (marker) that does not match the target contract\",\n\t\t\tfix: \"If bootstrapping, drop/reset the database then re-run `prisma-next db init`; otherwise reconcile schema/marker using your migration workflow\",\n\t\t\tmeta: {\n\t\t\t\tcode: \"MIGRATION.MARKER_ORIGIN_MISMATCH\",\n\t\t\t\t...ifDefined(\"markerStorageHash\", failure.marker?.storageHash),\n\t\t\t\t...ifDefined(\"destinationStorageHash\", failure.destination?.storageHash),\n\t\t\t\t...ifDefined(\"markerProfileHash\", failure.marker?.profileHash),\n\t\t\t\t...ifDefined(\"destinationProfileHash\", failure.destination?.profileHash)\n\t\t\t}\n\t\t});\n\t}\n\tif (failure.code === \"RUNNER_FAILED\") {\n\t\tconst fix = (typeof failure.meta?.[\"runnerErrorCode\"] === \"string\" ? failure.meta[\"runnerErrorCode\"] : void 0) === \"MIGRATION.LEGACY_MARKER_SHAPE\" ? \"Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `prisma-next db init` to recreate it with the current per-space schema.\" : \"Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run `prisma-next db init`\";\n\t\treturn errorRunnerFailed(failure.summary, {\n\t\t\twhy: failure.why ?? \"Migration runner failed\",\n\t\t\tfix,\n\t\t\t...failure.meta ? { meta: {\n\t\t\t\tcode: \"RUNNER_FAILED\",\n\t\t\t\t...failure.meta\n\t\t\t} } : { meta: { code: \"RUNNER_FAILED\" } }\n\t\t});\n\t}\n\tconst exhaustive = failure.code;\n\treturn assertNever(exhaustive, `Unhandled DbInitFailure code: ${String(exhaustive)}`);\n}\n/**\n* Executes the db init command and returns a structured Result.\n*/\nasync function executeDbInitCommand(options, flags, ui, startTime) {\n\tconst ctxResult = await prepareMigrationContext(options, flags, ui, {\n\t\tcommandName: \"db init\",\n\t\tdescription: \"Bootstrap a database to match the current contract\",\n\t\turl: \"https://pris.ly/db-init\"\n\t});\n\tif (!ctxResult.ok) return ctxResult;\n\tconst { client, config, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;\n\tconst { migrationsDir, refsDir } = resolveMigrationPaths(options.config, config);\n\ttry {\n\t\tawait client.connect(dbConnection);\n\t\tconst result = await client.dbInit({\n\t\t\tcontract: contractJson,\n\t\t\tmode: options.dryRun ? \"plan\" : \"apply\",\n\t\t\tmigrationsDir,\n\t\t\tonProgress\n\t\t});\n\t\tif (!result.ok) return notOk(mapDbInitFailure(result.failure));\n\t\tconst advancementHash = result.value.mode === \"apply\" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;\n\t\tlet refAdvancementFields = {\n\t\t\tadvancedRef: null,\n\t\t\tplannedAdvanceRef: null\n\t\t};\n\t\tif (computeRefAdvancementName({\n\t\t\t...ifDefined(\"advanceRef\", options.advanceRef),\n\t\t\t...ifDefined(\"db\", options.db)\n\t\t}) !== null) try {\n\t\t\tconst contractIR = await readContractIR(contractJson, contractPathAbsolute);\n\t\t\trefAdvancementFields = await buildRefAdvancementFields({\n\t\t\t\t...ifDefined(\"advanceRef\", options.advanceRef),\n\t\t\t\t...ifDefined(\"db\", options.db),\n\t\t\t\trefsDir,\n\t\t\t\tmigrationsDir,\n\t\t\t\tcontractIR,\n\t\t\t\tmode: result.value.mode,\n\t\t\t\thash: advancementHash\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n\t\t\tthrow error;\n\t\t}\n\t\treturn ok({\n\t\t\tok: true,\n\t\t\tmode: result.value.mode,\n\t\t\tplan: {\n\t\t\t\ttargetId: ctxResult.value.config.target.targetId,\n\t\t\t\tdestination: {\n\t\t\t\t\tstorageHash: result.value.destination.storageHash,\n\t\t\t\t\t...ifDefined(\"profileHash\", result.value.destination.profileHash)\n\t\t\t\t},\n\t\t\t\toperations: result.value.plan.operations.map((op) => ({\n\t\t\t\t\tid: op.id,\n\t\t\t\t\tlabel: op.label,\n\t\t\t\t\toperationClass: op.operationClass\n\t\t\t\t})),\n\t\t\t\t...ifDefined(\"preview\", result.value.plan.preview)\n\t\t\t},\n\t\t\t...result.value.execution ? { execution: {\n\t\t\t\toperationsPlanned: result.value.execution.operationsPlanned,\n\t\t\t\toperationsExecuted: result.value.execution.operationsExecuted\n\t\t\t} } : {},\n\t\t\t...result.value.marker ? { marker: {\n\t\t\t\tstorageHash: result.value.marker.storageHash,\n\t\t\t\t...ifDefined(\"profileHash\", result.value.marker.profileHash)\n\t\t\t} } : {},\n\t\t\t...ifDefined(\"perSpace\", result.value.perSpace),\n\t\t\tadvancedRef: refAdvancementFields.advancedRef,\n\t\t\tplannedAdvanceRef: refAdvancementFields.plannedAdvanceRef,\n\t\t\tsummary: result.value.summary,\n\t\t\ttimings: { total: Date.now() - startTime }\n\t\t});\n\t} catch (error) {\n\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\tif (isStructuredError(error) && error.code === \"CONTRACT.VALIDATION_FAILED\") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));\n\t\tconst safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === \"string\" ? dbConnection : void 0);\n\t\treturn notOk(errorUnexpected(safeMessage, { why: `Unexpected error during db init: ${safeMessage}` }));\n\t} finally {\n\t\tawait client.close();\n\t}\n}\nfunction createDbInitCommand() {\n\tconst command = new Command(\"init\");\n\tsetCommandDescriptions(command, \"Bootstrap a database to match the current contract and sign it\", \"Initializes a database to match your emitted contract using additive-only operations.\\nCreates any missing tables, columns, indexes, and constraints defined in your contract.\\nLeaves existing compatible structures in place, surfaces conflicts when destructive changes\\nwould be required, and signs the database to track contract state. Use --dry-run to\\npreview changes without applying.\");\n\tsetCommandExamples(command, [\"prisma-next db init --db $DATABASE_URL\", \"prisma-next db init --db $DATABASE_URL --dry-run\"]);\n\taddMigrationCommandOptions(command);\n\tcommand.option(\"--advance-ref <name>\", \"Ref to advance to the post-command contract hash\");\n\tcommand.action(async (options) => {\n\t\tconst flags = parseGlobalFlagsOrExit(options);\n\t\tconst startTime = Date.now();\n\t\tconst ui = createTerminalUI(flags);\n\t\tconst exitCode = handleResult(await executeDbInitCommand(options, flags, ui, startTime), flags, ui, (dbInitResult) => {\n\t\t\tif (flags.json) ui.output(formatMigrationJson(dbInitResult));\n\t\t\telse {\n\t\t\t\tconst output = dbInitResult.mode === \"plan\" ? formatMigrationPlanOutput(dbInitResult, flags) : formatMigrationApplyOutput(dbInitResult, flags);\n\t\t\t\tif (output) ui.log(output);\n\t\t\t}\n\t\t});\n\t\tprocess.exit(exitCode);\n\t});\n\treturn command;\n}\n//#endregion\nexport { createDbInitCommand };\n\n//# sourceMappingURL=db-init.mjs.map"],"mappings":";;;;;;;;;;;;;AAaA,SAAS,iBAAiB,SAAS;CAClC,IAAI,QAAQ,SAAS,mBAAmB,OAAO,6BAA6B,EAAE,WAAW,QAAQ,aAAa,CAAC,EAAE,CAAC;CAClH,IAAI,QAAQ,SAAS,oCAAoC;EACxD,MAAM,gBAAgB,CAAC;EACvB,IAAI,QAAQ,QAAQ,gBAAgB,QAAQ,aAAa,eAAe,QAAQ,QAAQ,eAAe,QAAQ,aAAa,aAAa,cAAc,KAAK,wBAAwB,QAAQ,OAAO,YAAY,iBAAiB,QAAQ,YAAY,YAAY,EAAE;EAClQ,IAAI,QAAQ,QAAQ,gBAAgB,QAAQ,aAAa,eAAe,QAAQ,QAAQ,eAAe,QAAQ,aAAa,aAAa,cAAc,KAAK,wBAAwB,QAAQ,OAAO,YAAY,iBAAiB,QAAQ,YAAY,YAAY,EAAE;EAClQ,OAAOA,eAAa,+DAA+D,cAAc,SAAS,IAAI,gBAAgB,cAAc,KAAK,OAAO,EAAE,KAAK,MAAM;GACpK,KAAK;GACL,KAAK;GACL,MAAM;IACL,MAAM;IACN,GAAG,UAAU,qBAAqB,QAAQ,QAAQ,WAAW;IAC7D,GAAG,UAAU,0BAA0B,QAAQ,aAAa,WAAW;IACvE,GAAG,UAAU,qBAAqB,QAAQ,QAAQ,WAAW;IAC7D,GAAG,UAAU,0BAA0B,QAAQ,aAAa,WAAW;GACxE;EACD,CAAC;CACF;CACA,IAAI,QAAQ,SAAS,i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O,MAAM,8BAA8B,+BAA+B,MAAM,WAAW,EAAE,OAAO,EAAE,MAAM,qBAAqB,EAAE,CAAC,CAAC;EAClN,MAAM,cAAc,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAAG,OAAO,iBAAiB,WAAW,eAAe,KAAK,CAAC;EACzJ,OAAO,MAAM,gBAAgB,aAAa,EAAE,KAAK,oCAAoC,cAAc,CAAC,CAAC;CACtG,UAAU;EACT,MAAM,OAAO,MAAM;CACpB;AACD;AACA,SAAS,sBAAsB;CAC9B,MAAM,UAAU,IAAI,QAAQ,MAAM;CAClC,uBAAuB,SAAS,kEAAkE,qYAAqY;CACve,mBAAmB,SAAS,CAAC,0CAA0C,kDAAkD,CAAC;CAC1H,2BAA2B,OAAO;CAClC,QAAQ,OAAO,wBAAwB,kDAAkD;CACzF,QAAQ,OAAO,OAAO,YAAY;EACjC,MAAM,QAAQ,uBAAuB,OAAO;EAC5C,MAAM,YAAY,KAAK,IAAI;EAC3B,MAAM,KAAK,iBAAiB,KAAK;EACjC,MAAM,WAAW,aAAa,MAAM,qBAAqB,SAAS,OAAO,IAAI,SAAS,GAAG,OAAO,KAAK,iBAAiB;GACrH,IAAI,MAAM,MAAM,GAAG,OAAO,oBAAoB,YAAY,CAAC;QACtD;IACJ,MAAM,SAAS,aAAa,SAAS,SAAS,0BAA0B,cAAc,KAAK,IAAI,2BAA2B,cAAc,KAAK;IAC7I,IAAI,QAAQ,GAAG,IAAI,MAAM;GAC1B;EACD,CAAC;EACD,QAAQ,KAAK,QAAQ;CACtB,CAAC;CACD,OAAO;AACR"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ct as setCommandExamples, o as createTerminalUI, q as handleResult, r as addGlobalOptions, st as setCommandDescriptions, tt as parseGlobalFlagsOrExit } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
2
|
+
import { t as inspectLiveSchema } from "./inspect-live-schema-CnwYTRZ0-BErPHMni.mjs";
|
|
3
|
+
import { n as formatIntrospectOutput, t as formatIntrospectJson } from "./verify-DnVNjc5C-BGdsblBK.mjs";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
//#region ../../../1-framework/3-tooling/cli/dist/commands/db-schema.mjs
|
|
6
|
+
function toIntrospectSchemaResult(result) {
|
|
7
|
+
return {
|
|
8
|
+
ok: true,
|
|
9
|
+
summary: "Schema read successfully",
|
|
10
|
+
target: result.target,
|
|
11
|
+
schema: result.schema,
|
|
12
|
+
meta: result.meta,
|
|
13
|
+
timings: result.timings
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function createDbSchemaCommand() {
|
|
17
|
+
const command = new Command("schema");
|
|
18
|
+
setCommandDescriptions(command, "Inspect the live database schema", "Reads the live database schema and prints it as a tree by default or as JSON with\n--json. This command is always read-only and never writes files. To save machine-\nreadable output, use shell redirection, for example `prisma-next db schema --json > schema.json`.");
|
|
19
|
+
setCommandExamples(command, [
|
|
20
|
+
"prisma-next db schema --db $DATABASE_URL",
|
|
21
|
+
"prisma-next db schema --db $DATABASE_URL --json",
|
|
22
|
+
"prisma-next db schema --db $DATABASE_URL --json > schema.json"
|
|
23
|
+
]);
|
|
24
|
+
addGlobalOptions(command).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").action(async (options) => {
|
|
25
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
26
|
+
const ui = createTerminalUI(flags);
|
|
27
|
+
const exitCode = handleResult(await inspectLiveSchema(options, flags, ui, Date.now(), {
|
|
28
|
+
commandName: "db schema",
|
|
29
|
+
description: "Inspect the live database schema",
|
|
30
|
+
url: "https://pris.ly/db-schema"
|
|
31
|
+
}), flags, ui, (value) => {
|
|
32
|
+
const introspectResult = toIntrospectSchemaResult(value);
|
|
33
|
+
if (flags.json) {
|
|
34
|
+
ui.output(formatIntrospectJson(introspectResult));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const output = formatIntrospectOutput(introspectResult, value.schemaView, flags);
|
|
38
|
+
if (output) ui.log(output);
|
|
39
|
+
});
|
|
40
|
+
process.exit(exitCode);
|
|
41
|
+
});
|
|
42
|
+
return command;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createDbSchemaCommand as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=db-schema-ClQCu3xY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-schema-ClQCu3xY.mjs","names":[],"sources":["../../../../1-framework/3-tooling/cli/dist/commands/db-schema.mjs"],"sourcesContent":["import { _ as createTerminalUI, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, t as addGlobalOptions, u as setCommandExamples, y as handleResult } from \"../command-helpers-CAoXqAY9.mjs\";\nimport { t as inspectLiveSchema } from \"../inspect-live-schema-CnwYTRZ0.mjs\";\nimport { n as formatIntrospectOutput, t as formatIntrospectJson } from \"../verify-DnVNjc5C.mjs\";\nimport { Command } from \"commander\";\n//#region src/commands/db-schema.ts\nfunction toIntrospectSchemaResult(result) {\n\treturn {\n\t\tok: true,\n\t\tsummary: \"Schema read successfully\",\n\t\ttarget: result.target,\n\t\tschema: result.schema,\n\t\tmeta: result.meta,\n\t\ttimings: result.timings\n\t};\n}\nfunction createDbSchemaCommand() {\n\tconst command = new Command(\"schema\");\n\tsetCommandDescriptions(command, \"Inspect the live database schema\", \"Reads the live database schema and prints it as a tree by default or as JSON with\\n--json. This command is always read-only and never writes files. To save machine-\\nreadable output, use shell redirection, for example `prisma-next db schema --json > schema.json`.\");\n\tsetCommandExamples(command, [\n\t\t\"prisma-next db schema --db $DATABASE_URL\",\n\t\t\"prisma-next db schema --db $DATABASE_URL --json\",\n\t\t\"prisma-next db schema --db $DATABASE_URL --json > schema.json\"\n\t]);\n\taddGlobalOptions(command).option(\"--db <url>\", \"Database connection string\").option(\"--config <path>\", \"Path to prisma-next.config.ts\").action(async (options) => {\n\t\tconst flags = parseGlobalFlagsOrExit(options);\n\t\tconst ui = createTerminalUI(flags);\n\t\tconst exitCode = handleResult(await inspectLiveSchema(options, flags, ui, Date.now(), {\n\t\t\tcommandName: \"db schema\",\n\t\t\tdescription: \"Inspect the live database schema\",\n\t\t\turl: \"https://pris.ly/db-schema\"\n\t\t}), flags, ui, (value) => {\n\t\t\tconst introspectResult = toIntrospectSchemaResult(value);\n\t\t\tif (flags.json) {\n\t\t\t\tui.output(formatIntrospectJson(introspectResult));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst output = formatIntrospectOutput(introspectResult, value.schemaView, flags);\n\t\t\tif (output) ui.log(output);\n\t\t});\n\t\tprocess.exit(exitCode);\n\t});\n\treturn command;\n}\n//#endregion\nexport { createDbSchemaCommand };\n\n//# sourceMappingURL=db-schema.mjs.map"],"mappings":";;;;;AAKA,SAAS,yBAAyB,QAAQ;CACzC,OAAO;EACN,IAAI;EACJ,SAAS;EACT,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,SAAS,OAAO;CACjB;AACD;AACA,SAAS,wBAAwB;CAChC,MAAM,UAAU,IAAI,QAAQ,QAAQ;CACpC,uBAAuB,SAAS,oCAAoC,yQAAyQ;CAC7U,mBAAmB,SAAS;EAC3B;EACA;EACA;CACD,CAAC;CACD,iBAAiB,OAAO,CAAC,CAAC,OAAO,cAAc,4BAA4B,CAAC,CAAC,OAAO,mBAAmB,+BAA+B,CAAC,CAAC,OAAO,OAAO,YAAY;EACjK,MAAM,QAAQ,uBAAuB,OAAO;EAC5C,MAAM,KAAK,iBAAiB,KAAK;EACjC,MAAM,WAAW,aAAa,MAAM,kBAAkB,SAAS,OAAO,IAAI,KAAK,IAAI,GAAG;GACrF,aAAa;GACb,aAAa;GACb,KAAK;EACN,CAAC,GAAG,OAAO,KAAK,UAAU;GACzB,MAAM,mBAAmB,yBAAyB,KAAK;GACvD,IAAI,MAAM,MAAM;IACf,GAAG,OAAO,qBAAqB,gBAAgB,CAAC;IAChD;GACD;GACA,MAAM,SAAS,uBAAuB,kBAAkB,MAAM,YAAY,KAAK;GAC/E,IAAI,QAAQ,GAAG,IAAI,MAAM;EAC1B,CAAC;EACD,QAAQ,KAAK,QAAQ;CACtB,CAAC;CACD,OAAO;AACR"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { t as MigrationToolsError } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { r as readContractSnapshotJson } from "./contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs";
|
|
3
|
+
import { $ as maskConnectionUrl, N as errorUnexpected, O as errorRuntime$1, Q as mapRefResolutionError, W as formatStyledHeader, Z as mapMigrationToolsError, at as resolveMigrationPaths, ct as setCommandExamples, d as errorContractValidationFailed, f as errorDatabaseConnectionRequired, h as errorFileNotFound, it as resolveContractPath, m as errorDriverRequired, o as createTerminalUI, q as handleResult, r as addGlobalOptions, st as setCommandDescriptions, t as CliStructuredError$1, tt as parseGlobalFlagsOrExit } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
4
|
+
import { r as loadConfig } from "./exports-Dl2aGAk7.mjs";
|
|
5
|
+
import { t as createProgressAdapter } from "./progress-adapter-CjAeTxY_-BXYSd1eY.mjs";
|
|
6
|
+
import { n as buildReadAggregate } from "./contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs";
|
|
7
|
+
import { t as createControlClient } from "./client-75qrAPqf-DZAVUxFa.mjs";
|
|
8
|
+
import { n as parseContractRef } from "./ref-resolution-BjJBWPjX.mjs";
|
|
9
|
+
import { a as formatSignJson, i as formatSchemaVerifyOutput, o as formatSignOutput, r as formatSchemaVerifyJson } from "./verify-DnVNjc5C-BGdsblBK.mjs";
|
|
10
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
11
|
+
import { relative, resolve } from "pathe";
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
13
|
+
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
14
|
+
import { Command } from "commander";
|
|
15
|
+
//#region ../../../1-framework/3-tooling/cli/dist/commands/db-sign.mjs
|
|
16
|
+
/**
|
|
17
|
+
* Executes the db sign command and returns a structured Result.
|
|
18
|
+
* Success: SignDatabaseResult (sign happened)
|
|
19
|
+
* Failure: CliStructuredError (infra error) or VerifyDatabaseSchemaResult (schema mismatch)
|
|
20
|
+
*/
|
|
21
|
+
async function executeDbSignCommand(contractArg, options, flags, ui) {
|
|
22
|
+
const config = await loadConfig(options.config);
|
|
23
|
+
const configPath = options.config ? relative(process.cwd(), resolve(options.config)) : "prisma-next.config.ts";
|
|
24
|
+
const contractPathAbsolute = resolveContractPath(config);
|
|
25
|
+
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
26
|
+
const effectiveContractArg = contractArg ?? options.contract;
|
|
27
|
+
if (!flags.json && !flags.quiet) {
|
|
28
|
+
const details = [{
|
|
29
|
+
label: "config",
|
|
30
|
+
value: configPath
|
|
31
|
+
}, {
|
|
32
|
+
label: "contract",
|
|
33
|
+
value: effectiveContractArg ?? contractPath
|
|
34
|
+
}];
|
|
35
|
+
if (options.db) details.push({
|
|
36
|
+
label: "database",
|
|
37
|
+
value: maskConnectionUrl(options.db)
|
|
38
|
+
});
|
|
39
|
+
const header = formatStyledHeader({
|
|
40
|
+
command: "db sign",
|
|
41
|
+
description: "Sign the database with your contract so you can safely run queries",
|
|
42
|
+
url: "https://pris.ly/db-sign",
|
|
43
|
+
details,
|
|
44
|
+
flags
|
|
45
|
+
});
|
|
46
|
+
ui.stderr(header);
|
|
47
|
+
}
|
|
48
|
+
let contractJson;
|
|
49
|
+
if (effectiveContractArg) try {
|
|
50
|
+
const { migrationsDir } = resolveMigrationPaths(options.config, config);
|
|
51
|
+
const loaded = await buildReadAggregate(config, { migrationsDir });
|
|
52
|
+
if (!loaded.ok) return notOk(loaded.failure);
|
|
53
|
+
const graph = loaded.value.aggregate.app.graph();
|
|
54
|
+
const bundles = loaded.value.aggregate.app.packages;
|
|
55
|
+
const refs = loaded.value.aggregate.app.refs;
|
|
56
|
+
const refResult = parseContractRef(effectiveContractArg, {
|
|
57
|
+
graph,
|
|
58
|
+
refs
|
|
59
|
+
});
|
|
60
|
+
if (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));
|
|
61
|
+
const targetHash = refResult.value.hash;
|
|
62
|
+
if (bundles.find((p) => p.metadata.to === targetHash)) contractJson = await readContractSnapshotJson(migrationsDir, targetHash);
|
|
63
|
+
else {
|
|
64
|
+
const defaultRaw = await readFile(contractPathAbsolute, "utf-8");
|
|
65
|
+
const defaultContract = JSON.parse(defaultRaw);
|
|
66
|
+
if (defaultContract["storage"]?.["storageHash"] === targetHash) contractJson = defaultContract;
|
|
67
|
+
else return notOk(errorRuntime$1(`No contract file found for hash "${targetHash}"`, {
|
|
68
|
+
why: `Resolved contract reference "${effectiveContractArg}" to hash "${targetHash}" but no migration produces that hash and the emitted contract does not match.`,
|
|
69
|
+
fix: "Ensure the target contract exists on disk — either as a migration endpoint or as the emitted contract.json."
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
74
|
+
if (error instanceof CliStructuredError$1) return notOk(error);
|
|
75
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to resolve contract reference: ${error instanceof Error ? error.message : String(error)}` }));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
let contractJsonContent;
|
|
79
|
+
try {
|
|
80
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof Error && error.code === "ENOENT") return notOk(errorFileNotFound(contractPathAbsolute, {
|
|
83
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
84
|
+
fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
|
|
85
|
+
}));
|
|
86
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}` }));
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
contractJson = JSON.parse(contractJsonContent);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path: contractPathAbsolute } }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const dbConnection = options.db ?? config.db?.connection;
|
|
95
|
+
if (!dbConnection) return notOk(errorDatabaseConnectionRequired({
|
|
96
|
+
why: `Database connection is required for db sign (set db.connection in ${configPath}, or pass --db <url>)`,
|
|
97
|
+
commandName: "db sign"
|
|
98
|
+
}));
|
|
99
|
+
if (!config.driver) return notOk(errorDriverRequired({ why: "Config.driver is required for db sign" }));
|
|
100
|
+
const client = createControlClient({
|
|
101
|
+
family: config.family,
|
|
102
|
+
target: config.target,
|
|
103
|
+
adapter: config.adapter,
|
|
104
|
+
driver: config.driver,
|
|
105
|
+
extensions: config.extensions ?? []
|
|
106
|
+
});
|
|
107
|
+
const onProgress = createProgressAdapter({
|
|
108
|
+
ui,
|
|
109
|
+
flags
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
const schemaVerifyResult = await client.schemaVerify({
|
|
113
|
+
contract: contractJson,
|
|
114
|
+
strict: false,
|
|
115
|
+
connection: dbConnection,
|
|
116
|
+
onProgress
|
|
117
|
+
});
|
|
118
|
+
if (!schemaVerifyResult.ok) return notOk(schemaVerifyResult);
|
|
119
|
+
return ok(await client.sign({
|
|
120
|
+
contract: contractJson,
|
|
121
|
+
contractPath,
|
|
122
|
+
configPath,
|
|
123
|
+
onProgress
|
|
124
|
+
}));
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof CliStructuredError$1) return notOk(error);
|
|
127
|
+
if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
|
|
128
|
+
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Unexpected error during db sign: ${error instanceof Error ? error.message : String(error)}` }));
|
|
129
|
+
} finally {
|
|
130
|
+
await client.close();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function createDbSignCommand() {
|
|
134
|
+
const command = new Command("sign");
|
|
135
|
+
setCommandDescriptions(command, "Sign the database with your contract so you can safely run queries", "Verifies that your database schema satisfies the emitted contract, and if so, writes or\nupdates the database signature. This command is idempotent and safe to run\nin CI/deployment pipelines. The signature records that this database instance is aligned\nwith a specific contract version.");
|
|
136
|
+
setCommandExamples(command, [
|
|
137
|
+
"prisma-next db sign --db $DATABASE_URL",
|
|
138
|
+
"prisma-next db sign production --db $DATABASE_URL",
|
|
139
|
+
"prisma-next db sign --contract production --db $DATABASE_URL"
|
|
140
|
+
]);
|
|
141
|
+
addGlobalOptions(command).argument("[contract]", "Contract reference (hash, prefix, ref name, or migration dir name)").option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--contract <contract>", "Contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)").action(async (positionalContract, options) => {
|
|
142
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
143
|
+
if (positionalContract && options.contract) {
|
|
144
|
+
process.stderr.write("Cannot specify both a positional contract argument and --contract flag.\n");
|
|
145
|
+
process.exit(2);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const ui = createTerminalUI(flags);
|
|
149
|
+
const result = await executeDbSignCommand(positionalContract, options, flags, ui);
|
|
150
|
+
if (result.ok) {
|
|
151
|
+
if (flags.json) ui.output(formatSignJson(result.value));
|
|
152
|
+
else {
|
|
153
|
+
const output = formatSignOutput(result.value, flags);
|
|
154
|
+
if (output) ui.log(output);
|
|
155
|
+
}
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|
|
158
|
+
const failure = result.failure;
|
|
159
|
+
if (failure instanceof CliStructuredError$1) {
|
|
160
|
+
const exitCode = handleResult(result, flags, ui);
|
|
161
|
+
process.exit(exitCode);
|
|
162
|
+
}
|
|
163
|
+
if (flags.json) ui.output(formatSchemaVerifyJson(failure));
|
|
164
|
+
else {
|
|
165
|
+
const output = formatSchemaVerifyOutput(failure, flags);
|
|
166
|
+
if (output) ui.log(output);
|
|
167
|
+
}
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
return command;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { createDbSignCommand as t };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=db-sign-jjXDgQ1u.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-sign-jjXDgQ1u.mjs","names":["errorRuntime","CliStructuredError"],"sources":["../../../../1-framework/3-tooling/cli/dist/commands/db-sign.mjs"],"sourcesContent":["import { A as formatStyledHeader, B as errorContractValidationFailed, F as CliStructuredError, U as errorDriverRequired, V as errorDatabaseConnectionRequired, W as errorFileNotFound, _ as createTerminalUI, ct as errorUnexpected, g as parseGlobalFlagsOrExit, i as maskConnectionUrl, l as setCommandDescriptions, lt as mapMigrationToolsError, o as resolveContractPath, rt as errorRuntime, s as resolveMigrationPaths, t as addGlobalOptions, u as setCommandExamples, ut as mapRefResolutionError, y as handleResult } from \"../command-helpers-CAoXqAY9.mjs\";\nimport { t as createProgressAdapter } from \"../progress-adapter-CjAeTxY_.mjs\";\nimport { n as buildReadAggregate } from \"../contract-space-aggregate-loader-CFH-336b.mjs\";\nimport { t as createControlClient } from \"../client-75qrAPqf.mjs\";\nimport { a as formatSignJson, i as formatSchemaVerifyOutput, o as formatSignOutput, r as formatSchemaVerifyJson } from \"../verify-DnVNjc5C.mjs\";\nimport { Command } from \"commander\";\nimport { loadConfig } from \"@internal/config-loader\";\nimport { notOk, ok } from \"@internal/utils/result\";\nimport { relative, resolve } from \"pathe\";\nimport { readFile } from \"node:fs/promises\";\nimport { isStructuredError } from \"@internal/utils/structured-error\";\nimport { MigrationToolsError } from \"@internal/migration-tools/errors\";\nimport { readContractSnapshotJson } from \"@internal/migration-tools/contract-snapshot-store\";\nimport { parseContractRef } from \"@internal/migration-tools/ref-resolution\";\n//#region src/commands/db-sign.ts\n/**\n* Executes the db sign command and returns a structured Result.\n* Success: SignDatabaseResult (sign happened)\n* Failure: CliStructuredError (infra error) or VerifyDatabaseSchemaResult (schema mismatch)\n*/\nasync function executeDbSignCommand(contractArg, options, flags, ui) {\n\tconst config = await loadConfig(options.config);\n\tconst configPath = options.config ? relative(process.cwd(), resolve(options.config)) : \"prisma-next.config.ts\";\n\tconst contractPathAbsolute = resolveContractPath(config);\n\tconst contractPath = relative(process.cwd(), contractPathAbsolute);\n\tconst effectiveContractArg = contractArg ?? options.contract;\n\tif (!flags.json && !flags.quiet) {\n\t\tconst details = [{\n\t\t\tlabel: \"config\",\n\t\t\tvalue: configPath\n\t\t}, {\n\t\t\tlabel: \"contract\",\n\t\t\tvalue: effectiveContractArg ?? contractPath\n\t\t}];\n\t\tif (options.db) details.push({\n\t\t\tlabel: \"database\",\n\t\t\tvalue: maskConnectionUrl(options.db)\n\t\t});\n\t\tconst header = formatStyledHeader({\n\t\t\tcommand: \"db sign\",\n\t\t\tdescription: \"Sign the database with your contract so you can safely run queries\",\n\t\t\turl: \"https://pris.ly/db-sign\",\n\t\t\tdetails,\n\t\t\tflags\n\t\t});\n\t\tui.stderr(header);\n\t}\n\tlet contractJson;\n\tif (effectiveContractArg) try {\n\t\tconst { migrationsDir } = resolveMigrationPaths(options.config, config);\n\t\tconst loaded = await buildReadAggregate(config, { migrationsDir });\n\t\tif (!loaded.ok) return notOk(loaded.failure);\n\t\tconst graph = loaded.value.aggregate.app.graph();\n\t\tconst bundles = loaded.value.aggregate.app.packages;\n\t\tconst refs = loaded.value.aggregate.app.refs;\n\t\tconst refResult = parseContractRef(effectiveContractArg, {\n\t\t\tgraph,\n\t\t\trefs\n\t\t});\n\t\tif (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));\n\t\tconst targetHash = refResult.value.hash;\n\t\tif (bundles.find((p) => p.metadata.to === targetHash)) contractJson = await readContractSnapshotJson(migrationsDir, targetHash);\n\t\telse {\n\t\t\tconst defaultRaw = await readFile(contractPathAbsolute, \"utf-8\");\n\t\t\tconst defaultContract = JSON.parse(defaultRaw);\n\t\t\tif (defaultContract[\"storage\"]?.[\"storageHash\"] === targetHash) contractJson = defaultContract;\n\t\t\telse return notOk(errorRuntime(`No contract file found for hash \"${targetHash}\"`, {\n\t\t\t\twhy: `Resolved contract reference \"${effectiveContractArg}\" to hash \"${targetHash}\" but no migration produces that hash and the emitted contract does not match.`,\n\t\t\t\tfix: \"Ensure the target contract exists on disk — either as a migration endpoint or as the emitted contract.json.\"\n\t\t\t}));\n\t\t}\n\t} catch (error) {\n\t\tif (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n\t\tif (error instanceof CliStructuredError) return notOk(error);\n\t\treturn notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to resolve contract reference: ${error instanceof Error ? error.message : String(error)}` }));\n\t}\n\telse {\n\t\tlet contractJsonContent;\n\t\ttry {\n\t\t\tcontractJsonContent = await readFile(contractPathAbsolute, \"utf-8\");\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.code === \"ENOENT\") return notOk(errorFileNotFound(contractPathAbsolute, {\n\t\t\t\twhy: `Contract file not found at ${contractPathAbsolute}`,\n\t\t\t\tfix: `Run \\`prisma-next contract emit\\` to generate ${contractPath}, or update \\`config.contract.output\\` in ${configPath}`\n\t\t\t}));\n\t\t\treturn notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}` }));\n\t\t}\n\t\ttry {\n\t\t\tcontractJson = JSON.parse(contractJsonContent);\n\t\t} catch (error) {\n\t\t\treturn notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path: contractPathAbsolute } }));\n\t\t}\n\t}\n\tconst dbConnection = options.db ?? config.db?.connection;\n\tif (!dbConnection) return notOk(errorDatabaseConnectionRequired({\n\t\twhy: `Database connection is required for db sign (set db.connection in ${configPath}, or pass --db <url>)`,\n\t\tcommandName: \"db sign\"\n\t}));\n\tif (!config.driver) return notOk(errorDriverRequired({ why: \"Config.driver is required for db sign\" }));\n\tconst client = createControlClient({\n\t\tfamily: config.family,\n\t\ttarget: config.target,\n\t\tadapter: config.adapter,\n\t\tdriver: config.driver,\n\t\textensions: config.extensions ?? []\n\t});\n\tconst onProgress = createProgressAdapter({\n\t\tui,\n\t\tflags\n\t});\n\ttry {\n\t\tconst schemaVerifyResult = await client.schemaVerify({\n\t\t\tcontract: contractJson,\n\t\t\tstrict: false,\n\t\t\tconnection: dbConnection,\n\t\t\tonProgress\n\t\t});\n\t\tif (!schemaVerifyResult.ok) return notOk(schemaVerifyResult);\n\t\treturn ok(await client.sign({\n\t\t\tcontract: contractJson,\n\t\t\tcontractPath,\n\t\t\tconfigPath,\n\t\t\tonProgress\n\t\t}));\n\t} catch (error) {\n\t\tif (error instanceof CliStructuredError) return notOk(error);\n\t\tif (isStructuredError(error) && error.code === \"CONTRACT.VALIDATION_FAILED\") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));\n\t\treturn notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Unexpected error during db sign: ${error instanceof Error ? error.message : String(error)}` }));\n\t} finally {\n\t\tawait client.close();\n\t}\n}\nfunction createDbSignCommand() {\n\tconst command = new Command(\"sign\");\n\tsetCommandDescriptions(command, \"Sign the database with your contract so you can safely run queries\", \"Verifies that your database schema satisfies the emitted contract, and if so, writes or\\nupdates the database signature. This command is idempotent and safe to run\\nin CI/deployment pipelines. The signature records that this database instance is aligned\\nwith a specific contract version.\");\n\tsetCommandExamples(command, [\n\t\t\"prisma-next db sign --db $DATABASE_URL\",\n\t\t\"prisma-next db sign production --db $DATABASE_URL\",\n\t\t\"prisma-next db sign --contract production --db $DATABASE_URL\"\n\t]);\n\taddGlobalOptions(command).argument(\"[contract]\", \"Contract reference (hash, prefix, ref name, or migration dir name)\").option(\"--db <url>\", \"Database connection string\").option(\"--config <path>\", \"Path to prisma-next.config.ts\").option(\"--contract <contract>\", \"Contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)\").action(async (positionalContract, options) => {\n\t\tconst flags = parseGlobalFlagsOrExit(options);\n\t\tif (positionalContract && options.contract) {\n\t\t\tprocess.stderr.write(\"Cannot specify both a positional contract argument and --contract flag.\\n\");\n\t\t\tprocess.exit(2);\n\t\t\treturn;\n\t\t}\n\t\tconst ui = createTerminalUI(flags);\n\t\tconst result = await executeDbSignCommand(positionalContract, options, flags, ui);\n\t\tif (result.ok) {\n\t\t\tif (flags.json) ui.output(formatSignJson(result.value));\n\t\t\telse {\n\t\t\t\tconst output = formatSignOutput(result.value, flags);\n\t\t\t\tif (output) ui.log(output);\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t}\n\t\tconst failure = result.failure;\n\t\tif (failure instanceof CliStructuredError) {\n\t\t\tconst exitCode = handleResult(result, flags, ui);\n\t\t\tprocess.exit(exitCode);\n\t\t}\n\t\tif (flags.json) ui.output(formatSchemaVerifyJson(failure));\n\t\telse {\n\t\t\tconst output = formatSchemaVerifyOutput(failure, flags);\n\t\t\tif (output) ui.log(output);\n\t\t}\n\t\tprocess.exit(1);\n\t});\n\treturn command;\n}\n//#endregion\nexport { createDbSignCommand };\n\n//# sourceMappingURL=db-sign.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,eAAe,qBAAqB,aAAa,SAAS,OAAO,IAAI;CACpE,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,aAAa,QAAQ,SAAS,SAAS,QAAQ,IAAI,GAAG,QAAQ,QAAQ,MAAM,CAAC,IAAI;CACvF,MAAM,uBAAuB,oBAAoB,MAAM;CACvD,MAAM,eA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ACA,MAAM,KAAK,iBAAiB,KAAK;EACjC,MAAM,SAAS,MAAM,qBAAqB,oBAAoB,SAAS,OAAO,EAAE;EAChF,IAAI,OAAO,IAAI;GACd,IAAI,MAAM,MAAM,GAAG,OAAO,eAAe,OAAO,KAAK,CAAC;QACjD;IACJ,MAAM,SAAS,iBAAiB,OAAO,OAAO,KAAK;IACnD,IAAI,QAAQ,GAAG,IAAI,MAAM;GAC1B;GACA,QAAQ,KAAK,CAAC;EACf;EACA,MAAM,UAAU,OAAO;EACvB,IAAI,mBAAmBA,sBAAoB;GAC1C,MAAM,WAAW,aAAa,QAAQ,OAAO,EAAE;GAC/C,QAAQ,KAAK,QAAQ;EACtB;EACA,IAAI,MAAM,MAAM,GAAG,OAAO,uBAAuB,OAAO,CAAC;OACpD;GACJ,MAAM,SAAS,yBAAyB,SAAS,KAAK;GACtD,IAAI,QAAQ,GAAG,IAAI,MAAM;EAC1B;EACA,QAAQ,KAAK,CAAC;CACf,CAAC;CACD,OAAO;AACR"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { t as MigrationToolsError } from "./errors-IpZm1Skp-BH495dRd.mjs";
|
|
2
|
+
import { r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-sf5nP4mb-MLpG-ihh.mjs";
|
|
3
|
+
import { B as formatMigrationJson, D as errorRunnerFailed, N as errorUnexpected, Q as mapRefResolutionError, V as formatMigrationPlanOutput, Z as mapMigrationToolsError, at as resolveMigrationPaths, ct as setCommandExamples, d as errorContractValidationFailed, n as ERROR_CODE_DESTRUCTIVE_CHANGES, o as createTerminalUI, ot as sanitizeErrorMessage, p as errorDestructiveChanges, q as handleResult, st as setCommandDescriptions, t as CliStructuredError$1, tt as parseGlobalFlagsOrExit, x as errorMigrationPlanningFailed, z as formatMigrationApplyOutput } from "./command-helpers-CAoXqAY9-DWUBcTXM.mjs";
|
|
4
|
+
import { n as buildReadAggregate } from "./contract-space-aggregate-loader-CFH-336b-BhAyRQEL.mjs";
|
|
5
|
+
import { n as prepareMigrationContext, t as addMigrationCommandOptions } from "./migration-command-scaffold-BCuoeAki-B1pVGX8d.mjs";
|
|
6
|
+
import { i as readContractIR, n as computeRefAdvancementName, t as buildRefAdvancementFields } from "./ref-advancement-CSPMoQs3-fEipZrdu.mjs";
|
|
7
|
+
import { n as parseContractRef } from "./ref-resolution-BjJBWPjX.mjs";
|
|
8
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
9
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
10
|
+
import { join } from "pathe";
|
|
11
|
+
import { assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
12
|
+
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
//#region ../../../1-framework/3-tooling/cli/dist/commands/db-update.mjs
|
|
15
|
+
/**
|
|
16
|
+
* Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.
|
|
17
|
+
*/
|
|
18
|
+
function mapDbUpdateFailure(failure) {
|
|
19
|
+
if (failure.code === "PLANNING_FAILED") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });
|
|
20
|
+
if (failure.code === "RUNNER_FAILED") {
|
|
21
|
+
const fix = (typeof failure.meta?.["runnerErrorCode"] === "string" ? failure.meta["runnerErrorCode"] : void 0) === "MIGRATION.LEGACY_MARKER_SHAPE" ? "Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `prisma-next db init` to recreate it with the current per-space schema." : "Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`";
|
|
22
|
+
return errorRunnerFailed(failure.summary, {
|
|
23
|
+
why: failure.why ?? "Migration runner failed",
|
|
24
|
+
fix,
|
|
25
|
+
meta: {
|
|
26
|
+
...failure.meta,
|
|
27
|
+
...failure.warnings && failure.warnings.length > 0 ? { plannerWarnings: failure.warnings } : {}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (failure.code === "DESTRUCTIVE_CHANGES") return errorDestructiveChanges(failure.summary, {
|
|
32
|
+
...ifDefined("why", failure.why),
|
|
33
|
+
fix: "Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first",
|
|
34
|
+
...ifDefined("meta", failure.meta)
|
|
35
|
+
});
|
|
36
|
+
const exhaustive = failure.code;
|
|
37
|
+
return assertNever(exhaustive, `Unhandled DbUpdateFailure code: ${String(exhaustive)}`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Executes the db update command and returns a structured Result.
|
|
41
|
+
*/
|
|
42
|
+
async function executeDbUpdateCommand(options, flags, ui, startTime) {
|
|
43
|
+
const ctxResult = await prepareMigrationContext(options, flags, ui, {
|
|
44
|
+
commandName: "db update",
|
|
45
|
+
description: "Update your database schema to match your contract",
|
|
46
|
+
url: "https://pris.ly/db-update"
|
|
47
|
+
});
|
|
48
|
+
if (!ctxResult.ok) return ctxResult;
|
|
49
|
+
const { client, config, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
|
|
50
|
+
let { contractJson } = ctxResult.value;
|
|
51
|
+
let contractJsonPathForSnapshot = contractPathAbsolute;
|
|
52
|
+
const { migrationsDir, refsDir } = resolveMigrationPaths(options.config, config);
|
|
53
|
+
if (options.to) try {
|
|
54
|
+
const loaded = await buildReadAggregate(config, { migrationsDir });
|
|
55
|
+
if (!loaded.ok) return notOk(loaded.failure);
|
|
56
|
+
const graph = loaded.value.aggregate.app.graph();
|
|
57
|
+
const bundles = loaded.value.aggregate.app.packages;
|
|
58
|
+
const refs = loaded.value.aggregate.app.refs;
|
|
59
|
+
const refResult = parseContractRef(options.to, {
|
|
60
|
+
graph,
|
|
61
|
+
refs
|
|
62
|
+
});
|
|
63
|
+
if (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));
|
|
64
|
+
const targetHash = refResult.value.hash;
|
|
65
|
+
if (!bundles.find((p) => p.metadata.to === targetHash)) return notOk(errorUnexpected(`No migration bundle found for --to "${options.to}" (resolved hash: ${targetHash})`, {
|
|
66
|
+
why: `The ref resolved successfully but no on-disk migration package has a destination (\`to\`) hash matching ${targetHash}.`,
|
|
67
|
+
fix: "Provide a ref or hash that corresponds to an existing migration package, or run `migration list` to see available migrations."
|
|
68
|
+
}));
|
|
69
|
+
contractJson = await readContractSnapshotJson(migrationsDir, targetHash);
|
|
70
|
+
contractJsonPathForSnapshot = join(contractSnapshotDir(migrationsDir, targetHash), "contract.json");
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
73
|
+
if (CliStructuredError$1.is(error)) return notOk(error);
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
await client.connect(dbConnection);
|
|
78
|
+
const result = await client.dbUpdate({
|
|
79
|
+
contract: contractJson,
|
|
80
|
+
mode: options.dryRun ? "plan" : "apply",
|
|
81
|
+
migrationsDir,
|
|
82
|
+
...flags.yes ? { acceptDataLoss: true } : {},
|
|
83
|
+
onProgress
|
|
84
|
+
});
|
|
85
|
+
if (!result.ok) return notOk(mapDbUpdateFailure(result.failure));
|
|
86
|
+
const advancementHash = result.value.mode === "apply" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;
|
|
87
|
+
let refAdvancementFields = {
|
|
88
|
+
advancedRef: null,
|
|
89
|
+
plannedAdvanceRef: null
|
|
90
|
+
};
|
|
91
|
+
if (computeRefAdvancementName({
|
|
92
|
+
...ifDefined("advanceRef", options.advanceRef),
|
|
93
|
+
...ifDefined("db", options.db)
|
|
94
|
+
}) !== null) try {
|
|
95
|
+
const contractIR = await readContractIR(contractJson, contractJsonPathForSnapshot);
|
|
96
|
+
refAdvancementFields = await buildRefAdvancementFields({
|
|
97
|
+
...ifDefined("advanceRef", options.advanceRef),
|
|
98
|
+
...ifDefined("db", options.db),
|
|
99
|
+
refsDir,
|
|
100
|
+
migrationsDir,
|
|
101
|
+
contractIR,
|
|
102
|
+
mode: result.value.mode,
|
|
103
|
+
hash: advancementHash
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
return ok({
|
|
110
|
+
ok: true,
|
|
111
|
+
mode: result.value.mode,
|
|
112
|
+
plan: {
|
|
113
|
+
targetId: ctxResult.value.config.target.targetId,
|
|
114
|
+
destination: {
|
|
115
|
+
storageHash: result.value.destination.storageHash,
|
|
116
|
+
...ifDefined("profileHash", result.value.destination.profileHash)
|
|
117
|
+
},
|
|
118
|
+
operations: result.value.plan.operations.map((op) => ({
|
|
119
|
+
id: op.id,
|
|
120
|
+
label: op.label,
|
|
121
|
+
operationClass: op.operationClass
|
|
122
|
+
})),
|
|
123
|
+
...ifDefined("preview", result.value.plan.preview)
|
|
124
|
+
},
|
|
125
|
+
...ifDefined("execution", result.value.execution ? {
|
|
126
|
+
operationsPlanned: result.value.execution.operationsPlanned,
|
|
127
|
+
operationsExecuted: result.value.execution.operationsExecuted
|
|
128
|
+
} : void 0),
|
|
129
|
+
...ifDefined("marker", result.value.marker ? {
|
|
130
|
+
storageHash: result.value.marker.storageHash,
|
|
131
|
+
...ifDefined("profileHash", result.value.marker.profileHash)
|
|
132
|
+
} : void 0),
|
|
133
|
+
...ifDefined("perSpace", result.value.perSpace),
|
|
134
|
+
...ifDefined("warnings", result.value.warnings),
|
|
135
|
+
advancedRef: refAdvancementFields.advancedRef,
|
|
136
|
+
plannedAdvanceRef: refAdvancementFields.plannedAdvanceRef,
|
|
137
|
+
summary: result.value.summary,
|
|
138
|
+
timings: { total: Date.now() - startTime }
|
|
139
|
+
});
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (CliStructuredError$1.is(error)) return notOk(error);
|
|
142
|
+
if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
|
|
143
|
+
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
144
|
+
return notOk(errorUnexpected(safeMessage, { why: `Unexpected error during db update: ${safeMessage}` }));
|
|
145
|
+
} finally {
|
|
146
|
+
await client.close();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function createDbUpdateCommand() {
|
|
150
|
+
const command = new Command("update");
|
|
151
|
+
setCommandDescriptions(command, "Update your database schema to match your contract", "Compares your database schema to the emitted contract and applies the necessary\nchanges. Works on any database, whether or not it has been initialized with `db init`.\nDestructive operations prompt for confirmation in interactive mode. Use -y to\nauto-accept or --dry-run to preview first.");
|
|
152
|
+
setCommandExamples(command, ["prisma-next db update --db $DATABASE_URL", "prisma-next db update --db $DATABASE_URL --dry-run"]);
|
|
153
|
+
addMigrationCommandOptions(command);
|
|
154
|
+
command.option("--to <contract>", "Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)");
|
|
155
|
+
command.option("--advance-ref <name>", "Ref to advance to the post-command contract hash");
|
|
156
|
+
command.action(async (options) => {
|
|
157
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
158
|
+
const startTime = Date.now();
|
|
159
|
+
const ui = createTerminalUI(flags);
|
|
160
|
+
let result = await executeDbUpdateCommand(options, flags, ui, startTime);
|
|
161
|
+
if (!result.ok && result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES && flags.interactive && !flags.json && !flags.yes) {
|
|
162
|
+
const destructiveOps = result.failure.meta?.destructiveOperations ?? [];
|
|
163
|
+
if (destructiveOps.length > 0) ui.warn(`${destructiveOps.length} destructive operation(s) that may cause data loss:\n${destructiveOps.map((op) => ` ${ui.yellow("▸")} ${op.label}`).join("\n")}`);
|
|
164
|
+
if (await ui.confirm("Apply destructive changes? This cannot be undone.")) result = await executeDbUpdateCommand(options, {
|
|
165
|
+
...flags,
|
|
166
|
+
yes: true
|
|
167
|
+
}, ui, Date.now());
|
|
168
|
+
}
|
|
169
|
+
const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {
|
|
170
|
+
if (flags.json) ui.output(formatMigrationJson(dbUpdateResult));
|
|
171
|
+
else {
|
|
172
|
+
const output = dbUpdateResult.mode === "plan" ? formatMigrationPlanOutput(dbUpdateResult, flags) : formatMigrationApplyOutput(dbUpdateResult, flags);
|
|
173
|
+
if (output) ui.log(output);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
process.exit(exitCode);
|
|
177
|
+
});
|
|
178
|
+
return command;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
export { createDbUpdateCommand as t };
|
|
182
|
+
|
|
183
|
+
//# sourceMappingURL=db-update-BQlrqtDD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-update-BQlrqtDD.mjs","names":["CliStructuredError"],"sources":["../../../../1-framework/3-tooling/cli/dist/commands/db-update.mjs"],"sourcesContent":["import { B as errorContractValidationFailed, C as formatMigrationApplyOutput, F as CliStructuredError, H as errorDestructiveChanges, I as ERROR_CODE_DESTRUCTIVE_CHANGES, T as formatMigrationPlanOutput, X as errorMigrationPlanningFailed, _ as createTerminalUI, c as sanitizeErrorMessage, ct as errorUnexpected, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, lt as mapMigrationToolsError, nt as errorRunnerFailed, s as resolveMigrationPaths, u as setCommandExamples, ut as mapRefResolutionError, w as formatMigrationJson, y as handleResult } from \"../command-helpers-CAoXqAY9.mjs\";\nimport { n as buildReadAggregate } from \"../contract-space-aggregate-loader-CFH-336b.mjs\";\nimport { n as prepareMigrationContext, t as addMigrationCommandOptions } from \"../migration-command-scaffold-BCuoeAki.mjs\";\nimport { i as readContractIR, n as computeRefAdvancementName, t as buildRefAdvancementFields } from \"../ref-advancement-CSPMoQs3.mjs\";\nimport { Command } from \"commander\";\nimport { ifDefined } from \"@internal/utils/defined\";\nimport { notOk, ok } from \"@internal/utils/result\";\nimport { join } from \"pathe\";\nimport { assertNever } from \"@internal/utils/internal-error\";\nimport { isStructuredError } from \"@internal/utils/structured-error\";\nimport { MigrationToolsError } from \"@internal/migration-tools/errors\";\nimport { contractSnapshotDir, readContractSnapshotJson } from \"@internal/migration-tools/contract-snapshot-store\";\nimport { parseContractRef } from \"@internal/migration-tools/ref-resolution\";\n//#region src/commands/db-update.ts\n/**\n* Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.\n*/\nfunction mapDbUpdateFailure(failure) {\n\tif (failure.code === \"PLANNING_FAILED\") return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });\n\tif (failure.code === \"RUNNER_FAILED\") {\n\t\tconst fix = (typeof failure.meta?.[\"runnerErrorCode\"] === \"string\" ? failure.meta[\"runnerErrorCode\"] : void 0) === \"MIGRATION.LEGACY_MARKER_SHAPE\" ? \"Legacy marker-table shape detected. Drop `prisma_contract.marker` (Postgres) or `_prisma_marker` (SQLite) and re-run `prisma-next db init` to recreate it with the current per-space schema.\" : \"Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`\";\n\t\treturn errorRunnerFailed(failure.summary, {\n\t\t\twhy: failure.why ?? \"Migration runner failed\",\n\t\t\tfix,\n\t\t\tmeta: {\n\t\t\t\t...failure.meta,\n\t\t\t\t...failure.warnings && failure.warnings.length > 0 ? { plannerWarnings: failure.warnings } : {}\n\t\t\t}\n\t\t});\n\t}\n\tif (failure.code === \"DESTRUCTIVE_CHANGES\") return errorDestructiveChanges(failure.summary, {\n\t\t...ifDefined(\"why\", failure.why),\n\t\tfix: \"Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first\",\n\t\t...ifDefined(\"meta\", failure.meta)\n\t});\n\tconst exhaustive = failure.code;\n\treturn assertNever(exhaustive, `Unhandled DbUpdateFailure code: ${String(exhaustive)}`);\n}\n/**\n* Executes the db update command and returns a structured Result.\n*/\nasync function executeDbUpdateCommand(options, flags, ui, startTime) {\n\tconst ctxResult = await prepareMigrationContext(options, flags, ui, {\n\t\tcommandName: \"db update\",\n\t\tdescription: \"Update your database schema to match your contract\",\n\t\turl: \"https://pris.ly/db-update\"\n\t});\n\tif (!ctxResult.ok) return ctxResult;\n\tconst { client, config, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;\n\tlet { contractJson } = ctxResult.value;\n\tlet contractJsonPathForSnapshot = contractPathAbsolute;\n\tconst { migrationsDir, refsDir } = resolveMigrationPaths(options.config, config);\n\tif (options.to) try {\n\t\tconst loaded = await buildReadAggregate(config, { migrationsDir });\n\t\tif (!loaded.ok) return notOk(loaded.failure);\n\t\tconst graph = loaded.value.aggregate.app.graph();\n\t\tconst bundles = loaded.value.aggregate.app.packages;\n\t\tconst refs = loaded.value.aggregate.app.refs;\n\t\tconst refResult = parseContractRef(options.to, {\n\t\t\tgraph,\n\t\t\trefs\n\t\t});\n\t\tif (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));\n\t\tconst targetHash = refResult.value.hash;\n\t\tif (!bundles.find((p) => p.metadata.to === targetHash)) return notOk(errorUnexpected(`No migration bundle found for --to \"${options.to}\" (resolved hash: ${targetHash})`, {\n\t\t\twhy: `The ref resolved successfully but no on-disk migration package has a destination (\\`to\\`) hash matching ${targetHash}.`,\n\t\t\tfix: \"Provide a ref or hash that corresponds to an existing migration package, or run `migration list` to see available migrations.\"\n\t\t}));\n\t\tcontractJson = await readContractSnapshotJson(migrationsDir, targetHash);\n\t\tcontractJsonPathForSnapshot = join(contractSnapshotDir(migrationsDir, targetHash), \"contract.json\");\n\t} catch (error) {\n\t\tif (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\tthrow error;\n\t}\n\ttry {\n\t\tawait client.connect(dbConnection);\n\t\tconst result = await client.dbUpdate({\n\t\t\tcontract: contractJson,\n\t\t\tmode: options.dryRun ? \"plan\" : \"apply\",\n\t\t\tmigrationsDir,\n\t\t\t...flags.yes ? { acceptDataLoss: true } : {},\n\t\t\tonProgress\n\t\t});\n\t\tif (!result.ok) return notOk(mapDbUpdateFailure(result.failure));\n\t\tconst advancementHash = result.value.mode === \"apply\" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;\n\t\tlet refAdvancementFields = {\n\t\t\tadvancedRef: null,\n\t\t\tplannedAdvanceRef: null\n\t\t};\n\t\tif (computeRefAdvancementName({\n\t\t\t...ifDefined(\"advanceRef\", options.advanceRef),\n\t\t\t...ifDefined(\"db\", options.db)\n\t\t}) !== null) try {\n\t\t\tconst contractIR = await readContractIR(contractJson, contractJsonPathForSnapshot);\n\t\t\trefAdvancementFields = await buildRefAdvancementFields({\n\t\t\t\t...ifDefined(\"advanceRef\", options.advanceRef),\n\t\t\t\t...ifDefined(\"db\", options.db),\n\t\t\t\trefsDir,\n\t\t\t\tmigrationsDir,\n\t\t\t\tcontractIR,\n\t\t\t\tmode: result.value.mode,\n\t\t\t\thash: advancementHash\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n\t\t\tthrow error;\n\t\t}\n\t\treturn ok({\n\t\t\tok: true,\n\t\t\tmode: result.value.mode,\n\t\t\tplan: {\n\t\t\t\ttargetId: ctxResult.value.config.target.targetId,\n\t\t\t\tdestination: {\n\t\t\t\t\tstorageHash: result.value.destination.storageHash,\n\t\t\t\t\t...ifDefined(\"profileHash\", result.value.destination.profileHash)\n\t\t\t\t},\n\t\t\t\toperations: result.value.plan.operations.map((op) => ({\n\t\t\t\t\tid: op.id,\n\t\t\t\t\tlabel: op.label,\n\t\t\t\t\toperationClass: op.operationClass\n\t\t\t\t})),\n\t\t\t\t...ifDefined(\"preview\", result.value.plan.preview)\n\t\t\t},\n\t\t\t...ifDefined(\"execution\", result.value.execution ? {\n\t\t\t\toperationsPlanned: result.value.execution.operationsPlanned,\n\t\t\t\toperationsExecuted: result.value.execution.operationsExecuted\n\t\t\t} : void 0),\n\t\t\t...ifDefined(\"marker\", result.value.marker ? {\n\t\t\t\tstorageHash: result.value.marker.storageHash,\n\t\t\t\t...ifDefined(\"profileHash\", result.value.marker.profileHash)\n\t\t\t} : void 0),\n\t\t\t...ifDefined(\"perSpace\", result.value.perSpace),\n\t\t\t...ifDefined(\"warnings\", result.value.warnings),\n\t\t\tadvancedRef: refAdvancementFields.advancedRef,\n\t\t\tplannedAdvanceRef: refAdvancementFields.plannedAdvanceRef,\n\t\t\tsummary: result.value.summary,\n\t\t\ttimings: { total: Date.now() - startTime }\n\t\t});\n\t} catch (error) {\n\t\tif (CliStructuredError.is(error)) return notOk(error);\n\t\tif (isStructuredError(error) && error.code === \"CONTRACT.VALIDATION_FAILED\") return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));\n\t\tconst safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === \"string\" ? dbConnection : void 0);\n\t\treturn notOk(errorUnexpected(safeMessage, { why: `Unexpected error during db update: ${safeMessage}` }));\n\t} finally {\n\t\tawait client.close();\n\t}\n}\nfunction createDbUpdateCommand() {\n\tconst command = new Command(\"update\");\n\tsetCommandDescriptions(command, \"Update your database schema to match your contract\", \"Compares your database schema to the emitted contract and applies the necessary\\nchanges. Works on any database, whether or not it has been initialized with `db init`.\\nDestructive operations prompt for confirmation in interactive mode. Use -y to\\nauto-accept or --dry-run to preview first.\");\n\tsetCommandExamples(command, [\"prisma-next db update --db $DATABASE_URL\", \"prisma-next db update --db $DATABASE_URL --dry-run\"]);\n\taddMigrationCommandOptions(command);\n\tcommand.option(\"--to <contract>\", \"Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)\");\n\tcommand.option(\"--advance-ref <name>\", \"Ref to advance to the post-command contract hash\");\n\tcommand.action(async (options) => {\n\t\tconst flags = parseGlobalFlagsOrExit(options);\n\t\tconst startTime = Date.now();\n\t\tconst ui = createTerminalUI(flags);\n\t\tlet result = await executeDbUpdateCommand(options, flags, ui, startTime);\n\t\tif (!result.ok && result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES && flags.interactive && !flags.json && !flags.yes) {\n\t\t\tconst destructiveOps = result.failure.meta?.destructiveOperations ?? [];\n\t\t\tif (destructiveOps.length > 0) ui.warn(`${destructiveOps.length} destructive operation(s) that may cause data loss:\\n${destructiveOps.map((op) => ` ${ui.yellow(\"▸\")} ${op.label}`).join(\"\\n\")}`);\n\t\t\tif (await ui.confirm(\"Apply destructive changes? This cannot be undone.\")) result = await executeDbUpdateCommand(options, {\n\t\t\t\t...flags,\n\t\t\t\tyes: true\n\t\t\t}, ui, Date.now());\n\t\t}\n\t\tconst exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {\n\t\t\tif (flags.json) ui.output(formatMigrationJson(dbUpdateResult));\n\t\t\telse {\n\t\t\t\tconst output = dbUpdateResult.mode === \"plan\" ? formatMigrationPlanOutput(dbUpdateResult, flags) : formatMigrationApplyOutput(dbUpdateResult, flags);\n\t\t\t\tif (output) ui.log(output);\n\t\t\t}\n\t\t});\n\t\tprocess.exit(exitCode);\n\t});\n\treturn command;\n}\n//#endregion\nexport { createDbUpdateCommand };\n\n//# sourceMappingURL=db-update.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAS,mBAAmB,SAAS;CACpC,IAAI,QAAQ,SAAS,mBAAmB,OAAO,6BAA6B,EAAE,WAAW,QAAQ,aAAa,CAAC,EAAE,CAAC;CAClH,IAAI,QAAQ,SAAS,iBAAiB;EACrC,MAAM,OAAO,OAAO,QAAQ,OAAO,uBAAuB,WAAW,QAAQ,KAAK,qBAAqB,KAAK,OAAO,kCAAkC,iMAAiM;EACtV,OAAO,kBAAkB,QAAQ,SAAS;GACzC,KAAK,QAAQ,OAAO;GACpB;GACA,MAAM;IACL,GAAG,QAAQ;IACX,GAAG,QAAQ,YAAY,QAAQ,SAAS,SAAS,IAAI,EAAE,iBAAiB,QAAQ,SAAS,IAAI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