feat[migration]!: added persistence table

This commit is contained in:
əlemi 2023-03-06 18:50:21 +01:00
parent 5f8780ce2f
commit 3a815d8536
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 71 additions and 8 deletions

View file

@ -2,15 +2,17 @@ pub use sea_orm_migration::prelude::*;
mod m20220101_000001_create_table;
mod m20230123_000947_skin_table;
mod m20230306_135803_persistence_table;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220101_000001_create_table::Migration),
Box::new(m20230123_000947_skin_table::Migration),
]
}
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220101_000001_create_table::Migration),
Box::new(m20230123_000947_skin_table::Migration),
Box::new(m20230306_135803_persistence_table::Migration),
]
}
}

View file

@ -0,0 +1,41 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Persistence::Table)
.if_not_exists()
.col(
ColumnDef::new(Persistence::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Persistence::Secret).string().not_null())
.col(ColumnDef::new(Persistence::LastEdit).date_time().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Persistence::Table).to_owned())
.await
}
}
#[derive(Iden)]
enum Persistence {
Table,
Id,
Secret,
LastEdit,
}

View file

@ -1,7 +1,8 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
pub mod prelude;
pub mod persistence;
pub mod property;
pub mod token;
pub mod user;

View file

@ -0,0 +1,18 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
use chrono::{Utc, DateTime};
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "persistence")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub secret: String,
pub last_edit: DateTime<Utc>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -1,5 +1,6 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.7
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0
pub use super::persistence::Entity as Persistence;
pub use super::property::Entity as Property;
pub use super::token::Entity as Token;
pub use super::user::Entity as User;