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)]
|
#[derive(Iden)]
|
||||||
enum NodeType {
|
enum NodeType {
|
||||||
Table, // Stores information about all defined Node types.
|
Table, // node_type: Stores information about all defined Node types.
|
||||||
|
|
||||||
Type, // The machine-readable name of this type.
|
Type, // The machine-readable name of this type.
|
||||||
Name, // The human-readable name of this type.
|
Name, // The human-readable name of this type.
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Node {
|
enum Node {
|
||||||
Table, // The base table for nodes.
|
Table, // node: The base table for nodes.
|
||||||
|
|
||||||
Nid, // The primary identifier for a node.
|
Nid, // The primary identifier for a node.
|
||||||
Vid, // The current {node_revision}.vid version identifier.
|
Vid, // The current NodeRevision.vid version identifier.
|
||||||
Type, // The {node_type}.type of this node.
|
Type, // The NodeType.type of this node.
|
||||||
Language, // The {languages}.language of this node.
|
Language, // The {languages}.language of this node.
|
||||||
Title, // The title of this node, always treated as non-markup plain text.
|
Title, // The title of this node, always treated as non-markup plain text.
|
||||||
Uid, // The {users}.uid that owns this node; initially, this is the user that
|
Uid, // The User.uid that owns this node; initially, this is the user that
|
||||||
// created it.
|
// created it.
|
||||||
Status, // Boolean indicating whether the node is published (visible to
|
Status, // Boolean indicating whether the node is published (visible to
|
||||||
// non-administrators).
|
// non-administrators).
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum NodeAccess {
|
enum NodeAccess {
|
||||||
Table, // Identifies which realm/grant pairs a user must possess in order to view,
|
Table, // node_access: Identifies which realm/grant pairs a user must possess in
|
||||||
// update, or delete specific nodes.
|
// order to view, update, or delete specific nodes.
|
||||||
|
|
||||||
Nid, // The {node}.nid this record affects.
|
Nid, // The Node.nid this record affects.
|
||||||
Gid, // The grant ID a user must possess in the specified realm to gain this
|
Gid, // The grant ID a user must possess in the specified realm to gain this
|
||||||
// row's privileges on the node.
|
// row's privileges on the node.
|
||||||
Realm, // The realm in which the user must possess the grant ID. Each node access
|
Realm, // The realm in which the user must possess the grant ID. Each node access
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum NodeRevision {
|
enum NodeRevision {
|
||||||
Table, // Stores information about each saved version of a {node}.
|
Table, // node_revision: Stores information about each saved version of a Node.
|
||||||
|
|
||||||
Nid, // The {node} this version belongs to.
|
Nid, // The Node this version belongs to.
|
||||||
Vid, // The primary identifier for this version.
|
Vid, // The primary identifier for this version.
|
||||||
Uid, // The {users}.uid that created this version.
|
Uid, // The User.uid that created this version.
|
||||||
Title, // The title of this version.
|
Title, // The title of this version.
|
||||||
Log, // The log entry explaining the changes in this version.
|
Log, // The log entry explaining the changes in this version.
|
||||||
Timestamp, // A Unix timestamp indicating when this version was created.
|
Timestamp, // A Unix timestamp indicating when this version was created.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Role {
|
enum Role {
|
||||||
Table, // Store user roles.
|
Table, // role: Store user roles.
|
||||||
|
|
||||||
Rid, // Primary Key: Unique role ID.
|
Rid, // Primary Key: Unique role ID.
|
||||||
Name, // Unique role name.
|
Name, // Unique role name.
|
||||||
|
|
@ -31,23 +31,25 @@ impl MigrationTrait for Migration {
|
||||||
.col(ColumnDef::new(Role::Weight)
|
.col(ColumnDef::new(Role::Weight)
|
||||||
.integer()
|
.integer()
|
||||||
.not_null()
|
.not_null()
|
||||||
.default(0)
|
.default(10)
|
||||||
)
|
)
|
||||||
// INDEXES.
|
// INDEXES.
|
||||||
.index(Index::create()
|
.index(Index::create()
|
||||||
.name("name-weight")
|
.name("weight-name")
|
||||||
.col(Role::Name)
|
|
||||||
.col(Role::Weight)
|
.col(Role::Weight)
|
||||||
|
.col(Role::Name)
|
||||||
)
|
)
|
||||||
.to_owned()
|
.to_owned()
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Built-in roles.
|
||||||
app::db::exec::<InsertStatement>(Query::insert()
|
app::db::exec::<InsertStatement>(Query::insert()
|
||||||
.into_table(Role::Table)
|
.into_table(Role::Table)
|
||||||
.columns(vec![Role::Name])
|
.columns(vec![Role::Name, Role::Weight])
|
||||||
.values_panic(vec!["anonymous".into()])
|
.values_panic(vec!["anonymous".into(), "1".into()])
|
||||||
.values_panic(vec!["authenticated".into()])
|
.values_panic(vec!["authenticated".into(), "2".into()])
|
||||||
|
.values_panic(vec!["administrator".into(), "3".into()])
|
||||||
)
|
)
|
||||||
.await.map(|_| ())
|
.await.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum RolePermission {
|
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.
|
Rid, // Foreign Key: Role::Rid.
|
||||||
Permission, // A single permission granted to the role identified by Rid.
|
Permission, // A single permission granted to the role identified by Rid.
|
||||||
Module, // The module declaring the permission.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
|
|
@ -28,10 +27,6 @@ impl MigrationTrait for Migration {
|
||||||
.string_len(128)
|
.string_len(128)
|
||||||
.not_null()
|
.not_null()
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(RolePermission::Module)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// INDEXES.
|
// INDEXES.
|
||||||
.primary_key(Index::create()
|
.primary_key(Index::create()
|
||||||
.col(RolePermission::Rid)
|
.col(RolePermission::Rid)
|
||||||
|
|
@ -45,8 +40,8 @@ impl MigrationTrait for Migration {
|
||||||
.name("fk_role_permission-rid")
|
.name("fk_role_permission-rid")
|
||||||
.from(RolePermission::Table, RolePermission::Rid)
|
.from(RolePermission::Table, RolePermission::Rid)
|
||||||
.to(Role::Table, Role::Rid)
|
.to(Role::Table, Role::Rid)
|
||||||
.on_delete(ForeignKeyAction::Cascade)
|
.on_delete(ForeignKeyAction::Restrict)
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
.on_update(ForeignKeyAction::Restrict)
|
||||||
)
|
)
|
||||||
.to_owned()
|
.to_owned()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum User {
|
enum User {
|
||||||
Table, // Stores user data.
|
Table, // user: Stores user data.
|
||||||
|
|
||||||
Uid, // Primary Key: Unique user ID.
|
Uid, // Primary Key: Unique user ID.
|
||||||
Name, // Unique user name.
|
Name, // Unique user name.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum UserRole {
|
enum UserRole {
|
||||||
Table, // Maps users to roles.
|
Table, // user_role: Maps users to roles.
|
||||||
|
|
||||||
Uid, // Foreign Key: User::Uid for user.
|
Uid, // Foreign Key: User::Uid for user.
|
||||||
Rid, // Foreign Key: Role::Rid for role.
|
Rid, // Foreign Key: Role::Rid for role.
|
||||||
|
|
@ -39,15 +39,15 @@ impl MigrationTrait for Migration {
|
||||||
.name("fk_user_role-uid")
|
.name("fk_user_role-uid")
|
||||||
.from(UserRole::Table, UserRole::Uid)
|
.from(UserRole::Table, UserRole::Uid)
|
||||||
.to(User::Table, User::Uid)
|
.to(User::Table, User::Uid)
|
||||||
.on_delete(ForeignKeyAction::Cascade)
|
.on_delete(ForeignKeyAction::Restrict)
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
.on_update(ForeignKeyAction::Restrict)
|
||||||
)
|
)
|
||||||
.foreign_key(ForeignKey::create()
|
.foreign_key(ForeignKey::create()
|
||||||
.name("fk_user_role-rid")
|
.name("fk_user_role-rid")
|
||||||
.from(UserRole::Table, UserRole::Rid)
|
.from(UserRole::Table, UserRole::Rid)
|
||||||
.to(Role::Table, Role::Rid)
|
.to(Role::Table, Role::Rid)
|
||||||
.on_delete(ForeignKeyAction::Cascade)
|
.on_delete(ForeignKeyAction::Restrict)
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
.on_update(ForeignKeyAction::Restrict)
|
||||||
)
|
)
|
||||||
.to_owned()
|
.to_owned()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue