/ migration / src / m20220101_000001_users.rs
m20220101_000001_users.rs
 1  use loco_rs::schema::*;
 2  use sea_orm_migration::prelude::*;
 3  
 4  #[derive(DeriveMigrationName)]
 5  pub struct Migration;
 6  
 7  #[async_trait::async_trait]
 8  impl MigrationTrait for Migration {
 9      async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
10          create_table(
11              m,
12              "users",
13              &[
14                  ("id", ColType::PkAuto),
15                  ("pid", ColType::Uuid),
16                  ("email", ColType::StringUniq),
17                  ("password", ColType::String),
18                  ("api_key", ColType::StringUniq),
19                  ("name", ColType::String),
20                  ("reset_token", ColType::StringNull),
21                  ("reset_sent_at", ColType::TimestampWithTimeZoneNull),
22                  ("email_verification_token", ColType::StringNull),
23                  (
24                      "email_verification_sent_at",
25                      ColType::TimestampWithTimeZoneNull,
26                  ),
27                  ("email_verified_at", ColType::TimestampWithTimeZoneNull),
28                  ("magic_link_token", ColType::StringNull),
29                  ("magic_link_expiration", ColType::TimestampWithTimeZoneNull),
30              ],
31              &[],
32          )
33          .await?;
34          Ok(())
35      }
36  
37      async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
38          drop_table(m, "users").await?;
39          Ok(())
40      }
41  }