chore: likes dont need to record generating activity

This commit is contained in:
əlemi 2024-06-07 23:15:57 +02:00
parent 06fcf09a5f
commit b7a8a6004f
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 54 additions and 16 deletions

View file

@ -7,20 +7,11 @@ pub struct Model {
pub internal: i64, pub internal: i64,
pub actor: i64, pub actor: i64,
pub object: i64, pub object: i64,
pub activity: i64,
pub published: ChronoDateTimeUtc, pub published: ChronoDateTimeUtc,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation { 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( #[sea_orm(
belongs_to = "super::actor::Entity", belongs_to = "super::actor::Entity",
from = "Column::Actor", from = "Column::Actor",
@ -39,12 +30,6 @@ pub enum Relation {
Objects, Objects,
} }
impl Related<super::activity::Entity> for Entity {
fn to() -> RelationDef {
Relation::Activities.def()
}
}
impl Related<super::actor::Entity> for Entity { impl Related<super::actor::Entity> for Entity {
fn to() -> RelationDef { fn to() -> RelationDef {
Relation::Actors.def() Relation::Actors.def()

View file

@ -8,6 +8,7 @@ mod m20240524_000005_create_attachments_tags_mentions;
mod m20240529_000001_add_relation_unique_index; mod m20240529_000001_add_relation_unique_index;
mod m20240605_000001_add_jobs_table; mod m20240605_000001_add_jobs_table;
mod m20240606_000001_add_audience_to_objects; mod m20240606_000001_add_audience_to_objects;
mod m20240607_000001_activity_ref_is_optional;
pub struct Migrator; pub struct Migrator;
@ -23,6 +24,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240529_000001_add_relation_unique_index::Migration), Box::new(m20240529_000001_add_relation_unique_index::Migration),
Box::new(m20240605_000001_add_jobs_table::Migration), Box::new(m20240605_000001_add_jobs_table::Migration),
Box::new(m20240606_000001_add_audience_to_objects::Migration), Box::new(m20240606_000001_add_audience_to_objects::Migration),
Box::new(m20240607_000001_activity_ref_is_optional::Migration),
] ]
} }
} }

View file

@ -19,7 +19,7 @@ pub enum Likes {
Internal, Internal,
Actor, Actor,
Object, Object,
Activity, Activity, // DROPPED
Published, Published,
} }

View file

@ -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(())
}
}