feat: follow rels

This commit is contained in:
April John 2024-07-26 00:25:49 +02:00
parent e8b78e4d8d
commit c2a79b128b
Signed by: aprl
GPG key ID: BCB934A2909C5460
2 changed files with 93 additions and 0 deletions

View file

@ -6,6 +6,7 @@ mod m20240417_233430_post_user_keys;
mod m20240505_002524_user_follow_relation; mod m20240505_002524_user_follow_relation;
mod m20240626_030922_store_ap_json_in_posts; mod m20240626_030922_store_ap_json_in_posts;
mod m20240719_235452_user_ap_column; mod m20240719_235452_user_ap_column;
mod m20240725_120932_follow_table_two_point_zero;
pub struct Migrator; pub struct Migrator;
@ -19,6 +20,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240505_002524_user_follow_relation::Migration), Box::new(m20240505_002524_user_follow_relation::Migration),
Box::new(m20240626_030922_store_ap_json_in_posts::Migration), Box::new(m20240626_030922_store_ap_json_in_posts::Migration),
Box::new(m20240719_235452_user_ap_column::Migration), Box::new(m20240719_235452_user_ap_column::Migration),
Box::new(m20240725_120932_follow_table_two_point_zero::Migration),
] ]
} }
} }

View file

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