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,35 +1,30 @@
use pagetop::prelude::*;
/// Stores information about all defined {node} types.
#[derive(Iden)]
enum NodeType {
Table, // Nombre de la tabla: node_type (Tipo de nodo).
Type, // The machine-readable name of this type
Name, // The human-readable name of this type
Table, // Stores information about all defined Node types.
Type, // The machine-readable name of this type.
Name, // The human-readable name of this type.
Description, // Descripción breve del tipo.
Help, // Help information shown to the user when creating a {node} of this type
HasTitle, // Boolean indicating whether this type uses the {node}.title field
TitleLabel, // The label displayed for the title field on the edit form
Custom, // A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE)
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
Help, // Help information shown to the user when creating a Node of this type.
HasTitle, // Boolean indicating whether this type uses the Node.Title field.
TitleLabel, // The label displayed for the title field on the edit form.
Custom, // A boolean indicating whether this type is defined by a module (FALSE) or
// by a user via Add content type (TRUE).
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;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220316_000001_create_table_node_type"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
manager.create_table(Table::create()
.table(NodeType::Table)
.if_not_exists()
.col(ColumnDef::new(NodeType::Type)
@ -80,11 +75,16 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(NodeType::Table)
.to_owned()
)
.await
}
}
impl MigrationName for Migration {
fn name(&self) -> &str {
module_name!()
}
}

View file

@ -1,39 +1,37 @@
use pagetop::prelude::*;
/// The base table for nodes.
#[derive(Iden)]
enum Node {
Table, // Nombre de la tabla: node (Nodo).
Nid, // The primary identifier for a node
Vid, // The current {node_revision}.vid version identifier
Type, // The {node_type}.type of this node
Language, // The {languages}.language of this node
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 created it
Status, // Boolean indicating whether the node is published (visible to non-administrators)
Created, // The Unix timestamp when the node was created
Changed, // The Unix timestamp when the node was most recently saved
Comment, // Whether comments are allowed on this node: 0 = no, 1 = closed (read 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
Table, // The base table for nodes.
Nid, // The primary identifier for a node.
Vid, // The current {node_revision}.vid version identifier.
Type, // The {node_type}.type of this node.
Language, // The {languages}.language of this node.
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
// created it.
Status, // Boolean indicating whether the node is published (visible to
// non-administrators).
Created, // The Unix timestamp when the node was created.
Changed, // The Unix timestamp when the node was most recently saved.
Comment, // Whether comments are allowed on this node: 0 = no, 1 = closed (read
// 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;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220316_000002_create_table_node"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
manager.create_table(Table::create()
.table(Node::Table)
.if_not_exists()
.col(ColumnDef::new(Node::Nid)
@ -100,11 +98,16 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(Node::Table)
.to_owned()
)
.await
}
}
impl MigrationName for Migration {
fn name(&self) -> &str {
module_name!()
}
}

View file

@ -1,31 +1,29 @@
use pagetop::prelude::*;
// Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.
#[derive(Iden)]
enum NodeAccess {
Table, // Nombre de la tabla: node_access (Acceso a nodos).
Nid, // The {node}.nid this record affects
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
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
Table, // Identifies which realm/grant pairs a user must possess in order to view,
// update, or delete specific nodes.
Nid, // The {node}.nid this record affects.
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.
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;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220316_000003_create_table_node_access"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
manager.create_table(Table::create()
.table(NodeAccess::Table)
.if_not_exists()
.col(ColumnDef::new(NodeAccess::Nid)
@ -60,11 +58,16 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(NodeAccess::Table)
.to_owned()
)
.await
}
}
impl MigrationName for Migration {
fn name(&self) -> &str {
module_name!()
}
}

View file

