From 3a815d8536a4d90749c24bb78cc10ad2478b7e1e Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 6 Mar 2023 18:50:21 +0100 Subject: [PATCH] feat[migration]!: added persistence table --- migration/src/lib.rs | 14 ++++--- .../src/m20230306_135803_persistence_table.rs | 41 +++++++++++++++++++ src/entities/mod.rs | 3 +- src/entities/persistence.rs | 18 ++++++++ src/entities/prelude.rs | 3 +- 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 migration/src/m20230306_135803_persistence_table.rs create mode 100644 src/entities/persistence.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 4422bca..a11d008 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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> { - vec![ - Box::new(m20220101_000001_create_table::Migration), - Box::new(m20230123_000947_skin_table::Migration), - ] - } + fn migrations() -> Vec> { + vec![ + Box::new(m20220101_000001_create_table::Migration), + Box::new(m20230123_000947_skin_table::Migration), + Box::new(m20230306_135803_persistence_table::Migration), + ] + } } diff --git a/migration/src/m20230306_135803_persistence_table.rs b/migration/src/m20230306_135803_persistence_table.rs new file mode 100644 index 0000000..f8c873e --- /dev/null +++ b/migration/src/m20230306_135803_persistence_table.rs @@ -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, +} diff --git a/src/entities/mod.rs b/src/entities/mod.rs index cb116a1..14aaab3 100644 --- a/src/entities/mod.rs +++ b/src/entities/mod.rs @@ -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; diff --git a/src/entities/persistence.rs b/src/entities/persistence.rs new file mode 100644 index 0000000..66a7a4a --- /dev/null +++ b/src/entities/persistence.rs @@ -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, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/entities/prelude.rs b/src/entities/prelude.rs index afe7139..56f6370 100644 --- a/src/entities/prelude.rs +++ b/src/entities/prelude.rs @@ -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;