From f48509e2d8856c301e4c6297f099033b2ce28873 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 23 Mar 2024 05:01:45 +0100 Subject: [PATCH] feat: added tables+entities for config, credentials simple password auth is bad and shall likely go but it's easy for now and i need a way to login to test user interactions as i make the outbox working --- .../m20240323_000001_add_user_configs.rs | 49 +++++++++++++++++++ ...m20240323_000002_add_simple_credentials.rs | 43 ++++++++++++++++ src/migrations/mod.rs | 4 ++ src/model/config.rs | 31 ++++++++++++ src/model/credential.rs | 28 +++++++++++ src/model/mod.rs | 4 +- src/model/user.rs | 6 +++ 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/migrations/m20240323_000001_add_user_configs.rs create mode 100644 src/migrations/m20240323_000002_add_simple_credentials.rs create mode 100644 src/model/config.rs create mode 100644 src/model/credential.rs diff --git a/src/migrations/m20240323_000001_add_user_configs.rs b/src/migrations/m20240323_000001_add_user_configs.rs new file mode 100644 index 00000000..42dc8fde --- /dev/null +++ b/src/migrations/m20240323_000001_add_user_configs.rs @@ -0,0 +1,49 @@ +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(Configs::Table) + .col( + ColumnDef::new(Configs::Id) + .string() + .not_null() + .primary_key() + ) + .col(ColumnDef::new(Configs::AcceptFollowRequests).boolean().not_null()) + .col(ColumnDef::new(Configs::ShowFollowersCount).boolean().not_null()) + .col(ColumnDef::new(Configs::ShowFollowingCount).boolean().not_null()) + .col(ColumnDef::new(Configs::ShowFollowers).boolean().not_null()) + .col(ColumnDef::new(Configs::ShowFollowing).boolean().not_null()) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Configs::Table).to_owned()) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Configs { + Table, + Id, + AcceptFollowRequests, + ShowFollowersCount, + ShowFollowingCount, + ShowFollowers, + ShowFollowing, +} diff --git a/src/migrations/m20240323_000002_add_simple_credentials.rs b/src/migrations/m20240323_000002_add_simple_credentials.rs new file mode 100644 index 00000000..ea0db292 --- /dev/null +++ b/src/migrations/m20240323_000002_add_simple_credentials.rs @@ -0,0 +1,43 @@ +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(Credentials::Table) + .col( + ColumnDef::new(Credentials::Id) + .string() + .not_null() + .primary_key() + ) + .col(ColumnDef::new(Credentials::Email).boolean().not_null()) + .col(ColumnDef::new(Credentials::Password).boolean().not_null()) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Credentials::Table).to_owned()) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Credentials { + Table, + Id, + Email, + Password, +} diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index 73d074c6..e4964f1c 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -4,6 +4,8 @@ mod m20240316_000001_create_table; mod m20240322_000001_create_relations; mod m20240322_000002_add_likes_shares; mod m20240322_000003_add_indexes; +mod m20240323_000001_add_user_configs; +mod m20240323_000002_add_simple_credentials; pub struct Migrator; @@ -15,6 +17,8 @@ impl MigratorTrait for Migrator { Box::new(m20240322_000001_create_relations::Migration), Box::new(m20240322_000002_add_likes_shares::Migration), Box::new(m20240322_000003_add_indexes::Migration), + Box::new(m20240323_000001_add_user_configs::Migration), + Box::new(m20240323_000002_add_simple_credentials::Migration), ] } } diff --git a/src/model/config.rs b/src/model/config.rs new file mode 100644 index 00000000..c1326457 --- /dev/null +++ b/src/model/config.rs @@ -0,0 +1,31 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "configs")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: String, + pub accept_follow_requests: bool, + pub show_followers_count: bool, + pub show_following_count: bool, + pub show_followers: bool, + pub show_following: bool, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::Id", + to = "super::user::Column::Id" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/model/credential.rs b/src/model/credential.rs new file mode 100644 index 00000000..f3cdc5fc --- /dev/null +++ b/src/model/credential.rs @@ -0,0 +1,28 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "credentials")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: String, + pub email: String, + pub password: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation { + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::Id", + to = "super::user::Column::Id" + )] + User, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::User.def() + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/model/mod.rs b/src/model/mod.rs index 283c5ae3..58943848 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,10 +1,12 @@ -pub mod user; pub mod object; pub mod activity; +pub mod user; +pub mod config; pub mod relation; pub mod share; pub mod like; +pub mod credential; pub mod faker; diff --git a/src/model/user.rs b/src/model/user.rs index ddbe001a..facf70f4 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -49,6 +49,12 @@ pub enum Relation { #[sea_orm(has_many = "super::object::Entity")] Object, + + #[sea_orm(has_one = "super::config::Entity")] + Config, + + #[sea_orm(has_one = "super::credential::Entity")] + Credential, } impl Related for Entity {