From 1ee7eb1498684b822f06d512744d790362be78dc Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 28 Jun 2024 05:10:57 +0200 Subject: [PATCH] feat: add indexes on followers/following fields will use them for proper address expansion soon:tm: --- upub/migrations/src/lib.rs | 2 + ..._000001_add_followers_following_indexes.rs | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 upub/migrations/src/m20240628_000001_add_followers_following_indexes.rs diff --git a/upub/migrations/src/lib.rs b/upub/migrations/src/lib.rs index 9f66b6e..40f2ef2 100644 --- a/upub/migrations/src/lib.rs +++ b/upub/migrations/src/lib.rs @@ -12,6 +12,7 @@ mod m20240607_000001_activity_ref_is_optional; mod m20240609_000001_add_instance_field_to_relations; mod m20240623_000001_add_dislikes_table; mod m20240626_000001_add_notifications_table; +mod m20240628_000001_add_followers_following_indexes; pub struct Migrator; @@ -31,6 +32,7 @@ impl MigratorTrait for Migrator { Box::new(m20240609_000001_add_instance_field_to_relations::Migration), Box::new(m20240623_000001_add_dislikes_table::Migration), Box::new(m20240626_000001_add_notifications_table::Migration), + Box::new(m20240628_000001_add_followers_following_indexes::Migration), ] } } diff --git a/upub/migrations/src/m20240628_000001_add_followers_following_indexes.rs b/upub/migrations/src/m20240628_000001_add_followers_following_indexes.rs new file mode 100644 index 0000000..e11b8e3 --- /dev/null +++ b/upub/migrations/src/m20240628_000001_add_followers_following_indexes.rs @@ -0,0 +1,45 @@ +use sea_orm_migration::prelude::*; + +use crate::m20240524_000001_create_actor_activity_object_tables::Actors; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_index( + Index::create() + .name("index-actors-followers") + .table(Actors::Table) + .col(Actors::Followers) + .to_owned() + ) + .await?; + + manager + .create_index( + Index::create() + .name("index-actors-following") + .table(Actors::Table) + .col(Actors::Following) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_index(Index::drop().name("index-actors-followers").table(Actors::Table).to_owned()) + .await?; + + manager + .drop_index(Index::drop().name("index-actors-following").table(Actors::Table).to_owned()) + .await?; + + Ok(()) + } +}