basket logic working
This commit is contained in:
@@ -52,6 +52,7 @@ mod m20260623_000004_currencies;
|
||||
mod m20260625_000001_add_avatar_to_users;
|
||||
mod m20260627_000001_order_residence_address;
|
||||
mod m20260627_000002_payment_settings;
|
||||
mod m20260627_000003_account_cart_items;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -108,6 +109,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260625_000001_add_avatar_to_users::Migration),
|
||||
Box::new(m20260627_000001_order_residence_address::Migration),
|
||||
Box::new(m20260627_000002_payment_settings::Migration),
|
||||
Box::new(m20260627_000003_account_cart_items::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
|
||||
48
migration/src/m20260627_000003_account_cart_items.rs
Normal file
48
migration/src/m20260627_000003_account_cart_items.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
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> {
|
||||
create_table(
|
||||
m,
|
||||
"account_cart_items",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("variant_id", ColType::Integer),
|
||||
("quantity", ColType::Integer),
|
||||
],
|
||||
&[("user", "")],
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-account_cart_items-variant_id-to-product_variants")
|
||||
.from(Alias::new("account_cart_items"), Alias::new("variant_id"))
|
||||
.to(Alias::new("product_variants"), Alias::new("id"))
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::NoAction)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.create_index(
|
||||
Index::create()
|
||||
.name("idx_account_cart_items_user_variant_unique")
|
||||
.table(Alias::new("account_cart_items"))
|
||||
.col(Alias::new("user_id"))
|
||||
.col(Alias::new("variant_id"))
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "account_cart_items").await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user