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)
.uuid()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(Users::Email)
.string_len(255)
.not_null()
.unique_key(),
)
.col(
ColumnDef::new(Users::PasswordHash)
.string_len(255)
.not_null(),
)
.col(ColumnDef::new(Users::Name).string_len(255).null())
.col(ColumnDef::new(Users::EmailVerifiedAt).timestamp_with_time_zone().null())
.col(ColumnDef::new(Users::LockedUntil).timestamp_with_time_zone().null())
.col(
ColumnDef::new(Users::FailedAttempts)
.integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Users::CreatedAt)
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Users::UpdatedAt)
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_users_email")
.table(Users::Table)
.col(Users::Email)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Users::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
pub enum Users {
Table,
Id,
Email,
PasswordHash,
Name,
EmailVerifiedAt,
LockedUntil,
FailedAttempts,
CreatedAt,
UpdatedAt,
}