Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

perf(migrations): add partial created_at indexes on events table (#13587)

Ayush Anandbe3634b52356
diff --git a/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/down.sql b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/down.sql
new file mode 100644
index 0000000000..228a43bd4c
--- /dev/null
+++ b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+DROP INDEX CONCURRENTLY IF EXISTS events_initiator_merchant_id_created_at_initial_index;
diff --git a/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/metadata.toml b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/metadata.toml
new file mode 100644
index 0000000000..79e9221c1f
--- /dev/null
+++ b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/metadata.toml
@@ -0,0 +1 @@
+run_in_transaction = false
diff --git a/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/up.sql b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/up.sql
new file mode 100644
index 0000000000..021914e0ca
--- /dev/null
+++ b/migrations/2026-08-07-000001_add_events_initiator_merchant_id_created_at_index/up.sql
@@ -0,0 +1,4 @@
+-- Your SQL goes here
+CREATE INDEX CONCURRENTLY IF NOT EXISTS events_initiator_merchant_id_created_at_initial_index
+ON events (initiator_merchant_id, created_at)
+WHERE event_id = initial_attempt_id;
diff --git a/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/down.sql b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/down.sql
new file mode 100644
index 0000000000..1852df8cca
--- /dev/null
+++ b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+DROP INDEX CONCURRENTLY IF EXISTS events_business_profile_id_created_at_initial_index;
diff --git a/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/metadata.toml b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/metadata.toml
new file mode 100644
index 0000000000..79e9221c1f
--- /dev/null
+++ b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/metadata.toml
@@ -0,0 +1 @@
+run_in_transaction = false
diff --git a/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/up.sql b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/up.sql
new file mode 100644
index 0000000000..edfb02c57b
--- /dev/null
+++ b/migrations/2026-08-07-000002_add_events_business_profile_id_created_at_index/up.sql
@@ -0,0 +1,4 @@
+-- Your SQL goes here
+CREATE INDEX CONCURRENTLY IF NOT EXISTS events_business_profile_id_created_at_initial_index
+ON events (business_profile_id, created_at)
+WHERE event_id = initial_attempt_id;