diff --git a/upub/core/src/model/like.rs b/upub/core/src/model/like.rs index c92f2b8..e8f1233 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 fe3fc45..4b3c101 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 7c058f8..6c6b058 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 0000000..347a7a2 --- /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(()) + } +}