wb_cache/test/simulation/db/migrations/
customer.rs

1use sea_orm_migration::prelude::*;
2
3pub struct Migration;
4
5impl MigrationName for Migration {
6    fn name(&self) -> &str {
7        "customer_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(Customers::Table)
18                    .if_not_exists()
19                    .col(ColumnDef::new(Customers::Id).integer().not_null().primary_key())
20                    .col(ColumnDef::new(Customers::Email).string().not_null())
21                    .col(ColumnDef::new(Customers::FirstName).string().not_null())
22                    .col(ColumnDef::new(Customers::LastName).string().not_null())
23                    .col(ColumnDef::new(Customers::RegisteredOn).integer().not_null())
24                    .index(Index::create().name("idx-unique-email").col(Customers::Email).unique())
25                    .to_owned(),
26            )
27            .await
28    }
29
30    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
31        manager
32            .drop_table(Table::drop().table(Customers::Table).to_owned())
33            .await
34    }
35}
36
37#[derive(Iden)]
38pub enum Customers {
39    Table,
40    Id,
41    Email,
42    FirstName,
43    LastName,
44    RegisteredOn,
45}