Appearance
MegaKassa data purge runbook
MegaKassa has been removed from application code. Legacy databases may still contain payment_provider_configs.provider = 'megakassa' rows. Leaving that config row in place breaks listProviderConfigs() after deploy because megakassa is no longer in HOSTED_PAYMENT_PROVIDERS.
This purge is irreversible. Always take a database backup first.
Prerequisites
- Deploy (or stage) a build that no longer registers MegaKassa adapters.
- Snapshot / dump Postgres (
pg_dumpor your managed-backup tool). - Confirm restore procedure for that snapshot.
- Set
DATABASE_URLto the target database.
Dry-run (mandatory)
bash
pnpm repair:megakassa-purgeReview printed counts for:
payment_provider_configspayment_provider_methodscashier_payment_methodspayment_method_routes/payment_route_providers/ usage counters / preferencespayments/withdrawals- classified
balance_transactionsandaudit_logrows
Confirm Fynzah SBP (fynzah:sbp:in), Fintrix, CryptoCloud, P2P, and Mercado Pago rows are not listed.
Pending work
If the dry-run aborts because MegaKassa payments/withdrawals are still pending / processing / created:
- Prefer settling or cancelling them in the admin UI, or
- Re-run with an explicit override after operator sign-off:
bash
pnpm repair:megakassa-purge -- --apply --allow-pendingApply
bash
pnpm repair:megakassa-purge -- --applyThe script runs all deletes in one transaction, then asserts zero remaining MegaKassa provider config/method/payment rows.
Re-run --apply a second time; it must report zero rows (idempotent).
Integrity notes
- Ledger rows are deleted only when
reference_idmatches a proven MegaKassa payment id, order id, or withdrawal id. - Ambiguous
audit_logmetadata that mentions MegaKassa outside payment-domain entity types causes an abort — classify manually before retrying. - Deleting credited ledger rows does not automatically rewrite wallet balances. If balances must match historical ledger totals, restore from the pre-purge backup instead of inventing corrective ledger entries.
Restore
Restore the pre-purge snapshot with your standard Postgres restore process, then re-run application migrations if required. Do not partially re-insert MegaKassa config into a post-removal codebase.
Verification after purge
bash
# Should find no application references (docs/runbook/script excluded intentionally)
rg -i 'megakassa' --glob '!apps/docs/**' --glob '!scripts/repair-megakassa-purge*' --glob '!node_modules'
pnpm --filter @repo/db exec vitest run src/operations/wallet/providersConfirm Admin → Cashier methods loads without errors and Fynzah SBP still works.