chore: admin table migrations, entity

This commit is contained in:
Sebastian Pravda 2022-10-24 11:45:24 +02:00
parent 63c7307e43
commit 9a00d053bd
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
6 changed files with 81 additions and 2 deletions

5
.gitignore vendored
View file

@ -11,4 +11,7 @@ Cargo.lock
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
*.pdb
.env

20
entity/src/admin.rs Normal file
View file

@ -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 {}

5
entity/src/mod.rs Normal file
View file

@ -0,0 +1,5 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub mod prelude;
pub mod admin;

3
entity/src/prelude.rs Normal file
View file

@ -0,0 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub use super::admin::Entity as Admin;

View file

@ -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<Box<dyn MigrationTrait>> {
vec![]
vec![Box::new(m20221024_111310_create_admin::Migration)]
}
}

View file

@ -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,
}