mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
feat: rename columns in organization for v2 (#5424)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -16,7 +16,7 @@ v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "stor
|
||||
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
|
||||
common_enums = { version = "0.1.0", path = "../common_enums" }
|
||||
common_utils = { version = "0.1.0", path = "../common_utils" }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }
|
||||
hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }
|
||||
hyperswitch_interfaces = { version = "0.1.0", path = "../hyperswitch_interfaces", default-features = false }
|
||||
masking = { version = "0.1.0", path = "../masking" }
|
||||
|
||||
@ -1,33 +1,189 @@
|
||||
use common_utils::{id_type, pii};
|
||||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
|
||||
|
||||
#[cfg(all(
|
||||
any(any(feature = "v1", feature = "v2"), feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
use crate::schema::organization;
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
use crate::schema_v2::organization;
|
||||
pub trait OrganizationBridge {
|
||||
fn get_organization_id(&self) -> id_type::OrganizationId;
|
||||
fn get_organization_name(&self) -> Option<String>;
|
||||
fn set_organization_name(&mut self, organization_name: String);
|
||||
}
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
||||
#[diesel(table_name = organization, primary_key(org_id), check_for_backend(diesel::pg::Pg))]
|
||||
#[diesel(
|
||||
table_name = organization,
|
||||
primary_key(org_id),
|
||||
check_for_backend(diesel::pg::Pg)
|
||||
)]
|
||||
pub struct Organization {
|
||||
pub org_id: id_type::OrganizationId,
|
||||
pub org_name: Option<String>,
|
||||
org_id: id_type::OrganizationId,
|
||||
org_name: Option<String>,
|
||||
pub organization_details: Option<pii::SecretSerdeValue>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub created_at: time::PrimitiveDateTime,
|
||||
pub modified_at: time::PrimitiveDateTime,
|
||||
#[allow(dead_code)]
|
||||
id: Option<id_type::OrganizationId>,
|
||||
#[allow(dead_code)]
|
||||
organization_name: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
||||
#[diesel(
|
||||
table_name = organization,
|
||||
primary_key(id),
|
||||
check_for_backend(diesel::pg::Pg)
|
||||
)]
|
||||
pub struct Organization {
|
||||
pub organization_details: Option<pii::SecretSerdeValue>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub created_at: time::PrimitiveDateTime,
|
||||
pub modified_at: time::PrimitiveDateTime,
|
||||
id: id_type::OrganizationId,
|
||||
organization_name: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
impl Organization {
|
||||
pub fn new(org_new: OrganizationNew) -> Self {
|
||||
let OrganizationNew {
|
||||
org_id,
|
||||
org_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
created_at,
|
||||
modified_at,
|
||||
id: _,
|
||||
organization_name: _,
|
||||
} = org_new;
|
||||
Self {
|
||||
id: Some(org_id.clone()),
|
||||
organization_name: org_name.clone(),
|
||||
org_id,
|
||||
org_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
created_at,
|
||||
modified_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
impl Organization {
|
||||
pub fn new(org_new: OrganizationNew) -> Self {
|
||||
let OrganizationNew {
|
||||
id,
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
created_at,
|
||||
modified_at,
|
||||
} = org_new;
|
||||
Self {
|
||||
id,
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
created_at,
|
||||
modified_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
#[derive(Clone, Debug, Insertable)]
|
||||
#[diesel(table_name = organization, primary_key(org_id))]
|
||||
pub struct OrganizationNew {
|
||||
pub org_id: id_type::OrganizationId,
|
||||
pub org_name: Option<String>,
|
||||
org_id: id_type::OrganizationId,
|
||||
org_name: Option<String>,
|
||||
id: Option<id_type::OrganizationId>,
|
||||
organization_name: Option<String>,
|
||||
pub organization_details: Option<pii::SecretSerdeValue>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub created_at: time::PrimitiveDateTime,
|
||||
pub modified_at: time::PrimitiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
#[derive(Clone, Debug, Insertable)]
|
||||
#[diesel(table_name = organization, primary_key(id))]
|
||||
pub struct OrganizationNew {
|
||||
id: id_type::OrganizationId,
|
||||
organization_name: Option<String>,
|
||||
pub organization_details: Option<pii::SecretSerdeValue>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub created_at: time::PrimitiveDateTime,
|
||||
pub modified_at: time::PrimitiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
impl OrganizationNew {
|
||||
pub fn new(id: id_type::OrganizationId, organization_name: Option<String>) -> Self {
|
||||
Self {
|
||||
org_id: id.clone(),
|
||||
org_name: organization_name.clone(),
|
||||
id: Some(id),
|
||||
organization_name,
|
||||
organization_details: None,
|
||||
metadata: None,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
impl OrganizationNew {
|
||||
pub fn new(id: id_type::OrganizationId, organization_name: Option<String>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
organization_name,
|
||||
organization_details: None,
|
||||
metadata: None,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
#[derive(Clone, Debug, AsChangeset)]
|
||||
#[diesel(table_name = organization)]
|
||||
pub struct OrganizationUpdateInternal {
|
||||
org_name: Option<String>,
|
||||
organization_name: Option<String>,
|
||||
organization_details: Option<pii::SecretSerdeValue>,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
modified_at: time::PrimitiveDateTime,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
#[derive(Clone, Debug, AsChangeset)]
|
||||
#[diesel(table_name = organization)]
|
||||
pub struct OrganizationUpdateInternal {
|
||||
organization_name: Option<String>,
|
||||
organization_details: Option<pii::SecretSerdeValue>,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
modified_at: time::PrimitiveDateTime,
|
||||
@ -35,21 +191,26 @@ pub struct OrganizationUpdateInternal {
|
||||
|
||||
pub enum OrganizationUpdate {
|
||||
Update {
|
||||
org_name: Option<String>,
|
||||
organization_name: Option<String>,
|
||||
organization_details: Option<pii::SecretSerdeValue>,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
impl From<OrganizationUpdate> for OrganizationUpdateInternal {
|
||||
fn from(value: OrganizationUpdate) -> Self {
|
||||
match value {
|
||||
OrganizationUpdate::Update {
|
||||
org_name,
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
} => Self {
|
||||
org_name,
|
||||
org_name: organization_name.clone(),
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
modified_at: common_utils::date_time::now(),
|
||||
@ -57,3 +218,79 @@ impl From<OrganizationUpdate> for OrganizationUpdateInternal {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
|
||||
impl From<OrganizationUpdate> for OrganizationUpdateInternal {
|
||||
fn from(value: OrganizationUpdate) -> Self {
|
||||
match value {
|
||||
OrganizationUpdate::Update {
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
} => Self {
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
modified_at: common_utils::date_time::now(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
impl OrganizationBridge for Organization {
|
||||
fn get_organization_id(&self) -> id_type::OrganizationId {
|
||||
self.org_id.clone()
|
||||
}
|
||||
fn get_organization_name(&self) -> Option<String> {
|
||||
self.org_name.clone()
|
||||
}
|
||||
fn set_organization_name(&mut self, organization_name: String) {
|
||||
self.org_name = Some(organization_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
impl OrganizationBridge for OrganizationNew {
|
||||
fn get_organization_id(&self) -> id_type::OrganizationId {
|
||||
self.org_id.clone()
|
||||
}
|
||||
fn get_organization_name(&self) -> Option<String> {
|
||||
self.org_name.clone()
|
||||
}
|
||||
fn set_organization_name(&mut self, organization_name: String) {
|
||||
self.org_name = Some(organization_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
impl OrganizationBridge for Organization {
|
||||
fn get_organization_id(&self) -> id_type::OrganizationId {
|
||||
self.id.clone()
|
||||
}
|
||||
fn get_organization_name(&self) -> Option<String> {
|
||||
self.organization_name.clone()
|
||||
}
|
||||
fn set_organization_name(&mut self, organization_name: String) {
|
||||
self.organization_name = Some(organization_name);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
impl OrganizationBridge for OrganizationNew {
|
||||
fn get_organization_id(&self) -> id_type::OrganizationId {
|
||||
self.id.clone()
|
||||
}
|
||||
fn get_organization_name(&self) -> Option<String> {
|
||||
self.organization_name.clone()
|
||||
}
|
||||
fn set_organization_name(&mut self, organization_name: String) {
|
||||
self.organization_name = Some(organization_name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
use common_utils::id_type;
|
||||
use diesel::{associations::HasTable, ExpressionMethods};
|
||||
|
||||
use crate::{
|
||||
organization::*, query::generics, schema::organization::dsl, PgPooledConn, StorageResult,
|
||||
};
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
use crate::schema::organization::dsl;
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
use crate::schema_v2::organization::dsl;
|
||||
use crate::{organization::*, query::generics, PgPooledConn, StorageResult};
|
||||
|
||||
impl OrganizationNew {
|
||||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Organization> {
|
||||
@ -16,7 +21,16 @@ impl Organization {
|
||||
conn: &PgPooledConn,
|
||||
org_id: id_type::OrganizationId,
|
||||
) -> StorageResult<Self> {
|
||||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(conn, dsl::org_id.eq(org_id))
|
||||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
|
||||
conn,
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
dsl::org_id.eq(org_id),
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
dsl::id.eq(org_id),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -32,7 +46,13 @@ impl Organization {
|
||||
_,
|
||||
>(
|
||||
conn,
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "merchant_account_v2")
|
||||
))]
|
||||
dsl::org_id.eq(org_id),
|
||||
#[cfg(all(feature = "v2", feature = "merchant_account_v2"))]
|
||||
dsl::id.eq(org_id),
|
||||
OrganizationUpdateInternal::from(update),
|
||||
)
|
||||
.await
|
||||
|
||||
@ -730,6 +730,9 @@ diesel::table! {
|
||||
metadata -> Nullable<Jsonb>,
|
||||
created_at -> Timestamp,
|
||||
modified_at -> Timestamp,
|
||||
#[max_length = 32]
|
||||
id -> Nullable<Varchar>,
|
||||
organization_name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -728,14 +728,14 @@ diesel::table! {
|
||||
use diesel::sql_types::*;
|
||||
use crate::enums::diesel_exports::*;
|
||||
|
||||
organization (org_id) {
|
||||
#[max_length = 32]
|
||||
org_id -> Varchar,
|
||||
org_name -> Nullable<Text>,
|
||||
organization (id) {
|
||||
organization_details -> Nullable<Jsonb>,
|
||||
metadata -> Nullable<Jsonb>,
|
||||
created_at -> Timestamp,
|
||||
modified_at -> Timestamp,
|
||||
#[max_length = 32]
|
||||
id -> Varchar,
|
||||
organization_name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ license.workspace = true
|
||||
[features]
|
||||
release = ["vergen", "external_services/aws_kms"]
|
||||
vergen = ["router_env/vergen"]
|
||||
v1 = ["diesel_models/v1"]
|
||||
v1 = ["diesel_models/v1", "hyperswitch_interfaces/v1"]
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.5.1"
|
||||
@ -32,7 +32,7 @@ tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] }
|
||||
|
||||
# First Party Crates
|
||||
common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }
|
||||
external_services = { version = "0.1.0", path = "../external_services" }
|
||||
hyperswitch_interfaces = { version = "0.1.0", path = "../hyperswitch_interfaces" }
|
||||
masking = { version = "0.1.0", path = "../masking" }
|
||||
|
||||
@ -25,7 +25,7 @@ api_models = { version = "0.1.0", path = "../api_models", features = ["errors"]
|
||||
cards = { version = "0.1.0", path = "../cards" }
|
||||
common_enums = { version = "0.1.0", path = "../common_enums" }
|
||||
common_utils = { version = "0.1.0", path = "../common_utils", features = ["async_ext", "metrics", "encryption_service", "keymanager"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }
|
||||
masking = { version = "0.1.0", path = "../masking" }
|
||||
router_derive = { version = "0.1.0", path = "../router_derive" }
|
||||
router_env = { version = "0.1.0", path = "../router_env" }
|
||||
|
||||
@ -9,6 +9,7 @@ license.workspace = true
|
||||
[features]
|
||||
default = ["dummy_connector", "frm", "payouts"]
|
||||
dummy_connector = []
|
||||
v1 = ["hyperswitch_domain_models/v1"]
|
||||
payouts = ["hyperswitch_domain_models/payouts"]
|
||||
frm = ["hyperswitch_domain_models/frm"]
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ payout_retry = ["payouts"]
|
||||
recon = ["email", "api_models/recon"]
|
||||
retry = []
|
||||
v2 = ["api_models/v2", "diesel_models/v2", "hyperswitch_domain_models/v2", "storage_impl/v2", "kgraph_utils/v2"]
|
||||
v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1"]
|
||||
v1 = ["api_models/v1", "diesel_models/v1", "hyperswitch_domain_models/v1", "storage_impl/v1", "hyperswitch_interfaces/v1"]
|
||||
customer_v2 = ["api_models/customer_v2", "diesel_models/customer_v2", "hyperswitch_domain_models/customer_v2"]
|
||||
merchant_account_v2 = ["api_models/merchant_account_v2", "diesel_models/merchant_account_v2", "hyperswitch_domain_models/merchant_account_v2"]
|
||||
payment_v2 = ["api_models/payment_v2", "diesel_models/payment_v2", "hyperswitch_domain_models/payment_v2"]
|
||||
@ -118,13 +118,13 @@ x509-parser = "0.16.0"
|
||||
|
||||
# First party crates
|
||||
|
||||
analytics = { version = "0.1.0", path = "../analytics", optional = true }
|
||||
analytics = { version = "0.1.0", path = "../analytics", optional = true, default-features = false }
|
||||
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
|
||||
cards = { version = "0.1.0", path = "../cards" }
|
||||
common_enums = { version = "0.1.0", path = "../common_enums" }
|
||||
common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals", "async_ext", "logs", "metrics", "keymanager", "encryption_service"] }
|
||||
currency_conversion = { version = "0.1.0", path = "../currency_conversion" }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] , default-features = false }
|
||||
euclid = { version = "0.1.0", path = "../euclid", features = ["valued_jit"] }
|
||||
events = { version = "0.1.0", path = "../events" }
|
||||
external_services = { version = "0.1.0", path = "../external_services" }
|
||||
|
||||
@ -12,6 +12,8 @@ use common_utils::{
|
||||
types::keymanager::{self as km_types, KeyManagerState},
|
||||
};
|
||||
use diesel_models::configs;
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), feature = "olap"))]
|
||||
use diesel_models::organization::OrganizationBridge;
|
||||
use error_stack::{report, FutureExt, ResultExt};
|
||||
use futures::future::try_join_all;
|
||||
use masking::{ExposeInterface, PeekInterface, Secret};
|
||||
@ -134,7 +136,7 @@ pub async fn update_organization(
|
||||
req: api::OrganizationRequest,
|
||||
) -> RouterResponse<api::OrganizationResponse> {
|
||||
let organization_update = diesel_models::organization::OrganizationUpdate::Update {
|
||||
org_name: req.organization_name,
|
||||
organization_name: req.organization_name,
|
||||
organization_details: req.organization_details,
|
||||
metadata: req.metadata,
|
||||
};
|
||||
@ -387,7 +389,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
|
||||
payout_routing_algorithm: self.payout_routing_algorithm,
|
||||
#[cfg(not(feature = "payouts"))]
|
||||
payout_routing_algorithm: None,
|
||||
organization_id: organization.org_id,
|
||||
organization_id: organization.get_organization_id(),
|
||||
is_recon_enabled: false,
|
||||
default_profile: None,
|
||||
recon_status: diesel_models::enums::ReconStatus::NotRequested,
|
||||
@ -638,7 +640,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
|
||||
},
|
||||
)?;
|
||||
|
||||
CreateOrValidateOrganization::new(self.organization_id.clone())
|
||||
let organization = CreateOrValidateOrganization::new(self.organization_id.clone())
|
||||
.create_or_validate(db)
|
||||
.await?;
|
||||
|
||||
@ -692,7 +694,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
|
||||
intent_fulfillment_time: None,
|
||||
frm_routing_algorithm: None,
|
||||
payout_routing_algorithm: None,
|
||||
organization_id: self.organization_id,
|
||||
organization_id: organization.get_organization_id(),
|
||||
is_recon_enabled: false,
|
||||
default_profile: None,
|
||||
recon_status: diesel_models::enums::ReconStatus::NotRequested,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use common_utils::{errors::CustomResult, id_type};
|
||||
use diesel_models::organization as storage;
|
||||
use diesel_models::{organization as storage, organization::OrganizationBridge};
|
||||
use error_stack::report;
|
||||
use router_env::{instrument, tracing};
|
||||
|
||||
@ -73,21 +73,14 @@ impl OrganizationInterface for super::MockDb {
|
||||
|
||||
if organizations
|
||||
.iter()
|
||||
.any(|org| org.org_id == organization.org_id)
|
||||
.any(|org| org.get_organization_id() == organization.get_organization_id())
|
||||
{
|
||||
Err(errors::StorageError::DuplicateValue {
|
||||
entity: "org_id",
|
||||
key: None,
|
||||
})?
|
||||
}
|
||||
let org = storage::Organization {
|
||||
org_id: organization.org_id.clone(),
|
||||
org_name: organization.org_name,
|
||||
organization_details: organization.organization_details,
|
||||
metadata: organization.metadata,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
};
|
||||
let org = storage::Organization::new(organization);
|
||||
organizations.push(org.clone());
|
||||
Ok(org)
|
||||
}
|
||||
@ -100,7 +93,7 @@ impl OrganizationInterface for super::MockDb {
|
||||
|
||||
organizations
|
||||
.iter()
|
||||
.find(|org| org.org_id == *org_id)
|
||||
.find(|org| org.get_organization_id() == *org_id)
|
||||
.cloned()
|
||||
.ok_or(
|
||||
errors::StorageError::ValueNotFound(format!(
|
||||
@ -120,18 +113,20 @@ impl OrganizationInterface for super::MockDb {
|
||||
|
||||
organizations
|
||||
.iter_mut()
|
||||
.find(|org| org.org_id == *org_id)
|
||||
.find(|org| org.get_organization_id() == *org_id)
|
||||
.map(|org| match &update {
|
||||
storage::OrganizationUpdate::Update {
|
||||
org_name,
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
} => storage::Organization {
|
||||
org_name: org_name.clone(),
|
||||
organization_details: organization_details.clone(),
|
||||
metadata: metadata.clone(),
|
||||
..org.to_owned()
|
||||
},
|
||||
} => {
|
||||
organization_name
|
||||
.as_ref()
|
||||
.map(|org_name| org.set_organization_name(org_name.to_owned()));
|
||||
organization_details.clone_into(&mut org.organization_details);
|
||||
metadata.clone_into(&mut org.metadata);
|
||||
org
|
||||
}
|
||||
})
|
||||
.ok_or(
|
||||
errors::StorageError::ValueNotFound(format!(
|
||||
@ -140,5 +135,6 @@ impl OrganizationInterface for super::MockDb {
|
||||
))
|
||||
.into(),
|
||||
)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ use common_utils::{
|
||||
ext_traits::{AsyncExt, Encode, ValueExt},
|
||||
types::keymanager::Identifier,
|
||||
};
|
||||
use diesel_models::organization::OrganizationBridge;
|
||||
use error_stack::{report, ResultExt};
|
||||
use hyperswitch_domain_models::{
|
||||
merchant_key_store::MerchantKeyStore, type_encryption::decrypt_optional,
|
||||
@ -30,8 +31,8 @@ use crate::{
|
||||
impl ForeignFrom<diesel_models::organization::Organization> for OrganizationResponse {
|
||||
fn foreign_from(org: diesel_models::organization::Organization) -> Self {
|
||||
Self {
|
||||
organization_id: org.org_id,
|
||||
organization_name: org.org_name,
|
||||
organization_id: org.get_organization_id(),
|
||||
organization_name: org.get_organization_name(),
|
||||
organization_details: org.organization_details,
|
||||
metadata: org.metadata,
|
||||
modified_at: org.modified_at,
|
||||
|
||||
@ -10,7 +10,7 @@ use common_utils::{
|
||||
};
|
||||
use diesel_models::{
|
||||
enums::{TotpStatus, UserRoleVersion, UserStatus},
|
||||
organization::{self as diesel_org, Organization},
|
||||
organization::{self as diesel_org, Organization, OrganizationBridge},
|
||||
user as storage_user,
|
||||
user_role::{UserRole, UserRoleNew},
|
||||
};
|
||||
@ -254,7 +254,7 @@ impl NewUserOrganization {
|
||||
}
|
||||
|
||||
pub fn get_organization_id(&self) -> id_type::OrganizationId {
|
||||
self.0.org_id.clone()
|
||||
self.0.get_organization_id()
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,14 +300,10 @@ impl From<(user_api::CreateInternalUserRequest, id_type::OrganizationId)> for Ne
|
||||
|
||||
impl From<UserMerchantCreateRequestWithToken> for NewUserOrganization {
|
||||
fn from(value: UserMerchantCreateRequestWithToken) -> Self {
|
||||
Self(diesel_org::OrganizationNew {
|
||||
org_id: value.2.org_id,
|
||||
org_name: Some(value.1.company_name),
|
||||
organization_details: None,
|
||||
metadata: None,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
})
|
||||
Self(diesel_org::OrganizationNew::new(
|
||||
value.2.org_id,
|
||||
Some(value.1.company_name),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1389,14 +1389,7 @@ impl ForeignFrom<api_models::organization::OrganizationNew>
|
||||
for diesel_models::organization::OrganizationNew
|
||||
{
|
||||
fn foreign_from(item: api_models::organization::OrganizationNew) -> Self {
|
||||
Self {
|
||||
org_id: item.org_id,
|
||||
org_name: item.org_name,
|
||||
organization_details: None,
|
||||
metadata: None,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
}
|
||||
Self::new(item.org_id, item.org_name)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1405,14 +1398,15 @@ impl ForeignFrom<api_models::organization::OrganizationRequest>
|
||||
{
|
||||
fn foreign_from(item: api_models::organization::OrganizationRequest) -> Self {
|
||||
let org_new = api_models::organization::OrganizationNew::new(None);
|
||||
Self {
|
||||
org_id: org_new.org_id,
|
||||
org_name: item.organization_name,
|
||||
organization_details: item.organization_details,
|
||||
metadata: item.metadata,
|
||||
created_at: common_utils::date_time::now(),
|
||||
modified_at: common_utils::date_time::now(),
|
||||
}
|
||||
let api_models::organization::OrganizationRequest {
|
||||
organization_name,
|
||||
organization_details,
|
||||
metadata,
|
||||
} = item;
|
||||
let mut org_new_db = Self::new(org_new.org_id, organization_name);
|
||||
org_new_db.organization_details = organization_details;
|
||||
org_new_db.metadata = metadata;
|
||||
org_new_db
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ uuid = { version = "1.8.0", features = ["v4"] }
|
||||
|
||||
# First party crates
|
||||
common_utils = { version = "0.1.0", path = "../common_utils", features = ["signals", "async_ext"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"] }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_store"], default-features = false }
|
||||
external_services = { version = "0.1.0", path = "../external_services" }
|
||||
hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }
|
||||
redis_interface = { version = "0.1.0", path = "../redis_interface" }
|
||||
|
||||
@ -21,7 +21,7 @@ payment_v2 = ["hyperswitch_domain_models/payment_v2", "diesel_models/payment_v2"
|
||||
api_models = { version = "0.1.0", path = "../api_models" }
|
||||
common_enums = { version = "0.1.0", path = "../common_enums" }
|
||||
common_utils = { version = "0.1.0", path = "../common_utils" }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models" }
|
||||
diesel_models = { version = "0.1.0", path = "../diesel_models", default-features = false }
|
||||
hyperswitch_domain_models = { version = "0.1.0", path = "../hyperswitch_domain_models", default-features = false }
|
||||
masking = { version = "0.1.0", path = "../masking" }
|
||||
redis_interface = { version = "0.1.0", path = "../redis_interface" }
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
ALTER TABLE organization
|
||||
DROP COLUMN id;
|
||||
ALTER TABLE organization
|
||||
DROP COLUMN organization_name;
|
||||
@ -0,0 +1,6 @@
|
||||
-- Your SQL goes here
|
||||
ALTER TABLE organization
|
||||
ADD COLUMN id VARCHAR(32);
|
||||
ALTER TABLE organization
|
||||
ADD COLUMN organization_name TEXT;
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
-- 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;
|
||||
@ -0,0 +1,18 @@
|
||||
-- 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);
|
||||
Reference in New Issue
Block a user