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 keys in payment_methods table (#5393)

Prajjwal Kumarca749b32591e
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index b8c5344cbb..55f8e935b1 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -934,7 +934,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
- payment_methods (id) {
+ payment_methods (payment_method_id) {
id -> Int4,
#[max_length = 64]
customer_id -> Varchar,
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 164600c88a..90046d3fd9 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -931,7 +931,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
- payment_methods (id) {
+ payment_methods (payment_method_id) {
id -> Int4,
#[max_length = 64]
customer_id -> Varchar,
diff --git a/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/down.sql b/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/down.sql
new file mode 100644
index 0000000000..26dd04d739
--- /dev/null
+++ b/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/down.sql
@@ -0,0 +1,5 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_methods DROP CONSTRAINT payment_methods_pkey;
+
+ALTER TABLE payment_methods
+ADD PRIMARY KEY (id);
diff --git a/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/up.sql b/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/up.sql
new file mode 100644
index 0000000000..5fc305bc92
--- /dev/null
+++ b/migrations/2024-07-22-082828_change_primary_key_for_payment_methods/up.sql
@@ -0,0 +1,12 @@
+-- Your SQL goes here
+-- The below query will lock the payment_methods 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 payment_methods DROP CONSTRAINT payment_methods_pkey;
+
+-- Use the `payment_method_id` column as primary key
+-- This is already unique, not null column
+-- So this query should not fail for not null or duplicate value reasons
+ALTER TABLE payment_methods
+ADD PRIMARY KEY (payment_method_id);