From b89bb87c1930e8d664edc6ee90a1989b7c81e4bc Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 29 May 2024 03:44:20 +0200 Subject: [PATCH] feat!: add instance internal id on objects table --- ..._000001_create_actor_activity_object_tables.rs | 9 +++++++++ src/model/instance.rs | 8 ++++++++ src/model/object.rs | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs b/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs index b5721bbd..afb659cb 100644 --- a/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs +++ b/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs @@ -46,6 +46,7 @@ pub enum Objects { Table, Internal, Id, + Instance, ObjectType, AttributedTo, Name, @@ -200,6 +201,14 @@ impl MigrationTrait for Migration { .auto_increment() ) .col(ColumnDef::new(Objects::Id).string().not_null().unique_key()) + .col(ColumnDef::new(Objects::Instance).big_integer().not_null()) + .foreign_key( + ForeignKey::create() + .name("fkey-objects-instances") + .from(Objects::Table, Objects::Instance) + .to(Instances::Table, Instances::Internal) + .on_update(ForeignKeyAction::Cascade) + ) .col(ColumnDef::new(Objects::ObjectType).string().not_null()) .col(ColumnDef::new(Objects::AttributedTo).string().null()) // .foreign_key( diff --git a/src/model/instance.rs b/src/model/instance.rs index 58039e59..b1c02266 100644 --- a/src/model/instance.rs +++ b/src/model/instance.rs @@ -27,6 +27,8 @@ pub enum Relation { Actors, #[sea_orm(has_many = "super::addressing::Entity")] Addressing, + #[sea_orm(has_many = "super::object::Entity")] + Objects, } impl Related for Entity { @@ -41,6 +43,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Objects.def() + } +} + impl ActiveModelBehavior for ActiveModel {} impl Entity { diff --git a/src/model/object.rs b/src/model/object.rs index 2abea5d8..c2f85e26 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -12,6 +12,7 @@ pub struct Model { pub internal: i64, #[sea_orm(unique)] pub id: String, + pub instance: i64, pub object_type: ObjectType, pub attributed_to: Option, pub name: Option, @@ -52,6 +53,14 @@ pub enum Relation { Attachments, #[sea_orm(has_many = "super::hashtag::Entity")] Hashtags, + #[sea_orm( + belongs_to = "super::instance::Entity", + from = "Column::Instance", + to = "super::instance::Column::Internal", + on_update = "Cascade", + on_delete = "NoAction" + )] + Instances, #[sea_orm(has_many = "super::like::Entity")] Likes, #[sea_orm(has_many = "super::mention::Entity")] @@ -102,6 +111,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Instances.def() + } +} + impl Related for Entity { fn to() -> RelationDef { Relation::Likes.def()