add index to jobs table (#21090)

This commit is contained in:
Benjamin Edwards
2024-08-06 14:49:01 -04:00
committed by GitHub
parent e65d6cfa06
commit 60a0609ef7
3 changed files with 51 additions and 3 deletions
@@ -0,0 +1,21 @@
package tables
import (
"database/sql"
"fmt"
)
func init() {
MigrationClient.AddMigration(Up_20240806101121, Down_20240802113716)
}
func Up_20240806101121(tx *sql.Tx) error {
if _, err := tx.Exec(`CREATE INDEX idx_jobs_state_not_before_updated_at ON jobs (state, not_before, updated_at);`); err != nil {
return fmt.Errorf("creating jobs index: %w", err)
}
return nil
}
func Down_20240806101121(tx *sql.Tx) error {
return nil
}
@@ -0,0 +1,26 @@
package tables
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestUp_20240806101121(t *testing.T) {
db := applyUpToPrev(t)
// Apply current migration
applyNext(t, db)
// Check if the index exists
var indexExists bool
err := db.QueryRow(`
SELECT 1 FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'jobs'
AND index_name = 'idx_jobs_state_not_before_updated_at'
`).Scan(&indexExists)
require.NoError(t, err)
require.True(t, indexExists, "Index idx_jobs_state_not_before_updated_at should exist")
}
File diff suppressed because one or more lines are too long