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

refactor(core): change primary key of refund table (#5367)

Prajjwal Kumarc698921c417d
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 171e1cfe2e..4b5f4a8ad4 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -1099,7 +1099,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
- refund (id) {
+ refund (merchant_id, refund_id) {
id -> Int4,
#[max_length = 64]
internal_reference_id -> Varchar,
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index d16ddcd651..a2e35a6d6a 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -1097,7 +1097,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
- refund (id) {
+ refund (merchant_id, refund_id) {
id -> Int4,
#[max_length = 64]
internal_reference_id -> Varchar,
diff --git a/migrations/2024-07-19-044034_change_primary_key_for_refund/down.sql b/migrations/2024-07-19-044034_change_primary_key_for_refund/down.sql
new file mode 100644
index 0000000000..42faa31536
--- /dev/null
+++ b/migrations/2024-07-19-044034_change_primary_key_for_refund/down.sql
@@ -0,0 +1,5 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE refund DROP CONSTRAINT refund_pkey;
+
+ALTER TABLE refund
+ADD PRIMARY KEY (id);
diff --git a/migrations/2024-07-19-044034_change_primary_key_for_refund/up.sql b/migrations/2024-07-19-044034_change_primary_key_for_refund/up.sql
new file mode 100644
index 0000000000..bbd6ef735d
--- /dev/null
+++ b/migrations/2024-07-19-044034_change_primary_key_for_refund/up.sql
@@ -0,0 +1,12 @@
+-- Your SQL goes here
+-- The below query will lock the refund table
+-- Running this query is not necessary on higher environments
+-- as the application will work fine without these queries being run
+-- This query should be run after the new version of application is deployed
+ALTER TABLE refund DROP CONSTRAINT refund_pkey;
+
+-- Use the `merchant_id, refund_id` columns as primary key
+-- These are already unique, not null columns
+-- So this query should not fail for not null or duplicate value reasons
+ALTER TABLE refund
+ADD PRIMARY KEY (merchant_id, refund_id);