diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index 438ef78..f89e717 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 0000000..0091229 --- /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 01820ad..ceba0d8 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 862e22e..ceef331 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 0000000..f2c34fa --- /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 {}