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(v2_migrations): re-organize v2 migrations (#5760)

Sanchith Hegdef32a32945d09
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 4ac16850ce..671b35a846 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -58,7 +58,7 @@ pub struct BusinessProfile {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
#[cfg(all(
@@ -101,7 +101,7 @@ pub struct BusinessProfileNew {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
#[cfg(all(
@@ -231,7 +231,7 @@ impl BusinessProfileUpdateInternal {
.or(source.always_collect_shipping_details_from_wallet_connector),
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
- api_version: source.api_version,
+ version: source.version,
}
}
}
@@ -271,6 +271,8 @@ pub struct BusinessProfile {
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
+ pub tax_connector_id: Option<String>,
+ pub is_tax_connector_enabled: Option<bool>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
@@ -278,9 +280,7 @@ pub struct BusinessProfile {
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
- pub tax_connector_id: Option<String>,
- pub is_tax_connector_enabled: Option<bool>,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
impl BusinessProfile {
@@ -328,6 +328,8 @@ pub struct BusinessProfileNew {
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
+ pub tax_connector_id: Option<String>,
+ pub is_tax_connector_enabled: Option<bool>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
@@ -335,9 +337,7 @@ pub struct BusinessProfileNew {
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
- pub tax_connector_id: Option<String>,
- pub is_tax_connector_enabled: Option<bool>,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -368,14 +368,14 @@ pub struct BusinessProfileUpdateInternal {
pub outgoing_webhook_custom_http_headers: Option<Encryption>,
pub always_collect_billing_details_from_wallet_connector: Option<bool>,
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
+ pub tax_connector_id: Option<String>,
+ pub is_tax_connector_enabled: Option<bool>,
pub routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub order_fulfillment_time: Option<i64>,
pub order_fulfillment_time_origin: Option<common_enums::OrderFulfillmentTimeOrigin>,
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
- pub tax_connector_id: Option<String>,
- pub is_tax_connector_enabled: Option<bool>,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -405,14 +405,14 @@ impl BusinessProfileUpdateInternal {
outgoing_webhook_custom_http_headers,
always_collect_billing_details_from_wallet_connector,
always_collect_shipping_details_from_wallet_connector,
+ tax_connector_id,
+ is_tax_connector_enabled,
routing_algorithm_id,
order_fulfillment_time,
order_fulfillment_time_origin,
frm_routing_algorithm_id,
payout_routing_algorithm_id,
default_fallback_routing,
- tax_connector_id,
- is_tax_connector_enabled,
} = self;
BusinessProfile {
id: source.id,
@@ -459,6 +459,8 @@ impl BusinessProfileUpdateInternal {
always_collect_shipping_details_from_wallet_connector:
always_collect_shipping_details_from_wallet_connector
.or(always_collect_shipping_details_from_wallet_connector),
+ tax_connector_id: tax_connector_id.or(source.tax_connector_id),
+ is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
routing_algorithm_id: routing_algorithm_id.or(source.routing_algorithm_id),
order_fulfillment_time: order_fulfillment_time.or(source.order_fulfillment_time),
order_fulfillment_time_origin: order_fulfillment_time_origin
@@ -467,9 +469,7 @@ impl BusinessProfileUpdateInternal {
payout_routing_algorithm_id: payout_routing_algorithm_id
.or(source.payout_routing_algorithm_id),
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
- tax_connector_id: tax_connector_id.or(source.tax_connector_id),
- is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
- api_version: source.api_version,
+ version: source.version,
}
}
}
@@ -507,6 +507,8 @@ impl From<BusinessProfileNew> for BusinessProfile {
collect_billing_details_from_wallet_connector: new
.collect_billing_details_from_wallet_connector,
outgoing_webhook_custom_http_headers: new.outgoing_webhook_custom_http_headers,
+ tax_connector_id: new.tax_connector_id,
+ is_tax_connector_enabled: new.is_tax_connector_enabled,
routing_algorithm_id: new.routing_algorithm_id,
always_collect_billing_details_from_wallet_connector: new
.always_collect_billing_details_from_wallet_connector,
@@ -517,9 +519,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
frm_routing_algorithm_id: new.frm_routing_algorithm_id,
payout_routing_algorithm_id: new.payout_routing_algorithm_id,
default_fallback_routing: new.default_fallback_routing,
- tax_connector_id: new.tax_connector_id,
- is_tax_connector_enabled: new.is_tax_connector_enabled,
- api_version: new.api_version,
+ version: new.version,
}
}
}
diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs
index ac7635e88c..d5566a72e2 100644
--- a/crates/diesel_models/src/merchant_account.rs
+++ b/crates/diesel_models/src/merchant_account.rs
@@ -158,8 +158,8 @@ pub struct MerchantAccount {
pub modified_at: time::PrimitiveDateTime,
pub organization_id: common_utils::id_type::OrganizationId,
pub recon_status: storage_enums::ReconStatus,
- pub id: common_utils::id_type::MerchantId,
pub version: common_enums::ApiVersion,
+ pub id: common_utils::id_type::MerchantId,
}
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
diff --git a/crates/diesel_models/src/merchant_connector_account.rs b/crates/diesel_models/src/merchant_connector_account.rs
index cd92f5492a..ab2672026b 100644
--- a/crates/diesel_models/src/merchant_connector_account.rs
+++ b/crates/diesel_models/src/merchant_connector_account.rs
@@ -102,8 +102,8 @@ pub struct MerchantConnectorAccount {
pub status: storage_enums::ConnectorStatus,
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
- pub id: id_type::MerchantConnectorAccountId,
pub version: common_enums::ApiVersion,
+ pub id: id_type::MerchantConnectorAccountId,
}
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 02d49a4b7c..e0f2b9a0bd 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -208,7 +208,7 @@ diesel::table! {
#[max_length = 64]
tax_connector_id -> Nullable<Varchar>,
is_tax_connector_enabled -> Nullable<Bool>,
- api_version -> ApiVersion,
+ version -> ApiVersion,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 6021b32802..410c541441 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -202,6 +202,9 @@ diesel::table! {
always_collect_billing_details_from_wallet_connector -> Nullable<Bool>,
always_collect_shipping_details_from_wallet_connector -> Nullable<Bool>,
#[max_length = 64]
+ tax_connector_id -> Nullable<Varchar>,
+ is_tax_connector_enabled -> Nullable<Bool>,
+ #[max_length = 64]
routing_algorithm_id -> Nullable<Varchar>,
order_fulfillment_time -> Nullable<Int8>,
order_fulfillment_time_origin -> Nullable<OrderFulfillmentTimeOrigin>,
@@ -212,10 +215,7 @@ diesel::table! {
default_fallback_routing -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
- #[max_length = 64]
- tax_connector_id -> Nullable<Varchar>,
- is_tax_connector_enabled -> Nullable<Bool>,
- api_version -> ApiVersion,
+ version -> ApiVersion,
}
}
@@ -660,9 +660,9 @@ diesel::table! {
#[max_length = 32]
organization_id -> Varchar,
recon_status -> ReconStatus,
+ version -> ApiVersion,
#[max_length = 64]
id -> Varchar,
- version -> ApiVersion,
}
}
@@ -693,9 +693,9 @@ diesel::table! {
status -> ConnectorStatus,
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
+ version -> ApiVersion,
#[max_length = 64]
id -> Varchar,
- version -> ApiVersion,
}
}
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index ce01681cc1..0910a2b0e9 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -56,7 +56,7 @@ pub struct BusinessProfile {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: bool,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
#[cfg(all(
@@ -141,7 +141,7 @@ impl From<BusinessProfileSetter> for BusinessProfile {
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: value.tax_connector_id,
is_tax_connector_enabled: value.is_tax_connector_enabled,
- api_version: consts::API_VERSION,
+ version: consts::API_VERSION,
}
}
}
@@ -439,7 +439,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
- api_version: self.api_version,
+ version: self.version,
})
}
@@ -503,7 +503,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.await?,
tax_connector_id: item.tax_connector_id,
is_tax_connector_enabled: item.is_tax_connector_enabled.unwrap_or(false),
- api_version: item.api_version,
+ version: item.version,
})
}
.await
@@ -552,7 +552,7 @@ impl super::behaviour::Conversion for BusinessProfile {
.always_collect_shipping_details_from_wallet_connector,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
- api_version: self.api_version,
+ version: self.version,
})
}
}
@@ -594,7 +594,7 @@ pub struct BusinessProfile {
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: bool,
- pub api_version: common_enums::ApiVersion,
+ pub version: common_enums::ApiVersion,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -677,7 +677,7 @@ impl From<BusinessProfileSetter> for BusinessProfile {
default_fallback_routing: value.default_fallback_routing,
tax_connector_id: value.tax_connector_id,
is_tax_connector_enabled: value.is_tax_connector_enabled,
- api_version: consts::API_VERSION,
+ version: consts::API_VERSION,
}
}
}
@@ -1002,7 +1002,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: self.default_fallback_routing,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
- api_version: self.api_version,
+ version: self.version,
})
}
@@ -1068,7 +1068,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: item.default_fallback_routing,
tax_connector_id: item.tax_connector_id,
is_tax_connector_enabled: item.is_tax_connector_enabled.unwrap_or(false),
- api_version: item.api_version,
+ version: item.version,
})
}
.await
@@ -1119,7 +1119,7 @@ impl super::behaviour::Conversion for BusinessProfile {
default_fallback_routing: self.default_fallback_routing,
tax_connector_id: self.tax_connector_id,
is_tax_connector_enabled: Some(self.is_tax_connector_enabled),
- api_version: self.api_version,
+ version: self.version,
})
}
}
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 37b7ae4e26..11ba1a0467 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1911,7 +1911,7 @@ impl<'a> MerchantDefaultConfigUpdate<'a> {
))]
struct DefaultFallbackRoutingConfigUpdate<'a> {
routable_connector: &'a Option<api_enums::RoutableConnectors>,
- merchant_connector_id: &'a common_utils::id_type::MerchantConnectorAccountId,
+ merchant_connector_id: &'a id_type::MerchantConnectorAccountId,
store: &'a dyn StorageInterface,
business_profile: domain::BusinessProfile,
key_store: hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,
@@ -4077,7 +4077,7 @@ impl BusinessProfileWrapper {
db: &dyn StorageInterface,
key_manager_state: &KeyManagerState,
merchant_key_store: &domain::MerchantKeyStore,
- algorithm_id: common_utils::id_type::RoutingId,
+ algorithm_id: id_type::RoutingId,
transaction_type: &storage::enums::TransactionType,
) -> RouterResult<()> {
let routing_cache_key = self.clone().get_routing_config_cache_key();
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index fc66a4f762..fa03065652 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -626,7 +626,7 @@ pub(crate) async fn get_payment_method_create_request(
.flatten(),
};
let payment_method_request = payment_methods::PaymentMethodCreate {
- payment_method: payment_method,
+ payment_method,
payment_method_type: payment_method_type
.get_required_value("Payment_method_type")
.change_context(errors::ApiErrorResponse::MissingRequiredField {
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index a8f5332290..0e9244f1b5 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3975,7 +3975,7 @@ pub async fn filter_payment_methods(
_mca_id: String,
_payment_methods: &[Secret<serde_json::Value>],
_req: &mut api::PaymentMethodListRequest,
- _resp: &mut Vec<ResponsePaymentMethodIntermediate>,
+ _resp: &mut [ResponsePaymentMethodIntermediate],
_payment_intent: Option<&storage::PaymentIntent>,
_payment_attempt: Option<&storage::PaymentAttempt>,
_address: Option<&domain::Address>,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f024147430..9282c8dd31 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -445,7 +445,7 @@ pub async fn get_token_pm_type_mandate_details(
#[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]
let connector_name = db
- .find_merchant_connector_account_by_id(key_manager_state, &mca_id, &merchant_key_store)
+ .find_merchant_connector_account_by_id(key_manager_state, mca_id, merchant_key_store)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: mca_id.clone().get_string_repr().to_string(),
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index 6a2689da40..6a922e1d40 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -657,7 +657,7 @@ where
pub async fn save_payment_method<FData>(
_state: &SessionState,
_connector_name: String,
- _merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
+ _merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
_save_payment_method_data: SavePaymentMethodData<FData>,
_customer_id: Option<id_type::CustomerId>,
_merchant_account: &domain::MerchantAccount,
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index e45beb8c04..e7acdd1800 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -300,7 +300,7 @@ pub async fn payouts_create_core(
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
req: payouts::PayoutCreateRequest,
- locale: &String,
+ locale: &str,
) -> RouterResponse<payouts::PayoutCreateResponse> {
// Validate create request
let (payout_id, payout_method_data, profile_id, customer) =
@@ -2220,10 +2220,10 @@ pub async fn payout_create_db_entries(
_merchant_account: &domain::MerchantAccount,
_key_store: &domain::MerchantKeyStore,
_req: &payouts::PayoutCreateRequest,
- _payout_id: &String,
- _profile_id: &String,
+ _payout_id: &str,
+ _profile_id: &str,
_stored_payout_method_data: Option<&payouts::PayoutMethodData>,
- _locale: &String,
+ _locale: &str,
_customer: Option<&domain::Customer>,
) -> RouterResult<PayoutData> {
todo!()
@@ -2240,7 +2240,7 @@ pub async fn payout_create_db_entries(
payout_id: &String,
profile_id: &common_utils::id_type::ProfileId,
stored_payout_method_data: Option<&payouts::PayoutMethodData>,
- locale: &String,
+ locale: &str,
customer: Option<&domain::Customer>,
) -> RouterResult<PayoutData> {
let db = &*state.store;
@@ -2652,8 +2652,8 @@ pub async fn create_payout_link(
customer_id: &CustomerId,
merchant_id: &common_utils::id_type::MerchantId,
req: &payouts::PayoutCreateRequest,
- payout_id: &String,
- locale: &String,
+ payout_id: &str,
+ locale: &str,
) -> RouterResult<PayoutLink> {
let payout_link_config_req = req.payout_link_config.to_owned();
diff --git a/migrations/2024-08-29-135449_add_api_version_to_business_profile/down.sql b/migrations/2024-08-29-135449_add_api_version_to_business_profile/down.sql
deleted file mode 100644
index 564ca16df8..0000000000
--- a/migrations/2024-08-29-135449_add_api_version_to_business_profile/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE business_profile DROP COLUMN api_version;
diff --git a/migrations/2024-08-29-135449_add_api_version_to_business_profile/up.sql b/migrations/2024-08-29-135449_add_api_version_to_business_profile/up.sql
deleted file mode 100644
index 50d44824ef..0000000000
--- a/migrations/2024-08-29-135449_add_api_version_to_business_profile/up.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- Your SQL goes here
-ALTER TABLE business_profile
-ADD COLUMN api_version "ApiVersion" DEFAULT 'v1' NOT NULL;
diff --git a/migrations/2024-08-29-135449_add_version_to_business_profile/down.sql b/migrations/2024-08-29-135449_add_version_to_business_profile/down.sql
new file mode 100644
index 0000000000..05b0d2bc3a
--- /dev/null
+++ b/migrations/2024-08-29-135449_add_version_to_business_profile/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE business_profile DROP COLUMN version;
diff --git a/migrations/2024-08-29-135449_add_version_to_business_profile/up.sql b/migrations/2024-08-29-135449_add_version_to_business_profile/up.sql
new file mode 100644
index 0000000000..93300d28bc
--- /dev/null
+++ b/migrations/2024-08-29-135449_add_version_to_business_profile/up.sql
@@ -0,0 +1,3 @@
+-- Your SQL goes here
+ALTER TABLE business_profile
+ADD COLUMN version "ApiVersion" DEFAULT 'v1' NOT NULL;
diff --git a/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/down.sql b/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/down.sql
deleted file mode 100644
index 5b704469b9..0000000000
--- a/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/down.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE payment_intent
-ADD id SERIAL;
-
-ALTER TABLE payment_attempt
-ADD id SERIAL;
diff --git a/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/up.sql b/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/up.sql
deleted file mode 100644
index 221ab4e9ae..0000000000
--- a/v2_migrations/2024-06-03-133421_remove_id_from_payment_table/up.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- The following queries must be run after the newer version of the application is deployed.
--- Running these queries can even be deferred for some time (a couple of weeks or even a month) until the
--- new version being deployed is considered stable
-ALTER TABLE payment_intent DROP COLUMN id;
-
-ALTER TABLE payment_attempt DROP COLUMN id;
diff --git a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql
deleted file mode 100644
index c222562b9a..0000000000
--- a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/down.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_account
-ADD COLUMN IF NOT EXISTS id SERIAL;
diff --git a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql b/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql
deleted file mode 100644
index 556c6721d4..0000000000
--- a/v2_migrations/2024-07-19-073520_remove_id_from_merchant_account/up.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- Your SQL goes here
--- Drop the id column as this will be used later as the primary key with a different type
-ALTER TABLE merchant_account DROP COLUMN IF EXISTS id;
diff --git a/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/down.sql b/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/down.sql
deleted file mode 100644
index 82fc50e6f4..0000000000
--- a/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_account DROP id;
diff --git a/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/up.sql b/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/up.sql
deleted file mode 100644
index a84fe8a79c..0000000000
--- a/v2_migrations/2024-07-25-064644_add_id_in_merchant_account/up.sql
+++ /dev/null
@@ -1,5 +0,0 @@
--- Your SQL goes here
--- Adding a new column called `id` which will be the new primary key for v2
--- Note that even though this will be the new primary key, the v1 application would still fill in null values
-ALTER TABLE merchant_account
-ADD COLUMN id VARCHAR(64);
diff --git a/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/down.sql b/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/down.sql
deleted file mode 100644
index e3870f5982..0000000000
--- a/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/down.sql
+++ /dev/null
@@ -1,16 +0,0 @@
--- This file should undo anything in `up.sql`
--- The new primary key for v2 merchant account will be `id`
-ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
-
--- In order to run this query, the merchant_id column should be unique and not null
--- We need to backfill the id, a simple strategy will be to copy the values of id to merchant_id
--- Query to update the merchant_id column with values of id
-UPDATE merchant_account
-SET merchant_id = id;
-
--- Note: This command might not run successfully for the existing table
--- This is because there will be some rows ( which are created via v2 application ) which will have id as empty
--- A backfill might be required to run this query
--- However if this is being run on a fresh database, this should succeed
-ALTER TABLE merchant_account
-ADD PRIMARY KEY (merchant_id);
diff --git a/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/up.sql b/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/up.sql
deleted file mode 100644
index ef98378907..0000000000
--- a/v2_migrations/2024-07-25-065100_change_primary_key_from_merchant_id_to_id/up.sql
+++ /dev/null
@@ -1,17 +0,0 @@
--- Your SQL goes here
--- The new primary key for v2 merchant account will be `id`
-ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
-
--- In order to make id as primary key, it should be unique and not null
--- We need to backfill the id, a simple strategy will be to copy the values of merchant_id to id
--- Query to update the id column with values of merchant_id
--- Note: This query will lock the table, so it should be run when there is no traffic
-UPDATE merchant_account
-SET id = merchant_id;
-
--- Note: This command might not run successfully for the existing table
--- This is because there will be some rows ( which are created via v1 application ) which will have id as empty
--- A backfill might be required to run this query
--- However if this is being run on a fresh database, this should succeed
-ALTER TABLE merchant_account
-ADD PRIMARY KEY (id);
diff --git a/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/down.sql b/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/down.sql
deleted file mode 100644
index d4f61709ad..0000000000
--- a/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/down.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_account
-ADD COLUMN merchant_id VARCHAR(64);
diff --git a/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/up.sql b/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/up.sql
deleted file mode 100644
index 9bdf043ebd..0000000000
--- a/v2_migrations/2024-07-25-065542_drop_merchant_id_from_merchant_account/up.sql
+++ /dev/null
@@ -1,4 +0,0 @@
--- Your SQL goes here
--- Note: This query should not be run on higher environments as this leads to data loss
--- The application will work fine even without these queries not being run
-ALTER TABLE merchant_account DROP merchant_id;
diff --git a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql
deleted file mode 100644
index 8880dda3a5..0000000000
--- a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/down.sql
+++ /dev/null
@@ -1,55 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_account
-ADD COLUMN return_url VARCHAR(255);
-
-ALTER TABLE merchant_account
-ADD COLUMN enable_payment_response_hash BOOLEAN DEFAULT FALSE;
-
-ALTER TABLE merchant_account
-ADD COLUMN payment_response_hash_key VARCHAR(255);
-
-ALTER TABLE merchant_account
-ADD COLUMN redirect_to_merchant_with_http_post BOOLEAN DEFAULT FALSE;
-
-ALTER TABLE merchant_account
-ADD COLUMN sub_merchants_enabled BOOLEAN DEFAULT FALSE;
-
-ALTER TABLE merchant_account
-ADD COLUMN parent_merchant_id VARCHAR(64);
-
--- The default value is for temporary purpose only
-ALTER TABLE merchant_account
-ADD COLUMN primary_business_details JSON NOT NULL DEFAULT '[{"country": "US", "business": "default"}]';
-
-ALTER TABLE merchant_account
-ALTER COLUMN primary_business_details DROP DEFAULT;
-
-ALTER TABLE merchant_account
-ADD COLUMN locker_id VARCHAR(64);
-
-ALTER TABLE merchant_account
-ADD COLUMN intent_fulfillment_time BIGINT;
-
-ALTER TABLE merchant_account
-ADD COLUMN default_profile VARCHAR(64);
-
-ALTER TABLE merchant_account
-ADD COLUMN payment_link_config JSONB NULL;
-
-ALTER TABLE merchant_account
-ADD COLUMN pm_collect_link_config JSONB NULL;
-
-ALTER TABLE merchant_account
-ADD COLUMN is_recon_enabled BOOLEAN NOT NULL DEFAULT FALSE;
-
-ALTER TABLE merchant_account
-ADD COLUMN webhook_details JSONB NULL;
-
-ALTER TABLE merchant_account
-ADD COLUMN routing_algorithm JSON;
-
-ALTER TABLE merchant_account
-ADD COLUMN frm_routing_algorithm JSONB;
-
-ALTER TABLE merchant_account
-ADD COLUMN payout_routing_algorithm JSONB;
diff --git a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql b/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql
deleted file mode 100644
index 0129f1b1cf..0000000000
--- a/v2_migrations/2024-07-26-065428_remove_deprecated_field_from_merchant_account/up.sql
+++ /dev/null
@@ -1,34 +0,0 @@
--- Your SQL goes here
-ALTER TABLE merchant_account DROP COLUMN return_url;
-
-ALTER TABLE merchant_account DROP enable_payment_response_hash;
-
-ALTER TABLE merchant_account DROP payment_response_hash_key;
-
-ALTER TABLE merchant_account DROP redirect_to_merchant_with_http_post;
-
-ALTER TABLE merchant_account DROP sub_merchants_enabled;
-
-ALTER TABLE merchant_account DROP parent_merchant_id;
-
-ALTER TABLE merchant_account DROP primary_business_details;
-
-ALTER TABLE merchant_account DROP locker_id;
-
-ALTER TABLE merchant_account DROP intent_fulfillment_time;
-
-ALTER TABLE merchant_account DROP default_profile;
-
-ALTER TABLE merchant_account DROP payment_link_config;
-
-ALTER TABLE merchant_account DROP pm_collect_link_config;
-
-ALTER TABLE merchant_account DROP is_recon_enabled;
-
-ALTER TABLE merchant_account DROP webhook_details;
-
-ALTER TABLE merchant_account DROP routing_algorithm;
-
-ALTER TABLE merchant_account DROP frm_routing_algorithm;
-
-ALTER TABLE merchant_account DROP payout_routing_algorithm;
diff --git a/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/down.sql b/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/down.sql
deleted file mode 100644
index a41a6c32be..0000000000
--- a/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/down.sql
+++ /dev/null
@@ -1,22 +0,0 @@
--- Alter queries
-ALTER TABLE organization
-ADD COLUMN org_id VARCHAR(32);
-
-ALTER TABLE organization
-ADD COLUMN org_name TEXT;
-
--- back fill
-UPDATE organization
-SET org_id = id
-WHERE org_id is NULL;
-
-ALTER TABLE organization
-DROP CONSTRAINT organization_pkey_id;
-
-ALTER TABLE organization
-ADD CONSTRAINT organization_pkey PRIMARY KEY (org_id);
-
--- back fill
-UPDATE organization
-SET org_name = organization_name
-WHERE org_name IS NULL AND organization_name IS NOT NULL;
\ No newline at end of file
diff --git a/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/up.sql b/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/up.sql
deleted file mode 100644
index 3ae4a3c3d3..0000000000
--- a/v2_migrations/2024-07-29-063217_drop-org_id-and-org_name-from-organization/up.sql
+++ /dev/null
@@ -1,18 +0,0 @@
--- Backfill
-UPDATE organization
-SET id = org_id
-WHERE id is NULL;
-
-UPDATE organization
-SET organization_name = org_name
-WHERE organization_name IS NULL AND org_name IS NOT NULL;
-
--- Alter queries
-ALTER TABLE organization
-DROP COLUMN org_id;
-
-ALTER TABLE organization
-DROP COLUMN org_name;
-
-ALTER TABLE organization
-ADD CONSTRAINT organization_pkey_id PRIMARY KEY (id);
\ No newline at end of file
diff --git a/v2_migrations/2024-07-30-100323_customer_v2/down.sql b/v2_migrations/2024-07-30-100323_customer_v2/down.sql
deleted file mode 100644
index 15b1ea3f53..0000000000
--- a/v2_migrations/2024-07-30-100323_customer_v2/down.sql
+++ /dev/null
@@ -1,20 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE customers DROP COLUMN IF EXISTS merchant_reference_id;
-ALTER TABLE customers DROP COLUMN IF EXISTS default_billing_address;
-ALTER TABLE customers DROP COLUMN IF EXISTS default_shipping_address;
-
--- Run this query only when V1 is deprecated
-ALTER TABLE customers DROP CONSTRAINT customers_pkey;
-ALTER TABLE customers DROP COLUMN IF EXISTS id;
-ALTER TABLE customers ADD COLUMN IF NOT EXISTS id SERIAL;
-
-ALTER TABLE customers ADD COLUMN customer_id VARCHAR(64);
-
--- Back filling before making it primary key
-UPDATE customers
-SET customer_id = id;
-
-
-ALTER TABLE customers ADD PRIMARY KEY (merchant_id, customer_id);
-
-ALTER TABLE customers ADD COLUMN address_id VARCHAR(64);
diff --git a/v2_migrations/2024-07-30-100323_customer_v2/up.sql b/v2_migrations/2024-07-30-100323_customer_v2/up.sql
deleted file mode 100644
index 7c2c5aee00..0000000000
--- a/v2_migrations/2024-07-30-100323_customer_v2/up.sql
+++ /dev/null
@@ -1,23 +0,0 @@
--- Your SQL goes here
-ALTER TABLE customers ADD COLUMN merchant_reference_id VARCHAR(64);
-ALTER TABLE customers ADD COLUMN IF NOT EXISTS default_billing_address BYTEA DEFAULT NULL;
-ALTER TABLE customers ADD COLUMN IF NOT EXISTS default_shipping_address BYTEA DEFAULT NULL;
-
--- Run this query only when V1 is deprecated
-ALTER TABLE customers DROP CONSTRAINT IF EXISTS customers_pkey;
-
-ALTER TABLE customers DROP COLUMN IF EXISTS id;
-
-ALTER TABLE customers ADD COLUMN IF NOT EXISTS id VARCHAR(64);
-
--- Back filling before making it primary key
-UPDATE customers
-SET id = customer_id;
-
-ALTER TABLE customers ADD PRIMARY KEY (id);
-
--- Run this query only when V1 is deprecated
-ALTER TABLE customers DROP COLUMN customer_id;
-
--- Run this query only when V1 is deprecated
-ALTER TABLE customers DROP COLUMN address_id;
\ No newline at end of file
diff --git a/v2_migrations/2024-07-31-065721_mca_v2/down.sql b/v2_migrations/2024-07-31-065721_mca_v2/down.sql
deleted file mode 100644
index 167cfd8fe5..0000000000
--- a/v2_migrations/2024-07-31-065721_mca_v2/down.sql
+++ /dev/null
@@ -1,21 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS frm_configs jsonb;
-
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
-
-ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
-
-DROP INDEX IF EXISTS merchant_connector_account_id_index;
-
-UPDATE merchant_connector_account SET merchant_connector_id = id;
-
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
-
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS id SERIAL;
-
-ALTER TABLE merchant_connector_account ADD PRIMARY KEY (merchant_connector_id);
-
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_country "CountryAlpha2";
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_label VARCHAR(255);
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS business_sub_label VARCHAR(64);
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS test_mode BOOLEAN;
diff --git a/v2_migrations/2024-07-31-065721_mca_v2/up.sql b/v2_migrations/2024-07-31-065721_mca_v2/up.sql
deleted file mode 100644
index ca7859af4e..0000000000
--- a/v2_migrations/2024-07-31-065721_mca_v2/up.sql
+++ /dev/null
@@ -1,26 +0,0 @@
--- Your SQL goes here
--- This migration is to remove the business_country, business_label, business_sub_label, and test_mode columns from the merchant_connector_account table
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_country;
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_label;
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_sub_label;
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS test_mode;
-
--- This migration is to modify the id column in merchant_connector_account table to be a VARCHAR(64) and to set the id column as primary key
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
-
-ALTER TABLE merchant_connector_account ADD COLUMN IF NOT EXISTS id VARCHAR(64);
-
--- Backfill the id column with the merchant_connector_id to prevent null values
-UPDATE merchant_connector_account SET id = merchant_connector_id;
-
-CREATE UNIQUE INDEX merchant_connector_account_id_index ON merchant_connector_account (id);
-
-ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
-
-ALTER TABLE merchant_connector_account ADD PRIMARY KEY (id);
-
--- This migration is to remove the merchant_connector_id column from the merchant_connector_account table
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS merchant_connector_id;
-
--- This migration is to remove the frm_configs column from the merchant_connector_account table
-ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS frm_configs;
\ No newline at end of file
diff --git a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql
deleted file mode 100644
index 95405fc43e..0000000000
--- a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/down.sql
+++ /dev/null
@@ -1,28 +0,0 @@
--- This adds back dropped columns in `up.sql`.
--- However, if the old columns were dropped, then we won't have data previously
--- stored in these columns.
-ALTER TABLE business_profile
-ADD COLUMN routing_algorithm JSON DEFAULT NULL,
- ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL,
- ADD COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
- ADD COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
-
-ALTER TABLE business_profile DROP COLUMN routing_algorithm_id,
- DROP COLUMN order_fulfillment_time,
- DROP COLUMN order_fulfillment_time_origin,
- DROP COLUMN frm_routing_algorithm_id,
- DROP COLUMN payout_routing_algorithm_id,
- DROP COLUMN default_fallback_routing;
-
-DROP TYPE "OrderFulfillmentTimeOrigin";
-
-ALTER TABLE business_profile
-ADD COLUMN profile_id VARCHAR(64);
-
-UPDATE business_profile
-SET profile_id = id;
-
-ALTER TABLE business_profile DROP COLUMN id;
-
-ALTER TABLE business_profile
-ADD PRIMARY KEY (profile_id);
diff --git a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql b/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql
deleted file mode 100644
index 35a0d6111d..0000000000
--- a/v2_migrations/2024-07-31-100300_business_profile_add_v2_columns_drop_v1_columns/up.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm');
-
-ALTER TABLE business_profile
-ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
- ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
- ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
- ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
- ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
- ADD COLUMN default_fallback_routing JSONB DEFAULT NULL;
-
--- Note: This query should not be run on higher environments as this leads to data loss.
--- The application will work fine even without these queries being run.
-ALTER TABLE business_profile DROP COLUMN routing_algorithm,
- DROP COLUMN intent_fulfillment_time,
- DROP COLUMN frm_routing_algorithm,
- DROP COLUMN payout_routing_algorithm;
-
--- This migration is to modify the id column in business_profile table to be a VARCHAR(64) and to set the id column as primary key
-ALTER TABLE business_profile
-ADD COLUMN id VARCHAR(64);
-
--- Backfill the id column with the profile_id to prevent null values
-UPDATE business_profile
-SET id = profile_id;
-
-ALTER TABLE business_profile DROP CONSTRAINT business_profile_pkey;
-
-ALTER TABLE business_profile
-ADD PRIMARY KEY (id);
-
-ALTER TABLE business_profile DROP COLUMN profile_id;
diff --git a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sql b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sql
deleted file mode 100644
index eca25b815c..0000000000
--- a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- This file should undo anything in `up.sql`
-ALTER TABLE merchant_connector_account ALTER COLUMN profile_id DROP NOT NULL;
\ No newline at end of file
diff --git a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sql b/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sql
deleted file mode 100644
index 216b8760d7..0000000000
--- a/v2_migrations/2024-08-12-075913_make_profile_id_mandatory_in_mca/up.sql
+++ /dev/null
@@ -1,3 +0,0 @@
--- Your SQL goes here
--- This migration is to make profile_id mandatory in mca table
-ALTER TABLE merchant_connector_account ALTER COLUMN profile_id SET NOT NULL;
diff --git a/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql b/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql
new file mode 100644
index 0000000000..63d514e4b5
--- /dev/null
+++ b/v2_migrations/2024-08-28-081721_add_v2_columns/down.sql
@@ -0,0 +1,14 @@
+-- This file drops all new columns being added as part of v2 refactoring.
+-- These migrations can be run as long as there's no v2 application running.
+ALTER TABLE customers DROP COLUMN IF EXISTS merchant_reference_id,
+ DROP COLUMN IF EXISTS default_billing_address,
+ DROP COLUMN IF EXISTS default_shipping_address;
+
+ALTER TABLE business_profile DROP COLUMN routing_algorithm_id,
+ DROP COLUMN order_fulfillment_time,
+ DROP COLUMN order_fulfillment_time_origin,
+ DROP COLUMN frm_routing_algorithm_id,
+ DROP COLUMN payout_routing_algorithm_id,
+ DROP COLUMN default_fallback_routing;
+
+DROP TYPE "OrderFulfillmentTimeOrigin";
diff --git a/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql b/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql
new file mode 100644
index 0000000000..1866e41299
--- /dev/null
+++ b/v2_migrations/2024-08-28-081721_add_v2_columns/up.sql
@@ -0,0 +1,16 @@
+-- This file contains all new columns being added as part of v2 refactoring.
+-- The new columns added should work with both v1 and v2 applications.
+ALTER TABLE customers
+ADD COLUMN IF NOT EXISTS merchant_reference_id VARCHAR(64),
+ ADD COLUMN IF NOT EXISTS default_billing_address BYTEA DEFAULT NULL,
+ ADD COLUMN IF NOT EXISTS default_shipping_address BYTEA DEFAULT NULL;
+
+CREATE TYPE "OrderFulfillmentTimeOrigin" AS ENUM ('create', 'confirm');
+
+ALTER TABLE business_profile
+ADD COLUMN routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+ ADD COLUMN order_fulfillment_time BIGINT DEFAULT NULL,
+ ADD COLUMN order_fulfillment_time_origin "OrderFulfillmentTimeOrigin" DEFAULT NULL,
+ ADD COLUMN frm_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+ ADD COLUMN payout_routing_algorithm_id VARCHAR(64) DEFAULT NULL,
+ ADD COLUMN default_fallback_routing JSONB DEFAULT NULL;
diff --git a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql
new file mode 100644
index 0000000000..1aa2f1f60e
--- /dev/null
+++ b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/down.sql
@@ -0,0 +1,22 @@
+-- This file contains queries to create the `id` column as a `SERIAL` column instead of `VARCHAR` column for tables that already have it.
+-- This is to revert the `id` columns to the previous state.
+ALTER TABLE merchant_account DROP id;
+
+ALTER TABLE merchant_account
+ADD COLUMN IF NOT EXISTS id SERIAL;
+
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
+
+ALTER TABLE merchant_connector_account
+ADD COLUMN IF NOT EXISTS id SERIAL;
+
+ALTER TABLE customers DROP COLUMN IF EXISTS id;
+
+ALTER TABLE customers
+ADD COLUMN IF NOT EXISTS id SERIAL;
+
+ALTER TABLE payment_intent
+ADD id SERIAL;
+
+ALTER TABLE payment_attempt
+ADD id SERIAL;
diff --git a/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql
new file mode 100644
index 0000000000..0e98d9792b
--- /dev/null
+++ b/v2_migrations/2024-08-28-081747_recreate_ids_for_v2/up.sql
@@ -0,0 +1,24 @@
+-- This file contains queries to re-create the `id` column as a `VARCHAR` column instead of `SERIAL` column for tables that already have it.
+-- It must be ensured that the deployed version of the application does not include the `id` column in any of its queries.
+-- Drop the id column as this will be used later as the primary key with a different type
+ALTER TABLE merchant_account DROP COLUMN IF EXISTS id;
+
+-- Adding a new column called `id` which will be the new primary key for v2
+-- Note that even though this will be the new primary key, the v1 application would still fill in null values
+ALTER TABLE merchant_account
+ADD COLUMN id VARCHAR(64);
+
+-- This migration is to modify the id column in merchant_connector_account table to be a VARCHAR(64) and to set the id column as primary key
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS id;
+
+ALTER TABLE merchant_connector_account
+ADD COLUMN IF NOT EXISTS id VARCHAR(64);
+
+ALTER TABLE customers DROP COLUMN IF EXISTS id;
+
+ALTER TABLE customers
+ADD COLUMN IF NOT EXISTS id VARCHAR(64);
+
+ALTER TABLE payment_intent DROP COLUMN id;
+
+ALTER TABLE payment_attempt DROP COLUMN id;
diff --git a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql
new file mode 100644
index 0000000000..5d9f96e15f
--- /dev/null
+++ b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql
@@ -0,0 +1,64 @@
+-- Backfill for organization table
+UPDATE ORGANIZATION
+SET org_id = id
+WHERE org_id IS NULL;
+
+ALTER TABLE ORGANIZATION DROP CONSTRAINT organization_pkey_id;
+
+ALTER TABLE ORGANIZATION
+ADD CONSTRAINT organization_pkey PRIMARY KEY (org_id);
+
+-- back fill
+UPDATE ORGANIZATION
+SET org_name = organization_name
+WHERE org_name IS NULL
+ AND organization_name IS NOT NULL;
+
+-- The new primary key for v2 merchant account will be `id`
+ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
+
+-- In order to run this query, the merchant_id column should be unique and not null
+-- We need to backfill the id, a simple strategy will be to copy the values of id to merchant_id
+-- Query to update the merchant_id column with values of id
+UPDATE merchant_account
+SET merchant_id = id
+WHERE merchant_id IS NULL;
+
+-- Note: This command might not run successfully for the existing table
+-- This is because there will be some rows ( which are created via v2 application ) which will have id as empty
+-- A backfill might be required to run this query
+-- However if this is being run on a fresh database, this should succeed
+ALTER TABLE merchant_account
+ADD PRIMARY KEY (merchant_id);
+
+UPDATE business_profile
+SET profile_id = id
+WHERE profile_id IS NULL;
+
+ALTER TABLE business_profile DROP COLUMN id;
+
+ALTER TABLE business_profile
+ADD PRIMARY KEY (profile_id);
+
+ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
+
+UPDATE merchant_connector_account
+SET merchant_connector_id = id
+WHERE merchant_connector_id IS NULL;
+
+ALTER TABLE merchant_connector_account
+ADD PRIMARY KEY (merchant_connector_id);
+
+ALTER TABLE merchant_connector_account
+ALTER COLUMN profile_id DROP NOT NULL;
+
+-- Run this query only when V1 is deprecated
+ALTER TABLE customers DROP CONSTRAINT customers_pkey;
+
+-- Back filling before making it primary key
+UPDATE customers
+SET customer_id = id
+WHERE customer_id IS NULL;
+
+ALTER TABLE customers
+ADD PRIMARY KEY (merchant_id, customer_id);
diff --git a/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql
new file mode 100644
index 0000000000..19cf516da1
--- /dev/null
+++ b/v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql
@@ -0,0 +1,77 @@
+-- This file contains queries to update the primary key constraints suitable to the v2 application.
+-- This also has queries to update other constraints and indexes on tables where applicable.
+-- Backfill for organization table
+UPDATE ORGANIZATION
+SET id = org_id
+WHERE id IS NULL;
+
+UPDATE ORGANIZATION
+SET organization_name = org_name
+WHERE organization_name IS NULL
+ AND org_name IS NOT NULL;
+
+-- Alter queries for organization table
+ALTER TABLE ORGANIZATION DROP CONSTRAINT organization_pkey;
+
+ALTER TABLE ORGANIZATION
+ADD CONSTRAINT organization_pkey_id PRIMARY KEY (id);
+
+-- The new primary key for v2 merchant account will be `id`
+ALTER TABLE merchant_account DROP CONSTRAINT merchant_account_pkey;
+
+-- In order to make id as primary key, it should be unique and not null
+-- We need to backfill the id, a simple strategy will be to copy the values of merchant_id to id
+-- Query to update the id column with values of merchant_id
+-- Note: This query will lock the table, so it should be run when there is no traffic
+UPDATE merchant_account
+SET id = merchant_id
+WHERE id IS NULL;
+
+-- Note: This command might not run successfully for the existing table
+-- This is because there will be some rows ( which are created via v1 application ) which will have id as empty
+-- A backfill might be required to run this query
+-- However if this is being run on a fresh database, this should succeed
+ALTER TABLE merchant_account
+ADD PRIMARY KEY (id);
+
+-- This migration is to modify the id column in business_profile table to be a VARCHAR(64) and to set the id column as primary key
+ALTER TABLE business_profile
+ADD COLUMN id VARCHAR(64);
+
+-- Backfill the id column with the profile_id to prevent null values
+UPDATE business_profile
+SET id = profile_id
+WHERE id IS NULL;
+
+ALTER TABLE business_profile DROP CONSTRAINT business_profile_pkey;
+
+ALTER TABLE business_profile
+ADD PRIMARY KEY (id);
+
+-- Backfill the id column with the merchant_connector_id to prevent null values
+UPDATE merchant_connector_account
+SET id = merchant_connector_id
+WHERE id IS NULL;
+
+ALTER TABLE merchant_connector_account DROP CONSTRAINT merchant_connector_account_pkey;
+
+ALTER TABLE merchant_connector_account
+ADD PRIMARY KEY (id);
+
+-- This migration is to make profile_id mandatory in mca table
+ALTER TABLE merchant_connector_account
+ALTER COLUMN profile_id
+SET NOT NULL;
+
+-- Run this query only when V1 is deprecated
+ALTER TABLE customers DROP CONSTRAINT IF EXISTS customers_pkey;
+
+-- Back filling before making it primary key
+-- This will fail when making `id` as primary key, if the `customer_id` column has duplicate values.
+-- Another option is to use a randomly generated ID instead.
+UPDATE customers
+SET id = customer_id
+WHERE id IS NULL;
+
+ALTER TABLE customers
+ADD PRIMARY KEY (id);
diff --git a/v2_migrations/2024-08-28-081847_drop_v1_columns/down.sql b/v2_migrations/2024-08-28-081847_drop_v1_columns/down.sql
new file mode 100644
index 0000000000..7ca0e260b4
--- /dev/null
+++ b/v2_migrations/2024-08-28-081847_drop_v1_columns/down.sql
@@ -0,0 +1,48 @@
+ALTER TABLE ORGANIZATION
+ADD COLUMN org_id VARCHAR(32),
+ ADD COLUMN org_name TEXT;
+
+ALTER TABLE merchant_account
+ADD COLUMN merchant_id VARCHAR(64),
+ ADD COLUMN return_url VARCHAR(255),
+ ADD COLUMN enable_payment_response_hash BOOLEAN DEFAULT FALSE,
+ ADD COLUMN payment_response_hash_key VARCHAR(255),
+ ADD COLUMN redirect_to_merchant_with_http_post BOOLEAN DEFAULT FALSE,
+ ADD COLUMN sub_merchants_enabled BOOLEAN DEFAULT FALSE,
+ ADD COLUMN parent_merchant_id VARCHAR(64),
+ ADD COLUMN locker_id VARCHAR(64),
+ ADD COLUMN intent_fulfillment_time BIGINT,
+ ADD COLUMN default_profile VARCHAR(64),
+ ADD COLUMN payment_link_config JSONB NULL,
+ ADD COLUMN pm_collect_link_config JSONB NULL,
+ ADD COLUMN is_recon_enabled BOOLEAN NOT NULL DEFAULT FALSE,
+ ADD COLUMN webhook_details JSONB NULL,
+ ADD COLUMN routing_algorithm JSON,
+ ADD COLUMN frm_routing_algorithm JSONB,
+ ADD COLUMN payout_routing_algorithm JSONB;
+
+-- The default value is for temporary purpose only
+ALTER TABLE merchant_account
+ADD COLUMN primary_business_details JSON NOT NULL DEFAULT '[{"country": "US", "business": "default"}]';
+
+ALTER TABLE merchant_account
+ALTER COLUMN primary_business_details DROP DEFAULT;
+
+ALTER TABLE business_profile
+ADD COLUMN profile_id VARCHAR(64),
+ ADD COLUMN routing_algorithm JSON DEFAULT NULL,
+ ADD COLUMN intent_fulfillment_time BIGINT DEFAULT NULL,
+ ADD COLUMN frm_routing_algorithm JSONB DEFAULT NULL,
+ ADD COLUMN payout_routing_algorithm JSONB DEFAULT NULL;
+
+ALTER TABLE merchant_connector_account
+ADD COLUMN IF NOT EXISTS business_country "CountryAlpha2",
+ ADD COLUMN IF NOT EXISTS business_label VARCHAR(255),
+ ADD COLUMN IF NOT EXISTS business_sub_label VARCHAR(64),
+ ADD COLUMN IF NOT EXISTS test_mode BOOLEAN,
+ ADD COLUMN IF NOT EXISTS frm_configs jsonb,
+ ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE customers
+ADD COLUMN customer_id VARCHAR(64),
+ ADD COLUMN address_id VARCHAR(64);
diff --git a/v2_migrations/2024-08-28-081847_drop_v1_columns/up.sql b/v2_migrations/2024-08-28-081847_drop_v1_columns/up.sql
new file mode 100644
index 0000000000..72344b8e7d
--- /dev/null
+++ b/v2_migrations/2024-08-28-081847_drop_v1_columns/up.sql
@@ -0,0 +1,46 @@
+-- This file contains queries to drop columns no longer used by the v2 application.
+-- It is safer to take a backup of the database before running these queries as they're destructive in nature.
+-- These queries should only be run when we're sure that data inserted by the v1 application is no longer required.
+ALTER TABLE ORGANIZATION DROP COLUMN org_id,
+ DROP COLUMN org_name;
+
+-- Note: This query should not be run on higher environments as this leads to data loss
+-- The application will work fine even without these queries not being run
+ALTER TABLE merchant_account DROP COLUMN merchant_id,
+ DROP COLUMN return_url,
+ DROP COLUMN enable_payment_response_hash,
+ DROP COLUMN payment_response_hash_key,
+ DROP COLUMN redirect_to_merchant_with_http_post,
+ DROP COLUMN sub_merchants_enabled,
+ DROP COLUMN parent_merchant_id,
+ DROP COLUMN primary_business_details,
+ DROP COLUMN locker_id,
+ DROP COLUMN intent_fulfillment_time,
+ DROP COLUMN default_profile,
+ DROP COLUMN payment_link_config,
+ DROP COLUMN pm_collect_link_config,
+ DROP COLUMN is_recon_enabled,
+ DROP COLUMN webhook_details,
+ DROP COLUMN routing_algorithm,
+ DROP COLUMN frm_routing_algorithm,
+ DROP COLUMN payout_routing_algorithm;
+
+-- Note: This query should not be run on higher environments as this leads to data loss.
+-- The application will work fine even without these queries being run.
+ALTER TABLE business_profile DROP COLUMN profile_id,
+ DROP COLUMN routing_algorithm,
+ DROP COLUMN intent_fulfillment_time,
+ DROP COLUMN frm_routing_algorithm,
+ DROP COLUMN payout_routing_algorithm;
+
+-- This migration is to remove the business_country, business_label, business_sub_label, test_mode, merchant_connector_id and frm_configs columns from the merchant_connector_account table
+ALTER TABLE merchant_connector_account DROP COLUMN IF EXISTS business_country,
+ DROP COLUMN IF EXISTS business_label,
+ DROP COLUMN IF EXISTS business_sub_label,
+ DROP COLUMN IF EXISTS test_mode,
+ DROP COLUMN IF EXISTS merchant_connector_id,
+ DROP COLUMN IF EXISTS frm_configs;
+
+-- Run this query only when V1 is deprecated
+ALTER TABLE customers DROP COLUMN customer_id,
+ DROP COLUMN address_id;