diff --git a/database/build/build_test.go b/database/build/build_test.go index 383c0573c..e97a06faf 100644 --- a/database/build/build_test.go +++ b/database/build/build_test.go @@ -28,8 +28,8 @@ func TestBuild_New(t *testing.T) { _mock.ExpectExec(CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1)) + _mock.ExpectExec(CreateEventIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1)) - _mock.ExpectExec(CreateSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _config := &gorm.Config{SkipDefaultTransaction: true} @@ -152,8 +152,8 @@ func testPostgres(t *testing.T) (*engine, sqlmock.Sqlmock) { _mock.ExpectExec(CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1)) + _mock.ExpectExec(CreateEventIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1)) - _mock.ExpectExec(CreateSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1)) // create the new mock Postgres database client diff --git a/database/build/index.go b/database/build/index.go index f224ccacc..4765ba534 100644 --- a/database/build/index.go +++ b/database/build/index.go @@ -12,6 +12,15 @@ CREATE INDEX IF NOT EXISTS builds_created ON builds (created); +` + + // CreateEventIndex represents a query to create an + // index on the builds table for the event column. + CreateEventIndex = ` +CREATE INDEX +IF NOT EXISTS +builds_event +ON builds (event); ` // CreateRepoIDIndex represents a query to create an @@ -21,15 +30,6 @@ CREATE INDEX IF NOT EXISTS builds_repo_id ON builds (repo_id); -` - - // CreateSourceIndex represents a query to create an - // index on the builds table for the source column. - CreateSourceIndex = ` -CREATE INDEX -IF NOT EXISTS -builds_source -ON builds (source); ` // CreateStatusIndex represents a query to create an @@ -54,18 +54,18 @@ func (e *engine) CreateBuildIndexes(ctx context.Context) error { return err } - // create the repo_id column index for the builds table + // create the event column index for the builds table err = e.client. WithContext(ctx). - Exec(CreateRepoIDIndex).Error + Exec(CreateEventIndex).Error if err != nil { return err } - // create the source column index for the builds table + // create the repo_id column index for the builds table err = e.client. WithContext(ctx). - Exec(CreateSourceIndex).Error + Exec(CreateRepoIDIndex).Error if err != nil { return err } diff --git a/database/build/index_test.go b/database/build/index_test.go index 03d02fc8d..1a0a00099 100644 --- a/database/build/index_test.go +++ b/database/build/index_test.go @@ -15,8 +15,8 @@ func TestBuild_Engine_CreateBuildIndexes(t *testing.T) { defer func() { _sql, _ := _postgres.client.DB(); _sql.Close() }() _mock.ExpectExec(CreateCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1)) + _mock.ExpectExec(CreateEventIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1)) - _mock.ExpectExec(CreateSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(CreateStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _sqlite := testSqlite(t) diff --git a/database/resource_test.go b/database/resource_test.go index cdc5dbaa3..794ed980e 100644 --- a/database/resource_test.go +++ b/database/resource_test.go @@ -35,8 +35,8 @@ func TestDatabase_Engine_NewResources(t *testing.T) { // ensure the mock expects the build queries _mock.ExpectExec(build.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(build.CreateCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1)) + _mock.ExpectExec(build.CreateEventIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(build.CreateRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1)) - _mock.ExpectExec(build.CreateSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1)) _mock.ExpectExec(build.CreateStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1)) // ensure the mock expects the dashboard queries _mock.ExpectExec(dashboard.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))