@vrplatform/kysely 1.3.45-4447 → 1.3.45-44494530923
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/build/.data.tar +2 -2
- package/build/main/camel-case/index.d.ts +4 -4
- package/build/main/camel-case/index.js +3 -2
- package/build/main/camel-case/index.js.map +1 -1
- package/build/main/connect-handoff.d.ts +12 -0
- package/build/main/connect-handoff.js +73 -0
- package/build/main/connect-handoff.js.map +1 -0
- package/build/main/control-plane/index.d.ts +421 -14
- package/build/main/control-plane/index.js +71 -0
- package/build/main/control-plane/index.js.map +1 -1
- package/build/main/domain.d.ts +4 -0
- package/build/main/domain.js +3 -0
- package/build/main/domain.js.map +1 -0
- package/build/main/error.d.ts +2 -1
- package/build/main/error.js +2 -1
- package/build/main/error.js.map +1 -1
- package/build/main/index.d.ts +57 -15
- package/build/main/index.js +498 -66
- package/build/main/index.js.map +1 -1
- package/build/main/isomorphic.d.ts +6 -6
- package/build/main/isomorphic.js +4 -8
- package/build/main/isomorphic.js.map +1 -1
- package/build/main/local/digest.d.ts +3 -3
- package/build/main/local/digest.js.map +1 -1
- package/build/main/local/generate.js +15 -13
- package/build/main/local/generate.js.map +1 -1
- package/build/main/local/index.d.ts +5 -1
- package/build/main/local/index.js +346 -12
- package/build/main/local/index.js.map +1 -1
- package/build/main/local/prune-pulled-schema.js +4 -1
- package/build/main/local/prune-pulled-schema.js.map +1 -1
- package/build/main/migration-source.d.ts +4 -0
- package/build/main/migration-source.js +45 -0
- package/build/main/migration-source.js.map +1 -0
- package/build/main/migration.d.ts +7 -0
- package/build/main/migration.js +11 -0
- package/build/main/migration.js.map +1 -0
- package/build/main/pganalyze-comment-plugin/comment-transformer.js +3 -1
- package/build/main/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/main/pganalyze-comment-plugin/index.js.map +1 -1
- package/build/main/plugins.d.ts +2 -2
- package/build/main/plugins.js.map +1 -1
- package/build/main/postgres-error.d.ts +9 -0
- package/build/main/postgres-error.js +28 -0
- package/build/main/postgres-error.js.map +1 -0
- package/build/main/query/index.d.ts +1 -0
- package/build/main/query/index.js +1 -0
- package/build/main/query/index.js.map +1 -1
- package/build/main/query/listing/status.d.ts +2 -12
- package/build/main/query/listing/status.js +35 -20
- package/build/main/query/listing/status.js.map +1 -1
- package/build/main/query/tenant/billing-partner.d.ts +4 -0
- package/build/main/query/tenant/billing-partner.js +8 -0
- package/build/main/query/tenant/billing-partner.js.map +1 -0
- package/build/main/query/tenant/feature-enabled.d.ts +6 -0
- package/build/main/query/tenant/feature-enabled.js +30 -0
- package/build/main/query/tenant/feature-enabled.js.map +1 -0
- package/build/main/query/tenant/index.d.ts +4 -0
- package/build/main/query/tenant/index.js +21 -0
- package/build/main/query/tenant/index.js.map +1 -0
- package/build/main/query/tenant/status.d.ts +9 -0
- package/build/main/query/tenant/status.js +32 -0
- package/build/main/query/tenant/status.js.map +1 -0
- package/build/main/query/tenant/where-uuid-in.d.ts +2 -0
- package/build/main/query/tenant/where-uuid-in.js +14 -0
- package/build/main/query/tenant/where-uuid-in.js.map +1 -0
- package/build/main/regional.d.ts +31 -4
- package/build/main/regional.js +69 -8
- package/build/main/regional.js.map +1 -1
- package/build/main/test/index.d.ts +21 -11
- package/build/main/test/index.js +31 -26
- package/build/main/test/index.js.map +1 -1
- package/build/main/transaction.d.ts +3 -3
- package/build/main/transaction.js.map +1 -1
- package/build/main/v1.generated.d.ts +1407 -177
- package/build/main/v1.generated.js.map +1 -1
- package/build/migrations-v2/0000000000000-baseline.ts +5 -0
- package/build/migrations-v2/0000000000001-public-audit-events-v2.ts +137 -0
- package/build/migrations-v2/0000000000002-audit-recovery-watermarks.ts +30 -0
- package/build/migrations-v2/0000000000003-audit-effect-recovery-watermark.ts +13 -0
- package/build/migrations-v2/0000000000004-audit-event-projected-at.ts +15 -0
- package/build/migrations-v2/0000000000005-audit-recovery-indexes.ts +63 -0
- package/build/migrations-v2/0000000000006-audit-action-public-event-projected-at.ts +22 -0
- package/build/migrations-v2/0000000000007-audit-action-public-event-projected-at-backfill.ts +35 -0
- package/build/migrations-v2/0000000000008-global-user-attribution.ts +33 -0
- package/build/migrations-v2/0000000000008-team-issue-rule-state.ts +52 -0
- package/build/migrations-v2/0000000000009-reservation-issue-projections.ts +45 -0
- package/build/migrations-v2/0000000000010-bank-rule-application-bank-record-delete-cascade.ts +26 -0
- package/build/migrations-v2/0000000000011-guest-balance-journal-entry-lookup-index.ts +25 -0
- package/build/migrations-v2/0000000000012-trial-free-analytics-billing-status.ts +72 -0
- package/build/migrations-v2/0000000000013-ui-permission-bundles.ts +45 -0
- package/build/migrations-v2/0000000000014-ui-permission-bundle-top-up.ts +32 -0
- package/build/migrations-v2/0000000000015-durable-flow-events.ts +163 -0
- package/build/migrations-v2/0000000000016-billing-listing-facts.ts +539 -0
- package/build/migrations-v2/0000000000016-managed-team-access.ts +34 -0
- package/build/migrations-v2/0000000000017-drop-trial-until.ts +42 -0
- package/build/migrations-v2/0000000000017-webhook-secret-reencryption-failures.ts +18 -0
- package/build/migrations-v2/0000000000018-accounting-integrity-monitoring.ts +276 -0
- package/build/migrations-v2/0000000000018-durable-flow-event-sensitive-input.ts +28 -0
- package/build/migrations-v2/0000000000019-accounting-integrity-run-shards.ts +26 -0
- package/build/migrations-v2/0000000000019-asynchronous-operations.ts +736 -0
- package/build/migrations-v2/0000000000020-accounting-integrity-case-classification.ts +52 -0
- package/build/migrations-v2/0000000000021-payment-line-classification-monitor-indexes.ts +31 -0
- package/build/migrations-v2/0000000000022-accounting-integrity-controlled-repairs.ts +281 -0
- package/build/migrations-v2/0000000000023-line-classification-usage.ts +325 -0
- package/build/migrations-v2/0000000000024-tenant-region-migration.ts +108 -0
- package/build/migrations-v2/0000000000025-partner-ach-denial-default.ts +30 -0
- package/build/migrations-v2/0000000000026-line-classification-usage-capture.ts +399 -0
- package/build/migrations-v2/0000000000027-payout-replacement-chain.ts +27 -0
- package/build/migrations-v2/0000000000028-accounting-integrity-operator-workflow.ts +108 -0
- package/build/migrations-v2/0000000000029-accounting-integrity-definition-artifacts.ts +40 -0
- package/build/migrations-v2/0000000000030-accounting-integrity-review-metadata-compatibility.ts +49 -0
- package/build/migrations-v2/0000000000031-ui-permission-role-simplification.ts +70 -0
- package/build/migrations-v2/0000000000032-tenant-delete-ownership-cascades.ts +44 -0
- package/build/migrations-v2/0000000000033-plaid-connect-session-telemetry.ts +31 -0
- package/build/migrations-v2/0000000000033-reservation-issue-seed-bucket-index.ts +19 -0
- package/build/migrations-v2/0000000000034-retire-recent-classification-indexes.ts +29 -0
- package/build/migrations-v2/0000000000035-core-change-autovacuum.ts +24 -0
- package/build/migrations-v2/0000000000036-journal-entry-inactive-reason-constraint.ts +33 -0
- package/build/migrations-v2/0000000000037-journal-entry-inactive-reasons.ts +19 -0
- package/build/{migrations/0000000000023-journal-entry-currency-mismatch-reason.ts → migrations-v2/0000000000038-journal-entry-group-inactive-reason.ts} +4 -4
- package/build/migrations-v2/0000000000039-reservation-guest-breakdown.ts +19 -0
- package/build/migrations-v2/0000000000040-csv-import-source-identity-index.ts +23 -0
- package/build/migrations-v2/0000000000041-payment-returns.ts +38 -0
- package/build/migrations-v2/0000000000042-operation-resource-types.ts +609 -0
- package/build/migrations-v2/0000000000043-reservation-journal-freshness.ts +149 -0
- package/build/migrations-v2/0000000000044-reservation-journal-freshness-backfill.ts +254 -0
- package/build/migrations-v2/0000000000045-reservation-journal-freshness-revision-repair.ts +83 -0
- package/build/migrations-v2/0000000000046-materialized-reservation-journal-operations.ts +709 -0
- package/build/migrations-v2/0000000000047-public-audit-completion.ts +77 -0
- package/build/migrations-v2/0000000000048-reservation-journal-full-refresh-repair.ts +136 -0
- package/build/migrations-v2/0000000000049-queued-journal-operation-failures.ts +60 -0
- package/build/migrations-v2/0000000000050-connection-oauth-state.ts +43 -0
- package/build/migrations-v2/0000000000051-owner-statement-email-delivery.ts +134 -0
- package/build/migrations-v2/0000000000052-fee-journal-lock-skip-operations.ts +59 -0
- package/build/migrations-v2/0000000000053-fee-journal-lock-skip-null-attempt.ts +44 -0
- package/build/migrations-v2/0000000000054-journal-refresh-issue-codes.ts +16 -0
- package/build/migrations-v2/0000000000055-tenant-billing-subscription.ts +8 -0
- package/build/migrations-v2/0000000000056-journal-operation-failure-precedence.ts +306 -0
- package/build/migrations-v2/0000000000057-journal-invalidation-failure-code.ts +28 -0
- package/build/migrations-v2/0000000000058-journal-invalidation-locked-failure.ts +16 -0
- package/build/migrations-v2/0000000000059-billing-active-listing-cross-region-partner.ts +135 -0
- package/build/migrations-v2/0000000000060-accounting-integrity-change-driven.ts +99 -0
- package/build/migrations-v2/0000000000061-tenant-pending-onboarding-status.ts +37 -0
- package/build/migrations-v2/0000000000062-statement-payout-operations.ts +16 -0
- package/build/migrations-v2/0000000000063-missing-account-assignments-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000064-journal-invalidation-source-lookup-index.ts +26 -0
- package/build/migrations-v2/0000000000065-hasura-connection-event-credentials.ts +42 -0
- package/build/migrations-v2/0000000000066-recurring-fee-listing-subscription-match-by.ts +51 -0
- package/build/migrations-v2/0000000000067-connection-credential-metadata.ts +60 -0
- package/build/migrations-v2/0000000000068-connection-credential-version.ts +34 -0
- package/build/migrations-v2/0000000000069-owner-statement-contact-email-delivery.ts +84 -0
- package/build/migrations-v2/0000000000070-payment-writer-compatibility.ts +69 -0
- package/build/migrations-v2/0000000000071-payments.ts +532 -0
- package/build/migrations-v2/0000000000072-journal-entry-payment-index.ts +21 -0
- package/build/migrations-v2/0000000000073-batch-invalidation-operation-registration.ts +74 -0
- package/build/migrations-v2/0000000000074-owner-statement-email-history.ts +34 -0
- package/build/migrations-v2/0000000000075-tenant-deletion-lookup-indexes.ts +46 -0
- package/build/migrations-v2/0000000000076-tenant-onboarding-not-null.ts +23 -0
- package/build/migrations-v2/0000000000077-payment-writer-statement-attachment.ts +92 -0
- package/build/migrations-v2/0000000000078-trigger-timeout-indexes.ts +44 -0
- package/build/migrations-v2/0000000000079-core-change-tenant-statistics.ts +26 -0
- package/build/migrations-v2/0000000000080-drop-legacy-tracking-event.ts +60 -0
- package/build/migrations-v2/0000000000081-recurring-fee-planner-operation-status.ts +35 -0
- package/build/migrations-v2/0000000000082-reservation-search-trigram-indexes.ts +54 -0
- package/build/migrations-v2/0000000000083-journal-entry-deposit-lookup-index.ts +31 -0
- package/build/migrations-v2/0000000000084-journal-entry-reservation-revenue-indexes.ts +57 -0
- package/build/migrations-v2/0000000000085-owner-statement-link-email-template.ts +23 -0
- package/build/migrations-v2/0000000000086-contact-payment-setup.ts +72 -0
- package/build/migrations-v2/0000000000087-address-delete-fk-indexes.ts +30 -0
- package/build/migrations-v2/0000000000088-owner-statement-email-switch.ts +76 -0
- package/build/migrations-v2/0000000000089-contact-bank-details-requested-at.ts +21 -0
- package/build/migrations-v2/0000000000090-contact-bank-account-api-key.ts +22 -0
- package/build/migrations-v2/0000000000091-contact-bank-details-request.ts +78 -0
- package/build/migrations-v2/0000000000092-payment-provider-reference.ts +22 -0
- package/build/migrations-v2/0000000000093-payment-reversal-offline-undo.ts +18 -0
- package/build/migrations-v2/0000000000094-reservation-status-checkout-index.ts +37 -0
- package/build/migrations-v2/0000000000095-payment-batches.ts +196 -0
- package/build/migrations-v2/0000000000096-guide-ongoing-tasks-issue-codes.ts +26 -0
- package/build/migrations-v2/0000000000097-reservation-line-mapping-suggestions.ts +53 -0
- package/build/migrations-v2/0000000000098-cancelled-reservation-balances-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000099-contact-bank-account-request-source.ts +28 -0
- package/build/migrations-v2/0000000000100-drop-regional-feature-flags.ts +105 -0
- package/build/migrations-v2/0000000000101-bank-record-match-source.ts +45 -0
- package/build/migrations-v2/0000000000102-owner-statement-email-one-template.ts +63 -0
- package/build/migrations-v2/0000000000103-reservation-line-mapping-update-operation.ts +10 -0
- package/build/migrations-v2/0000000000104-export-job-payment-batch-pdf.ts +12 -0
- package/build/migrations-v2/0000000000105-drop-regional-token.ts +60 -0
- package/build/migrations-v2/0000000000106-incremental-audit-action-source.ts +158 -0
- package/build/migrations-v2/0000000000107-audit-mutation-transaction-insert-index.ts +44 -0
- package/build/migrations-v2/0000000000108-reservation-stay-type.ts +24 -0
- package/build/migrations-v2/0000000000109-long-term-liabilities-category-order.ts +21 -0
- package/build/migrations-v2/0000000000110-pms-sync-failures-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000110-reservation-line-type-taxable.ts +21 -0
- package/build/migrations-v2/0000000000111-reservation-line-type-suggestion-taxable.ts +20 -0
- package/build/migrations-v2/0000000000112-contact-payment-method-outside-default.ts +44 -0
- package/build/migrations-v2/0000000000113-merchant-fee-reference-assignment.ts +25 -0
- package/build/migrations-v2/0000000000114-recurring-fee-nights-filter.ts +32 -0
- package/build/migrations-v2/0000000000115-bank-records-with-suggested-rule-issue-code.ts +13 -0
- package/build/migrations-v2/0000000000116-guest-review.ts +45 -0
- package/build/migrations-v2/0000000000117-ramp-external-funding-accounts.ts +91 -0
- package/build/migrations-v2/0000000000118-pm-payout-assignment.ts +25 -0
- package/build/migrations-v2/0000000000119-chart-of-accounts-classifications.ts +46 -0
- package/build/migrations-v2/0000000000120-feedback.ts +41 -0
- package/build/migrations-v2/0000000000121-source-owner-block-calendar-index.ts +43 -0
- package/build/migrations-v2/0000000000122-recurring-fee-stay-types-filter.ts +20 -0
- package/build/migrations-v2/0000000000123-reservation-owner-stay-type-index.ts +40 -0
- package/build/migrations-v2/0000000000124-remove-tenant-test-and-billable-columns.ts +63 -0
- package/build/migrations-v2/0000000000125-ramp-application.ts +56 -0
- package/build/migrations-v2/0000000000126-advanced-deposits-update-operation.ts +10 -0
- package/build/migrations-v2/0000000000127-contact-1099-tax-details.ts +46 -0
- package/build/migrations-v2/0000000000128-tax-1099-email-templates.ts +36 -0
- package/build/migrations-v2/0000000000129-tenant-locked-at.ts +18 -0
- package/build/migrations-v2/0000000000130-second-factor-reset.ts +65 -0
- package/build/migrations-v2/0000000000131-payout-hold.ts +49 -0
- package/build/migrations-v2/0000000000132-member-invite-approval.ts +62 -0
- package/build/migrations-v2/0000000000133-audit-action-client-ip.ts +38 -0
- package/build/migrations-v2/0000000000134-drop-orphaned-hasura-triggers.ts +39 -0
- package/build/migrations-v2/0000000000135-drop-orphaned-hasura-triggers-literal.ts +42 -0
- package/build/migrations-v2/0000000000136-drop-all-hasura-triggers.ts +43 -0
- package/build/migrations-v2/0000000000137-webhook-event.ts +57 -0
- package/build/migrations-v2/0000000000138-contact-tax-details-requested-at.ts +24 -0
- package/build/migrations-v2/0000000000139-tax-statement-1099.ts +140 -0
- package/build/migrations-v2/0000000000140-owner-payment-settings.ts +53 -0
- package/build/migrations-v2/0000000000141-owner-payment-requests.ts +100 -0
- package/build/migrations-v2/0000000000148-statement-level-operation-triggers.ts +229 -0
- package/build/migrations-v2/0000000000151-core-change-unused-indexes.ts +85 -0
- package/build/migrations-v2/0000000000154-accounting-integrity-backlog-performance.ts +68 -0
- package/build/migrations-v2/0000000000155-source-last-successful-hash.ts +23 -0
- package/build/module/camel-case/index.d.ts +4 -4
- package/build/module/camel-case/index.js +4 -3
- package/build/module/camel-case/index.js.map +1 -1
- package/build/module/connect-handoff.d.ts +12 -0
- package/build/module/connect-handoff.js +70 -0
- package/build/module/connect-handoff.js.map +1 -0
- package/build/module/control-plane/index.d.ts +421 -14
- package/build/module/control-plane/index.js +58 -1
- package/build/module/control-plane/index.js.map +1 -1
- package/build/module/domain.d.ts +4 -0
- package/build/module/domain.js +2 -0
- package/build/module/domain.js.map +1 -0
- package/build/module/error.d.ts +2 -1
- package/build/module/error.js +3 -1
- package/build/module/error.js.map +1 -1
- package/build/module/index.d.ts +57 -15
- package/build/module/index.js +496 -64
- package/build/module/index.js.map +1 -1
- package/build/module/isomorphic.d.ts +6 -6
- package/build/module/isomorphic.js +2 -7
- package/build/module/isomorphic.js.map +1 -1
- package/build/module/local/digest.d.ts +3 -3
- package/build/module/local/digest.js.map +1 -1
- package/build/module/local/generate.js +15 -13
- package/build/module/local/generate.js.map +1 -1
- package/build/module/local/index.d.ts +5 -1
- package/build/module/local/index.js +347 -13
- package/build/module/local/index.js.map +1 -1
- package/build/module/local/prune-pulled-schema.js +4 -1
- package/build/module/local/prune-pulled-schema.js.map +1 -1
- package/build/module/migration-source.d.ts +4 -0
- package/build/module/migration-source.js +42 -0
- package/build/module/migration-source.js.map +1 -0
- package/build/module/migration.d.ts +7 -0
- package/build/module/migration.js +8 -0
- package/build/module/migration.js.map +1 -0
- package/build/module/pganalyze-comment-plugin/comment-transformer.js +3 -1
- package/build/module/pganalyze-comment-plugin/comment-transformer.js.map +1 -1
- package/build/module/plugins.d.ts +2 -2
- package/build/module/plugins.js.map +1 -1
- package/build/module/postgres-error.d.ts +9 -0
- package/build/module/postgres-error.js +24 -0
- package/build/module/postgres-error.js.map +1 -0
- package/build/module/query/index.d.ts +1 -0
- package/build/module/query/index.js +1 -0
- package/build/module/query/index.js.map +1 -1
- package/build/module/query/listing/status.d.ts +2 -12
- package/build/module/query/listing/status.js +35 -18
- package/build/module/query/listing/status.js.map +1 -1
- package/build/module/query/tenant/billing-partner.d.ts +4 -0
- package/build/module/query/tenant/billing-partner.js +5 -0
- package/build/module/query/tenant/billing-partner.js.map +1 -0
- package/build/module/query/tenant/feature-enabled.d.ts +6 -0
- package/build/module/query/tenant/feature-enabled.js +27 -0
- package/build/module/query/tenant/feature-enabled.js.map +1 -0
- package/build/module/query/tenant/index.d.ts +4 -0
- package/build/module/query/tenant/index.js +5 -0
- package/build/module/query/tenant/index.js.map +1 -0
- package/build/module/query/tenant/status.d.ts +9 -0
- package/build/module/query/tenant/status.js +28 -0
- package/build/module/query/tenant/status.js.map +1 -0
- package/build/module/query/tenant/where-uuid-in.d.ts +2 -0
- package/build/module/query/tenant/where-uuid-in.js +11 -0
- package/build/module/query/tenant/where-uuid-in.js.map +1 -0
- package/build/module/regional.d.ts +31 -4
- package/build/module/regional.js +68 -8
- package/build/module/regional.js.map +1 -1
- package/build/module/test/index.d.ts +21 -11
- package/build/module/test/index.js +31 -26
- package/build/module/test/index.js.map +1 -1
- package/build/module/transaction.d.ts +3 -3
- package/build/module/transaction.js.map +1 -1
- package/build/module/v1.generated.d.ts +1407 -177
- package/build/module/v1.generated.js.map +1 -1
- package/package.json +19 -16
- package/build/migrations/0000000000001-init.ts +0 -5
- package/build/migrations/0000000000009-drop-store-schema.ts +0 -14
- package/build/migrations/0000000000010-bank-rules.ts +0 -190
- package/build/migrations/0000000000011-bank-rule-line-adjustments.ts +0 -65
- package/build/migrations/0000000000012-bank-rule-conditions.ts +0 -45
- package/build/migrations/0000000000013-bank-rule-name-unique.ts +0 -15
- package/build/migrations/0000000000014-bank-rule-drop-legacy-conditions.ts +0 -41
- package/build/migrations/0000000000015-booking-channel-logo-dev-provider.ts +0 -70
- package/build/migrations/0000000000016-owner-statement-draft-status.ts +0 -22
- package/build/migrations/0000000000017-tenant-migration-markers.ts +0 -18
- package/build/migrations/0000000000018-security-deposits-payable-category.ts +0 -63
- package/build/migrations/0000000000019-tenant-app-settings.ts +0 -76
- package/build/migrations/0000000000020-operating-opening-trial-balance.ts +0 -36
- package/build/migrations/0000000000021-audit-foreign-key-indexes.ts +0 -77
- package/build/migrations/0000000000022-opening-trial-balance-combined-columns.ts +0 -30
- package/build/migrations/0000000000024-listing-parent.ts +0 -37
- package/build/migrations/0000000000025-journal-entry-parent-listing.ts +0 -26
- package/build/migrations/0000000000026-booking-channel-logo-slots.ts +0 -89
- package/build/migrations/0000000000027-list-browse-performance-indexes.ts +0 -52
- package/build/migrations/0000000000028-flow-setting-status-jsonb.ts +0 -20
- package/build/migrations/0000000000029-tenant-slug.ts +0 -328
- package/build/migrations/0000000000030-pms-accounting-windows.ts +0 -50
- package/build/migrations/0000000000031-owner-statement-projection-listing-revision.ts +0 -20
- package/build/migrations/0000000000032-flow-event-listening.ts +0 -28
- package/build/migrations/0000000000033-opening-trial-balance-transaction.ts +0 -272
- package/build/migrations/0000000000034-historic-general-ledger.ts +0 -24
- package/build/migrations/0000000000035-tenant-regional-placement.ts +0 -37
- package/build/migrations/0000000000036-control-plane-projection-events.ts +0 -43
- package/build/migrations/0000000000037-tenant-guide-onboarding.ts +0 -21
- package/build/migrations/0000000000038-tracking-event-analytics-sink.ts +0 -31
- package/build/migrations/0000000000039-crunchy-region.ts +0 -86
- package/build/migrations/0000000000040-hostaway-region.ts +0 -72
- package/build/migrations/0000000000041-audit-tenant-fk.ts +0 -66
- package/build/migrations/0000000000042-ramp-staging-connect-params.ts +0 -35
- package/build/migrations/0000000000043-gl-pms-accounting-window-guard.ts +0 -125
- package/build/migrations/0000000000044-tenant-cross-region-fks.ts +0 -45
- package/build/migrations/0000000000045-cloudflare-region-env.ts +0 -100
- package/build/migrations/0000000000046-control-plane-outbox-alias.ts +0 -46
- package/build/migrations/0000000000047-ramp-contact-last-4-digits.ts +0 -16
- package/build/migrations/0000000000047-tenant-status-backfill.ts +0 -40
- package/build/migrations/0000000000048-tenant-status-constraint.ts +0 -24
- package/build/migrations/0000000000049-health-tenant-issues.ts +0 -69
- package/build/migrations/0000000000050-partner-webhooks.ts +0 -135
- package/build/migrations/0000000000051-health-webhook-runtime-grants.ts +0 -42
- package/build/migrations/0000000000052-feature-approval-team-enablement.ts +0 -13
- package/build/migrations/0000000000053-health-webhook-enums.ts +0 -296
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
7
|
+
await sql`create type accounting.payment_provider as enum ('ramp')`.execute(
|
|
8
|
+
db
|
|
9
|
+
);
|
|
10
|
+
await sql`
|
|
11
|
+
create type accounting.payment_method as enum ('ach', 'check', 'wire', 'cash', 'other')
|
|
12
|
+
`.execute(db);
|
|
13
|
+
await sql`create type accounting.payment_origin as enum ('vrp', 'provider')`.execute(
|
|
14
|
+
db
|
|
15
|
+
);
|
|
16
|
+
await sql`
|
|
17
|
+
create type accounting.payment_status as enum (
|
|
18
|
+
'pending', 'submitting', 'scheduled', 'processing', 'succeeded', 'failed', 'canceled'
|
|
19
|
+
)
|
|
20
|
+
`.execute(db);
|
|
21
|
+
await sql`
|
|
22
|
+
create type accounting.payment_issue as enum (
|
|
23
|
+
'unknownOutcome', 'unknownStatus', 'currencyMismatch', 'recipientMismatch',
|
|
24
|
+
'unmappedFundingAccount', 'unlinkedMovement', 'allocationOutOfRange',
|
|
25
|
+
'conflictingEvidence', 'amountMismatch', 'accountingConfiguration', 'overpayment'
|
|
26
|
+
)
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
create type accounting.payment_resource_type as enum ('bill', 'payment', 'transfer')
|
|
30
|
+
`.execute(db);
|
|
31
|
+
await sql`
|
|
32
|
+
create type accounting.payment_observation_origin as enum ('provider', 'review')
|
|
33
|
+
`.execute(db);
|
|
34
|
+
await sql`
|
|
35
|
+
create type accounting.payment_reversal_kind as enum (
|
|
36
|
+
'providerReturn', 'offlineReversal', 'bankUnmatch'
|
|
37
|
+
)
|
|
38
|
+
`.execute(db);
|
|
39
|
+
await sql`
|
|
40
|
+
create type accounting.payment_command_kind as enum ('submit', 'cancel', 'refresh')
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
create type accounting.payment_command_outcome as enum (
|
|
44
|
+
'accepted', 'rejected', 'unknown', 'conflictingEvidence'
|
|
45
|
+
)
|
|
46
|
+
`.execute(db);
|
|
47
|
+
|
|
48
|
+
await sql`
|
|
49
|
+
create table accounting.payment (
|
|
50
|
+
id uuid primary key default gen_random_uuid(),
|
|
51
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
52
|
+
transaction_id uuid not null references accounting.transaction (id) on delete restrict,
|
|
53
|
+
contact_id uuid references accounting.contact (id) on delete restrict,
|
|
54
|
+
account_id uuid null references accounting.account (id) on delete restrict,
|
|
55
|
+
amount integer not null check (amount > 0),
|
|
56
|
+
currency text not null references public.currency (name),
|
|
57
|
+
method accounting.payment_method not null,
|
|
58
|
+
provider accounting.payment_provider null,
|
|
59
|
+
connection_id uuid null references public.connection (id) on delete restrict,
|
|
60
|
+
funding_account_connection_id uuid null
|
|
61
|
+
references accounting.account_connection (id) on delete restrict,
|
|
62
|
+
recipient_ref text null check (recipient_ref is null or length(recipient_ref) between 1 and 500),
|
|
63
|
+
funding_entity_ref text null
|
|
64
|
+
check (funding_entity_ref is null or length(funding_entity_ref) between 1 and 500),
|
|
65
|
+
funding_account_ref text null
|
|
66
|
+
check (funding_account_ref is null or length(funding_account_ref) between 1 and 500),
|
|
67
|
+
destination_ref text null
|
|
68
|
+
check (destination_ref is null or length(destination_ref) between 1 and 500),
|
|
69
|
+
requested_date date null,
|
|
70
|
+
reference text null check (reference is null or length(reference) <= 500),
|
|
71
|
+
origin accounting.payment_origin not null default 'vrp',
|
|
72
|
+
provider_bill_ref text null
|
|
73
|
+
check (provider_bill_ref is null or length(provider_bill_ref) between 1 and 500),
|
|
74
|
+
provider_payment_ref text null
|
|
75
|
+
check (provider_payment_ref is null or length(provider_payment_ref) between 1 and 500),
|
|
76
|
+
bank_record_id uuid null references accounting.bank_record (id) on delete restrict,
|
|
77
|
+
status accounting.payment_status not null default 'pending',
|
|
78
|
+
settled_at timestamptz null,
|
|
79
|
+
posting_date date null,
|
|
80
|
+
terminal_at timestamptz null,
|
|
81
|
+
provider_updated_at timestamptz null,
|
|
82
|
+
observed_at timestamptz null,
|
|
83
|
+
provider_status text null check (provider_status is null or length(provider_status) <= 200),
|
|
84
|
+
provider_method text null check (provider_method is null or length(provider_method) <= 200),
|
|
85
|
+
scheduled_at timestamptz null,
|
|
86
|
+
initiated_at timestamptz null,
|
|
87
|
+
issue accounting.payment_issue null,
|
|
88
|
+
funding_debited integer null check (funding_debited >= 0),
|
|
89
|
+
funding_refunded integer null check (funding_refunded >= 0),
|
|
90
|
+
funding_currency text null references public.currency (name),
|
|
91
|
+
closure_requested_at timestamptz null,
|
|
92
|
+
closure_confirmed_at timestamptz null,
|
|
93
|
+
replaces_payment_id uuid null references accounting.payment (id) on delete restrict,
|
|
94
|
+
operation_id uuid null,
|
|
95
|
+
idempotency_key text not null check (length(idempotency_key) between 1 and 200),
|
|
96
|
+
request_fingerprint text not null,
|
|
97
|
+
is_historical_copy boolean not null default false,
|
|
98
|
+
created_at timestamptz not null default now(),
|
|
99
|
+
updated_at timestamptz not null default now(),
|
|
100
|
+
unique (tenant_id, transaction_id, idempotency_key),
|
|
101
|
+
check (replaces_payment_id is distinct from id),
|
|
102
|
+
check (num_nonnulls(funding_debited, funding_refunded, funding_currency) in (0, 3)),
|
|
103
|
+
check ((status = 'succeeded') = (settled_at is not null)),
|
|
104
|
+
check (
|
|
105
|
+
(status in ('succeeded', 'failed', 'canceled')) = (terminal_at is not null)
|
|
106
|
+
),
|
|
107
|
+
check (origin <> 'provider' or provider_payment_ref is not null),
|
|
108
|
+
check (provider is null or account_id is not null),
|
|
109
|
+
check (
|
|
110
|
+
(provider is null and connection_id is null and funding_account_connection_id is null
|
|
111
|
+
and origin = 'vrp')
|
|
112
|
+
or (provider is not null and method = 'ach' and connection_id is not null
|
|
113
|
+
and funding_account_connection_id is not null)
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
`.execute(db);
|
|
117
|
+
await sql`
|
|
118
|
+
create unique index payment_replacement_idx on accounting.payment (tenant_id, replaces_payment_id)
|
|
119
|
+
where replaces_payment_id is not null
|
|
120
|
+
`.execute(db);
|
|
121
|
+
await sql`
|
|
122
|
+
create unique index payment_provider_payment_idx
|
|
123
|
+
on accounting.payment (tenant_id, connection_id, provider_payment_ref)
|
|
124
|
+
where provider_payment_ref is not null
|
|
125
|
+
`.execute(db);
|
|
126
|
+
await sql`
|
|
127
|
+
create index payment_provider_bill_idx
|
|
128
|
+
on accounting.payment (tenant_id, connection_id, provider_bill_ref)
|
|
129
|
+
where provider_bill_ref is not null
|
|
130
|
+
`.execute(db);
|
|
131
|
+
await sql`
|
|
132
|
+
create index payment_bank_record_idx
|
|
133
|
+
on accounting.payment (tenant_id, bank_record_id) where bank_record_id is not null
|
|
134
|
+
`.execute(db);
|
|
135
|
+
await sql`
|
|
136
|
+
create index payment_transaction_idx on accounting.payment (tenant_id, transaction_id)
|
|
137
|
+
`.execute(db);
|
|
138
|
+
await sql`create index payment_contact_idx on accounting.payment (tenant_id, contact_id)`.execute(
|
|
139
|
+
db
|
|
140
|
+
);
|
|
141
|
+
await sql`create index payment_account_idx on accounting.payment (tenant_id, account_id)`.execute(
|
|
142
|
+
db
|
|
143
|
+
);
|
|
144
|
+
await sql`
|
|
145
|
+
create index payment_connection_idx on accounting.payment (tenant_id, connection_id)
|
|
146
|
+
where connection_id is not null
|
|
147
|
+
`.execute(db);
|
|
148
|
+
await sql`
|
|
149
|
+
create index payment_funding_account_connection_idx
|
|
150
|
+
on accounting.payment (tenant_id, funding_account_connection_id)
|
|
151
|
+
where funding_account_connection_id is not null
|
|
152
|
+
`.execute(db);
|
|
153
|
+
await sql`
|
|
154
|
+
create index payment_open_idx on accounting.payment (tenant_id, transaction_id)
|
|
155
|
+
where terminal_at is null
|
|
156
|
+
`.execute(db);
|
|
157
|
+
|
|
158
|
+
await sql`
|
|
159
|
+
create table accounting.payment_allocation (
|
|
160
|
+
id uuid primary key default gen_random_uuid(),
|
|
161
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
162
|
+
payment_id uuid not null references accounting.payment (id) on delete restrict,
|
|
163
|
+
transaction_line_id uuid not null references accounting.transaction_line (id) on delete restrict,
|
|
164
|
+
amount integer not null check (amount <> 0),
|
|
165
|
+
created_at timestamptz not null default now(),
|
|
166
|
+
unique (tenant_id, payment_id, transaction_line_id)
|
|
167
|
+
)
|
|
168
|
+
`.execute(db);
|
|
169
|
+
await sql`
|
|
170
|
+
create index payment_allocation_line_idx
|
|
171
|
+
on accounting.payment_allocation (tenant_id, transaction_line_id)
|
|
172
|
+
`.execute(db);
|
|
173
|
+
|
|
174
|
+
await sql`
|
|
175
|
+
create table accounting.payment_reversal (
|
|
176
|
+
id uuid primary key default gen_random_uuid(),
|
|
177
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
178
|
+
payment_id uuid not null references accounting.payment (id) on delete restrict,
|
|
179
|
+
kind accounting.payment_reversal_kind not null,
|
|
180
|
+
effective_at timestamptz not null,
|
|
181
|
+
posting_date date null,
|
|
182
|
+
reason text null check (reason is null or length(reason) <= 500),
|
|
183
|
+
idempotency_key text not null check (length(idempotency_key) between 1 and 200),
|
|
184
|
+
request_fingerprint text not null,
|
|
185
|
+
created_at timestamptz not null default now(),
|
|
186
|
+
unique (tenant_id, payment_id)
|
|
187
|
+
)
|
|
188
|
+
`.execute(db);
|
|
189
|
+
await sql`
|
|
190
|
+
create index payment_reversal_payment_idx
|
|
191
|
+
on accounting.payment_reversal (tenant_id, payment_id)
|
|
192
|
+
`.execute(db);
|
|
193
|
+
|
|
194
|
+
await sql`
|
|
195
|
+
create table accounting.payment_observation (
|
|
196
|
+
id uuid primary key default gen_random_uuid(),
|
|
197
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
198
|
+
connection_id uuid not null references public.connection (id) on delete restrict,
|
|
199
|
+
resource_type accounting.payment_resource_type not null,
|
|
200
|
+
external_id text not null check (length(external_id) between 1 and 500),
|
|
201
|
+
provider_bill_ref text null
|
|
202
|
+
check (provider_bill_ref is null or length(provider_bill_ref) between 1 and 500),
|
|
203
|
+
provider_payment_ref text null
|
|
204
|
+
check (provider_payment_ref is null or length(provider_payment_ref) between 1 and 500),
|
|
205
|
+
payment_id uuid null references accounting.payment (id) on delete restrict,
|
|
206
|
+
origin accounting.payment_observation_origin not null default 'provider',
|
|
207
|
+
event_key text not null check (length(event_key) between 1 and 500),
|
|
208
|
+
source_id uuid null references public.source (id) on delete restrict,
|
|
209
|
+
provider_updated_at timestamptz null,
|
|
210
|
+
observed_at timestamptz not null,
|
|
211
|
+
provider_status text null check (provider_status is null or length(provider_status) <= 200),
|
|
212
|
+
status accounting.payment_status null,
|
|
213
|
+
terminal_at timestamptz null,
|
|
214
|
+
settled_at timestamptz null,
|
|
215
|
+
returned_at timestamptz null,
|
|
216
|
+
paid_amount integer null check (paid_amount is null or paid_amount > 0),
|
|
217
|
+
issue accounting.payment_issue null,
|
|
218
|
+
funding_debited integer null check (funding_debited >= 0),
|
|
219
|
+
funding_refunded integer null check (funding_refunded >= 0),
|
|
220
|
+
funding_currency text null references public.currency (name),
|
|
221
|
+
snapshot jsonb null check (snapshot is null or jsonb_typeof(snapshot) = 'object'),
|
|
222
|
+
fingerprint text not null,
|
|
223
|
+
created_at timestamptz not null default now(),
|
|
224
|
+
unique (tenant_id, connection_id, resource_type, external_id, event_key),
|
|
225
|
+
check (num_nonnulls(funding_debited, funding_refunded, funding_currency) in (0, 3))
|
|
226
|
+
)
|
|
227
|
+
`.execute(db);
|
|
228
|
+
await sql`
|
|
229
|
+
create index payment_observation_payment_idx
|
|
230
|
+
on accounting.payment_observation (tenant_id, payment_id)
|
|
231
|
+
`.execute(db);
|
|
232
|
+
await sql`
|
|
233
|
+
create index payment_observation_source_idx
|
|
234
|
+
on accounting.payment_observation (tenant_id, source_id) where source_id is not null
|
|
235
|
+
`.execute(db);
|
|
236
|
+
|
|
237
|
+
await sql`
|
|
238
|
+
create table accounting.payment_command (
|
|
239
|
+
id uuid primary key,
|
|
240
|
+
tenant_id uuid not null references public.tenant (id) on delete restrict,
|
|
241
|
+
payment_id uuid not null references accounting.payment (id) on delete restrict,
|
|
242
|
+
kind accounting.payment_command_kind not null,
|
|
243
|
+
idempotency_key text not null check (length(idempotency_key) between 1 and 200),
|
|
244
|
+
fingerprint text not null,
|
|
245
|
+
outcome accounting.payment_command_outcome null,
|
|
246
|
+
outcome_at timestamptz null,
|
|
247
|
+
provider_failure_code text null
|
|
248
|
+
check (provider_failure_code is null or length(provider_failure_code) <= 200),
|
|
249
|
+
created_at timestamptz not null default now(),
|
|
250
|
+
unique (tenant_id, payment_id, idempotency_key)
|
|
251
|
+
)
|
|
252
|
+
`.execute(db);
|
|
253
|
+
await sql`
|
|
254
|
+
create index payment_command_payment_idx on accounting.payment_command (tenant_id, payment_id)
|
|
255
|
+
`.execute(db);
|
|
256
|
+
|
|
257
|
+
await sql`
|
|
258
|
+
alter table accounting.journal_entry add column payment_id uuid null
|
|
259
|
+
`.execute(db);
|
|
260
|
+
|
|
261
|
+
await sql`
|
|
262
|
+
create function accounting.ensure_payment_tenant_links() returns trigger
|
|
263
|
+
language plpgsql as $$
|
|
264
|
+
begin
|
|
265
|
+
if tg_table_name = 'payment' then
|
|
266
|
+
if not exists (select 1 from accounting.transaction
|
|
267
|
+
where id = new.transaction_id and tenant_id = new.tenant_id)
|
|
268
|
+
or (new.account_id is not null and not exists (select 1 from accounting.account
|
|
269
|
+
where id = new.account_id and tenant_id = new.tenant_id))
|
|
270
|
+
or (new.contact_id is not null and not exists (select 1 from accounting.contact
|
|
271
|
+
where id = new.contact_id and tenant_id = new.tenant_id))
|
|
272
|
+
or (new.connection_id is not null and not exists (select 1 from public.connection
|
|
273
|
+
where id = new.connection_id and tenant_id = new.tenant_id))
|
|
274
|
+
or (new.funding_account_connection_id is not null and not exists (
|
|
275
|
+
select 1 from accounting.account_connection
|
|
276
|
+
where id = new.funding_account_connection_id and tenant_id = new.tenant_id))
|
|
277
|
+
or (new.bank_record_id is not null and not exists (select 1 from accounting.bank_record
|
|
278
|
+
where id = new.bank_record_id and tenant_id = new.tenant_id))
|
|
279
|
+
or (new.replaces_payment_id is not null and not exists (
|
|
280
|
+
select 1 from accounting.payment where id = new.replaces_payment_id
|
|
281
|
+
and tenant_id = new.tenant_id and transaction_id = new.transaction_id)) then
|
|
282
|
+
raise exception 'Payment reference belongs to another tenant';
|
|
283
|
+
end if;
|
|
284
|
+
elsif tg_table_name = 'payment_observation' then
|
|
285
|
+
if not exists (select 1 from public.connection
|
|
286
|
+
where id = new.connection_id and tenant_id = new.tenant_id)
|
|
287
|
+
or (new.payment_id is not null and not exists (select 1 from accounting.payment
|
|
288
|
+
where id = new.payment_id and tenant_id = new.tenant_id))
|
|
289
|
+
or (new.source_id is not null and not exists (select 1 from public.source
|
|
290
|
+
where id = new.source_id and tenant_id = new.tenant_id)) then
|
|
291
|
+
raise exception 'Payment observation reference belongs to another tenant';
|
|
292
|
+
end if;
|
|
293
|
+
elsif tg_table_name = 'payment_allocation' then
|
|
294
|
+
if not exists (
|
|
295
|
+
select 1 from accounting.payment p
|
|
296
|
+
join accounting.transaction_line line on line.id = new.transaction_line_id
|
|
297
|
+
and line.tenant_id = p.tenant_id and line.transaction_id = p.transaction_id
|
|
298
|
+
where p.id = new.payment_id and p.tenant_id = new.tenant_id
|
|
299
|
+
) then
|
|
300
|
+
raise exception 'Payment allocation reference belongs to another transaction or tenant';
|
|
301
|
+
end if;
|
|
302
|
+
elsif tg_table_name = 'payment_reversal' then
|
|
303
|
+
if not exists (select 1 from accounting.payment
|
|
304
|
+
where id = new.payment_id and tenant_id = new.tenant_id) then
|
|
305
|
+
raise exception 'Payment reversal reference belongs to another tenant';
|
|
306
|
+
end if;
|
|
307
|
+
elsif tg_table_name = 'payment_command' and not exists (
|
|
308
|
+
select 1 from accounting.payment
|
|
309
|
+
where id = new.payment_id and tenant_id = new.tenant_id) then
|
|
310
|
+
raise exception 'Payment command reference belongs to another tenant';
|
|
311
|
+
end if;
|
|
312
|
+
return new;
|
|
313
|
+
end $$
|
|
314
|
+
`.execute(db);
|
|
315
|
+
for (const table of [
|
|
316
|
+
'payment',
|
|
317
|
+
'payment_allocation',
|
|
318
|
+
'payment_reversal',
|
|
319
|
+
'payment_observation',
|
|
320
|
+
'payment_command',
|
|
321
|
+
]) {
|
|
322
|
+
await sql`
|
|
323
|
+
create trigger ${sql.raw(`${table}_tenant_links`)}
|
|
324
|
+
before insert or update on ${sql.raw(`accounting.${table}`)}
|
|
325
|
+
for each row execute function accounting.ensure_payment_tenant_links()
|
|
326
|
+
`.execute(db);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
await sql`
|
|
330
|
+
create function accounting.protect_payment_instructions() returns trigger
|
|
331
|
+
language plpgsql as $$
|
|
332
|
+
begin
|
|
333
|
+
if (new.tenant_id, new.transaction_id, new.contact_id, new.account_id, new.amount,
|
|
334
|
+
new.currency, new.method, new.provider, new.connection_id,
|
|
335
|
+
new.funding_account_connection_id, new.recipient_ref, new.funding_entity_ref,
|
|
336
|
+
new.funding_account_ref, new.destination_ref, new.requested_date, new.reference, new.origin,
|
|
337
|
+
new.replaces_payment_id, new.idempotency_key,
|
|
338
|
+
new.request_fingerprint, new.is_historical_copy, new.created_at)
|
|
339
|
+
is distinct from
|
|
340
|
+
(old.tenant_id, old.transaction_id, old.contact_id, old.account_id, old.amount,
|
|
341
|
+
old.currency, old.method, old.provider, old.connection_id,
|
|
342
|
+
old.funding_account_connection_id, old.recipient_ref, old.funding_entity_ref,
|
|
343
|
+
old.funding_account_ref, old.destination_ref, old.requested_date, old.reference, old.origin,
|
|
344
|
+
old.replaces_payment_id, old.idempotency_key,
|
|
345
|
+
old.request_fingerprint, old.is_historical_copy, old.created_at) then
|
|
346
|
+
raise exception 'Payment instructions cannot be changed';
|
|
347
|
+
end if;
|
|
348
|
+
if (old.settled_at is not null and new.settled_at is distinct from old.settled_at)
|
|
349
|
+
or (old.posting_date is not null and new.posting_date is distinct from old.posting_date)
|
|
350
|
+
or (old.provider_payment_ref is not null and new.provider_payment_ref is distinct from old.provider_payment_ref)
|
|
351
|
+
or (old.bank_record_id is not null and new.bank_record_id is distinct from old.bank_record_id) then
|
|
352
|
+
raise exception 'Payment settlement evidence cannot be changed once recorded';
|
|
353
|
+
end if;
|
|
354
|
+
new.updated_at := now();
|
|
355
|
+
return new;
|
|
356
|
+
end $$
|
|
357
|
+
`.execute(db);
|
|
358
|
+
await sql`
|
|
359
|
+
create trigger payment_instructions_immutable before update on accounting.payment
|
|
360
|
+
for each row execute function accounting.protect_payment_instructions()
|
|
361
|
+
`.execute(db);
|
|
362
|
+
await sql`
|
|
363
|
+
create function accounting.protect_payment_evidence_updates() returns trigger
|
|
364
|
+
language plpgsql as $$
|
|
365
|
+
begin
|
|
366
|
+
if tg_table_name = 'payment_command' then
|
|
367
|
+
if (to_jsonb(new) - array['outcome', 'outcome_at', 'provider_failure_code']) =
|
|
368
|
+
(to_jsonb(old) - array['outcome', 'outcome_at', 'provider_failure_code'])
|
|
369
|
+
then return new; end if;
|
|
370
|
+
elsif tg_table_name = 'payment_reversal' then
|
|
371
|
+
if (to_jsonb(new) - array['posting_date']) =
|
|
372
|
+
(to_jsonb(old) - array['posting_date']) then return new; end if;
|
|
373
|
+
elsif tg_table_name = 'payment_observation' then
|
|
374
|
+
if (to_jsonb(new) - array['payment_id']) =
|
|
375
|
+
(to_jsonb(old) - array['payment_id']) then return new; end if;
|
|
376
|
+
end if;
|
|
377
|
+
raise exception 'Payment evidence cannot be changed';
|
|
378
|
+
end $$
|
|
379
|
+
`.execute(db);
|
|
380
|
+
for (const table of [
|
|
381
|
+
'payment_observation',
|
|
382
|
+
'payment_reversal',
|
|
383
|
+
'payment_command',
|
|
384
|
+
]) {
|
|
385
|
+
await sql`
|
|
386
|
+
create trigger ${sql.raw(`${table}_evidence_update`)}
|
|
387
|
+
before update on ${sql.raw(`accounting.${table}`)}
|
|
388
|
+
for each row execute function accounting.protect_payment_evidence_updates()
|
|
389
|
+
`.execute(db);
|
|
390
|
+
}
|
|
391
|
+
// Deleting a transaction may remove its offline payments; the caller names the
|
|
392
|
+
// transaction in a transaction-local setting. Provider evidence is never deleted.
|
|
393
|
+
await sql`
|
|
394
|
+
create function accounting.protect_payment_evidence() returns trigger
|
|
395
|
+
language plpgsql as $$
|
|
396
|
+
begin
|
|
397
|
+
if old.tenant_id::text = current_setting('accounting.delete_payments_of_tenant', true)
|
|
398
|
+
and exists (select 1 from public.tenant t
|
|
399
|
+
where t.id = old.tenant_id and t.migration_status = 'frozen') then
|
|
400
|
+
return old;
|
|
401
|
+
end if;
|
|
402
|
+
if tg_table_name in ('payment', 'payment_allocation', 'payment_reversal')
|
|
403
|
+
and exists (
|
|
404
|
+
select 1 from accounting.payment p
|
|
405
|
+
where p.id = (case when tg_table_name = 'payment'
|
|
406
|
+
then to_jsonb(old) ->> 'id' else to_jsonb(old) ->> 'payment_id' end)::uuid
|
|
407
|
+
and p.provider is null
|
|
408
|
+
and p.transaction_id::text
|
|
409
|
+
= current_setting('accounting.delete_offline_payments_of', true)
|
|
410
|
+
) then
|
|
411
|
+
return old;
|
|
412
|
+
end if;
|
|
413
|
+
raise exception 'Payment evidence cannot be deleted';
|
|
414
|
+
end $$
|
|
415
|
+
`.execute(db);
|
|
416
|
+
for (const table of [
|
|
417
|
+
'payment',
|
|
418
|
+
'payment_observation',
|
|
419
|
+
'payment_allocation',
|
|
420
|
+
'payment_reversal',
|
|
421
|
+
'payment_command',
|
|
422
|
+
]) {
|
|
423
|
+
await sql`
|
|
424
|
+
create trigger ${sql.raw(`${table}_evidence_immutable`)}
|
|
425
|
+
before delete on ${sql.raw(`accounting.${table}`)}
|
|
426
|
+
for each row execute function accounting.protect_payment_evidence()
|
|
427
|
+
`.execute(db);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
await sql`
|
|
431
|
+
do $$
|
|
432
|
+
begin
|
|
433
|
+
if exists (select 1 from pg_roles where rolname = 'application') then
|
|
434
|
+
grant usage on schema accounting to application;
|
|
435
|
+
grant select, insert, update, delete on accounting.payment,
|
|
436
|
+
accounting.payment_command to application;
|
|
437
|
+
grant select, insert, delete on accounting.payment_allocation to application;
|
|
438
|
+
grant select, insert, update, delete on accounting.payment_reversal,
|
|
439
|
+
accounting.payment_observation to application;
|
|
440
|
+
end if;
|
|
441
|
+
end;
|
|
442
|
+
$$
|
|
443
|
+
`.execute(db);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
447
|
+
for (const table of [
|
|
448
|
+
'payment_command',
|
|
449
|
+
'payment_observation',
|
|
450
|
+
'payment_reversal',
|
|
451
|
+
'payment_allocation',
|
|
452
|
+
'payment',
|
|
453
|
+
]) {
|
|
454
|
+
const rows = await sql<{ count: number }>`
|
|
455
|
+
select count(*)::int as count from ${sql.raw(`accounting.${table}`)}
|
|
456
|
+
`.execute(db);
|
|
457
|
+
if (rows.rows[0]?.count) {
|
|
458
|
+
throw Object.assign(
|
|
459
|
+
new Error('Payment tables still hold rows; refusing to drop'),
|
|
460
|
+
{ details: { table } }
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
for (const table of [
|
|
465
|
+
'payment',
|
|
466
|
+
'payment_observation',
|
|
467
|
+
'payment_allocation',
|
|
468
|
+
'payment_reversal',
|
|
469
|
+
'payment_command',
|
|
470
|
+
]) {
|
|
471
|
+
await sql`
|
|
472
|
+
drop trigger ${sql.raw(`${table}_evidence_immutable`)} on ${sql.raw(`accounting.${table}`)}
|
|
473
|
+
`.execute(db);
|
|
474
|
+
}
|
|
475
|
+
for (const table of [
|
|
476
|
+
'payment_observation',
|
|
477
|
+
'payment_reversal',
|
|
478
|
+
'payment_command',
|
|
479
|
+
]) {
|
|
480
|
+
await sql`
|
|
481
|
+
drop trigger ${sql.raw(`${table}_evidence_update`)} on ${sql.raw(`accounting.${table}`)}
|
|
482
|
+
`.execute(db);
|
|
483
|
+
}
|
|
484
|
+
for (const table of [
|
|
485
|
+
'payment',
|
|
486
|
+
'payment_observation',
|
|
487
|
+
'payment_allocation',
|
|
488
|
+
'payment_reversal',
|
|
489
|
+
'payment_command',
|
|
490
|
+
]) {
|
|
491
|
+
await sql`
|
|
492
|
+
drop trigger ${sql.raw(`${table}_tenant_links`)} on ${sql.raw(`accounting.${table}`)}
|
|
493
|
+
`.execute(db);
|
|
494
|
+
}
|
|
495
|
+
await sql`drop trigger payment_instructions_immutable on accounting.payment`.execute(
|
|
496
|
+
db
|
|
497
|
+
);
|
|
498
|
+
await sql`alter table accounting.journal_entry drop column payment_id`.execute(
|
|
499
|
+
db
|
|
500
|
+
);
|
|
501
|
+
await sql`drop function accounting.protect_payment_evidence()`.execute(db);
|
|
502
|
+
await sql`drop function accounting.protect_payment_evidence_updates()`.execute(
|
|
503
|
+
db
|
|
504
|
+
);
|
|
505
|
+
await sql`drop function accounting.ensure_payment_tenant_links()`.execute(db);
|
|
506
|
+
await sql`drop function accounting.protect_payment_instructions()`.execute(
|
|
507
|
+
db
|
|
508
|
+
);
|
|
509
|
+
for (const table of [
|
|
510
|
+
'payment_command',
|
|
511
|
+
'payment_observation',
|
|
512
|
+
'payment_reversal',
|
|
513
|
+
'payment_allocation',
|
|
514
|
+
'payment',
|
|
515
|
+
]) {
|
|
516
|
+
await sql`drop table ${sql.raw(`accounting.${table}`)}`.execute(db);
|
|
517
|
+
}
|
|
518
|
+
for (const type of [
|
|
519
|
+
'payment_command_outcome',
|
|
520
|
+
'payment_command_kind',
|
|
521
|
+
'payment_reversal_kind',
|
|
522
|
+
'payment_observation_origin',
|
|
523
|
+
'payment_resource_type',
|
|
524
|
+
'payment_issue',
|
|
525
|
+
'payment_status',
|
|
526
|
+
'payment_origin',
|
|
527
|
+
'payment_method',
|
|
528
|
+
'payment_provider',
|
|
529
|
+
]) {
|
|
530
|
+
await sql`drop type ${sql.raw(`accounting.${type}`)}`.execute(db);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
5
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
6
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
7
|
+
|
|
8
|
+
await sql`
|
|
9
|
+
create index if not exists
|
|
10
|
+
journal_entry_payment_idx
|
|
11
|
+
on accounting.journal_entry (tenant_id, payment_id)
|
|
12
|
+
where payment_id is not null
|
|
13
|
+
`.execute(db);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
17
|
+
await sql`
|
|
18
|
+
drop index if exists
|
|
19
|
+
accounting.journal_entry_payment_idx
|
|
20
|
+
`.execute(db);
|
|
21
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up<Database>(db: Kysely<Database>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create function core.register_inserted_reservation_journal_operations()
|
|
7
|
+
returns trigger
|
|
8
|
+
language plpgsql
|
|
9
|
+
as $$
|
|
10
|
+
declare
|
|
11
|
+
target_action_id uuid;
|
|
12
|
+
begin
|
|
13
|
+
for target_action_id in
|
|
14
|
+
select distinct action_id from inserted_invalidations
|
|
15
|
+
where action_id is not null
|
|
16
|
+
order by action_id
|
|
17
|
+
loop
|
|
18
|
+
perform core.register_reservation_journal_operation(target_action_id);
|
|
19
|
+
end loop;
|
|
20
|
+
return null;
|
|
21
|
+
end;
|
|
22
|
+
$$
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
drop trigger refresh_reservation_journal_invalidation_operation
|
|
26
|
+
on accounting.reservation_journal_invalidation
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
create trigger refresh_reservation_journal_invalidation_operation
|
|
30
|
+
after update of action_id, applied_at
|
|
31
|
+
on accounting.reservation_journal_invalidation
|
|
32
|
+
for each row
|
|
33
|
+
execute function core.refresh_reservation_journal_invalidation_operation()
|
|
34
|
+
`.execute(db);
|
|
35
|
+
await sql`
|
|
36
|
+
create trigger register_inserted_reservation_journal_operations
|
|
37
|
+
after insert on accounting.reservation_journal_invalidation
|
|
38
|
+
referencing new table as inserted_invalidations
|
|
39
|
+
for each statement
|
|
40
|
+
execute function core.register_inserted_reservation_journal_operations()
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
do $$
|
|
44
|
+
begin
|
|
45
|
+
if exists (select 1 from pg_roles where rolname = 'application') then
|
|
46
|
+
grant execute on function
|
|
47
|
+
core.register_inserted_reservation_journal_operations()
|
|
48
|
+
to application;
|
|
49
|
+
end if;
|
|
50
|
+
end;
|
|
51
|
+
$$
|
|
52
|
+
`.execute(db);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function down<Database>(db: Kysely<Database>): Promise<void> {
|
|
56
|
+
await sql`
|
|
57
|
+
drop trigger register_inserted_reservation_journal_operations
|
|
58
|
+
on accounting.reservation_journal_invalidation
|
|
59
|
+
`.execute(db);
|
|
60
|
+
await sql`
|
|
61
|
+
drop trigger refresh_reservation_journal_invalidation_operation
|
|
62
|
+
on accounting.reservation_journal_invalidation
|
|
63
|
+
`.execute(db);
|
|
64
|
+
await sql`
|
|
65
|
+
create trigger refresh_reservation_journal_invalidation_operation
|
|
66
|
+
after insert or update of action_id, applied_at
|
|
67
|
+
on accounting.reservation_journal_invalidation
|
|
68
|
+
for each row
|
|
69
|
+
execute function core.refresh_reservation_journal_invalidation_operation()
|
|
70
|
+
`.execute(db);
|
|
71
|
+
await sql`
|
|
72
|
+
drop function core.register_inserted_reservation_journal_operations()
|
|
73
|
+
`.execute(db);
|
|
74
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// Expand only: support can see why a portal user got no statement email and
|
|
5
|
+
// which action sent each email. Existing writers leave the new columns null.
|
|
6
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
7
|
+
await sql`set local lock_timeout = '5s'`.execute(db);
|
|
8
|
+
await sql`set local statement_timeout = '60s'`.execute(db);
|
|
9
|
+
|
|
10
|
+
await sql`
|
|
11
|
+
alter type core.email_delivery_failure_code
|
|
12
|
+
add value if not exists 'notifications_disabled'
|
|
13
|
+
`.execute(db);
|
|
14
|
+
await sql`
|
|
15
|
+
create type core.email_notification_trigger as enum (
|
|
16
|
+
'publish', 'resend', 'link_replacement'
|
|
17
|
+
)
|
|
18
|
+
`.execute(db);
|
|
19
|
+
await sql`
|
|
20
|
+
alter table core.email_notification
|
|
21
|
+
add column trigger core.email_notification_trigger,
|
|
22
|
+
add column requested_by_user_id uuid
|
|
23
|
+
`.execute(db);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The enum value is retained so historical deliveries remain readable.
|
|
27
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
28
|
+
await sql`
|
|
29
|
+
alter table core.email_notification
|
|
30
|
+
drop column if exists requested_by_user_id,
|
|
31
|
+
drop column if exists trigger
|
|
32
|
+
`.execute(db);
|
|
33
|
+
await sql`drop type if exists core.email_notification_trigger`.execute(db);
|
|
34
|
+
}
|