Actualiza formato del código de las migraciones
This commit is contained in:
parent
e7f9bf8778
commit
f30f84e993
8 changed files with 486 additions and 512 deletions
|
|
@ -1,90 +1,90 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
/// Stores information about all defined {node} types.
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum NodeType {
|
enum NodeType {
|
||||||
Table, // Nombre de la tabla: node_type (Tipo de nodo).
|
Table, // Stores information about all defined Node types.
|
||||||
Type, // The machine-readable name of this type
|
|
||||||
Name, // The human-readable name of this type
|
Type, // The machine-readable name of this type.
|
||||||
Description, // Descripción breve del tipo.
|
Name, // The human-readable name of this type.
|
||||||
Help, // Help information shown to the user when creating a {node} of this type
|
Description, // Descripción breve del tipo.
|
||||||
HasTitle, // Boolean indicating whether this type uses the {node}.title field
|
Help, // Help information shown to the user when creating a Node of this type.
|
||||||
TitleLabel, // The label displayed for the title field on the edit form
|
HasTitle, // Boolean indicating whether this type uses the Node.Title field.
|
||||||
Custom, // A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE)
|
TitleLabel, // The label displayed for the title field on the edit form.
|
||||||
Locked, // A boolean indicating whether the administrator can change the machine name of this type
|
Custom, // A boolean indicating whether this type is defined by a module (FALSE) or
|
||||||
Disabled, // A boolean indicating whether the node type is disabled
|
// by a user via Add content type (TRUE).
|
||||||
OrigType, // The original machine-readable name of this node type. This may be different from the current type name if the locked field is 0
|
Locked, // A boolean indicating whether the administrator can change the machine
|
||||||
|
// name of this type.
|
||||||
|
Disabled, // A boolean indicating whether the node type is disabled.
|
||||||
|
OrigType, // The original machine-readable name of this node type, this may be
|
||||||
|
// different from the current type name if the locked field is 0.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m20220316_000001_create_table_node_type"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(NodeType::Table)
|
||||||
Table::create()
|
.if_not_exists()
|
||||||
.table(NodeType::Table)
|
.col(ColumnDef::new(NodeType::Type)
|
||||||
.if_not_exists()
|
.integer()
|
||||||
.col(ColumnDef::new(NodeType::Type)
|
.not_null()
|
||||||
.integer()
|
.auto_increment()
|
||||||
.not_null()
|
.primary_key(),
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Name)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Description)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Help)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::HasTitle)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::TitleLabel)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Custom)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Locked)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::Disabled)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeType::OrigType)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(NodeType::Name)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::Description)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::Help)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::HasTitle)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::TitleLabel)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::Custom)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::Locked)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::Disabled)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeType::OrigType)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(NodeType::Table)
|
||||||
.table(NodeType::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
module_name!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,110 +1,113 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
/// The base table for nodes.
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Node {
|
enum Node {
|
||||||
Table, // Nombre de la tabla: node (Nodo).
|
Table, // The base table for nodes.
|
||||||
Nid, // The primary identifier for a node
|
|
||||||
Vid, // The current {node_revision}.vid version identifier
|
Nid, // The primary identifier for a node.
|
||||||
Type, // The {node_type}.type of this node
|
Vid, // The current {node_revision}.vid version identifier.
|
||||||
Language, // The {languages}.language of this node
|
Type, // The {node_type}.type of this node.
|
||||||
Title, // The title of this node, always treated as non-markup plain text
|
Language, // The {languages}.language of this node.
|
||||||
Uid, // The {users}.uid that owns this node; initially, this is the user that created it
|
Title, // The title of this node, always treated as non-markup plain text.
|
||||||
Status, // Boolean indicating whether the node is published (visible to non-administrators)
|
Uid, // The {users}.uid that owns this node; initially, this is the user that
|
||||||
Created, // The Unix timestamp when the node was created
|
// created it.
|
||||||
Changed, // The Unix timestamp when the node was most recently saved
|
Status, // Boolean indicating whether the node is published (visible to
|
||||||
Comment, // Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write)
|
// non-administrators).
|
||||||
Promote, // Boolean indicating whether the node should be displayed on the front page
|
Created, // The Unix timestamp when the node was created.
|
||||||
Sticky, // Boolean indicating whether the node should be displayed at the top of lists in which it appears
|
Changed, // The Unix timestamp when the node was most recently saved.
|
||||||
Tnid, // The translation set id for this node, which equals the node id of the source post in each set
|
Comment, // Whether comments are allowed on this node: 0 = no, 1 = closed (read
|
||||||
Translate, // A boolean indicating whether this translation page needs to be updated
|
// only), 2 = open (read/write).
|
||||||
|
Promote, // Boolean indicating whether the node should be displayed on the front
|
||||||
|
// page.
|
||||||
|
Sticky, // Boolean indicating whether the node should be displayed at the top of
|
||||||
|
// lists in which it appears.
|
||||||
|
Tnid, // The translation set id for this node, which equals the node id of the
|
||||||
|
// source post in each set.
|
||||||
|
Translate, // A boolean indicating whether this translation page needs to be updated.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m20220316_000002_create_table_node"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(Node::Table)
|
||||||
Table::create()
|
.if_not_exists()
|
||||||
.table(Node::Table)
|
.col(ColumnDef::new(Node::Nid)
|
||||||
.if_not_exists()
|
.integer()
|
||||||
.col(ColumnDef::new(Node::Nid)
|
.not_null()
|
||||||
.integer()
|
.auto_increment()
|
||||||
.not_null()
|
.primary_key(),
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Vid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Type)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Language)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Title)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Uid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Status)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Created)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Changed)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Comment)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Promote)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Sticky)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Tnid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Node::Translate)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(Node::Vid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Type)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Language)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Title)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Uid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Status)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Created)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Changed)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Comment)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Promote)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Sticky)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Tnid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(Node::Translate)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(Node::Table)
|
||||||
.table(Node::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
module_name!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,73 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
// Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum NodeAccess {
|
enum NodeAccess {
|
||||||
Table, // Nombre de la tabla: node_access (Acceso a nodos).
|
Table, // Identifies which realm/grant pairs a user must possess in order to view,
|
||||||
Nid, // The {node}.nid this record affects
|
// update, or delete specific nodes.
|
||||||
Gid, // The grant ID a user must possess in the specified realm to gain this row's privileges on the node
|
|
||||||
Realm, // The realm in which the user must possess the grant ID. Each node access node can define one or more realms
|
Nid, // The {node}.nid this record affects.
|
||||||
GrantView, // Boolean indicating whether a user with the realm/grant pair can view this node
|
Gid, // The grant ID a user must possess in the specified realm to gain this
|
||||||
GrantUpdate, // Boolean indicating whether a user with the realm/grant pair can edit this node
|
// row's privileges on the node.
|
||||||
GrantDelete, // Boolean indicating whether a user with the realm/grant pair can delete this node
|
Realm, // The realm in which the user must possess the grant ID. Each node access
|
||||||
|
// node can define one or more realms.
|
||||||
|
GrantView, // Boolean indicating whether a user with the realm/grant pair can view this
|
||||||
|
// node.
|
||||||
|
GrantUpdate, // Boolean indicating whether a user with the realm/grant pair can edit this
|
||||||
|
// node.
|
||||||
|
GrantDelete, // Boolean indicating whether a user with the realm/grant pair can delete
|
||||||
|
// this node.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m20220316_000003_create_table_node_access"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(NodeAccess::Table)
|
||||||
Table::create()
|
.if_not_exists()
|
||||||
.table(NodeAccess::Table)
|
.col(ColumnDef::new(NodeAccess::Nid)
|
||||||
.if_not_exists()
|
.integer()
|
||||||
.col(ColumnDef::new(NodeAccess::Nid)
|
.not_null()
|
||||||
.integer()
|
.auto_increment()
|
||||||
.not_null()
|
.primary_key(),
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeAccess::Gid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeAccess::Realm)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeAccess::GrantView)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeAccess::GrantUpdate)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeAccess::GrantDelete)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(NodeAccess::Gid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeAccess::Realm)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeAccess::GrantView)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeAccess::GrantUpdate)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeAccess::GrantDelete)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(NodeAccess::Table)
|
||||||
.table(NodeAccess::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
module_name!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,90 +1,91 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
// Stores information about each saved version of a {node}.
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum NodeRevision {
|
enum NodeRevision {
|
||||||
Table, // Nombre de la tabla: node_revisión (Versiones de nodos).
|
Table, // Stores information about each saved version of a {node}.
|
||||||
Nid, // The {node} this version belongs to
|
|
||||||
Vid, // The primary identifier for this version
|
Nid, // The {node} this version belongs to.
|
||||||
Uid, // The {users}.uid that created this version
|
Vid, // The primary identifier for this version.
|
||||||
Title, // The title of this version
|
Uid, // The {users}.uid that created this version.
|
||||||
Log, // The log entry explaining the changes in this version
|
Title, // The title of this version.
|
||||||
Timestamp, // A Unix timestamp indicating when this version was created
|
Log, // The log entry explaining the changes in this version.
|
||||||
Status, // Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators)
|
Timestamp, // A Unix timestamp indicating when this version was created.
|
||||||
Comment, // Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write)
|
Status, // Boolean indicating whether the node (at the time of this revision) is
|
||||||
Promote, // Boolean indicating whether the node (at the time of this revision) should be displayed on the front page
|
// published (visible to non-administrators).
|
||||||
Sticky, // Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears
|
Comment, // Whether comments are allowed on this node (at the time of this revision):
|
||||||
|
// 0 = no, 1 = closed (read only), 2 = open (read/write).
|
||||||
|
Promote, // Boolean indicating whether the node (at the time of this revision) should
|
||||||
|
// be displayed on the front page.
|
||||||
|
Sticky, // Boolean indicating whether the node (at the time of this revision) should
|
||||||
|
// be displayed at the top of lists in which it appears.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m20220316_000004_create_table_node_revision"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(NodeRevision::Table)
|
||||||
Table::create()
|
.if_not_exists()
|
||||||
.table(NodeRevision::Table)
|
.col(ColumnDef::new(NodeRevision::Nid)
|
||||||
.if_not_exists()
|
.integer()
|
||||||
.col(ColumnDef::new(NodeRevision::Nid)
|
.not_null()
|
||||||
.integer()
|
.auto_increment()
|
||||||
.not_null()
|
.primary_key(),
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Vid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Uid)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Title)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Log)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Timestamp)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Status)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Comment)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Promote)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(NodeRevision::Sticky)
|
|
||||||
.string()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(NodeRevision::Vid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Uid)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Title)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Log)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Timestamp)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Status)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Comment)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Promote)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(NodeRevision::Sticky)
|
||||||
|
.string()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(NodeRevision::Table)
|
||||||
.table(NodeRevision::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MigrationName for Migration {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
module_name!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Role { Table,
|
enum Role {
|
||||||
Rid,
|
Table, // Store user roles.
|
||||||
Name,
|
|
||||||
Weight,
|
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;
|
pub struct Migration;
|
||||||
|
|
@ -12,37 +14,32 @@ pub struct Migration;
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager.create_table(
|
manager.create_table(Table::create()
|
||||||
// Store user roles.
|
.table(Role::Table)
|
||||||
Table::create()
|
.if_not_exists()
|
||||||
.table(Role::Table)
|
.col(ColumnDef::new(Role::Rid)
|
||||||
.if_not_exists()
|
.unsigned()
|
||||||
// Primary Key: Unique role ID.
|
.not_null()
|
||||||
.col(ColumnDef::new(Role::Rid)
|
.auto_increment()
|
||||||
.unsigned()
|
.primary_key()
|
||||||
.not_null()
|
)
|
||||||
.auto_increment()
|
.col(ColumnDef::new(Role::Name)
|
||||||
.primary_key()
|
.string_len(64)
|
||||||
)
|
.not_null()
|
||||||
// Unique role name.
|
.unique_key()
|
||||||
.col(ColumnDef::new(Role::Name)
|
)
|
||||||
.string_len(64)
|
.col(ColumnDef::new(Role::Weight)
|
||||||
.not_null()
|
.integer()
|
||||||
.unique_key()
|
.not_null()
|
||||||
)
|
.default(0)
|
||||||
// The weight of this role in listings and the user interface.
|
)
|
||||||
.col(ColumnDef::new(Role::Weight)
|
// INDEXES.
|
||||||
.integer()
|
.index(Index::create()
|
||||||
.not_null()
|
.name("name-weight")
|
||||||
.default(0)
|
.col(Role::Name)
|
||||||
)
|
.col(Role::Weight)
|
||||||
// INDEXES.
|
)
|
||||||
.index(Index::create()
|
.to_owned()
|
||||||
.name("name-weight")
|
|
||||||
.col(Role::Name)
|
|
||||||
.col(Role::Weight)
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,72 +1,64 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum RolePermission { Table,
|
enum RolePermission {
|
||||||
Rid,
|
Table, // Stores the permissions assigned to user roles.
|
||||||
Permission,
|
|
||||||
Module,
|
Rid, // Foreign Key: Role::Rid.
|
||||||
|
Permission, // A single permission granted to the role identified by Rid.
|
||||||
|
Module, // The module declaring the permission.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Role { Table,
|
enum Role { Table, Rid, /* ... */ }
|
||||||
Rid,
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(RolePermission::Table)
|
||||||
// Stores the permissions assigned to user roles.
|
.if_not_exists()
|
||||||
Table::create()
|
.col(ColumnDef::new(RolePermission::Rid)
|
||||||
.table(RolePermission::Table)
|
.unsigned()
|
||||||
.if_not_exists()
|
.not_null()
|
||||||
// Foreign Key: Role::Rid.
|
|
||||||
.col(ColumnDef::new(RolePermission::Rid)
|
|
||||||
.unsigned()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// A single permission granted to the role identified by Rid.
|
|
||||||
.col(ColumnDef::new(RolePermission::Permission)
|
|
||||||
.string_len(128)
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// The module declaring the permission.
|
|
||||||
.col(ColumnDef::new(RolePermission::Module)
|
|
||||||
.string_len(255)
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// INDEXES.
|
|
||||||
.primary_key(Index::create()
|
|
||||||
.col(RolePermission::Rid)
|
|
||||||
.col(RolePermission::Permission)
|
|
||||||
)
|
|
||||||
.index(Index::create()
|
|
||||||
.name("permission")
|
|
||||||
.col(RolePermission::Permission)
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk_role_permission-rid")
|
|
||||||
.from(RolePermission::Table, RolePermission::Rid)
|
|
||||||
.to(Role::Table, Role::Rid)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade)
|
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(RolePermission::Permission)
|
||||||
|
.string_len(128)
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(RolePermission::Module)
|
||||||
|
.string_len(255)
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
// INDEXES.
|
||||||
|
.primary_key(Index::create()
|
||||||
|
.col(RolePermission::Rid)
|
||||||
|
.col(RolePermission::Permission)
|
||||||
|
)
|
||||||
|
.index(Index::create()
|
||||||
|
.name("permission")
|
||||||
|
.col(RolePermission::Permission)
|
||||||
|
)
|
||||||
|
.foreign_key(ForeignKey::create()
|
||||||
|
.name("fk_role_permission-rid")
|
||||||
|
.from(RolePermission::Table, RolePermission::Rid)
|
||||||
|
.to(Role::Table, Role::Rid)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade)
|
||||||
|
.on_update(ForeignKeyAction::Cascade)
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(RolePermission::Table)
|
||||||
.table(RolePermission::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum User { Table,
|
enum User {
|
||||||
Uid,
|
Table, // Stores user data.
|
||||||
Name,
|
|
||||||
Pass,
|
Uid, // Primary Key: Unique user ID.
|
||||||
Mail,
|
Name, // Unique user name.
|
||||||
Created,
|
Pass, // User's password (hashed).
|
||||||
Changed,
|
Mail, // User's e-mail address.
|
||||||
Access,
|
Created, // Timestamp for when user was created.
|
||||||
Login,
|
Changed, // Timestamp for when user was changed.
|
||||||
Status,
|
Access, // Timestamp for previous time user accessed the site.
|
||||||
Timezone,
|
Login, // Timestamp for user's last login.
|
||||||
|
Status, // Whether the user is active(1) or blocked(0).
|
||||||
|
Timezone, // User's time zone.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
@ -19,74 +21,60 @@ pub struct Migration;
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(User::Table)
|
||||||
// Stores user data.
|
.if_not_exists()
|
||||||
Table::create()
|
.col(ColumnDef::new(User::Uid)
|
||||||
.table(User::Table)
|
.unsigned()
|
||||||
.if_not_exists()
|
.not_null()
|
||||||
// Primary Key: Unique user ID.
|
.primary_key()
|
||||||
.col(ColumnDef::new(User::Uid)
|
|
||||||
.unsigned()
|
|
||||||
.not_null()
|
|
||||||
.primary_key()
|
|
||||||
)
|
|
||||||
// Unique user name.
|
|
||||||
.col(ColumnDef::new(User::Name)
|
|
||||||
.string_len(60)
|
|
||||||
.not_null()
|
|
||||||
.unique_key()
|
|
||||||
)
|
|
||||||
// User's password (hashed).
|
|
||||||
.col(ColumnDef::new(User::Pass)
|
|
||||||
.string_len(128)
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// User's e-mail address.
|
|
||||||
.col(ColumnDef::new(User::Mail)
|
|
||||||
.string_len(255)
|
|
||||||
)
|
|
||||||
// Timestamp for when user was created.
|
|
||||||
.col(ColumnDef::new(User::Created)
|
|
||||||
.timestamp()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// Timestamp for when user was changed.
|
|
||||||
.col(ColumnDef::new(User::Changed)
|
|
||||||
.timestamp()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// Timestamp for previous time user accessed the site.
|
|
||||||
.col(ColumnDef::new(User::Access)
|
|
||||||
.timestamp()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// Timestamp for user's last login.
|
|
||||||
.col(ColumnDef::new(User::Login)
|
|
||||||
.timestamp()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// Whether the user is active(1) or blocked(0).
|
|
||||||
.col(ColumnDef::new(User::Status)
|
|
||||||
.boolean()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// User's time zone.
|
|
||||||
.col(ColumnDef::new(User::Timezone)
|
|
||||||
.string_len(32)
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(User::Name)
|
||||||
|
.string_len(60)
|
||||||
|
.not_null()
|
||||||
|
.unique_key()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Pass)
|
||||||
|
.string_len(128)
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Mail)
|
||||||
|
.string_len(255)
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Created)
|
||||||
|
.timestamp()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Changed)
|
||||||
|
.timestamp()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Access)
|
||||||
|
.timestamp()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Login)
|
||||||
|
.timestamp()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Status)
|
||||||
|
.boolean()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(User::Timezone)
|
||||||
|
.string_len(32)
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(User::Table)
|
||||||
.table(User::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,75 +1,65 @@
|
||||||
use pagetop::prelude::*;
|
use pagetop::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum UserRole { Table,
|
enum UserRole {
|
||||||
Uid,
|
Table, // Maps users to roles.
|
||||||
Rid,
|
|
||||||
|
Uid, // Foreign Key: User::Uid for user.
|
||||||
|
Rid, // Foreign Key: Role::Rid for role.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum User { Table,
|
enum User { Table, Uid, /* ... */ }
|
||||||
Uid,
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
#[derive(Iden)]
|
#[derive(Iden)]
|
||||||
enum Role { Table,
|
enum Role { Table, Rid, /* ... */ }
|
||||||
Rid,
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Migration;
|
pub struct Migration;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigrationTrait for Migration {
|
impl MigrationTrait for Migration {
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.create_table(Table::create()
|
||||||
.create_table(
|
.table(UserRole::Table)
|
||||||
// Maps users to roles.
|
.if_not_exists()
|
||||||
Table::create()
|
.col(ColumnDef::new(UserRole::Uid)
|
||||||
.table(UserRole::Table)
|
.unsigned()
|
||||||
.if_not_exists()
|
.not_null()
|
||||||
// Foreign Key: User::Uid for user.
|
|
||||||
.col(ColumnDef::new(UserRole::Uid)
|
|
||||||
.unsigned()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// Foreign Key: Role::Rid for role.
|
|
||||||
.col(ColumnDef::new(UserRole::Rid)
|
|
||||||
.unsigned()
|
|
||||||
.not_null()
|
|
||||||
)
|
|
||||||
// INDEXES.
|
|
||||||
.primary_key(Index::create()
|
|
||||||
.col(UserRole::Uid)
|
|
||||||
.col(UserRole::Rid)
|
|
||||||
)
|
|
||||||
.foreign_key(
|
|
||||||
ForeignKey::create()
|
|
||||||
.name("fk_user_role-uid")
|
|
||||||
.from(UserRole::Table, UserRole::Uid)
|
|
||||||
.to(User::Table, User::Uid)
|
|
||||||
.on_delete(ForeignKeyAction::Cascade)
|
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
|
||||||
)
|
|
||||||
.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)
|
|
||||||
)
|
|
||||||
.to_owned()
|
|
||||||
)
|
)
|
||||||
.await
|
.col(ColumnDef::new(UserRole::Rid)
|
||||||
|
.unsigned()
|
||||||
|
.not_null()
|
||||||
|
)
|
||||||
|
// INDEXES.
|
||||||
|
.primary_key(Index::create()
|
||||||
|
.col(UserRole::Uid)
|
||||||
|
.col(UserRole::Rid)
|
||||||
|
)
|
||||||
|
.foreign_key(ForeignKey::create()
|
||||||
|
.name("fk_user_role-uid")
|
||||||
|
.from(UserRole::Table, UserRole::Uid)
|
||||||
|
.to(User::Table, User::Uid)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade)
|
||||||
|
.on_update(ForeignKeyAction::Cascade)
|
||||||
|
)
|
||||||
|
.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)
|
||||||
|
)
|
||||||
|
.to_owned()
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
manager
|
manager.drop_table(Table::drop()
|
||||||
.drop_table(Table::drop()
|
.table(UserRole::Table)
|
||||||
.table(UserRole::Table)
|
.to_owned()
|
||||||
.to_owned()
|
)
|
||||||
)
|
.await
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue