Skip to content

Commit

Permalink
refactor(db/build): drop source index, add event index
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk committed Dec 18, 2024
1 parent 355107d commit 9f4c7be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
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

0 comments on commit 9f4c7be

Please sign in to comment.