Actualiza formato del código de las migraciones

This commit is contained in:
Manuel Cillero 2022-04-24 21:57:07 +02:00
parent e7f9bf8778
commit f30f84e993
8 changed files with 486 additions and 512 deletions

View file

@ -1,10 +1,12 @@
use pagetop::prelude::*;
#[derive(Iden)]
enum Role { Table,
Rid,
Name,
Weight,
enum Role {
Table, // Store user roles.
Rid, // Primary Key: Unique role ID.
Name, // Unique role name.
Weight, // The weight of this role in listings and the user interface.
}
pub struct Migration;
@ -12,37 +14,32 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.create_table(
// Store user roles.
Table::create()
.table(Role::Table)
.if_not_exists()
// Primary Key: Unique role ID.
.col(ColumnDef::new(Role::Rid)
.unsigned()
.not_null()
.auto_increment()
.primary_key()
)
// Unique role name.
.col(ColumnDef::new(Role::Name)
.string_len(64)
.not_null()
.unique_key()
)
// The weight of this role in listings and the user interface.
.col(ColumnDef::new(Role::Weight)
.integer()
.not_null()
.default(0)
)
// INDEXES.
.index(Index::create()
.name("name-weight")
.col(Role::Name)
.col(Role::Weight)
)
.to_owned()
manager.create_table(Table::create()
.table(Role::Table)
.if_not_exists()
.col(ColumnDef::new(Role::Rid)
.unsigned()
.not_null()
.auto_increment()
.primary_key()
)
.col(ColumnDef::new(Role::Name)
.string_len(64)
.not_null()
.unique_key()
)
.col(ColumnDef::new(Role::Weight)
.integer()
.not_null()
.default(0)
)
// INDEXES.
.index(Index::create()
.name("name-weight")
.col(Role::Name)
.col(Role::Weight)
)
.to_owned()
)
.await?;