diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 22cdf3e..1fd1819 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -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 ] diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 1b89e0d..2d8fcfc 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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> { vec![ Box::new(m20230619_221344_create_user::Migration), + Box::new(m20230620_232650_create_keypair::Migration), ] } } diff --git a/migration/src/m20230619_221344_create_user.rs b/migration/src/m20230619_221344_create_user.rs index fdc0b7a..45dc8df 100644 --- a/migration/src/m20230619_221344_create_user.rs +++ b/migration/src/m20230619_221344_create_user.rs @@ -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, } diff --git a/migration/src/m20230620_232650_create_keypair.rs b/migration/src/m20230620_232650_create_keypair.rs new file mode 100644 index 0000000..4301f68 --- /dev/null +++ b/migration/src/m20230620_232650_create_keypair.rs @@ -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, +}