From c2a79b128bf5aa4c9ac7d584a3b3c846b7f55239 Mon Sep 17 00:00:00 2001 From: April John Date: Fri, 26 Jul 2024 00:25:49 +0200 Subject: [PATCH] feat: follow rels --- migration/src/lib.rs | 2 + ...0725_120932_follow_table_two_point_zero.rs | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 migration/src/m20240725_120932_follow_table_two_point_zero.rs diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 7e79646..6dfdb68 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -6,6 +6,7 @@ mod m20240417_233430_post_user_keys; mod m20240505_002524_user_follow_relation; mod m20240626_030922_store_ap_json_in_posts; mod m20240719_235452_user_ap_column; +mod m20240725_120932_follow_table_two_point_zero; pub struct Migrator; @@ -19,6 +20,7 @@ impl MigratorTrait for Migrator { Box::new(m20240505_002524_user_follow_relation::Migration), Box::new(m20240626_030922_store_ap_json_in_posts::Migration), Box::new(m20240719_235452_user_ap_column::Migration), + Box::new(m20240725_120932_follow_table_two_point_zero::Migration), ] } } diff --git a/migration/src/m20240725_120932_follow_table_two_point_zero.rs b/migration/src/m20240725_120932_follow_table_two_point_zero.rs new file mode 100644 index 0000000..8c9f25f --- /dev/null +++ b/migration/src/m20240725_120932_follow_table_two_point_zero.rs @@ -0,0 +1,91 @@ +use sea_orm_migration::prelude::*; + +use crate::m20240417_230111_user_table::User; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let _ = manager + .drop_table(Table::drop().table(FollowRelation::Table).to_owned()) + .await; + manager + .create_table( + Table::create() + .table(FollowRelation::Table) + .if_not_exists() + .col( + ColumnDef::new(FollowRelation::Id) + .string() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(FollowRelation::FolloweeId) + .string() + .not_null(), + ) + .col( + ColumnDef::new(FollowRelation::FollowerId) + .string() + .not_null(), + ) + .col(ColumnDef::new(FollowRelation::FolloweeHost).string()) + .col(ColumnDef::new(FollowRelation::FollowerHost).string()) + .col(ColumnDef::new(FollowRelation::FolloweeInbox).string()) + .col(ColumnDef::new(FollowRelation::FollowerInbox).string()) + .col(ColumnDef::new(FollowRelation::AcceptId).string()) + .col(ColumnDef::new(FollowRelation::ApId).string()) + .col(ColumnDef::new(FollowRelation::ApAcceptId).string()) + .col(ColumnDef::new(FollowRelation::Remote).boolean().not_null()) + .col(ColumnDef::new(FollowRelation::ApJson).string().not_null()) + .col( + ColumnDef::new(FollowRelation::ApAcceptJson) + .string() + .not_null(), + ) + .foreign_key( + ForeignKey::create() + .name("fk_follow_relation_followee_id") + .from(FollowRelation::Table, FollowRelation::FolloweeId) + .to(User::Table, User::Id) + .on_delete(ForeignKeyAction::Cascade), + ) + .foreign_key( + ForeignKey::create() + .name("fk_follow_relation_follower_id") + .from(FollowRelation::Table, FollowRelation::FollowerId) + .to(User::Table, User::Id) + .on_delete(ForeignKeyAction::Cascade), + ) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(FollowRelation::Table).to_owned()) + .await + } +} + +#[derive(DeriveIden)] +enum FollowRelation { + Table, + Id, + AcceptId, + Remote, // true if initial Follow came from Remote + ApId, + ApAcceptId, + FolloweeId, + FollowerId, + FolloweeHost, + FollowerHost, + FolloweeInbox, + FollowerInbox, + ApJson, + ApAcceptJson, +}