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::Username)
.string()
.not_null()
.unique_key(),
)
.col(
ColumnDef::new(Users::Email)
.string()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(Users::Password).string().not_null())
.col(
ColumnDef::new(Users::IsActive)
.boolean()
.not_null()
.default(true),
)
.col(
ColumnDef::new(Users::IsStaff)
.boolean()
.not_null()
.default(false),
)
.col(
ColumnDef::new(Users::IsSuperuser)
.boolean()
.not_null()
.default(false),
)
.col(ColumnDef::new(Users::Roles).text().null())
.col(
ColumnDef::new(Users::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Users::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Users::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Users {
Table,
Id,
Username,
Email,
Password,
IsActive,
IsStaff,
IsSuperuser,
Roles,
CreatedAt,
UpdatedAt,
}