personal discounts to businesses done

This commit is contained in:
Priec
2026-06-21 23:21:24 +02:00
parent ed566b5347
commit c713627a2c
35 changed files with 912 additions and 39 deletions

View File

@@ -36,6 +36,7 @@ mod m20260618_000003_account_type;
mod m20260618_000004_account_ownership;
mod m20260620_000001_add_totp_to_users;
mod m20260621_000001_add_sale_price_to_products;
mod m20260621_000002_account_product_prices;
pub struct Migrator;
#[async_trait::async_trait]
@@ -76,6 +77,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260618_000004_account_ownership::Migration),
Box::new(m20260620_000001_add_totp_to_users::Migration),
Box::new(m20260621_000001_add_sale_price_to_products::Migration),
Box::new(m20260621_000002_account_product_prices::Migration),
// inject-above (do not remove this comment)
]
}

View File

@@ -0,0 +1,40 @@
use loco_rs::schema::*;
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
// A manually negotiated price (in minor units) for one product, for one
// business account — the "personal agreement" layer. `user`/`product`
// add the user_id/product_id FKs; the unique index below keeps it to one
// row per (account, product).
create_table(
m,
"account_product_prices",
&[
("id", ColType::PkAuto),
("price_cents", ColType::BigInteger),
],
&[("user", ""), ("product", "")],
)
.await?;
m.create_index(
Index::create()
.name("idx_account_product_prices_user_product_unique")
.table(Alias::new("account_product_prices"))
.col(Alias::new("user_id"))
.col(Alias::new("product_id"))
.unique()
.to_owned(),
)
.await
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
drop_table(m, "account_product_prices").await
}
}