diff --git a/crates/diesel_models/src/query/merchant_account.rs b/crates/diesel_models/src/query/merchant_account.rs index dd2f284305be..66526e11cb2d 100644 --- a/crates/diesel_models/src/query/merchant_account.rs +++ b/crates/diesel_models/src/query/merchant_account.rs @@ -22,7 +22,7 @@ impl MerchantAccount { ) -> StorageResult { match generics::generic_update_by_id::<::Table, _, _, _>( conn, - self.id, + self.merchant_id.clone(), merchant_account, ) .await diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index a5185dc6076a..6bfcd0257486 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -633,7 +633,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - merchant_account (id) { + merchant_account (merchant_id) { id -> Int4, #[max_length = 64] merchant_id -> Varchar, diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index da8729cf8357..0efb4cb51042 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -633,7 +633,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - merchant_account (id) { + merchant_account (merchant_id) { id -> Int4, #[max_length = 64] merchant_id -> Varchar, diff --git a/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/down.sql b/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/down.sql new file mode 100644 index 000000000000..2f169d80194d --- /dev/null +++ b/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey; + +ALTER TABLE merchant_account +ADD PRIMARY KEY (id); diff --git a/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/up.sql b/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/up.sql new file mode 100644 index 000000000000..5db5076c07ae --- /dev/null +++ b/migrations/2024-07-15-111327_change_primary_key_for_merchant_account/up.sql @@ -0,0 +1,13 @@ +-- Your SQL goes here +-- The below query will lock the merchant account table +-- Running this query is not necessary on higher environments +-- as the application will work fine without these queries being run +-- This query is necessary for the application to not use id in update of merchant_account +-- This query should be run after the new version of application is deployed +ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey; + +-- Use the `merchant_id` column as primary key +-- This is already a unique, not null column +-- So this query should not fail for not null or duplicate values reasons +ALTER TABLE merchant_account +ADD PRIMARY KEY (merchant_id);