asklyphe/authservice/migration/src/m20240814_015232_create_verification_code.rs

46 lines
1.5 KiB
Rust
Raw Normal View History

2025-03-12 12:32:15 -07:00
use sea_orm_migration::{prelude::*, schema::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(VerificationCode::Table)
.if_not_exists()
.col(ColumnDef::new(VerificationCode::Id).string().not_null().primary_key())
.col(ColumnDef::new(VerificationCode::User).string().not_null())
.col(ColumnDef::new(VerificationCode::SetNewEmail).boolean().not_null())
.col(ColumnDef::new(VerificationCode::Code).string().not_null().unique_key())
.col(ColumnDef::new(VerificationCode::CreatedOn).date_time().not_null())
.col(ColumnDef::new(VerificationCode::DeathDate).date_time().not_null())
.col(ColumnDef::new(VerificationCode::Used).boolean().not_null())
.col(ColumnDef::new(VerificationCode::UsedOn).date_time())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(VerificationCode::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum VerificationCode {
Table,
Id,
User,
Code,
SetNewEmail,
CreatedOn,
DeathDate,
Used,
UsedOn,
}