From b7a8a6004f1718e98ad51eb2cbf33cb57f5bb977 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 7 Jun 2024 23:15:57 +0200 Subject: [PATCH] chore: likes dont need to record generating activity --- upub/core/src/model/like.rs | 15 ------ upub/migrations/src/lib.rs | 2 + ...24_000002_create_relations_likes_shares.rs | 2 +- ...0240607_000001_activity_ref_is_optional.rs | 51 +++++++++++++++++++ 4 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 upub/migrations/src/m20240607_000001_activity_ref_is_optional.rs diff --git a/upub/core/src/model/like.rs b/upub/core/src/model/like.rs index c92f2b8d..e8f12336 100644 --- a/upub/core/src/model/like.rs +++ b/upub/core/src/model/like.rs @@ -7,20 +7,11 @@ pub struct Model { pub internal: i64, pub actor: i64, pub object: i64, - pub activity: i64, pub published: ChronoDateTimeUtc, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "super::activity::Entity", - from = "Column::Activity", - to = "super::activity::Column::Internal", - on_update = "Cascade", - on_delete = "Cascade" - )] - Activities, #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Actor", @@ -39,12 +30,6 @@ pub enum Relation { Objects, } -impl Related for Entity { - fn to() -> RelationDef { - Relation::Activities.def() - } -} - impl Related for Entity { fn to() -> RelationDef { Relation::Actors.def() diff --git a/upub/migrations/src/lib.rs b/upub/migrations/src/lib.rs index fe3fc45a..4b3c1016 100644 --- a/upub/migrations/src/lib.rs +++ b/upub/migrations/src/lib.rs @@ -8,6 +8,7 @@ mod m20240524_000005_create_attachments_tags_mentions; mod m20240529_000001_add_relation_unique_index; mod m20240605_000001_add_jobs_table; mod m20240606_000001_add_audience_to_objects; +mod m20240607_000001_activity_ref_is_optional; pub struct Migrator; @@ -23,6 +24,7 @@ impl MigratorTrait for Migrator { Box::new(m20240529_000001_add_relation_unique_index::Migration), Box::new(m20240605_000001_add_jobs_table::Migration), Box::new(m20240606_000001_add_audience_to_objects::Migration), + Box::new(m20240607_000001_activity_ref_is_optional::Migration), ] } } diff --git a/upub/migrations/src/m20240524_000002_create_relations_likes_shares.rs b/upub/migrations/src/m20240524_000002_create_relations_likes_shares.rs index 7c058f85..6c6b058e 100644 --- a/upub/migrations/src/m20240524_000002_create_relations_likes_shares.rs +++ b/upub/migrations/src/m20240524_000002_create_relations_likes_shares.rs @@ -19,7 +19,7 @@ pub enum Likes { Internal, Actor, Object, - Activity, + Activity, // DROPPED Published, } diff --git a/upub/migrations/src/m20240607_000001_activity_ref_is_optional.rs b/upub/migrations/src/m20240607_000001_activity_ref_is_optional.rs new file mode 100644 index 00000000..347a7a27 --- /dev/null +++ b/upub/migrations/src/m20240607_000001_activity_ref_is_optional.rs @@ -0,0 +1,51 @@ +use sea_orm_migration::prelude::*; + +use crate::m20240524_000002_create_relations_likes_shares::{Announces, Likes}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + + manager + .alter_table( + Table::alter() + .table(Likes::Table) + .drop_column(Likes::Activity) + .to_owned() + ) + .await?; + + manager + .create_index( + Index::create() + .name("index-announces-actor-object") + .table(Announces::Table) + .col(Announces::Actor) + .col(Announces::Object) + .to_owned() + ).await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + + manager + .alter_table( + Table::alter() + .table(Likes::Table) + .add_column(ColumnDef::new(Likes::Activity).big_integer().not_null()) + .to_owned() + ) + .await?; + + manager + .drop_index(Index::drop().name("index-announces-actor-object").table(Announces::Table).to_owned()) + .await?; + + Ok(()) + } +}