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

fix(migrations): create unique indexes on payment intent and attempt in v2 compatible migrations (#14901)

Hrithikeshb0bc2ca6a909
diff --git a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql
index 965c6fd9dc..1729dabb21 100644
--- a/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql
+++ b/v2_compatible_migrations/2024-08-28-081757_drop_not_null_constraints_on_v1_columns/up.sql
@@ -5,7 +5,7 @@ ALTER TABLE organization
ALTER COLUMN org_id DROP NOT NULL;
-- Create index on org_id in organization table
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_organization_org_id ON organization (org_id);
+CREATE UNIQUE INDEX idx_organization_org_id ON organization (org_id);
------------------------ Merchant Account -------------------
@@ -17,7 +17,7 @@ ALTER TABLE merchant_account
ALTER COLUMN is_recon_enabled DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_merchant_account_merchant_id ON merchant_account (merchant_id);
+CREATE UNIQUE INDEX idx_merchant_account_merchant_id ON merchant_account (merchant_id);
------------------------ Business Profile -------------------
ALTER TABLE business_profile
@@ -25,21 +25,21 @@ ALTER TABLE business_profile
ALTER COLUMN profile_id DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_business_profile_profile_id ON business_profile (profile_id);
+CREATE UNIQUE INDEX idx_business_profile_profile_id ON business_profile (profile_id);
---------------- Merchant Connector Account -----------------
ALTER TABLE merchant_connector_account
DROP CONSTRAINT merchant_connector_account_pkey,
ALTER COLUMN merchant_connector_id DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_merchant_connector_account_merchant_connector_id ON merchant_connector_account (merchant_connector_id);
+CREATE UNIQUE INDEX idx_merchant_connector_account_merchant_connector_id ON merchant_connector_account (merchant_connector_id);
------------------------ Customers --------------------------
ALTER TABLE customers
DROP CONSTRAINT customers_pkey,
ALTER COLUMN customer_id DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_customers_merchant_id_customer_id ON customers (merchant_id, customer_id);
+CREATE UNIQUE INDEX idx_customers_merchant_id_customer_id ON customers (merchant_id, customer_id);
---------------------- Payment Intent -----------------------
ALTER TABLE payment_intent
@@ -48,7 +48,7 @@ ALTER TABLE payment_intent
ALTER COLUMN active_attempt_id DROP NOT NULL,
ALTER COLUMN active_attempt_id DROP DEFAULT;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_payment_intent_payment_id_merchant_id ON payment_intent (payment_id, merchant_id);
+CREATE UNIQUE INDEX idx_payment_intent_payment_id_merchant_id ON payment_intent (payment_id, merchant_id);
---------------------- Payment Attempt ----------------------
ALTER TABLE payment_attempt
@@ -56,7 +56,7 @@ ALTER TABLE payment_attempt
ALTER COLUMN attempt_id DROP NOT NULL,
ALTER COLUMN amount DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_payment_attempt_attempt_id_merchant_id ON payment_attempt (attempt_id, merchant_id);
+CREATE UNIQUE INDEX idx_payment_attempt_attempt_id_merchant_id ON payment_attempt (attempt_id, merchant_id);
ALTER TABLE payment_attempt
ALTER COLUMN confirm DROP NOT NULL;
@@ -66,7 +66,7 @@ ALTER TABLE payment_methods
DROP CONSTRAINT payment_methods_pkey,
ALTER COLUMN payment_method_id DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_payment_methods_payment_method_id ON payment_methods (payment_method_id);
+CREATE UNIQUE INDEX idx_payment_methods_payment_method_id ON payment_methods (payment_method_id);
---------------------- Refunds ----------------------
ALTER TABLE refund
@@ -76,4 +76,4 @@ ALTER TABLE refund
ALTER TABLE refund
ALTER COLUMN internal_reference_id DROP NOT NULL;
-- This is done to nullify the effects of dropping primary key for v1
-CREATE INDEX idx_refund_refund_id_merchant_id ON refund (refund_id, merchant_id);
\ No newline at end of file
+CREATE UNIQUE INDEX idx_refund_refund_id_merchant_id ON refund (refund_id, merchant_id);
\ No newline at end of file