Repository: juspay/hyperswitch
File: crates/diesel_models/src/user.rs (Rust)

Code before:
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use masking::Secret;
use time::PrimitiveDateTime;

use crate::{diesel_impl::OptionalDieselArray, enums::TotpStatus, schema::users};

pub mod dashboard_metadata;
pub mod sample_data;
pub mod theme;

#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
#[diesel(table_name = users, primary_key(user_id), check_for_backend(diesel::pg::Pg))]
pub struct User {
    pub user_id: String,
    pub email: pii::Email,
    pub name: Secret<String>,
    pub password: Option<Secret<String>>,
    pub is_verified: bool,
    pub created_at: PrimitiveDateTime,
    pub last_modified_at: PrimitiveDateTime,
    pub totp_status: TotpStatus,
    pub totp_secret: Option<Encryption>,
    #[diesel(deserialize_as = OptionalDieselArray<Secret<String>>)]
    pub totp_recovery_codes: Option<Vec<Secret<String>>>,
    pub last_password_modified_at: Option<PrimitiveDateTime>,
    pub lineage_context: Option<serde_json::Value>,
}

#[derive(
    router_derive::Setter, Clone, Debug, Default, Insertable, router_derive::DebugAsDisplay,
)]
#[diesel(table_name = users)]
pub struct UserNew {
    pub user_id: String,
    pub email: pii::Email,
    pub name: Secret<String>,
    pub password: Option<Secret<String>>,
    pub is_verified: bool,
    pub created_at: Option<PrimitiveDateTime>,
    pub last_modified_at: Option<PrimitiveDateTime>,
    pub totp_status: TotpStatus,
    pub totp_secret: Option<Encryption>,
    pub totp_recovery_codes: Option<Vec<Secret<String>>>,
    pub last_password_modified_at: Option<PrimitiveDateTime>,
    pub lineage_context: Option<serde_json::Value>,
}

#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = users)]
pub struct UserUpdateInternal {
    name: Option<String>,

Review comment (suggestion):
Can't we use the `LineageContext` struct here instead of JSON?

Refer this: https://github.com/juspay/hyperswitch/blob/b04ccafe48394fad86bf072b2e3a74626cc26550/crates/diesel_models/src/merchant_account.rs#L33


Code after:
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use masking::Secret;
use time::PrimitiveDateTime;

use crate::{diesel_impl::OptionalDieselArray, enums::TotpStatus, schema::users};

pub mod dashboard_metadata;
pub mod sample_data;
pub mod theme;

#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
#[diesel(table_name = users, primary_key(user_id), check_for_backend(diesel::pg::Pg))]
pub struct User {
    pub user_id: String,
    pub email: pii::Email,
    pub name: Secret<String>,
    pub password: Option<Secret<String>>,
    pub is_verified: bool,
    pub created_at: PrimitiveDateTime,
    pub last_modified_at: PrimitiveDateTime,
    pub totp_status: TotpStatus,
    pub totp_secret: Option<Encryption>,
    #[diesel(deserialize_as = OptionalDieselArray<Secret<String>>)]
    pub totp_recovery_codes: Option<Vec<Secret<String>>>,
    pub last_password_modified_at: Option<PrimitiveDateTime>,
    pub lineage_context: Option<LineageContext>,
}

#[derive(
    router_derive::Setter, Clone, Debug, Default, Insertable, router_derive::DebugAsDisplay,
)]
#[diesel(table_name = users)]
pub struct UserNew {
    pub user_id: String,
    pub email: pii::Email,
    pub name: Secret<String>,
    pub password: Option<Secret<String>>,
    pub is_verified: bool,
    pub created_at: Option<PrimitiveDateTime>,
    pub last_modified_at: Option<PrimitiveDateTime>,
    pub totp_status: TotpStatus,
    pub totp_secret: Option<Encryption>,
    pub totp_recovery_codes: Option<Vec<Secret<String>>>,
    pub last_password_modified_at: Option<PrimitiveDateTime>,
    pub lineage_context: Option<LineageContext>,
}

#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = users)]
pub struct UserUpdateInternal {
    name: Option<String>,