Skip to content
Closed
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
16 changes: 16 additions & 0 deletions internal/storage/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ var _migrations = []migrations.Migration{
return nil
},
},
{
// Migration 8 dropped the (trigger_id, event_id) primary key in favour
// of (id), leaving trigger_id unindexed. ListTriggersOccurrences filters
// WHERE trigger_id = ? and orders by date, so without this index every
// page is a sequential scan over an ever-growing table. Built
// CONCURRENTLY to avoid blocking writes during deploy.
Up: func(ctx context.Context, tx bun.IDB) error {
if _, err := tx.ExecContext(ctx, `
create index concurrently if not exists triggers_occurrences_trigger_id_date_idx
on triggers_occurrences (trigger_id, date);
`); err != nil {
return err
}
return nil
},
},
}

func Migrate(ctx context.Context, db *bun.DB) error {
Expand Down
Loading