Añade la creación de tablas asociadas a usuarios

This commit is contained in:
Manuel Cillero 2022-04-19 01:47:33 +02:00
parent d37b2e09ab
commit 4af6586003
7 changed files with 327 additions and 56 deletions

View file

@ -0,0 +1,65 @@
use pagetop::db::migration::*;
#[derive(Iden)]
enum Role { Table,
Rid,
Name,
Weight,
}
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()
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
.table(Role::Table)
.to_owned()
)
.await
}
}
impl MigrationName for Migration {
fn name(&self) -> &str {
module_name!()
}
}