Create user and keypair migrations
This commit is contained in:
parent
3d18134278
commit
8e4adedf98
4 changed files with 95 additions and 22 deletions
|
@ -14,9 +14,6 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
|
|||
[dependencies.sea-orm-migration]
|
||||
version = "0.11.0"
|
||||
features = [
|
||||
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
|
||||
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
|
||||
# e.g.
|
||||
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
# "sqlx-postgres", # `DATABASE_DRIVER` feature
|
||||
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
|
||||
"sqlx-postgres", # `DATABASE_DRIVER` feature
|
||||
]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20230619_221344_create_user;
|
||||
mod m20230620_232650_create_keypair;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
@ -9,6 +10,7 @@ impl MigratorTrait for Migrator {
|
|||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20230619_221344_create_user::Migration),
|
||||
Box::new(m20230620_232650_create_keypair::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,43 +6,69 @@ pub struct Migration;
|
|||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
todo!();
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Post::Table)
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(User::Id).text().not_null().primary_key())
|
||||
.col(
|
||||
ColumnDef::new(Post::Id)
|
||||
.integer()
|
||||
ColumnDef::new(User::Activated)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
.default(false),
|
||||
)
|
||||
.col(ColumnDef::new(User::Username).text().not_null())
|
||||
.col(ColumnDef::new(User::Email).text().not_null())
|
||||
.col(ColumnDef::new(User::PasswordHash).text().not_null())
|
||||
.col(ColumnDef::new(User::MfaKey).text())
|
||||
.col(ColumnDef::new(User::DisplayName).text().not_null())
|
||||
.col(ColumnDef::new(User::Summary).text().not_null().default(""))
|
||||
.col(ColumnDef::new(User::Created).date_time().not_null())
|
||||
.col(
|
||||
ColumnDef::new(User::ManuallyApprovesFollowers)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(User::Discoverable)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(User::AlwaysMarkAsNsfw)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(ColumnDef::new(Post::Title).string().not_null())
|
||||
.col(ColumnDef::new(Post::Text).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Replace the sample below with your own migration scripts
|
||||
todo!();
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Post::Table).to_owned())
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum User {
|
||||
pub enum User {
|
||||
Table,
|
||||
Id,
|
||||
Title,
|
||||
Text,
|
||||
Activated,
|
||||
Username,
|
||||
Email,
|
||||
PasswordHash,
|
||||
MfaKey,
|
||||
DisplayName,
|
||||
Summary,
|
||||
Created,
|
||||
ManuallyApprovesFollowers,
|
||||
Discoverable,
|
||||
AlwaysMarkAsNsfw,
|
||||
}
|
||||
|
|
48
migration/src/m20230620_232650_create_keypair.rs
Normal file
48
migration/src/m20230620_232650_create_keypair.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
use crate::m20230619_221344_create_user::User;
|
||||
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(KeyPair::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(KeyPair::User)
|
||||
.text()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(KeyPair::Public).string().not_null())
|
||||
.col(ColumnDef::new(KeyPair::Private).string().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-user_id-keypair_user")
|
||||
.from(KeyPair::Table, KeyPair::User)
|
||||
.to(User::Table, User::Id),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(KeyPair::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum KeyPair {
|
||||
Table,
|
||||
User,
|
||||
Public,
|
||||
Private,
|
||||
}
|
Loading…
Add table
Reference in a new issue