Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(db/build): drop source index, add event index #1228

Merged
merged 4 commits into from
Dec 27, 2024
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
4 changes: 2 additions & 2 deletions database/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions database/build/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion database/build/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion database/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading