Retoca las migraciones principales
This commit is contained in:
parent
f30f84e993
commit
42a4731bdd
8 changed files with 29 additions and 32 deletions
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
#[derive(Iden)]
|
||||
enum Role {
|
||||
Table, // Store user roles.
|
||||
Table, // role: Store user roles.
|
||||
|
||||
Rid, // Primary Key: Unique role ID.
|
||||
Name, // Unique role name.
|
||||
|
|
@ -31,23 +31,25 @@ impl MigrationTrait for Migration {
|
|||
.col(ColumnDef::new(Role::Weight)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0)
|
||||
.default(10)
|
||||
)
|
||||
// INDEXES.
|
||||
.index(Index::create()
|
||||
.name("name-weight")
|
||||
.col(Role::Name)
|
||||
.name("weight-name")
|
||||
.col(Role::Weight)
|
||||
.col(Role::Name)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Built-in roles.
|
||||
app::db::exec::<InsertStatement>(Query::insert()
|
||||
.into_table(Role::Table)
|
||||
.columns(vec![Role::Name])
|
||||
.values_panic(vec!["anonymous".into()])
|
||||
.values_panic(vec!["authenticated".into()])
|
||||
.columns(vec![Role::Name, Role::Weight])
|
||||
.values_panic(vec!["anonymous".into(), "1".into()])
|
||||
.values_panic(vec!["authenticated".into(), "2".into()])
|
||||
.values_panic(vec!["administrator".into(), "3".into()])
|
||||
)
|
||||
.await.map(|_| ())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ use pagetop::prelude::*;
|
|||
|
||||
#[derive(Iden)]
|
||||
enum RolePermission {
|
||||
Table, // Stores the permissions assigned to user roles.
|
||||
Table, // role_permission: Stores the permissions assigned to user roles.
|
||||
|
||||
Rid, // Foreign Key: Role::Rid.
|
||||
Permission, // A single permission granted to the role identified by Rid.
|
||||
Module, // The module declaring the permission.
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
|
|
@ -28,10 +27,6 @@ impl MigrationTrait for Migration {
|
|||
.string_len(128)
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(RolePermission::Module)
|
||||
.string_len(255)
|
||||
.not_null()
|
||||
)
|
||||
// INDEXES.
|
||||
.primary_key(Index::create()
|
||||
.col(RolePermission::Rid)
|
||||
|
|
@ -45,8 +40,8 @@ impl MigrationTrait for Migration {
|
|||
.name("fk_role_permission-rid")
|
||||
.from(RolePermission::Table, RolePermission::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
#[derive(Iden)]
|
||||
enum User {
|
||||
Table, // Stores user data.
|
||||
Table, // user: Stores user data.
|
||||
|
||||
Uid, // Primary Key: Unique user ID.
|
||||
Name, // Unique user name.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
|||
|
||||
#[derive(Iden)]
|
||||
enum UserRole {
|
||||
Table, // Maps users to roles.
|
||||
Table, // user_role: Maps users to roles.
|
||||
|
||||
Uid, // Foreign Key: User::Uid for user.
|
||||
Rid, // Foreign Key: Role::Rid for role.
|
||||
|
|
@ -39,15 +39,15 @@ impl MigrationTrait for Migration {
|
|||
.name("fk_user_role-uid")
|
||||
.from(UserRole::Table, UserRole::Uid)
|
||||
.to(User::Table, User::Uid)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.foreign_key(ForeignKey::create()
|
||||
.name("fk_user_role-rid")
|
||||
.from(UserRole::Table, UserRole::Rid)
|
||||
.to(Role::Table, Role::Rid)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade)
|
||||
.on_delete(ForeignKeyAction::Restrict)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue