wb_cache/test/simulation/db/migrations/
order.rs1use sea_orm_migration::prelude::*;
2
3pub struct Migration;
4
5impl MigrationName for Migration {
6 fn name(&self) -> &str {
7 "order_migration"
8 }
9}
10
11#[async_trait::async_trait]
12impl MigrationTrait for Migration {
13 async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
14 manager
15 .create_table(
16 Table::create()
17 .table(Orders::Table)
18 .if_not_exists()
19 .col(ColumnDef::new(Orders::Id).uuid().not_null().primary_key())
20 .col(ColumnDef::new(Orders::CustomerId).integer().not_null())
21 .col(ColumnDef::new(Orders::ProductId).integer().not_null())
22 .col(ColumnDef::new(Orders::Quantity).integer().not_null())
23 .col(ColumnDef::new(Orders::Status).string().not_null())
24 .col(ColumnDef::new(Orders::PurchasedOn).integer().not_null())
25 .foreign_key(
26 ForeignKey::create()
27 .name("fk-orders-customer_id")
28 .from(Orders::Table, Orders::CustomerId)
29 .to(super::customer::Customers::Table, super::customer::Customers::Id)
30 .on_delete(ForeignKeyAction::Cascade),
31 )
32 .foreign_key(
33 ForeignKey::create()
34 .name("fk-orders-product_id")
35 .from(Orders::Table, Orders::ProductId)
36 .to(super::product::Products::Table, super::product::Products::Id)
37 .on_delete(ForeignKeyAction::Cascade),
38 )
39 .to_owned(),
40 )
41 .await?;
42
43 manager
44 .create_index(
45 Index::create()
46 .name("idx-orders-purchased_on")
47 .table(Orders::Table)
48 .col(Orders::PurchasedOn)
49 .to_owned(),
50 )
51 .await?;
52
53 Ok(())
54 }
55
56 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
57 manager.drop_table(Table::drop().table(Orders::Table).to_owned()).await
58 }
59}
60
61#[derive(Iden)]
62pub enum Orders {
63 Table,
64 Id,
65 CustomerId,
66 ProductId,
67 Quantity,
68 Status,
69 PurchasedOn,
70}