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
This commit is contained in:
əlemi 2024-03-23 05:01:45 +01:00
parent b90f7307bc
commit f48509e2d8
Signed by: alemi
GPG key ID: A4895B84D311642C
7 changed files with 164 additions and 1 deletions

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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),
]
}
}

31
src/model/config.rs Normal file
View file

@ -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<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

28
src/model/credential.rs Normal file
View file

@ -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<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -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;

View file

@ -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<super::activity::Entity> for Entity {