From 8cb8632521ae64491ff7b8f16e03e6c5160892b0 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 22 Mar 2024 02:29:37 +0100 Subject: [PATCH] feat: added relation table --- src/activitypub/mod.rs | 3 +- .../m20240322_000001_create_relations.rs | 44 +++++++++++++++++++ src/migrations/mod.rs | 4 +- src/model/mod.rs | 2 + src/model/relation.rs | 15 +++++++ 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/migrations/m20240322_000001_create_relations.rs create mode 100644 src/model/relation.rs diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index 438ef785..f89e7171 100644 --- a/src/activitypub/mod.rs +++ b/src/activitypub/mod.rs @@ -7,9 +7,8 @@ pub mod jsonld; pub use jsonld::JsonLD; use axum::{extract::State, http::StatusCode, Json}; -use sea_orm::{EntityTrait, IntoActiveModel}; -use crate::{activitystream::{object::{activity::{Activity, ActivityType}, actor::{ActorMut, ActorType}, ObjectMut, ObjectType}, Base, BaseMut, BaseType, Node}, model, server::Context, url}; +use crate::{activitystream::{object::{actor::{ActorMut, ActorType}, ObjectMut}, BaseMut}, server::Context, url}; use self::jsonld::LD; diff --git a/src/migrations/m20240322_000001_create_relations.rs b/src/migrations/m20240322_000001_create_relations.rs new file mode 100644 index 00000000..00912295 --- /dev/null +++ b/src/migrations/m20240322_000001_create_relations.rs @@ -0,0 +1,44 @@ +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(Relations::Table) + .if_not_exists() + .col( + ColumnDef::new(Relations::Id) + .integer() + .not_null() + .primary_key() + ) + .col(ColumnDef::new(Relations::Follower).string().not_null()) + .col(ColumnDef::new(Relations::Following).string().not_null()) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Relations::Table).to_owned()) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Relations { + Table, + Id, + Follower, + Following, +} diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index 01820ada..ceba0d8d 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -1,6 +1,7 @@ use sea_orm_migration::prelude::*; mod m20240316_000001_create_table; +mod m20240322_000001_create_relations; pub struct Migrator; @@ -8,7 +9,8 @@ pub struct Migrator; impl MigratorTrait for Migrator { fn migrations() -> Vec> { vec![ - Box::new(m20240316_000001_create_table::Migration) + Box::new(m20240316_000001_create_table::Migration), + Box::new(m20240322_000001_create_relations::Migration), ] } } diff --git a/src/model/mod.rs b/src/model/mod.rs index 862e22ec..ceef3316 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1,6 +1,8 @@ pub mod user; pub mod object; pub mod activity; +pub mod relation; + pub mod faker; #[derive(Debug, Clone, thiserror::Error)] diff --git a/src/model/relation.rs b/src/model/relation.rs new file mode 100644 index 00000000..f2c34fa5 --- /dev/null +++ b/src/model/relation.rs @@ -0,0 +1,15 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "relations")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub follower: String, + pub following: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {}