refactor(accounts): move accounts related tables to accounts schema (#7626)

This commit is contained in:
Hrithikesh
2025-04-03 21:22:34 +05:30
committed by GitHub
parent d892ee7af0
commit 4b7f55aeed
18 changed files with 130 additions and 68 deletions

View File

@@ -1,15 +1,24 @@
//! Common types to be used in payment methods
use diesel::{
backend::Backend, deserialize, deserialize::FromSql, sql_types::Jsonb, AsExpression, Queryable,
backend::Backend,
deserialize,
deserialize::FromSql,
sql_types::{Json, Jsonb},
AsExpression, Queryable,
};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
/// Details of all the payment methods enabled for the connector for the given merchant account
// sql_type for this can be json instead of jsonb. This is because validation at database is not required since it will always be written by the application.
// This is a performance optimization to avoid json validation at database level.
// jsonb enables faster querying on json columns, but it doesn't justify here since we are not querying on this column.
// https://docs.rs/diesel/latest/diesel/sql_types/struct.Jsonb.html
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, AsExpression)]
#[serde(deny_unknown_fields)]
#[diesel(sql_type = Jsonb)]
#[diesel(sql_type = Json)]
pub struct PaymentMethodsEnabled {
/// Type of payment method.
#[schema(value_type = PaymentMethod,example = "card")]

View File

@@ -68,6 +68,7 @@ pub struct Profile {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: Option<common_utils::id_type::ProfileId>,
}
#[cfg(feature = "v1")]
@@ -120,6 +121,7 @@ pub struct ProfileNew {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: Option<common_utils::id_type::ProfileId>,
}
#[cfg(feature = "v1")]
@@ -289,6 +291,7 @@ impl ProfileUpdateInternal {
is_clear_pan_retries_enabled: is_clear_pan_retries_enabled
.unwrap_or(source.is_clear_pan_retries_enabled),
force_3ds_challenge,
id: source.id,
is_debit_routing_enabled,
merchant_business_country: merchant_business_country
.or(source.merchant_business_country),
@@ -348,6 +351,7 @@ pub struct Profile {
pub force_3ds_challenge: Option<bool>,
pub is_debit_routing_enabled: bool,
pub merchant_business_country: Option<common_enums::CountryAlpha2>,
pub id: common_utils::id_type::ProfileId,
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>,
@@ -356,7 +360,6 @@ pub struct Profile {
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub three_ds_decision_manager_config: Option<common_types::payments::DecisionManagerRecord>,
pub should_collect_cvv_during_payment: bool,
pub id: common_utils::id_type::ProfileId,
}
impl Profile {

View File

@@ -54,6 +54,7 @@ pub struct MerchantConnectorAccount {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}
#[cfg(feature = "v1")]
@@ -98,8 +99,8 @@ pub struct MerchantConnectorAccount {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
pub id: id_type::MerchantConnectorAccountId,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}
#[cfg(feature = "v2")]
@@ -140,6 +141,7 @@ pub struct MerchantConnectorAccountNew {
pub additional_merchant_data: Option<Encryption>,
pub connector_wallets_details: Option<Encryption>,
pub version: common_enums::ApiVersion,
pub id: Option<id_type::MerchantConnectorAccountId>,
}
#[cfg(feature = "v2")]
@@ -167,8 +169,8 @@ pub struct MerchantConnectorAccountNew {
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,
pub feature_metadata: Option<MerchantConnectorAccountFeatureMetadata>,
}

View File

@@ -223,6 +223,8 @@ diesel::table! {
force_3ds_challenge -> Nullable<Bool>,
is_debit_routing_enabled -> Bool,
merchant_business_country -> Nullable<CountryAlpha2>,
#[max_length = 64]
id -> Nullable<Varchar>,
}
}
@@ -788,6 +790,8 @@ diesel::table! {
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
version -> ApiVersion,
#[max_length = 64]
id -> Nullable<Varchar>,
}
}

View File

@@ -220,6 +220,8 @@ diesel::table! {
is_debit_routing_enabled -> Bool,
merchant_business_country -> Nullable<CountryAlpha2>,
#[max_length = 64]
id -> Varchar,
#[max_length = 64]
routing_algorithm_id -> Nullable<Varchar>,
order_fulfillment_time -> Nullable<Int8>,
order_fulfillment_time_origin -> Nullable<OrderFulfillmentTimeOrigin>,
@@ -230,8 +232,6 @@ diesel::table! {
default_fallback_routing -> Nullable<Jsonb>,
three_ds_decision_manager_config -> Nullable<Jsonb>,
should_collect_cvv_during_payment -> Bool,
#[max_length = 64]
id -> Varchar,
}
}
@@ -750,7 +750,7 @@ diesel::table! {
connector_name -> Varchar,
connector_account_details -> Bytea,
disabled -> Nullable<Bool>,
payment_methods_enabled -> Nullable<Array<Nullable<Jsonb>>>,
payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,
connector_type -> ConnectorType,
metadata -> Nullable<Jsonb>,
#[max_length = 255]
@@ -767,9 +767,9 @@ diesel::table! {
additional_merchant_data -> Nullable<Bytea>,
connector_wallets_details -> Nullable<Bytea>,
version -> ApiVersion,
feature_metadata -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
feature_metadata -> Nullable<Jsonb>,
}
}

View File

@@ -641,7 +641,8 @@ impl super::behaviour::Conversion for Profile {
async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
Ok(diesel_models::business_profile::Profile {
profile_id: self.profile_id,
profile_id: self.profile_id.clone(),
id: Some(self.profile_id),
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,
@@ -793,7 +794,8 @@ impl super::behaviour::Conversion for Profile {
async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
Ok(diesel_models::business_profile::ProfileNew {
profile_id: self.profile_id,
profile_id: self.profile_id.clone(),
id: Some(self.profile_id),
merchant_id: self.merchant_id,
profile_name: self.profile_name,
created_at: self.created_at,

View File

@@ -356,7 +356,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {
connector_account_details: self.connector_account_details.into(),
test_mode: self.test_mode,
disabled: self.disabled,
merchant_connector_id: self.merchant_connector_id,
merchant_connector_id: self.merchant_connector_id.clone(),
id: Some(self.merchant_connector_id),
payment_methods_enabled: self.payment_methods_enabled,
connector_type: self.connector_type,
metadata: self.metadata,
@@ -452,7 +453,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {
connector_account_details: Some(self.connector_account_details.into()),
test_mode: self.test_mode,
disabled: self.disabled,
merchant_connector_id: self.merchant_connector_id,
merchant_connector_id: self.merchant_connector_id.clone(),
id: Some(self.merchant_connector_id),
payment_methods_enabled: self.payment_methods_enabled,
connector_type: Some(self.connector_type),
metadata: self.metadata,

View File

@@ -161,7 +161,14 @@ pub trait GlobalStorageInterface:
#[async_trait::async_trait]
pub trait AccountsStorageInterface:
Send + Sync + dyn_clone::DynClone + OrganizationInterface + 'static
Send
+ Sync
+ dyn_clone::DynClone
+ OrganizationInterface
+ merchant_account::MerchantAccountInterface
+ business_profile::ProfileInterface
+ merchant_connector_account::MerchantConnectorAccountInterface
+ 'static
{
}

View File

@@ -82,7 +82,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
business_profile: domain::Profile,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
business_profile
.construct_new()
.await
@@ -106,7 +106,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
profile_id: &common_utils::id_type::ProfileId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_profile_id(&conn, profile_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
@@ -126,7 +126,7 @@ impl ProfileInterface for Store {
merchant_id: &common_utils::id_type::MerchantId,
profile_id: &common_utils::id_type::ProfileId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_merchant_id_profile_id(&conn, merchant_id, profile_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
@@ -147,7 +147,7 @@ impl ProfileInterface for Store {
profile_name: &str,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::find_by_profile_name_merchant_id(&conn, profile_name, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))?
@@ -168,7 +168,7 @@ impl ProfileInterface for Store {
current_state: domain::Profile,
profile_update: domain::ProfileUpdate,
) -> CustomResult<domain::Profile, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
Conversion::convert(current_state)
.await
.change_context(errors::StorageError::EncryptionError)?
@@ -190,7 +190,7 @@ impl ProfileInterface for Store {
profile_id: &common_utils::id_type::ProfileId,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
storage::Profile::delete_by_profile_id_merchant_id(&conn, profile_id, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
@@ -203,7 +203,7 @@ impl ProfileInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<Vec<domain::Profile>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::Profile::list_profile_by_merchant_id(&conn, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))

View File

@@ -112,7 +112,7 @@ impl MerchantAccountInterface for Store {
merchant_account: domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
merchant_account
.construct_new()
.await
@@ -137,7 +137,7 @@ impl MerchantAccountInterface for Store {
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let fetch_func = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantAccount::find_by_merchant_id(&conn, merchant_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
@@ -183,7 +183,7 @@ impl MerchantAccountInterface for Store {
merchant_account: storage::MerchantAccountUpdate,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let updated_merchant_account = Conversion::convert(this)
.await
@@ -214,7 +214,7 @@ impl MerchantAccountInterface for Store {
merchant_account: storage::MerchantAccountUpdate,
merchant_key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let updated_merchant_account = storage::MerchantAccount::update_with_specific_fields(
&conn,
merchant_id,
@@ -245,7 +245,7 @@ impl MerchantAccountInterface for Store {
) -> CustomResult<(domain::MerchantAccount, domain::MerchantKeyStore), errors::StorageError>
{
let fetch_by_pub_key_func = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantAccount::find_by_publishable_key(&conn, publishable_key)
.await
@@ -294,7 +294,7 @@ impl MerchantAccountInterface for Store {
organization_id: &common_utils::id_type::OrganizationId,
) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {
use futures::future::try_join_all;
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let encrypted_merchant_accounts =
storage::MerchantAccount::list_by_organization_id(&conn, organization_id)
@@ -338,7 +338,7 @@ impl MerchantAccountInterface for Store {
&self,
merchant_id: &common_utils::id_type::MerchantId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let is_deleted_func = || async {
storage::MerchantAccount::delete_by_merchant_id(&conn, merchant_id)
@@ -375,7 +375,7 @@ impl MerchantAccountInterface for Store {
state: &KeyManagerState,
merchant_ids: Vec<common_utils::id_type::MerchantId>,
) -> CustomResult<Vec<domain::MerchantAccount>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let encrypted_merchant_accounts =
storage::MerchantAccount::list_multiple_merchant_accounts(&conn, merchant_ids)
@@ -439,7 +439,7 @@ impl MerchantAccountInterface for Store {
)>,
errors::StorageError,
> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let encrypted_merchant_accounts =
storage::MerchantAccount::list_all_merchant_accounts(&conn, limit, offset)
.await
@@ -460,7 +460,7 @@ impl MerchantAccountInterface for Store {
&self,
merchant_account: storage::MerchantAccountUpdate,
) -> CustomResult<usize, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let db_func = || async {
storage::MerchantAccount::update_all_merchant_accounts(

View File

@@ -240,7 +240,7 @@ impl MerchantConnectorAccountInterface for Store {
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let find_call = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::find_by_merchant_id_connector(
&conn,
merchant_id,
@@ -291,7 +291,7 @@ impl MerchantConnectorAccountInterface for Store {
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let find_call = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::find_by_profile_id_connector_name(
&conn,
profile_id,
@@ -345,7 +345,7 @@ impl MerchantConnectorAccountInterface for Store {
connector_name: &str,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::find_by_merchant_id_connector_name(
&conn,
merchant_id,
@@ -381,7 +381,7 @@ impl MerchantConnectorAccountInterface for Store {
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let find_call = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::find_by_merchant_id_merchant_connector_id(
&conn,
merchant_id,
@@ -436,7 +436,7 @@ impl MerchantConnectorAccountInterface for Store {
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let find_call = || async {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::find_by_id(&conn, id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
@@ -483,7 +483,7 @@ impl MerchantConnectorAccountInterface for Store {
t: domain::MerchantConnectorAccount,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
t.construct_new()
.await
.change_context(errors::StorageError::EncryptionError)?
@@ -510,7 +510,7 @@ impl MerchantConnectorAccountInterface for Store {
key_store: &domain::MerchantKeyStore,
connector_type: common_enums::ConnectorType,
) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::list_enabled_by_profile_id(
&conn,
@@ -545,7 +545,7 @@ impl MerchantConnectorAccountInterface for Store {
get_disabled: bool,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<domain::MerchantConnectorAccounts, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
let merchant_connector_account_vec =
storage::MerchantConnectorAccount::find_by_merchant_id(
&conn,
@@ -583,7 +583,7 @@ impl MerchantConnectorAccountInterface for Store {
profile_id: &common_utils::id_type::ProfileId,
key_store: &domain::MerchantKeyStore,
) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
let conn = connection::pg_accounts_connection_read(self).await?;
storage::MerchantConnectorAccount::list_by_profile_id(&conn, profile_id)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
@@ -613,7 +613,7 @@ impl MerchantConnectorAccountInterface for Store {
storage::MerchantConnectorAccountUpdateInternal,
)>,
) -> CustomResult<(), errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
async fn update_call(
connection: &diesel_models::PgPooledConn,
@@ -731,7 +731,7 @@ impl MerchantConnectorAccountInterface for Store {
let _merchant_connector_id = this.merchant_connector_id.clone();
let update_call = || async {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
Conversion::convert(this)
.await
.change_context(errors::StorageError::EncryptionError)?
@@ -811,7 +811,7 @@ impl MerchantConnectorAccountInterface for Store {
let _merchant_connector_id = this.get_id().clone();
let update_call = || async {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
Conversion::convert(this)
.await
.change_context(errors::StorageError::EncryptionError)?
@@ -879,7 +879,7 @@ impl MerchantConnectorAccountInterface for Store {
merchant_id: &common_utils::id_type::MerchantId,
merchant_connector_id: &common_utils::id_type::MerchantConnectorAccountId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let delete_call = || async {
storage::MerchantConnectorAccount::delete_by_merchant_id_merchant_connector_id(
&conn,
@@ -954,7 +954,7 @@ impl MerchantConnectorAccountInterface for Store {
&self,
id: &common_utils::id_type::MerchantConnectorAccountId,
) -> CustomResult<bool, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
let conn = connection::pg_accounts_connection_write(self).await?;
let delete_call = || async {
storage::MerchantConnectorAccount::delete_by_id(&conn, id)
.await
@@ -1240,7 +1240,8 @@ impl MerchantConnectorAccountInterface for MockDb {
connector_account_details: t.connector_account_details.into(),
test_mode: t.test_mode,
disabled: t.disabled,
merchant_connector_id: t.merchant_connector_id,
merchant_connector_id: t.merchant_connector_id.clone(),
id: Some(t.merchant_connector_id),
payment_methods_enabled: t.payment_methods_enabled,
metadata: t.metadata,
frm_configs: None,

View File

@@ -1,3 +1,6 @@
-- This file should undo anything in `up.sql`
ALTER TABLE business_profile
DROP COLUMN id;
ALTER TABLE merchant_connector_account
ALTER COLUMN payment_methods_enabled TYPE JSON [ ];
DROP COLUMN id;

View File

@@ -0,0 +1,6 @@
-- Your SQL goes here
ALTER TABLE business_profile
ADD COLUMN id VARCHAR(64);
ALTER TABLE merchant_connector_account
ADD COLUMN id VARCHAR(64);

View File

@@ -1,9 +1,5 @@
-- 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_connector_account DROP COLUMN IF EXISTS id;
ALTER TABLE business_profile DROP COLUMN IF EXISTS id;
ALTER TABLE customers DROP COLUMN IF EXISTS id;

View File

@@ -2,17 +2,6 @@
-- 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
------------------------ Merchant Connector Account -----------------------
-- 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
ADD COLUMN IF NOT EXISTS id VARCHAR(64);
------------------------ Business Profile -----------------------
-- 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);
------------------------ Customers -----------------------

View File

@@ -1,10 +1,13 @@
------------------------ Organization -----------------------
-- Drop index on org_id in organization table
DROP INDEX IF EXISTS idx_organization_org_id;
-- Re-add primary key constraint on `organization`
ALTER TABLE organization
ADD CONSTRAINT organization_pkey PRIMARY KEY (org_id),
ALTER COLUMN org_id SET NOT NULL;
------------------------ Merchant Account -------------------
DROP INDEX IF EXISTS idx_merchant_account_merchant_id;
ALTER TABLE merchant_account
ADD PRIMARY KEY (merchant_id),
ALTER COLUMN primary_business_details SET NOT NULL,
@@ -12,32 +15,40 @@ ALTER TABLE merchant_account
ALTER COLUMN is_recon_enabled SET DEFAULT FALSE;
------------------------ Business Profile -------------------
DROP INDEX IF EXISTS idx_business_profile_profile_id;
ALTER TABLE business_profile
ADD PRIMARY KEY (profile_id);
---------------- Merchant Connector Account -----------------
DROP INDEX IF EXISTS idx_merchant_connector_account_merchant_connector_id;
ALTER TABLE merchant_connector_account
ADD PRIMARY KEY (merchant_connector_id);
------------------------ Customers --------------------------
DROP INDEX IF EXISTS idx_customers_merchant_id_customer_id;
ALTER TABLE customers
ADD PRIMARY KEY (merchant_id, customer_id);
---------------------- Payment Intent -----------------------
DROP INDEX IF EXISTS idx_payment_intent_payment_id_merchant_id;
ALTER TABLE payment_intent
ADD PRIMARY KEY (payment_id, merchant_id),
ALTER COLUMN active_attempt_id SET NOT NULL,
ALTER COLUMN active_attempt_id SET DEFAULT 'xxx';
---------------------- Payment Attempt ----------------------
DROP INDEX IF EXISTS idx_payment_attempt_attempt_id_merchant_id;
ALTER TABLE payment_attempt
ADD PRIMARY KEY (attempt_id, merchant_id),
ALTER COLUMN amount SET NOT NULL;
---------------------- Payment Methods ----------------------
DROP INDEX IF EXISTS idx_payment_methods_payment_method_id;
ALTER TABLE payment_methods
ADD PRIMARY KEY (payment_method_id);
---------------------- Refunds ----------------------
DROP INDEX IF EXISTS idx_refund_refund_id_merchant_id;
ALTER TABLE refund
ADD PRIMARY KEY (refund_id,merchant_id);

View File

@@ -1,9 +1,14 @@
-- Drop not null constraint on org_id in organization table
-- Drop not null constraint on org_id in organization table
-- Drop not null constraints on not null columns of v1 which are either dropped or made nullable in v2.
------------------------ Organization -----------------------
ALTER TABLE organization
DROP CONSTRAINT organization_pkey,
ALTER COLUMN org_id DROP NOT NULL;
-- Create index on org_id in organization table
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_organization_org_id ON organization (org_id);
------------------------ Merchant Account -------------------
-- Drop not null in merchant_account table for v1 columns that are dropped in v2
ALTER TABLE merchant_account
DROP CONSTRAINT merchant_account_pkey,
@@ -11,33 +16,58 @@ ALTER TABLE merchant_account
ALTER COLUMN primary_business_details DROP NOT NULL,
ALTER COLUMN is_recon_enabled DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_merchant_account_merchant_id ON merchant_account (merchant_id);
------------------------ Business Profile -------------------
ALTER TABLE business_profile
DROP CONSTRAINT business_profile_pkey,
ALTER COLUMN profile_id DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_business_profile_profile_id ON business_profile (profile_id);
---------------- Merchant Connector Account -----------------
ALTER TABLE merchant_connector_account
DROP CONSTRAINT merchant_connector_account_pkey,
ALTER COLUMN merchant_connector_id DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_merchant_connector_account_merchant_connector_id ON merchant_connector_account (merchant_connector_id);
------------------------ Customers --------------------------
ALTER TABLE customers
DROP CONSTRAINT customers_pkey,
ALTER COLUMN customer_id DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_customers_merchant_id_customer_id ON customers (merchant_id, customer_id);
---------------------- Payment Intent -----------------------
ALTER TABLE payment_intent
DROP CONSTRAINT payment_intent_pkey,
ALTER COLUMN payment_id DROP NOT NULL,
ALTER COLUMN active_attempt_id DROP NOT NULL,
ALTER COLUMN active_attempt_id DROP DEFAULT;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_payment_intent_payment_id_merchant_id ON payment_intent (payment_id, merchant_id);
---------------------- Payment Attempt ----------------------
ALTER TABLE payment_attempt
DROP CONSTRAINT payment_attempt_pkey,
ALTER COLUMN attempt_id DROP NOT NULL,
ALTER COLUMN amount DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_payment_attempt_attempt_id_merchant_id ON payment_attempt (attempt_id, merchant_id);
---------------------- Payment Methods ----------------------
ALTER TABLE payment_methods
DROP CONSTRAINT payment_methods_pkey,
ALTER COLUMN payment_method_id DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_payment_methods_payment_method_id ON payment_methods (payment_method_id);
---------------------- Refunds ----------------------
ALTER TABLE refund
DROP CONSTRAINT refund_pkey,
ALTER COLUMN refund_id DROP NOT NULL;
ALTER COLUMN refund_id DROP NOT NULL;
-- This is done to mullify the effects of droping primary key for v1
CREATE INDEX idx_refund_refund_id_merchant_id ON refund (refund_id, merchant_id);

View File

@@ -1,3 +0,0 @@
-- Your SQL goes here
ALTER TABLE merchant_connector_account
ALTER COLUMN payment_methods_enabled TYPE JSONB [ ];