wb_cache/test/simulation/db/migrations/
session.rs1use sea_orm_migration::prelude::*;
2
3pub struct Migration;
4
5impl MigrationName for Migration {
6 fn name(&self) -> &str {
7 "session_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(Sessions::Table)
18 .if_not_exists()
19 .col(ColumnDef::new(Sessions::Id).big_integer().not_null().primary_key())
20 .col(ColumnDef::new(Sessions::CustomerId).integer().null())
21 .col(ColumnDef::new(Sessions::ExpiresOn).integer().not_null())
22 .foreign_key(
23 ForeignKey::create()
24 .name("fk-sessions-customer_id")
25 .from(Sessions::Table, Sessions::CustomerId)
26 .to(super::customer::Customers::Table, super::customer::Customers::Id)
27 .on_delete(ForeignKeyAction::Cascade),
28 )
29 .to_owned(),
30 )
31 .await?;
32
33 Ok(())
34 }
35
36 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
37 manager
38 .drop_table(Table::drop().table(Sessions::Table).to_owned())
39 .await
40 }
41}
42
43#[derive(Iden)]
44pub enum Sessions {
45 Table,
46 Id,
47 CustomerId,
48 ExpiresOn,
49}