312ff7e21ba3e5bddfa5be7ef696712f31211b51 / migration / src / m20220101_000001_create_users_table.rs
Raw
use sea_orm_migration::prelude::*;
#[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(Users::Table)
.if_not_exists()
.col(
ColumnDef::new(Users::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Users::Uuid).uuid().not_null().unique_key())
.col(
ColumnDef::new(Users::Name)
.string_len(32)
.not_null()
.unique_key(),
)
.col(
ColumnDef::new(Users::Email)
.string()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(Users::Passwd).string_len(32).not_null())
.col(ColumnDef::new(Users::Description).string())
.col(
ColumnDef::new(Users::CreatedAt)
.timestamp_with_time_zone()
.default(Expr::current_timestamp())
.not_null(),
)
.col(ColumnDef::new(Users::DeletedAt).timestamp_with_time_zone())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Users::Table).to_owned())
.await
}
}
#[derive(Iden)]
pub enum Users {
Table,
Id,
Uuid,
Name,
Email,
Passwd,
Description,
CreatedAt,
DeletedAt,
}