0 is out of stock and nothing is available from now on
This commit is contained in:
@@ -41,6 +41,7 @@ mod m20260621_000003_discount_profiles;
|
||||
mod m20260621_000004_add_business_sale_price_to_products;
|
||||
mod m20260622_000001_audience_discount_profiles;
|
||||
mod m20260622_000002_product_variants;
|
||||
mod m20260622_000003_variant_stock_nullable;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -86,6 +87,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260621_000004_add_business_sale_price_to_products::Migration),
|
||||
Box::new(m20260622_000001_audience_discount_profiles::Migration),
|
||||
Box::new(m20260622_000002_product_variants::Migration),
|
||||
Box::new(m20260622_000003_variant_stock_nullable::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
|
||||
36
migration/src/m20260622_000003_variant_stock_nullable.rs
Normal file
36
migration/src/m20260622_000003_variant_stock_nullable.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
//! Make `product_variants.stock` nullable: a NULL stock means the variant is
|
||||
//! "available" but not inventory-tracked — always purchasable, no quantity cap,
|
||||
//! and never decremented on order. A numeric stock is tracked/capped as before.
|
||||
|
||||
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> {
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
ALTER TABLE product_variants ALTER COLUMN stock DROP DEFAULT;
|
||||
ALTER TABLE product_variants ALTER COLUMN stock DROP NOT NULL;
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
UPDATE product_variants SET stock = 0 WHERE stock IS NULL;
|
||||
ALTER TABLE product_variants ALTER COLUMN stock SET DEFAULT 0;
|
||||
ALTER TABLE product_variants ALTER COLUMN stock SET NOT NULL;
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user