Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/migrations/m20260308_200000_add_indexes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use rapina::migration::prelude::*;
use rapina::sea_orm_migration;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Index for PR lookups by repo + number + status (find_queued_pr, find_active_pr)
manager
.create_index(
Index::create()
.name("idx_pr_repo_number_status")
.table(PullRequests::Table)
.col(PullRequests::RepoOwner)
.col(PullRequests::RepoName)
.col(PullRequests::PrNumber)
.col(PullRequests::Status)
.to_owned(),
)
.await?;

// Index for queue ordering (get_queue, get_next_queued, dashboard active PRs)
manager
.create_index(
Index::create()
.name("idx_pr_status_priority_queued")
.table(PullRequests::Table)
.col(PullRequests::Status)
.col(PullRequests::Priority)
.col(PullRequests::QueuedAt)
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(
Index::drop()
.name("idx_pr_repo_number_status")
.table(PullRequests::Table)
.to_owned(),
)
.await?;
manager
.drop_index(
Index::drop()
.name("idx_pr_status_priority_queued")
.table(PullRequests::Table)
.to_owned(),
)
.await?;
Ok(())
}
}

#[derive(DeriveIden)]
enum PullRequests {
Table,
RepoOwner,
RepoName,
PrNumber,
Status,
Priority,
QueuedAt,
}
3 changes: 3 additions & 0 deletions src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ mod m20260307_200000_add_installation_id;

mod m20260308_120000_add_approved_by;

mod m20260308_200000_add_indexes;

rapina::migrations! {
m20260307_033928_create_pull_requests,
m20260307_130846_create_batchs,
m20260307_131338_create_merge_events,
m20260307_200000_add_installation_id,
m20260308_120000_add_approved_by,
m20260308_200000_add_indexes,
}