Skip to content

Commit

Permalink
refactor(merchant_account): change primary key for merchant account (#…
Browse files Browse the repository at this point in the history
…5327)

Co-authored-by: hrithikesh026 <[email protected]>
  • Loading branch information
Narayanbhat166 and hrithikesh026 authored Jul 18, 2024
1 parent 6d74527 commit a0c367e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/diesel_models/src/query/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl MerchantAccount {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.id,
self.merchant_id.clone(),
merchant_account,
)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit a0c367e

Please sign in to comment.