Skip to content

Commit

Permalink
chore: admin table migrations, entity
Browse files Browse the repository at this point in the history
  • Loading branch information
starvy committed Oct 24, 2022
1 parent 63c7307 commit 9a00d05
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ Cargo.lock
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
*.pdb


.env
20 changes: 20 additions & 0 deletions entity/src/admin.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions entity/src/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub mod prelude;

pub mod admin;
3 changes: 3 additions & 0 deletions entity/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub use super::admin::Entity as Admin;
4 changes: 3 additions & 1 deletion migration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
}
}
46 changes: 46 additions & 0 deletions migration/src/m20221024_111310_create_admin.rs
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 9a00d05

Please sign in to comment.