oswilno/crates/migration/src/m20230805_000001_add_email.rs

37 lines
946 B
Rust
Raw Normal View History

2023-08-09 15:42:29 +02:00
use crate::m20220101_000001_create_table::Account;
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
let table = Table::alter()
.table(Account::Accounts)
.add_column(
ColumnDef::new(Account::Email)
.string()
.unique_key()
.default("filler@example.com")
.not_null(),
)
.to_owned();
m.alter_table(table).await?;
Ok(())
}
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.alter_table(
Table::alter()
.table(Account::Accounts)
.drop_column(Account::Email)
.to_owned(),
)
.await?;
Ok(())
}
}