@ -1,35 +1,31 @@
use pagetop::prelude::*;
// Stores information about each saved version of a {node}.
#[derive(Iden)]
enum NodeRevision {
Table, // Nombre de la tabla: node_revisión (Versiones de nodos).
Nid, // The {node} this version belongs to
Vid, // The primary identifier for this version
Uid, // The {users}.uid that created this version
Title, // The title of this version
Log, // The log entry explaining the changes in this version
Timestamp, // A Unix timestamp indicating when this version was created
Status, // Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators)
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
Table, // Stores information about each saved version of a {node}.
Nid, // The {node} this version belongs to.
Vid, // The primary identifier for this version.
Uid, // The {users}.uid that created this version.
Title, // The title of this version.
Log, // The log entry explaining the changes in this version.
Timestamp, // A Unix timestamp indicating when this version was created.
Status, // Boolean indicating whether the node (at the time of this revision) is
// published (visible to non-administrators).
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;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220316_000004_create_table_node_revision"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
manager.create_table(Table::create()
.table(NodeRevision::Table)
.if_not_exists()
.col(ColumnDef::new(NodeRevision::Nid)
@ -80,11 +76,16 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(NodeRevision::Table)
.to_owned()
)
.await
}
}
impl MigrationName for Migration {
fn name(&self) -> &str {
module_name!()
}
}

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,25 +14,20 @@ 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()
manager.create_table(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()

View file

@ -1,39 +1,33 @@
use pagetop::prelude::*;
#[derive(Iden)]
enum RolePermission { Table,
Rid,
Permission,
Module,
enum RolePermission {
Table, // 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)]
enum Role { Table,
Rid,
// ...
}
enum Role { Table, Rid, /* ... */ }
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
// Stores the permissions assigned to user roles.
Table::create()
manager.create_table(Table::create()
.table(RolePermission::Table)
.if_not_exists()
// 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()
@ -47,8 +41,7 @@ impl MigrationTrait for Migration {
.name("permission")
.col(RolePermission::Permission)
)
.foreign_key(
ForeignKey::create()
.foreign_key(ForeignKey::create()
.name("fk_role_permission-rid")
.from(RolePermission::Table, RolePermission::Rid)
.to(Role::Table, Role::Rid)
@ -61,8 +54,7 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(RolePermission::Table)
.to_owned()
)

View file

@ -1,17 +1,19 @@
use pagetop::prelude::*;
#[derive(Iden)]
enum User { Table,
Uid,
Name,
Pass,
Mail,
Created,
Changed,
Access,
Login,
Status,
Timezone,
enum User {
Table, // Stores user data.
Uid, // Primary Key: Unique user ID.
Name, // Unique user name.
Pass, // User's password (hashed).
Mail, // User's e-mail address.
Created, // Timestamp for when user was created.
Changed, // Timestamp for when user was changed.
Access, // Timestamp for previous time user accessed the site.
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;
@ -19,59 +21,46 @@ pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
// Stores user data.
Table::create()
manager.create_table(Table::create()
.table(User::Table)
.if_not_exists()
// Primary Key: Unique user ID.
.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)
)
@ -81,8 +70,7 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(User::Table)
.to_owned()
)

View file

@ -1,38 +1,31 @@
use pagetop::prelude::*;
#[derive(Iden)]
enum UserRole { Table,
Uid,
Rid,
enum UserRole {
Table, // Maps users to roles.
Uid, // Foreign Key: User::Uid for user.
Rid, // Foreign Key: Role::Rid for role.
}
#[derive(Iden)]
enum User { Table,
Uid,
// ...
}
enum User { Table, Uid, /* ... */ }
#[derive(Iden)]
enum Role { Table,
Rid,
// ...
}
enum Role { Table, Rid, /* ... */ }
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
// Maps users to roles.
Table::create()
manager.create_table(Table::create()
.table(UserRole::Table)
.if_not_exists()
// 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()
@ -42,16 +35,14 @@ impl MigrationTrait for Migration {
.col(UserRole::Uid)
.col(UserRole::Rid)
)
.foreign_key(
ForeignKey::create()
.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()
.foreign_key(ForeignKey::create()
.name("fk_user_role-rid")
.from(UserRole::Table, UserRole::Rid)
.to(Role::Table, Role::Rid)
@ -64,8 +55,7 @@ impl MigrationTrait for Migration {
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop()
manager.drop_table(Table::drop()
.table(UserRole::Table)
.to_owned()
)