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
9 changes: 9 additions & 0 deletions database/postgres/ddl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,14 @@ CREATE INDEX CONCURRENTLY
IF NOT EXISTS
builds_created
ON builds (created);
`

// CreateBuildSourceIndex represents a query to create an
// index on the builds table for the source column.
CreateBuildSourceIndex = `
CREATE INDEX CONCURRENTLY
IF NOT EXISTS
builds_source
ON builds (source);
`
)
6 changes: 6 additions & 0 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ func createIndexes(c *client) error {
return fmt.Errorf("unable to create builds_created index for the %s table: %w", constants.TableBuild, err)
}

// create the builds_source index for the builds table
err = c.Postgres.Exec(ddl.CreateBuildSourceIndex).Error
if err != nil {
return fmt.Errorf("unable to create builds_source index for the %s table: %w", constants.TableBuild, err)
}

// create the hooks_repo_id index for the hooks table
err = c.Postgres.Exec(ddl.CreateHookRepoIDIndex).Error
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestPostgres_setupDatabase(t *testing.T) {
_mock.ExpectExec(ddl.CreateBuildRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateHookRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateLogBuildIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateRepoOrgNameIndex).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down Expand Up @@ -207,6 +208,7 @@ func TestPostgres_createIndexes(t *testing.T) {
_mock.ExpectExec(ddl.CreateBuildRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateHookRepoIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateLogBuildIDIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateRepoOrgNameIndex).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down
9 changes: 9 additions & 0 deletions database/sqlite/ddl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,14 @@ CREATE INDEX
IF NOT EXISTS
builds_created
ON builds (created);
`

// CreateBuildSourceIndex represents a query to create an
// index on the builds table for the source column.
CreateBuildSourceIndex = `
CREATE INDEX
IF NOT EXISTS
builds_source
ON builds (source);
`
)
6 changes: 6 additions & 0 deletions database/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ func createIndexes(c *client) error {
return fmt.Errorf("unable to create builds_created index for the %s table: %w", constants.TableBuild, err)
}

// create the builds_source index for the builds table
err = c.Sqlite.Exec(ddl.CreateBuildSourceIndex).Error
if err != nil {
return fmt.Errorf("unable to create builds_source index for the %s table: %w", constants.TableBuild, err)
}

// create the hooks_repo_id index for the hooks table
err = c.Sqlite.Exec(ddl.CreateHookRepoIDIndex).Error
if err != nil {
Expand Down