company or personal
This commit is contained in:
@@ -32,6 +32,7 @@ mod m20260617_000002_add_shipment_to_orders;
|
||||
mod m20260617_000003_add_phone_to_orders;
|
||||
mod m20260618_000001_o_auth2_sessions;
|
||||
mod m20260618_000002_customer_profiles;
|
||||
mod m20260618_000003_account_type;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -68,6 +69,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260617_000003_add_phone_to_orders::Migration),
|
||||
Box::new(m20260618_000001_o_auth2_sessions::Migration),
|
||||
Box::new(m20260618_000002_customer_profiles::Migration),
|
||||
Box::new(m20260618_000003_account_type::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
|
||||
39
migration/src/m20260618_000003_account_type.rs
Normal file
39
migration/src/m20260618_000003_account_type.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
// Personal vs company purchasing. `account_type` is "personal" or "company";
|
||||
// the company_* columns hold the Slovak invoicing identifiers (IČO, DIČ and the
|
||||
// optional VAT id IČ DPH) and are only filled for company accounts/orders.
|
||||
const COMPANY_COLUMNS: [&str; 4] = ["company_name", "company_id", "tax_id", "vat_id"];
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
for table in ["customer_profiles", "orders"] {
|
||||
add_column(
|
||||
m,
|
||||
table,
|
||||
"account_type",
|
||||
ColType::StringWithDefault("personal".to_string()),
|
||||
)
|
||||
.await?;
|
||||
for col in COMPANY_COLUMNS {
|
||||
add_column(m, table, col, ColType::StringNull).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
for table in ["customer_profiles", "orders"] {
|
||||
remove_column(m, table, "account_type").await?;
|
||||
for col in COMPANY_COLUMNS {
|
||||
remove_column(m, table, col).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user