From 9a00d053bd2726a01639ea86c0d69a68e8d70181 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Mon, 24 Oct 2022 11:45:24 +0200 Subject: [PATCH] chore: admin table migrations, entity --- .gitignore | 5 +- entity/src/admin.rs | 20 ++++++++ entity/src/mod.rs | 5 ++ entity/src/prelude.rs | 3 ++ migration/src/lib.rs | 4 +- .../src/m20221024_111310_create_admin.rs | 46 +++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 entity/src/admin.rs create mode 100644 entity/src/mod.rs create mode 100644 entity/src/prelude.rs create mode 100644 migration/src/m20221024_111310_create_admin.rs diff --git a/.gitignore b/.gitignore index ada8be92..4e85060b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ Cargo.lock **/*.rs.bk # MSVC Windows builds of rustc generate these, which store debugging information -*.pdb \ No newline at end of file +*.pdb + + +.env \ No newline at end of file diff --git a/entity/src/admin.rs b/entity/src/admin.rs new file mode 100644 index 00000000..0133bec6 --- /dev/null +++ b/entity/src/admin.rs @@ -0,0 +1,20 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "admin")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub name: String, + pub public_key: String, + #[sea_orm(column_type = "Text")] + pub private_key_hash: String, + pub password_hash: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/mod.rs b/entity/src/mod.rs new file mode 100644 index 00000000..a9862cfd --- /dev/null +++ b/entity/src/mod.rs @@ -0,0 +1,5 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 + +pub mod prelude; + +pub mod admin; diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs new file mode 100644 index 00000000..2f2b6273 --- /dev/null +++ b/entity/src/prelude.rs @@ -0,0 +1,3 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 + +pub use super::admin::Entity as Admin; diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 838e47ad..434a0602 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -1,10 +1,12 @@ pub use sea_orm_migration::prelude::*; +mod m20221024_111310_create_admin; + pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![] + vec![Box::new(m20221024_111310_create_admin::Migration)] } } diff --git a/migration/src/m20221024_111310_create_admin.rs b/migration/src/m20221024_111310_create_admin.rs new file mode 100644 index 00000000..f7864ae7 --- /dev/null +++ b/migration/src/m20221024_111310_create_admin.rs @@ -0,0 +1,46 @@ +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(Admin::Table) + .if_not_exists() + .col( + ColumnDef::new(Admin::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Admin::Name).string().not_null()) + .col(ColumnDef::new(Admin::PublicKey).string().not_null()) + .col(ColumnDef::new(Admin::PrivateKeyHash).text().not_null()) + .col(ColumnDef::new(Admin::PasswordHash).string().not_null()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Admin::Table).to_owned()) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Admin { + Table, + Id, + Name, + PublicKey, + PrivateKeyHash, + PasswordHash, +}