diff --git a/src/migrations/m20240316_000001_create_table.rs b/src/migrations/m20240316_000001_create_table.rs index 1078b91..62c6895 100644 --- a/src/migrations/m20240316_000001_create_table.rs +++ b/src/migrations/m20240316_000001_create_table.rs @@ -32,7 +32,6 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Users::PrivateKey).string().null()) .col(ColumnDef::new(Users::Created).date_time().not_null()) .col(ColumnDef::new(Users::Updated).date_time().not_null()) - .index(Index::create().col(Users::Domain)) .to_owned() ) .await?; @@ -56,9 +55,6 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Activities::Cc).json().null()) .col(ColumnDef::new(Activities::Bcc).json().null()) .col(ColumnDef::new(Activities::Published).date_time().not_null()) - .index(Index::create().col(Activities::Published)) - .index(Index::create().col(Activities::Actor)) - .index(Index::create().col(Activities::Object)) .to_owned() ).await?; @@ -86,7 +82,6 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Objects::Cc).json().null()) .col(ColumnDef::new(Objects::Bcc).json().null()) .col(ColumnDef::new(Objects::Published).string().not_null()) - .index(Index::create().col(Objects::AttributedTo)) .to_owned() ).await?; diff --git a/src/migrations/m20240322_000001_create_relations.rs b/src/migrations/m20240322_000001_create_relations.rs index 5443363..e797c4d 100644 --- a/src/migrations/m20240322_000001_create_relations.rs +++ b/src/migrations/m20240322_000001_create_relations.rs @@ -19,9 +19,6 @@ impl MigrationTrait for Migration { ) .col(ColumnDef::new(Relations::Follower).string().not_null()) .col(ColumnDef::new(Relations::Following).string().not_null()) - .index(Index::create().col(Relations::Follower).col(Relations::Following).unique()) - .index(Index::create().col(Relations::Follower)) - .index(Index::create().col(Relations::Following)) .to_owned() ) .await?; diff --git a/src/migrations/m20240322_000002_add_likes_shares.rs b/src/migrations/m20240322_000002_add_likes_shares.rs index 3e775f4..4a53522 100644 --- a/src/migrations/m20240322_000002_add_likes_shares.rs +++ b/src/migrations/m20240322_000002_add_likes_shares.rs @@ -19,9 +19,6 @@ impl MigrationTrait for Migration { ) .col(ColumnDef::new(Likes::Actor).string().not_null()) .col(ColumnDef::new(Likes::Likes).string().not_null()) - .index(Index::create().col(Likes::Actor).col(Likes::Likes).unique()) - .index(Index::create().col(Likes::Actor)) - .index(Index::create().col(Likes::Likes)) .to_owned() ) .await?; @@ -40,8 +37,6 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Shares::Actor).string().not_null()) .col(ColumnDef::new(Shares::Shares).string().not_null()) .col(ColumnDef::new(Shares::Date).date_time().not_null()) - .index(Index::create().col(Shares::Actor)) - .index(Index::create().col(Shares::Shares)) .to_owned() ) .await?; diff --git a/src/migrations/m20240322_000003_add_indexes.rs b/src/migrations/m20240322_000003_add_indexes.rs new file mode 100644 index 0000000..52a6310 --- /dev/null +++ b/src/migrations/m20240322_000003_add_indexes.rs @@ -0,0 +1,173 @@ +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 + .create_index( + Index::create() + .name("user-domain-index") + .table(Users::Table) + .col(Users::Domain) + .to_owned() + ) + .await?; + + manager + .create_index( + Index::create() + .name("activities-published-descending-index") + .table(Activities::Table) + .col((Activities::Published, IndexOrder::Desc)) + .to_owned() + ) + .await?; + + manager + .create_index( + Index::create() + .name("activities-actor-index") + .table(Activities::Table) + .col(Activities::Actor) + .to_owned() + ) + .await?; + + manager + .create_index( + Index::create() + .name("activities-object-index") + .table(Activities::Table) + .col(Activities::Object) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("objects-attributed-to-index") + .table(Objects::Table) + .col(Objects::AttributedTo) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("shares-actor-index") + .table(Shares::Table) + .col(Shares::Actor) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("shares-shares-index") + .table(Shares::Table) + .col(Shares::Shares) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("likes-actor-index") + .table(Likes::Table) + .col(Likes::Actor) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("likes-likes-index") + .table(Likes::Table) + .col(Likes::Likes) + .to_owned() + ).await?; + + manager + .create_index( + Index::create() + .name("likes-actor-likes-index") + .table(Likes::Table) + .col(Likes::Actor) + .col(Likes::Likes) + .to_owned() + ).await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_index(Index::drop().name("user-domain-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("activities-published-descending-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("activities-actor-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("activities-object-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("objects-attributed-to-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("shares-actor-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("shares-shares-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("likes-actor-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("likes-likes-index").to_owned()) + .await?; + manager + .drop_index(Index::drop().name("likes-actor-likes-index").to_owned()) + .await?; + Ok(()) + } +} + +#[derive(DeriveIden)] +enum Likes { + Table, + Actor, + Likes, +} + +#[derive(DeriveIden)] +enum Shares { + Table, + Actor, + Shares, +} + +#[derive(DeriveIden)] +enum Users { + Table, + Domain, +} + +#[derive(DeriveIden)] +enum Activities { + Table, + Actor, + Object, + Published, +} + +#[derive(DeriveIden)] +enum Objects { + Table, + AttributedTo, +} diff --git a/src/migrations/mod.rs b/src/migrations/mod.rs index 7c8fac8..73d074c 100644 --- a/src/migrations/mod.rs +++ b/src/migrations/mod.rs @@ -3,6 +3,7 @@ use sea_orm_migration::prelude::*; mod m20240316_000001_create_table; mod m20240322_000001_create_relations; mod m20240322_000002_add_likes_shares; +mod m20240322_000003_add_indexes; pub struct Migrator; @@ -13,6 +14,7 @@ impl MigratorTrait for Migrator { Box::new(m20240316_000001_create_table::Migration), Box::new(m20240322_000001_create_relations::Migration), Box::new(m20240322_000002_add_likes_shares::Migration), + Box::new(m20240322_000003_add_indexes::Migration), ] } }