init
This commit is contained in:
103
migration/src/m20240101_000004_create_menus_table.rs
Normal file
103
migration/src/m20240101_000004_create_menus_table.rs
Normal file
@ -0,0 +1,103 @@
|
||||
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(Menus::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Menus::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Menus::ParentId).integer())
|
||||
.col(
|
||||
ColumnDef::new(Menus::Name)
|
||||
.string()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Menus::Path).string())
|
||||
.col(ColumnDef::new(Menus::Component).string())
|
||||
.col(ColumnDef::new(Menus::Icon).string())
|
||||
.col(
|
||||
ColumnDef::new(Menus::SortOrder)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Menus::MenuType)
|
||||
.tiny_integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Menus::Visible)
|
||||
.tiny_integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Menus::Status)
|
||||
.tiny_integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.col(ColumnDef::new(Menus::PermissionKey).string())
|
||||
.col(
|
||||
ColumnDef::new(Menus::CreatedAt)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Menus::UpdatedAt)
|
||||
.timestamp()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_menus_parent_id")
|
||||
.from(Menus::Table, Menus::ParentId)
|
||||
.to(Menus::Table, Menus::Id)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Menus::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Menus {
|
||||
Table,
|
||||
Id,
|
||||
ParentId,
|
||||
Name,
|
||||
Path,
|
||||
Component,
|
||||
Icon,
|
||||
SortOrder,
|
||||
MenuType,
|
||||
Visible,
|
||||
Status,
|
||||
PermissionKey,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
Reference in New Issue
Block a user