A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.
JavaScript
fix(db): preserve pending outcomes during atomic outbox upgrade
generaltony0078290beed180c
diff --git a/packages/db/src/migrate.js b/packages/db/src/migrate.jsindex abd717c..ef23d5e 100644--- a/packages/db/src/migrate.js+++ b/packages/db/src/migrate.js@@ -85,6 +85,30 @@ export function runMigrations(targetDb) {}}+ // Older outboxes allowed only one legacy terminal event per payment. A UPI+ // payment can emit OBSERVED_SUCCESS and then RECONCILED, so retain each event.+ // Copy only already-pending rows: upgrading must not notify historic orders.+ const outboxColumns = db.query("PRAGMA table_info(payment_webhook_outbox)");+ if (outboxColumns.length && !outboxColumns.some(column => column.name === 'event_type' && column.pk)) {+ db.transaction(() => {+ db.exec('DROP TRIGGER IF EXISTS trg_terminal_payment_webhook_outbox;');+ db.exec(`+ CREATE TABLE payment_webhook_outbox_upgrade (+ payment_id TEXT NOT NULL REFERENCES payment_sessions(id) ON DELETE CASCADE,+ event_type TEXT NOT NULL CHECK(event_type IN ('SUCCESS','FAILED','EXPIRED','CANCELLED','OBSERVED_SUCCESS','MANUAL_REVIEW','RECONCILED')),+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),+ PRIMARY KEY (payment_id, event_type)+ );+ INSERT INTO payment_webhook_outbox_upgrade (payment_id, event_type, created_at)+ SELECT payment_id, event_type, created_at FROM payment_webhook_outbox;+ DROP TABLE payment_webhook_outbox;+ ALTER TABLE payment_webhook_outbox_upgrade RENAME TO payment_webhook_outbox;+ `);+ // Reinstall the new trigger in the same transaction as the table upgrade.+ db.exec(schemaSql);+ });+ }+// Execute schema DDLdb.exec(schemaSql);