From 6d74527f4428c8cb61e89d59385bfb2dd8056c2e Mon Sep 17 00:00:00 2001 From: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:01:29 +0530 Subject: [PATCH] refactor(router): remove id dependency from merchant connector account, dispute and mandate (#5330) Co-authored-by: hrithikesh026 Co-authored-by: sai-harsha-vardhan --- .../src/query/merchant_connector_account.rs | 2 +- crates/diesel_models/src/schema.rs | 6 +++--- crates/diesel_models/src/schema_v2.rs | 6 +++--- .../down.sql | 3 +++ .../up.sql | 11 +++++++++++ .../down.sql | 3 +++ .../up.sql | 11 +++++++++++ .../down.sql | 5 +++++ .../up.sql | 12 ++++++++++++ 9 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 migrations/2024-07-15-120121_change_primary_key_for_dispute/down.sql create mode 100644 migrations/2024-07-15-120121_change_primary_key_for_dispute/up.sql create mode 100644 migrations/2024-07-15-143920_change_primary_key_for_mandate/down.sql create mode 100644 migrations/2024-07-15-143920_change_primary_key_for_mandate/up.sql create mode 100644 migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/down.sql create mode 100644 migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/up.sql diff --git a/crates/diesel_models/src/query/merchant_connector_account.rs b/crates/diesel_models/src/query/merchant_connector_account.rs index bd24d12ec2..d275211ebd 100644 --- a/crates/diesel_models/src/query/merchant_connector_account.rs +++ b/crates/diesel_models/src/query/merchant_connector_account.rs @@ -25,7 +25,7 @@ impl MerchantConnectorAccount { ) -> StorageResult { match generics::generic_update_by_id::<::Table, _, _, _>( conn, - self.id, + self.merchant_connector_id.to_owned(), merchant_connector_account, ) .await diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index a5185dc607..68689e8644 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -336,7 +336,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - dispute (id) { + dispute (dispute_id) { id -> Int4, #[max_length = 64] dispute_id -> Varchar, @@ -587,7 +587,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - mandate (id) { + mandate (mandate_id) { id -> Int4, #[max_length = 64] mandate_id -> Varchar, @@ -677,7 +677,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - merchant_connector_account (id) { + merchant_connector_account (merchant_connector_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 da8729cf83..e353cbd566 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -336,7 +336,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - dispute (id) { + dispute (dispute_id) { id -> Int4, #[max_length = 64] dispute_id -> Varchar, @@ -587,7 +587,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - mandate (id) { + mandate (mandate_id) { id -> Int4, #[max_length = 64] mandate_id -> Varchar, @@ -677,7 +677,7 @@ diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; - merchant_connector_account (id) { + merchant_connector_account (merchant_connector_id) { id -> Int4, #[max_length = 64] merchant_id -> Varchar, diff --git a/migrations/2024-07-15-120121_change_primary_key_for_dispute/down.sql b/migrations/2024-07-15-120121_change_primary_key_for_dispute/down.sql new file mode 100644 index 0000000000..ff4e1664cb --- /dev/null +++ b/migrations/2024-07-15-120121_change_primary_key_for_dispute/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE dispute DROP CONSTRAINT dispute_pkey; + +ALTER TABLE dispute ADD PRIMARY KEY (id); \ No newline at end of file diff --git a/migrations/2024-07-15-120121_change_primary_key_for_dispute/up.sql b/migrations/2024-07-15-120121_change_primary_key_for_dispute/up.sql new file mode 100644 index 0000000000..794daa8850 --- /dev/null +++ b/migrations/2024-07-15-120121_change_primary_key_for_dispute/up.sql @@ -0,0 +1,11 @@ +-- Your SQL goes here +-- The below query will lock the dispute 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 dispute +-- This query should be run only after the new version of application is deployed +ALTER TABLE dispute DROP CONSTRAINT dispute_pkey; + +-- Use the `dispute_id` column as primary key +ALTER TABLE dispute +ADD PRIMARY KEY (dispute_id); diff --git a/migrations/2024-07-15-143920_change_primary_key_for_mandate/down.sql b/migrations/2024-07-15-143920_change_primary_key_for_mandate/down.sql new file mode 100644 index 0000000000..b04e648e07 --- /dev/null +++ b/migrations/2024-07-15-143920_change_primary_key_for_mandate/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE mandate DROP CONSTRAINT mandate_pkey; + +ALTER TABLE mandate ADD PRIMARY KEY (id); \ No newline at end of file diff --git a/migrations/2024-07-15-143920_change_primary_key_for_mandate/up.sql b/migrations/2024-07-15-143920_change_primary_key_for_mandate/up.sql new file mode 100644 index 0000000000..13ff09a17e --- /dev/null +++ b/migrations/2024-07-15-143920_change_primary_key_for_mandate/up.sql @@ -0,0 +1,11 @@ +-- Your SQL goes here +-- The below query will lock the mandate 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 mandate +-- This query should be run only after the new version of application is deployed +ALTER TABLE mandate DROP CONSTRAINT mandate_pkey; + +-- Use the `mandate_id` column as primary key +ALTER TABLE mandate +ADD PRIMARY KEY (mandate_id); diff --git a/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/down.sql b/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/down.sql new file mode 100644 index 0000000000..2107fd6370 --- /dev/null +++ b/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey; + +ALTER TABLE merchant_connector_account +ADD PRIMARY KEY (id); diff --git a/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/up.sql b/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/up.sql new file mode 100644 index 0000000000..c12fc937bb --- /dev/null +++ b/migrations/2024-07-15-170210_change_primary_key_for_merchant_connector_account/up.sql @@ -0,0 +1,12 @@ +-- Your SQL goes here +-- The below query will lock the merchant connector account 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 only after the new version of application is deployed +ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey; + +-- Use the `merchant_connector_id` column as primary key +-- This is not a unique column, but in an ideal scenario there should not be any duplicate keys as this is being generated by the application +-- So this query should not fail for not null or duplicate values reasons +ALTER TABLE merchant_connector_account +ADD PRIMARY KEY (merchant_connector_id);