diff --git a/src/migrations/m20240520_000001_add_published_to_addressing_actor_index.rs b/src/migrations/m20240520_000001_add_published_to_addressing_actor_index.rs new file mode 100644 index 0000000..55975c4 --- /dev/null +++ b/src/migrations/m20240520_000001_add_published_to_addressing_actor_index.rs @@ -0,0 +1,82 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + + manager + .drop_index(Index::drop().name("addressing-actor-index").to_owned()) + .await?; + + manager + .create_index( + Index::create() + .name("addressing-actor-index") + .table(Addressing::Table) + .col(Addressing::Actor) + .col(Addressing::Published) + .to_owned() + ) + .await?; + + manager + .drop_index(Index::drop().name("addressing-server-index").to_owned()) + .await?; + + manager + .create_index( + Index::create() + .name("addressing-server-index") + .table(Addressing::Table) + .col(Addressing::Server) + .col(Addressing::Published) + .to_owned() + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_index(Index::drop().name("addressing-actor-index").to_owned()) + .await?; + + manager + .create_index( + Index::create() + .name("addressing-actor-index") + .table(Addressing::Table) + .col(Addressing::Actor) + .to_owned() + ) + .await?; + + manager + .drop_index(Index::drop().name("addressing-server-index").to_owned()) + .await?; + + manager + .create_index( + Index::create() + .name("addressing-server-index") + .table(Addressing::Table) + .col(Addressing::Server) + .to_owned() + ) + .await?; + + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Addressing { + Table, + Actor, + Server, + Published, +} diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index 8468333..392d0fb 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -15,6 +15,7 @@ mod m20240424_000001_add_sensitive_field; mod m20240429_000001_add_relays_table; mod m20240502_000001_add_object_updated; mod m20240512_000001_add_url_to_objects; +mod m20240520_000001_add_published_to_addressing_actor_index; pub struct Migrator; @@ -37,6 +38,7 @@ impl MigratorTrait for Migrator { Box::new(m20240429_000001_add_relays_table::Migration), Box::new(m20240502_000001_add_object_updated::Migration), Box::new(m20240512_000001_add_url_to_objects::Migration), + Box::new(m20240520_000001_add_published_to_addressing_actor_index::Migration), ] } }