From c97b35a6a70cbec9aebc30cf0d64224509052bfe Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 28 May 2024 01:25:47 +0200 Subject: [PATCH] feat!: also store like activity oops redo all your migrations (: this will be necessary to do undos in the frontend --- ...240524_000002_create_relations_likes_shares.rs | 10 ++++++++++ src/model/like.rs | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/migrations/m20240524_000002_create_relations_likes_shares.rs b/src/migrations/m20240524_000002_create_relations_likes_shares.rs index 36a8bdce..4a139666 100644 --- a/src/migrations/m20240524_000002_create_relations_likes_shares.rs +++ b/src/migrations/m20240524_000002_create_relations_likes_shares.rs @@ -19,6 +19,7 @@ pub enum Likes { Internal, Actor, Object, + Activity, Published, } @@ -130,6 +131,15 @@ impl MigrationTrait for Migration { .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) + .col(ColumnDef::new(Likes::Activity).big_integer().not_null()) + .foreign_key( + ForeignKey::create() + .name("fkey-likes-activity") + .from(Likes::Table, Likes::Activity) + .to(Activities::Table, Activities::Internal) + .on_update(ForeignKeyAction::Cascade) + .on_delete(ForeignKeyAction::Cascade) + ) .col(ColumnDef::new(Likes::Published).date_time().not_null().default(Expr::current_timestamp())) .to_owned() ) diff --git a/src/model/like.rs b/src/model/like.rs index 1ca919fc..004dd4e6 100644 --- a/src/model/like.rs +++ b/src/model/like.rs @@ -7,11 +7,20 @@ 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", @@ -30,6 +39,12 @@ pub enum Relation { Objects, } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Activities.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::Actors.def()