From 94ec7d0d375878d986b2d72c6d30d5c70c9775a8 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 25 May 2024 04:37:17 +0200 Subject: [PATCH] chore: better id, mix strings and numbers in joins "hot" joins will use internal ids (relations, like/share, addressing) while "slow" relations will use full ap ids (attributed to, context, user configs) --- ...001_create_actor_activity_object_tables.rs | 123 ++++++++++-------- ...24_000002_create_relations_likes_shares.rs | 78 +++++------ ...524_000003_create_users_auth_and_config.rs | 30 +++-- ...524_000004_create_addressing_deliveries.rs | 32 ++--- ...000005_create_attachments_tags_mentions.rs | 50 +++---- src/model/activity.rs | 8 +- src/model/actor.rs | 10 +- src/model/addressing.rs | 18 +-- src/model/announce.rs | 12 +- src/model/attachment.rs | 6 +- src/model/config.rs | 7 +- src/model/credential.rs | 5 +- src/model/delivery.rs | 6 +- src/model/hashtag.rs | 6 +- src/model/instance.rs | 6 +- src/model/like.rs | 12 +- src/model/mention.rs | 8 +- src/model/object.rs | 20 ++- src/model/relation.rs | 26 ++-- src/model/session.rs | 4 +- 20 files changed, 249 insertions(+), 218 deletions(-) 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 7b2a7914..7c3439f4 100644 --- a/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs +++ b/src/migrations/m20240524_000001_create_actor_activity_object_tables.rs @@ -2,9 +2,9 @@ use sea_orm_migration::prelude::*; #[derive(DeriveIden)] pub enum Actors { Table, + Internal, Id, - ApId, - Instance, + Domain, ActorType, Name, Summary, @@ -28,8 +28,8 @@ pub enum Actors { #[derive(DeriveIden)] pub enum Activities { Table, + Internal, Id, - ApId, ActivityType, Actor, Object, @@ -44,8 +44,8 @@ pub enum Activities { #[derive(DeriveIden)] pub enum Objects { Table, + Internal, Id, - ApId, ObjectType, AttributedTo, Name, @@ -69,11 +69,12 @@ pub enum Objects { #[derive(DeriveIden)] pub enum Instances { Table, - Id, - Name, + Internal, Domain, + Name, Software, Version, + Icon, DownSince, Users, Posts, @@ -95,16 +96,17 @@ impl MigrationTrait for Migration { .table(Instances::Table) .comment("known other instances in the fediverse") .col( - ColumnDef::new(Instances::Id) - .integer() + ColumnDef::new(Instances::Internal) + .big_integer() .not_null() .auto_increment() .primary_key() ) + .col(ColumnDef::new(Instances::Domain).string().not_null().unique_key()) .col(ColumnDef::new(Instances::Name).string().null()) - .col(ColumnDef::new(Instances::Domain).string().not_null()) .col(ColumnDef::new(Instances::Software).string().null()) .col(ColumnDef::new(Instances::Version).string().null()) + .col(ColumnDef::new(Instances::Icon).string().null()) .col(ColumnDef::new(Instances::DownSince).date_time().null()) .col(ColumnDef::new(Instances::Users).integer().null()) .col(ColumnDef::new(Instances::Posts).integer().null()) @@ -115,7 +117,7 @@ impl MigrationTrait for Migration { .await?; manager - .create_index(Index::create().name("index-instances-domain").table(Instances::Table).col(Instances::Domain).to_owned()) + .create_index(Index::create().unique().name("index-instances-domain").table(Instances::Table).col(Instances::Domain).to_owned()) .await?; @@ -126,22 +128,22 @@ impl MigrationTrait for Migration { .table(Actors::Table) .comment("main actors table, with users and applications") .col( - ColumnDef::new(Actors::Id) - .integer() + ColumnDef::new(Actors::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Actors::ApId).string().not_null().unique_key()) + .col(ColumnDef::new(Actors::Id).string().not_null().unique_key()) .col(ColumnDef::new(Actors::ActorType).string().not_null()) - .col(ColumnDef::new(Actors::Instance).integer().not_null()) - .foreign_key( - ForeignKey::create() - .name("fkey-actors-instances") - .from(Actors::Table, Actors::Instance) - .to(Instances::Table, Instances::Id) - .on_update(ForeignKeyAction::Cascade) - ) + .col(ColumnDef::new(Actors::Domain).string().not_null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-actors-instances") + // .from(Actors::Table, Actors::Domain) + // .to(Instances::Table, Instances::Domain) + // .on_update(ForeignKeyAction::Cascade) + // ) .col(ColumnDef::new(Actors::Name).string().null()) .col(ColumnDef::new(Actors::Summary).string().null()) .col(ColumnDef::new(Actors::Image).string().null()) @@ -164,7 +166,7 @@ impl MigrationTrait for Migration { .await?; manager - .create_index(Index::create().unique().name("index-actors-ap-id").table(Actors::Table).col(Actors::ApId).to_owned()) + .create_index(Index::create().unique().name("index-actors-id").table(Actors::Table).col(Actors::Id).to_owned()) .await?; manager @@ -183,27 +185,34 @@ impl MigrationTrait for Migration { .table(Objects::Table) .comment("objects are all AP documents which are neither actors nor activities") .col( - ColumnDef::new(Objects::Id) - .integer() + ColumnDef::new(Objects::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Objects::ApId).string().not_null().unique_key()) + .col(ColumnDef::new(Objects::Id).string().not_null().unique_key()) .col(ColumnDef::new(Objects::ObjectType).string().not_null()) - .col(ColumnDef::new(Objects::AttributedTo).integer().null()) - .foreign_key( - ForeignKey::create() - .name("fkey-objects-attributed-to") - .from(Objects::Table, Objects::AttributedTo) - .to(Actors::Table, Actors::Id) - .on_update(ForeignKeyAction::Cascade) - ) + .col(ColumnDef::new(Objects::AttributedTo).string().null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-objects-attributed-to") + // .from(Objects::Table, Objects::AttributedTo) + // .to(Actors::Table, Actors::Internal) + // .on_update(ForeignKeyAction::Cascade) + // ) .col(ColumnDef::new(Objects::Name).string().null()) .col(ColumnDef::new(Objects::Summary).string().null()) .col(ColumnDef::new(Objects::Content).string().null()) .col(ColumnDef::new(Objects::Sensitive).boolean().not_null().default(false)) .col(ColumnDef::new(Objects::InReplyTo).string().null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-objects-in-reply-to") + // .from(Objects::Table, Objects::InReplyTo) + // .to(Objects::Table, Objects::Id) + // .on_update(ForeignKeyAction::Cascade) + // ) .col(ColumnDef::new(Objects::Url).string().null()) .col(ColumnDef::new(Objects::Likes).integer().not_null().default(0)) .col(ColumnDef::new(Objects::Announces).integer().not_null().default(0)) @@ -219,7 +228,7 @@ impl MigrationTrait for Migration { ).await?; manager - .create_index(Index::create().unique().name("index-objects-ap-id").table(Objects::Table).col(Objects::ApId).to_owned()) + .create_index(Index::create().unique().name("index-objects-id").table(Objects::Table).col(Objects::Id).to_owned()) .await?; manager @@ -246,30 +255,30 @@ impl MigrationTrait for Migration { .table(Activities::Table) .comment("all activities this instance ever received or generated") .col( - ColumnDef::new(Activities::Id) - .integer() + ColumnDef::new(Activities::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Activities::ApId).string().not_null().unique_key()) + .col(ColumnDef::new(Activities::Id).string().not_null().unique_key()) .col(ColumnDef::new(Activities::ActivityType).string().not_null()) - .col(ColumnDef::new(Activities::Actor).integer().not_null()) - .foreign_key( - ForeignKey::create() - .name("fkey-activities-actors") - .from(Activities::Table, Activities::Actor) - .to(Actors::Table, Actors::Id) - .on_update(ForeignKeyAction::Cascade) - ) - .col(ColumnDef::new(Activities::Object).integer().null()) - .foreign_key( - ForeignKey::create() - .name("fkey-activities-objects") - .from(Activities::Table, Activities::Object) - .to(Objects::Table, Objects::Id) - .on_update(ForeignKeyAction::Cascade) - ) + .col(ColumnDef::new(Activities::Actor).string().not_null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-activities-actors") + // .from(Activities::Table, Activities::Actor) + // .to(Actors::Table, Actors::Id) + // .on_update(ForeignKeyAction::Cascade) + // ) + .col(ColumnDef::new(Activities::Object).string().null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-activities-objects") + // .from(Activities::Table, Activities::Object) + // .to(Objects::Table, Objects::Internal) + // .on_update(ForeignKeyAction::Cascade) + // ) .col(ColumnDef::new(Activities::Target).string().null()) .col(ColumnDef::new(Activities::To).json().null()) .col(ColumnDef::new(Activities::Bto).json().null()) @@ -280,7 +289,7 @@ impl MigrationTrait for Migration { ).await?; manager - .create_index(Index::create().unique().name("index-activities-ap-id").table(Activities::Table).col(Activities::ApId).to_owned()) + .create_index(Index::create().unique().name("index-activities-id").table(Activities::Table).col(Activities::Id).to_owned()) .await?; manager @@ -304,7 +313,7 @@ impl MigrationTrait for Migration { .await?; manager - .drop_index(Index::drop().name("index-actors-ap-id").table(Actors::Table).to_owned()) + .drop_index(Index::drop().name("index-actors-id").table(Actors::Table).to_owned()) .await?; manager @@ -321,7 +330,7 @@ impl MigrationTrait for Migration { .await?; manager - .drop_index(Index::drop().name("index-activities-ap-id").table(Activities::Table).to_owned()) + .drop_index(Index::drop().name("index-activities-id").table(Activities::Table).to_owned()) .await?; manager @@ -342,7 +351,7 @@ impl MigrationTrait for Migration { .await?; manager - .drop_index(Index::drop().name("index-objects-ap-id").table(Objects::Table).to_owned()) + .drop_index(Index::drop().name("index-objects-id").table(Objects::Table).to_owned()) .await?; manager diff --git a/src/migrations/m20240524_000002_create_relations_likes_shares.rs b/src/migrations/m20240524_000002_create_relations_likes_shares.rs index 1893ba95..cceddd99 100644 --- a/src/migrations/m20240524_000002_create_relations_likes_shares.rs +++ b/src/migrations/m20240524_000002_create_relations_likes_shares.rs @@ -5,7 +5,7 @@ use super::m20240524_000001_create_actor_activity_object_tables::{Activities, Ac #[derive(DeriveIden)] pub enum Relations { Table, - Id, + Internal, Follower, Following, Activity, @@ -16,9 +16,9 @@ pub enum Relations { #[allow(clippy::enum_variant_names)] pub enum Likes { Table, - Id, + Internal, Actor, - Likes, + Object, Published, } @@ -26,9 +26,9 @@ pub enum Likes { #[allow(clippy::enum_variant_names)] pub enum Announces { Table, - Id, + Internal, Actor, - Announces, + Object, Published, } @@ -44,44 +44,44 @@ impl MigrationTrait for Migration { .table(Relations::Table) .comment("follow relations between actors (applications too! for relays)") .col( - ColumnDef::new(Relations::Id) - .integer() + ColumnDef::new(Relations::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Relations::Follower).integer().not_null()) + .col(ColumnDef::new(Relations::Follower).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-relations-follower") .from(Relations::Table, Relations::Follower) - .to(Actors::Table, Actors::Id) + .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Relations::Following).integer().not_null()) + .col(ColumnDef::new(Relations::Following).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-relations-following") .from(Relations::Table, Relations::Following) - .to(Actors::Table, Actors::Id) + .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Relations::Accept).integer().null()) + .col(ColumnDef::new(Relations::Accept).big_integer().null()) .foreign_key( ForeignKey::create() .name("fkey-relations-accept") .from(Relations::Table, Relations::Accept) - .to(Activities::Table, Activities::Id) + .to(Activities::Table, Activities::Internal) .on_update(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Relations::Activity).integer().not_null()) + .col(ColumnDef::new(Relations::Activity).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-relations-activity") .from(Relations::Table, Relations::Activity) - .to(Activities::Table, Activities::Id) + .to(Activities::Table, Activities::Internal) .on_update(ForeignKeyAction::Cascade) ) .to_owned() @@ -102,27 +102,27 @@ impl MigrationTrait for Migration { .table(Likes::Table) .comment("all like events, joining actor to object") .col( - ColumnDef::new(Likes::Id) - .integer() + ColumnDef::new(Likes::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Likes::Actor).integer().not_null()) + .col(ColumnDef::new(Likes::Actor).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-likes-actor") .from(Likes::Table, Likes::Actor) - .to(Actors::Table, Actors::Id) + .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Likes::Likes).integer().not_null()) + .col(ColumnDef::new(Likes::Object).big_integer().not_null()) .foreign_key( ForeignKey::create() - .name("fkey-likes-likes") - .from(Likes::Table, Likes::Likes) - .to(Objects::Table, Objects::Id) + .name("fkey-likes-object") + .from(Likes::Table, Likes::Object) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) @@ -136,17 +136,17 @@ impl MigrationTrait for Migration { .await?; manager - .create_index(Index::create().name("index-likes-likes").table(Likes::Table).col(Likes::Likes).to_owned()) + .create_index(Index::create().name("index-likes-object").table(Likes::Table).col(Likes::Likes).to_owned()) .await?; manager .create_index( Index::create() .unique() - .name("index-likes-actor-likes") + .name("index-likes-actor-object") .table(Likes::Table) .col(Likes::Actor) - .col(Likes::Likes) + .col(Likes::Object) .to_owned() ).await?; @@ -156,27 +156,27 @@ impl MigrationTrait for Migration { .table(Announces::Table) .comment("all share/boost/reblog events, joining actor to object") .col( - ColumnDef::new(Announces::Id) - .integer() + ColumnDef::new(Announces::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Announces::Actor).integer().not_null()) + .col(ColumnDef::new(Announces::Actor).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-announces-actor") .from(Announces::Table, Announces::Actor) - .to(Actors::Table, Actors::Id) + .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Announces::Announces).integer().not_null()) + .col(ColumnDef::new(Announces::Object).big_integer().not_null()) .foreign_key( ForeignKey::create() - .name("fkey-announces-announces") - .from(Announces::Table, Announces::Announces) - .to(Objects::Table, Objects::Id) + .name("fkey-announces-object") + .from(Announces::Table, Announces::Object) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) @@ -190,7 +190,7 @@ impl MigrationTrait for Migration { .await?; manager - .create_index(Index::create().name("index-announces-announces").table(Announces::Table).col(Announces::Announces).to_owned()) + .create_index(Index::create().name("index-announces-object").table(Announces::Table).col(Announces::Announces).to_owned()) .await?; Ok(()) @@ -217,10 +217,10 @@ impl MigrationTrait for Migration { .drop_index(Index::drop().name("index-likes-actor").table(Likes::Table).to_owned()) .await?; manager - .drop_index(Index::drop().name("index-likes-likes").table(Likes::Table).to_owned()) + .drop_index(Index::drop().name("index-likes-object").table(Likes::Table).to_owned()) .await?; manager - .drop_index(Index::drop().name("index-likes-actor-likes").table(Likes::Table).to_owned()) + .drop_index(Index::drop().name("index-likes-actor-object").table(Likes::Table).to_owned()) .await?; manager @@ -228,10 +228,10 @@ impl MigrationTrait for Migration { .await?; manager - .drop_index(Index::drop().name("shares-actor-index").table(Announces::Table).to_owned()) + .drop_index(Index::drop().name("index-announces-actor").table(Announces::Table).to_owned()) .await?; manager - .drop_index(Index::drop().name("shares-shares-index").table(Announces::Table).to_owned()) + .drop_index(Index::drop().name("index-announces-object").table(Announces::Table).to_owned()) .await?; Ok(()) diff --git a/src/migrations/m20240524_000003_create_users_auth_and_config.rs b/src/migrations/m20240524_000003_create_users_auth_and_config.rs index bd83a335..aeb48347 100644 --- a/src/migrations/m20240524_000003_create_users_auth_and_config.rs +++ b/src/migrations/m20240524_000003_create_users_auth_and_config.rs @@ -5,7 +5,7 @@ use super::m20240524_000001_create_actor_activity_object_tables::Actors; #[derive(DeriveIden)] pub enum Configs { Table, - Id, + Internal, Actor, AcceptFollowRequests, ShowFollowersCount, @@ -17,7 +17,7 @@ pub enum Configs { #[derive(DeriveIden)] pub enum Credentials { Table, - Id, + Internal, Actor, Login, Password, @@ -26,7 +26,7 @@ pub enum Credentials { #[derive(DeriveIden)] pub enum Sessions { Table, - Id, + Internal, Actor, Secret, Expires, @@ -44,13 +44,13 @@ impl MigrationTrait for Migration { .table(Configs::Table) .comment("configuration for each local user") .col( - ColumnDef::new(Configs::Id) - .integer() + ColumnDef::new(Configs::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Configs::Actor).integer().not_null()) + .col(ColumnDef::new(Configs::Actor).string().not_null().unique_key()) .foreign_key( ForeignKey::create() .name("fkey-config-actor") @@ -69,7 +69,7 @@ impl MigrationTrait for Migration { .await?; manager - .create_index(Index::create().name("index-configs-actor").table(Configs::Table).col(Configs::Actor).to_owned()) + .create_index(Index::create().unique().name("index-configs-actor").table(Configs::Table).col(Configs::Actor).to_owned()) .await?; manager @@ -78,13 +78,13 @@ impl MigrationTrait for Migration { .table(Credentials::Table) .comment("simple login credentials to authenticate local users") .col( - ColumnDef::new(Credentials::Id) - .integer() + ColumnDef::new(Credentials::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Credentials::Actor).integer().not_null()) + .col(ColumnDef::new(Credentials::Actor).string().not_null().unique_key()) .foreign_key( ForeignKey::create() .name("fkey-credentials-actor") @@ -99,6 +99,10 @@ impl MigrationTrait for Migration { ) .await?; + manager + .create_index(Index::create().unique().name("index-credentials-actor").table(Credentials::Table).col(Credentials::Actor).to_owned()) + .await?; + manager .create_index(Index::create().name("index-credentials-login").table(Credentials::Table).col(Credentials::Login).to_owned()) .await?; @@ -109,13 +113,13 @@ impl MigrationTrait for Migration { .table(Sessions::Table) .comment("authenticated sessions from local users") .col( - ColumnDef::new(Sessions::Id) - .integer() + ColumnDef::new(Sessions::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Sessions::Actor).integer().not_null()) + .col(ColumnDef::new(Sessions::Actor).string().not_null()) .foreign_key( ForeignKey::create() .name("fkey-sessions-actor") diff --git a/src/migrations/m20240524_000004_create_addressing_deliveries.rs b/src/migrations/m20240524_000004_create_addressing_deliveries.rs index 6d7e3309..2c824612 100644 --- a/src/migrations/m20240524_000004_create_addressing_deliveries.rs +++ b/src/migrations/m20240524_000004_create_addressing_deliveries.rs @@ -5,7 +5,7 @@ use super::m20240524_000001_create_actor_activity_object_tables::{Activities, Ac #[derive(DeriveIden)] pub enum Addressing { Table, - Id, + Internal, Actor, Instance, Activity, @@ -16,7 +16,7 @@ pub enum Addressing { #[derive(DeriveIden)] pub enum Deliveries { Table, - Id, + Internal, Actor, Target, Activity, @@ -37,42 +37,42 @@ impl MigrationTrait for Migration { .table(Addressing::Table) .comment("this join table contains all addressing relations, serving effectively as permissions truth table") .col( - ColumnDef::new(Addressing::Id) - .integer() + ColumnDef::new(Addressing::Internal) + .big_integer() .not_null() .auto_increment() .primary_key() ) - .col(ColumnDef::new(Addressing::Actor).integer().not_null()) + .col(ColumnDef::new(Addressing::Actor).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-addressing-actor") .from(Addressing::Table, Addressing::Actor) - .to(Actors::Table, Actors::Id) + .to(Actors::Table, Actors::Internal) .on_update(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Addressing::Instance).integer().not_null()) + .col(ColumnDef::new(Addressing::Instance).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-addressing-instance") .from(Addressing::Table, Addressing::Instance) - .to(Instances::Table, Instances::Id) + .to(Instances::Table, Instances::Internal) .on_update(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Addressing::Activity).integer().null()) + .col(ColumnDef::new(Addressing::Activity).big_integer().null()) .foreign_key( ForeignKey::create() .name("fkey-addressing-activity") .from(Addressing::Table, Addressing::Activity) - .to(Activities::Table, Activities::Id) + .to(Activities::Table, Activities::Internal) .on_update(ForeignKeyAction::Cascade) ) - .col(ColumnDef::new(Addressing::Object).integer().null()) + .col(ColumnDef::new(Addressing::Object).big_integer().null()) .foreign_key( ForeignKey::create() .name("fkey-addressing-object") .from(Addressing::Table, Addressing::Object) - .to(Objects::Table, Objects::Id) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) ) .col(ColumnDef::new(Addressing::Published).date_time().not_null().default(Expr::current_timestamp())) @@ -116,13 +116,13 @@ impl MigrationTrait for Migration { .table(Deliveries::Table) .comment("this table contains all enqueued outgoing delivery jobs") .col( - ColumnDef::new(Deliveries::Id) - .integer() + ColumnDef::new(Deliveries::Internal) + .big_integer() .not_null() .auto_increment() .primary_key() ) - .col(ColumnDef::new(Deliveries::Actor).integer().not_null()) + .col(ColumnDef::new(Deliveries::Actor).string().not_null()) .foreign_key( ForeignKey::create() .name("fkey-deliveries-actor") @@ -132,7 +132,7 @@ impl MigrationTrait for Migration { .on_delete(ForeignKeyAction::Cascade) ) .col(ColumnDef::new(Deliveries::Target).string().not_null()) - .col(ColumnDef::new(Deliveries::Activity).integer().not_null()) + .col(ColumnDef::new(Deliveries::Activity).string().not_null()) .foreign_key( ForeignKey::create() .name("fkey-deliveries-activity") diff --git a/src/migrations/m20240524_000005_create_attachments_tags_mentions.rs b/src/migrations/m20240524_000005_create_attachments_tags_mentions.rs index 1e6ed270..bf0c2c5e 100644 --- a/src/migrations/m20240524_000005_create_attachments_tags_mentions.rs +++ b/src/migrations/m20240524_000005_create_attachments_tags_mentions.rs @@ -1,11 +1,11 @@ use sea_orm_migration::prelude::*; -use super::m20240524_000001_create_actor_activity_object_tables::{Actors, Objects}; +use super::m20240524_000001_create_actor_activity_object_tables::Objects; #[derive(DeriveIden)] pub enum Attachments { Table, - Id, + Internal, DocumentType, Url, Object, @@ -17,7 +17,7 @@ pub enum Attachments { #[derive(DeriveIden)] pub enum Mentions { Table, - Id, + Internal, Object, Actor, Published, @@ -26,7 +26,7 @@ pub enum Mentions { #[derive(DeriveIden)] pub enum Hashtags { Table, - Id, + Internal, Object, Name, Published, @@ -44,19 +44,19 @@ impl MigrationTrait for Migration { .table(Attachments::Table) .comment("media attachments related to objects") .col( - ColumnDef::new(Attachments::Id) - .integer() + ColumnDef::new(Attachments::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) .col(ColumnDef::new(Attachments::Url).string().not_null().unique_key()) - .col(ColumnDef::new(Attachments::Object).integer().not_null()) + .col(ColumnDef::new(Attachments::Object).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-attachments-object") .from(Attachments::Table, Attachments::Object) - .to(Objects::Table, Objects::Id) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) @@ -78,30 +78,30 @@ impl MigrationTrait for Migration { .table(Mentions::Table) .comment("join table relating posts to mentioned users") .col( - ColumnDef::new(Mentions::Id) - .integer() + ColumnDef::new(Mentions::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Mentions::Object).integer().not_null()) + .col(ColumnDef::new(Mentions::Object).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-mentions-object") .from(Mentions::Table, Mentions::Object) - .to(Objects::Table, Objects::Id) - .on_update(ForeignKeyAction::Cascade) - .on_delete(ForeignKeyAction::Cascade) - ) - .col(ColumnDef::new(Mentions::Actor).integer().not_null()) - .foreign_key( - ForeignKey::create() - .name("fkey-mentions-actor") - .from(Mentions::Table, Mentions::Actor) - .to(Actors::Table, Actors::Id) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) + .col(ColumnDef::new(Mentions::Actor).string().not_null()) + // .foreign_key( + // ForeignKey::create() + // .name("fkey-mentions-actor") + // .from(Mentions::Table, Mentions::Actor) + // .to(Actors::Table, Actors::Internal) + // .on_update(ForeignKeyAction::Cascade) + // .on_delete(ForeignKeyAction::Cascade) + // ) .col(ColumnDef::new(Mentions::Published).date_time().not_null().default(Expr::current_timestamp())) .to_owned() ) @@ -128,18 +128,18 @@ impl MigrationTrait for Migration { .table(Hashtags::Table) .comment("join table relating posts to hashtags") .col( - ColumnDef::new(Hashtags::Id) - .integer() + ColumnDef::new(Hashtags::Internal) + .big_integer() .not_null() .primary_key() .auto_increment() ) - .col(ColumnDef::new(Hashtags::Object).integer().not_null()) + .col(ColumnDef::new(Hashtags::Object).big_integer().not_null()) .foreign_key( ForeignKey::create() .name("fkey-hashtags-object") .from(Hashtags::Table, Hashtags::Object) - .to(Objects::Table, Objects::Id) + .to(Objects::Table, Objects::Internal) .on_update(ForeignKeyAction::Cascade) .on_delete(ForeignKeyAction::Cascade) ) diff --git a/src/model/activity.rs b/src/model/activity.rs index 351d2f47..df312cd5 100644 --- a/src/model/activity.rs +++ b/src/model/activity.rs @@ -7,12 +7,12 @@ use crate::routes::activitypub::jsonld::LD; #[sea_orm(table_name = "activities")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, + pub internal: i64, #[sea_orm(unique)] - pub ap_id: String, + pub id: String, pub activity_type: ActivityType, - pub actor: i32, - pub object: Option, + pub actor: String, + pub object: Option, pub target: Option, pub to: Option, pub bto: Option, diff --git a/src/model/actor.rs b/src/model/actor.rs index 66de0a1c..32233dca 100644 --- a/src/model/actor.rs +++ b/src/model/actor.rs @@ -8,11 +8,11 @@ use crate::routes::activitypub::jsonld::LD; #[sea_orm(table_name = "actors")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, + pub internal: i64, #[sea_orm(unique)] - pub ap_id: String, + pub id: String, pub actor_type: ActorType, - pub instance: i32, + pub domain: String, pub name: Option, pub summary: Option, pub image: Option, @@ -49,8 +49,8 @@ pub enum Relation { Deliveries, #[sea_orm( belongs_to = "super::instance::Entity", - from = "Column::Instance", - to = "super::instance::Column::Id", + from = "Column::Domain", + to = "super::instance::Column::Domain", on_update = "Cascade", on_delete = "NoAction" )] diff --git a/src/model/addressing.rs b/src/model/addressing.rs index 1e308d4e..26175bea 100644 --- a/src/model/addressing.rs +++ b/src/model/addressing.rs @@ -7,11 +7,11 @@ use crate::routes::activitypub::jsonld::LD; #[sea_orm(table_name = "addressing")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, - pub instance: i32, - pub activity: Option, - pub object: Option, + pub internal: i64, + pub actor: Option, + pub instance: Option, + pub activity: Option, + pub object: Option, pub published: ChronoDateTimeUtc, } @@ -20,7 +20,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::activity::Entity", from = "Column::Activity", - to = "super::activity::Column::Id", + to = "super::activity::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] @@ -28,7 +28,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Actor", - to = "super::actor::Column::Id", + to = "super::actor::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] @@ -36,7 +36,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::instance::Entity", from = "Column::Instance", - to = "super::instance::Column::Id", + to = "super::instance::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] @@ -44,7 +44,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::object::Entity", from = "Column::Object", - to = "super::object::Column::Id", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] diff --git a/src/model/announce.rs b/src/model/announce.rs index fc7a4044..5a800b41 100644 --- a/src/model/announce.rs +++ b/src/model/announce.rs @@ -4,9 +4,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "announces")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, - pub announces: i32, + pub internal: i64, + pub actor: i64, + pub object: i64, pub published: ChronoDateTimeUtc, } @@ -15,15 +15,15 @@ pub enum Relation { #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Actor", - to = "super::actor::Column::Id", + to = "super::actor::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] Actors, #[sea_orm( belongs_to = "super::object::Entity", - from = "Column::Announces", - to = "super::object::Column::Id", + from = "Column::Object", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] diff --git a/src/model/attachment.rs b/src/model/attachment.rs index c7c8914a..30930f4e 100644 --- a/src/model/attachment.rs +++ b/src/model/attachment.rs @@ -9,10 +9,10 @@ use super::addressing::Event; #[sea_orm(table_name = "attachments")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, + pub internal: i64, #[sea_orm(unique)] pub url: String, - pub object: i32, + pub object: i64, pub document_type: String, pub name: Option, pub media_type: String, @@ -24,7 +24,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::object::Entity", from = "Column::Object", - to = "super::object::Column::Id", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] diff --git a/src/model/config.rs b/src/model/config.rs index f95bf43f..5335dec3 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -4,8 +4,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "configs")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, + pub internal: i64, + #[sea_orm(unique)] + pub actor: String, pub accept_follow_requests: bool, pub show_followers_count: bool, pub show_following_count: bool, @@ -16,7 +17,7 @@ pub struct Model { impl Default for Model { fn default() -> Self { Model { - id: 0, actor: 0, + internal: 0, actor: "".into(), accept_follow_requests: true, show_following_count: true, show_following: true, diff --git a/src/model/credential.rs b/src/model/credential.rs index 5255ead5..be2d2c69 100644 --- a/src/model/credential.rs +++ b/src/model/credential.rs @@ -4,8 +4,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "credentials")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, + pub internal: i64, + #[sea_orm(unique)] + pub actor: String, pub login: String, pub password: String, } diff --git a/src/model/delivery.rs b/src/model/delivery.rs index 6835f4dd..eac7aa00 100644 --- a/src/model/delivery.rs +++ b/src/model/delivery.rs @@ -4,10 +4,10 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "deliveries")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, + pub internal: i64, + pub actor: String, pub target: String, - pub activity: i32, + pub activity: String, pub created: ChronoDateTimeUtc, pub not_before: ChronoDateTimeUtc, pub attempt: i32, diff --git a/src/model/hashtag.rs b/src/model/hashtag.rs index d17b1d3c..bcd603ba 100644 --- a/src/model/hashtag.rs +++ b/src/model/hashtag.rs @@ -4,8 +4,8 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "hashtags")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub object: i32, + pub internal: i64, + pub object: i64, pub name: String, pub published: ChronoDateTimeUtc, } @@ -15,7 +15,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::object::Entity", from = "Column::Object", - to = "super::object::Column::Id", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] diff --git a/src/model/instance.rs b/src/model/instance.rs index 125fc1f1..fe63ac40 100644 --- a/src/model/instance.rs +++ b/src/model/instance.rs @@ -4,11 +4,13 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "instances")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub name: Option, + pub internal: i64, + #[sea_orm(unique)] pub domain: String, + pub name: Option, pub software: Option, pub version: Option, + pub icon: Option, pub down_since: Option, pub users: Option, pub posts: Option, diff --git a/src/model/like.rs b/src/model/like.rs index 66456fcd..1ca919fc 100644 --- a/src/model/like.rs +++ b/src/model/like.rs @@ -4,9 +4,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "likes")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, - pub likes: i32, + pub internal: i64, + pub actor: i64, + pub object: i64, pub published: ChronoDateTimeUtc, } @@ -15,15 +15,15 @@ pub enum Relation { #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Actor", - to = "super::actor::Column::Id", + to = "super::actor::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] Actors, #[sea_orm( belongs_to = "super::object::Entity", - from = "Column::Likes", - to = "super::object::Column::Id", + from = "Column::Object", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] diff --git a/src/model/mention.rs b/src/model/mention.rs index 139d00c0..f08cb043 100644 --- a/src/model/mention.rs +++ b/src/model/mention.rs @@ -4,9 +4,9 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "mentions")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub object: i32, - pub actor: i32, + pub internal: i64, + pub object: i64, + pub actor: String, pub published: ChronoDateTimeUtc, } @@ -23,7 +23,7 @@ pub enum Relation { #[sea_orm( belongs_to = "super::object::Entity", from = "Column::Object", - to = "super::object::Column::Id", + to = "super::object::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] diff --git a/src/model/object.rs b/src/model/object.rs index a56257b8..bb1c9f63 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -9,11 +9,11 @@ use super::Audience; #[sea_orm(table_name = "objects")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, + pub internal: i64, #[sea_orm(unique)] - pub ap_id: String, + pub id: String, pub object_type: String, - pub attributed_to: Option, + pub attributed_to: Option, pub name: Option, pub summary: Option, pub content: Option, @@ -56,6 +56,14 @@ pub enum Relation { Likes, #[sea_orm(has_many = "super::mention::Entity")] Mentions, + #[sea_orm( + belongs_to = "Entity", + from = "Column::InReplyTo", + to = "Column::Id", + on_update = "Cascade", + on_delete = "NoAction" + )] + Objects, } impl Related for Entity { @@ -106,6 +114,12 @@ impl Related for Entity { } } +impl Related for Entity { + fn to() -> RelationDef { + Relation::Objects.def() + } +} + impl ActiveModelBehavior for ActiveModel {} impl ActiveModel { diff --git a/src/model/relation.rs b/src/model/relation.rs index 44d01df6..2a917419 100644 --- a/src/model/relation.rs +++ b/src/model/relation.rs @@ -4,11 +4,11 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "relations")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub follower: i32, - pub following: i32, - pub accept: Option, - pub activity: i32, + pub internal: i64, + pub follower: i64, + pub following: i64, + pub accept: Option, + pub activity: i64, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -16,35 +16,35 @@ pub enum Relation { #[sea_orm( belongs_to = "super::activity::Entity", from = "Column::Accept", - to = "super::activity::Column::Id", + to = "super::activity::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] - Activities2, + ActivitiesAccept, #[sea_orm( belongs_to = "super::activity::Entity", from = "Column::Activity", - to = "super::activity::Column::Id", + to = "super::activity::Column::Internal", on_update = "Cascade", on_delete = "NoAction" )] - Activities1, + ActivitiesFollow, #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Follower", - to = "super::actor::Column::Id", + to = "super::actor::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] - Actors2, + ActorsFollower, #[sea_orm( belongs_to = "super::actor::Entity", from = "Column::Following", - to = "super::actor::Column::Id", + to = "super::actor::Column::Internal", on_update = "Cascade", on_delete = "Cascade" )] - Actors1, + ActorsFollowing, } impl ActiveModelBehavior for ActiveModel {} diff --git a/src/model/session.rs b/src/model/session.rs index 0e7dfea2..f8ba460a 100644 --- a/src/model/session.rs +++ b/src/model/session.rs @@ -4,8 +4,8 @@ use sea_orm::entity::prelude::*; #[sea_orm(table_name = "sessions")] pub struct Model { #[sea_orm(primary_key)] - pub id: i32, - pub actor: i32, + pub internal: i64, + pub actor: String, pub secret: String, pub expires: ChronoDateTimeUtc, }