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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor: alter subscription table to update primary key (#9272)
Prajjwal Kumar5e1fd0b187b9
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 0d4564c83c..c50499093c 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1469,8 +1469,7 @@ diesel::table! {use diesel::sql_types::*;use crate::enums::diesel_exports::*;- subscription (id) {- id -> Int4,+ subscription (subscription_id, merchant_id) {#[max_length = 128]subscription_id -> Varchar,#[max_length = 128]@@ -1480,7 +1479,7 @@ diesel::table! {#[max_length = 128]payment_method_id -> Nullable<Varchar>,#[max_length = 128]- mca_id -> Nullable<Varchar>,+ merchant_connector_id -> Nullable<Varchar>,#[max_length = 128]client_secret -> Nullable<Varchar>,#[max_length = 128]@@ -1492,6 +1491,8 @@ diesel::table! {metadata -> Nullable<Jsonb>,created_at -> Timestamp,modified_at -> Timestamp,+ #[max_length = 64]+ profile_id -> Varchar,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex b734e2c4bb..66b007a537 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1404,8 +1404,7 @@ diesel::table! {use diesel::sql_types::*;use crate::enums::diesel_exports::*;- subscription (id) {- id -> Int4,+ subscription (subscription_id, merchant_id) {#[max_length = 128]subscription_id -> Varchar,#[max_length = 128]@@ -1415,7 +1414,7 @@ diesel::table! {#[max_length = 128]payment_method_id -> Nullable<Varchar>,#[max_length = 128]- mca_id -> Nullable<Varchar>,+ merchant_connector_id -> Nullable<Varchar>,#[max_length = 128]client_secret -> Nullable<Varchar>,#[max_length = 128]@@ -1427,6 +1426,8 @@ diesel::table! {metadata -> Nullable<Jsonb>,created_at -> Timestamp,modified_at -> Timestamp,+ #[max_length = 64]+ profile_id -> Varchar,}}diff --git a/crates/diesel_models/src/subscription.rs b/crates/diesel_models/src/subscription.rsindex 0cabb6a7b4..b2cb6e4847 100644--- a/crates/diesel_models/src/subscription.rs+++ b/crates/diesel_models/src/subscription.rs@@ -11,7 +11,7 @@ pub struct SubscriptionNew {status: String,billing_processor: Option<String>,payment_method_id: Option<String>,- mca_id: Option<String>,+ merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,client_secret: Option<String>,connector_subscription_id: Option<String>,merchant_id: common_utils::id_type::MerchantId,@@ -19,20 +19,19 @@ pub struct SubscriptionNew {metadata: Option<SecretSerdeValue>,created_at: time::PrimitiveDateTime,modified_at: time::PrimitiveDateTime,+ profile_id: common_utils::id_type::ProfileId,}#[derive(Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Deserialize, Serialize,)]-#[diesel(table_name = subscription, primary_key(id), check_for_backend(diesel::pg::Pg))]+#[diesel(table_name = subscription, primary_key(subscription_id, merchant_id), check_for_backend(diesel::pg::Pg))]pub struct Subscription {- #[serde(skip_serializing, skip_deserializing)]- pub id: i32,pub subscription_id: String,pub status: String,pub billing_processor: Option<String>,pub payment_method_id: Option<String>,- pub mca_id: Option<String>,+ pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,pub client_secret: Option<String>,pub connector_subscription_id: Option<String>,pub merchant_id: common_utils::id_type::MerchantId,@@ -40,6 +39,7 @@ pub struct Subscription {pub metadata: Option<serde_json::Value>,pub created_at: time::PrimitiveDateTime,pub modified_at: time::PrimitiveDateTime,+ pub profile_id: common_utils::id_type::ProfileId,}#[derive(Clone, Debug, Eq, PartialEq, AsChangeset, router_derive::DebugAsDisplay, Deserialize)]@@ -57,12 +57,13 @@ impl SubscriptionNew {status: String,billing_processor: Option<String>,payment_method_id: Option<String>,- mca_id: Option<String>,+ merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,client_secret: Option<String>,connector_subscription_id: Option<String>,merchant_id: common_utils::id_type::MerchantId,customer_id: common_utils::id_type::CustomerId,metadata: Option<SecretSerdeValue>,+ profile_id: common_utils::id_type::ProfileId,) -> Self {let now = common_utils::date_time::now();Self {@@ -70,7 +71,7 @@ impl SubscriptionNew {status,billing_processor,payment_method_id,- mca_id,+ merchant_connector_id,client_secret,connector_subscription_id,merchant_id,@@ -78,6 +79,7 @@ impl SubscriptionNew {metadata,created_at: now,modified_at: now,+ profile_id,}}}diff --git a/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/down.sql b/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/down.sqlnew file mode 100644index 0000000000..638142fe99--- /dev/null+++ b/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/down.sql@@ -0,0 +1,11 @@+ALTER TABLE subscription+ DROP CONSTRAINT IF EXISTS subscription_pkey,+ DROP COLUMN IF EXISTS profile_id,+ ADD COLUMN IF NOT EXISTS id SERIAL NOT NULL,+ ADD CONSTRAINT subscription_pkey PRIMARY KEY (id);++ALTER TABLE subscription+ RENAME COLUMN merchant_connector_id TO mca_id;++CREATE UNIQUE INDEX IF NOT EXISTS merchant_subscription_unique_index+ ON subscription (merchant_id, subscription_id);diff --git a/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/up.sql b/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/up.sqlnew file mode 100644index 0000000000..3af1f9c04c--- /dev/null+++ b/migrations/2025-09-04-063109_update_subscription_table_with_profile_id/up.sql@@ -0,0 +1,10 @@+DROP INDEX IF EXISTS merchant_subscription_unique_index;++ALTER TABLE subscription+ DROP CONSTRAINT IF EXISTS subscription_pkey,+ DROP COLUMN IF EXISTS id,+ ADD COLUMN IF NOT EXISTS profile_id VARCHAR(64) NOT NULL,+ ADD CONSTRAINT subscription_pkey PRIMARY KEY (subscription_id, merchant_id);++ALTER TABLE subscription+ RENAME COLUMN mca_id TO merchant_connector_id;