Elimina Refinery y Barrel en favor de SeaORM
Se integran las funcionalidades de SeaORM en el funcionamiento de PageTop para abstraer el uso y acceso a la base de datos.
This commit is contained in:
parent
619b7b73c6
commit
4b5d8ce38a
16 changed files with 150 additions and 98 deletions
|
|
@ -1,13 +0,0 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub fn migration() -> String {
|
||||
let mut m = db::Migration::new();
|
||||
|
||||
m.create_table("system", |t| {
|
||||
t.add_column("id", db::types::primary());
|
||||
t.add_column("title", db::types::varchar(255));
|
||||
t.add_column("is_completed", db::types::boolean().default(false));
|
||||
});
|
||||
|
||||
m.make::<db::Database>()
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
localize!("en-US", "src/base/module/admin/locales");
|
||||
embed_migrations!("src/base/module/admin/migrations");
|
||||
|
||||
mod summary;
|
||||
|
||||
|
|
@ -26,8 +25,4 @@ impl Module for AdminModule {
|
|||
.route("", server::web::get().to(summary::summary))
|
||||
);
|
||||
}
|
||||
|
||||
fn configure_migrations(&self) -> Option<db::Migrations> {
|
||||
Some(migrations::runner())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
src/base/module/user/entity/mod.rs
Normal file
1
src/base/module/user/entity/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod user;
|
||||
18
src/base/module/user/entity/user.rs
Normal file
18
src/base/module/user/entity/user.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use crate::db::entity::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
#[serde(skip_deserializing)]
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
#[sea_orm(column_type = "Text")]
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
use crate::db::migration::*;
|
||||
|
||||
#[derive(Iden)]
|
||||
enum User {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Text,
|
||||
}
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20220312_000001_create_table_user"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(User::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(User::Title)
|
||||
.string()
|
||||
.not_null()
|
||||
)
|
||||
.col(ColumnDef::new(User::Text)
|
||||
.string()
|
||||
.not_null()
|
||||
)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop()
|
||||
.table(User::Table)
|
||||
.to_owned()
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
12
src/base/module/user/migration/mod.rs
Normal file
12
src/base/module/user/migration/mod.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use crate::db::migration::*;
|
||||
|
||||
pub mod m20220312_000001_create_table_user;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![Box::new(m20220312_000001_create_table_user::Migration)]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub fn migration() -> String {
|
||||
let mut m = db::Migration::new();
|
||||
|
||||
m.create_table("user", |t| {
|
||||
t.add_column("id", db::types::primary());
|
||||
t.add_column("title", db::types::varchar(255));
|
||||
t.add_column("is_completed", db::types::boolean().default(false));
|
||||
});
|
||||
|
||||
m.make::<db::Database>()
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
localize!("en-US", "src/base/module/user/locales");
|
||||
embed_migrations!("src/base/module/user/migrations");
|
||||
|
||||
mod entity;
|
||||
mod migration;
|
||||
|
||||
pub struct UserModule;
|
||||
|
||||
|
|
@ -22,8 +24,8 @@ impl Module for UserModule {
|
|||
cfg.route("/user/login", server::web::get().to(login));
|
||||
}
|
||||
|
||||
fn configure_migrations(&self) -> Option<db::Migrations> {
|
||||
Some(migrations::runner())
|
||||
fn migrations(&self, dbconn: &db::DbConn) -> Result<(), db::DbErr> {
|
||||
db_migrations!(dbconn)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue