Initial commit
This commit is contained in:
12
migration/src/lib.rs
Normal file
12
migration/src/lib.rs
Normal file
@ -0,0 +1,12 @@
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20220101_000001_create_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)]
|
||||
}
|
||||
}
|
80
migration/src/m20220101_000001_create_table.rs
Normal file
80
migration/src/m20220101_000001_create_table.rs
Normal file
@ -0,0 +1,80 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(Iden)]
|
||||
enum MasterPass {
|
||||
Table,
|
||||
#[iden = "user_id"]
|
||||
UserId,
|
||||
Salt,
|
||||
#[iden = "password_hash"]
|
||||
PasswordHash,
|
||||
}
|
||||
|
||||
#[derive(Iden)]
|
||||
enum Account {
|
||||
Table,
|
||||
#[iden = "user_id"]
|
||||
UserId,
|
||||
Name,
|
||||
Salt,
|
||||
#[iden = "enc_login"]
|
||||
EncLogin,
|
||||
#[iden = "enc_password"]
|
||||
EncPassword,
|
||||
}
|
||||
|
||||
#[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(MasterPass::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(MasterPass::UserId)
|
||||
.integer()
|
||||
.primary_key()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(MasterPass::Salt).binary_len(64).not_null())
|
||||
.col(
|
||||
ColumnDef::new(MasterPass::PasswordHash)
|
||||
.binary_len(128)
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Account::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Account::UserId).integer().not_null())
|
||||
.col(ColumnDef::new(Account::Name).string_len(256).not_null())
|
||||
.col(ColumnDef::new(Account::Salt).binary_len(64).not_null())
|
||||
.col(ColumnDef::new(Account::EncLogin).var_binary(256).not_null())
|
||||
.col(
|
||||
ColumnDef::new(Account::EncPassword)
|
||||
.var_binary(256)
|
||||
.not_null(),
|
||||
)
|
||||
.primary_key(Index::create().col(Account::UserId).col(Account::Name))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(sea_query::Table::drop().table(MasterPass::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(sea_query::Table::drop().table(Account::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
6
migration/src/main.rs
Normal file
6
migration/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
cli::run_cli(migration::Migrator).await;
|
||||
}
|
Reference in New Issue
Block a user