Skip to content

Commit

Permalink
Remove unused SQL query ListProfilesByProjectID (#3954)
Browse files Browse the repository at this point in the history
Remove unused SQL query

Also delete tests and custom methods around its return type.
  • Loading branch information
dmjb authored Jul 23, 2024
1 parent d04dd1c commit 0c7a148
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 167 deletions.
15 changes: 0 additions & 15 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions database/query/profiles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,6 @@ SELECT * FROM profiles WHERE id = $1 AND project_id = $2 FOR UPDATE;
-- name: GetProfileByNameAndLock :one
SELECT * FROM profiles WHERE lower(name) = lower(sqlc.arg(name)) AND project_id = $1 FOR UPDATE;

-- name: ListProfilesByProjectID :many
WITH helper AS(
SELECT pr.id as profid,
ARRAY_AGG(ROW(ps.id, ps.profile_id, ps.entity, ps.selector, ps.comment)::profile_selector) AS selectors
FROM profiles pr
JOIN profile_selectors ps
ON pr.id = ps.profile_id
WHERE pr.project_id = $1
GROUP BY pr.id
)
SELECT
sqlc.embed(profiles),
sqlc.embed(profiles_with_entity_profiles),
helper.selectors::profile_selector[] AS profiles_with_selectors
FROM profiles
JOIN profiles_with_entity_profiles ON profiles.id = profiles_with_entity_profiles.profid
LEFT JOIN helper ON profiles.id = helper.profid
WHERE profiles.project_id = $1;

-- name: ListProfilesByProjectIDAndLabel :many
WITH helper AS(
SELECT pr.id as profid,
Expand Down
20 changes: 0 additions & 20 deletions internal/db/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ func (r ListProfilesByProjectIDAndLabelRow) GetSelectors() []ProfileSelector {
return r.ProfilesWithSelectors
}

// GetProfile returns the profile
func (r ListProfilesByProjectIDRow) GetProfile() Profile {
return r.Profile
}

// GetEntityProfile returns the entity profile
func (r ListProfilesByProjectIDRow) GetEntityProfile() NullEntities {
return r.ProfilesWithEntityProfile.Entity
}

// GetContextualRules returns the contextual rules
func (r ListProfilesByProjectIDRow) GetContextualRules() pqtype.NullRawMessage {
return r.ProfilesWithEntityProfile.ContextualRules
}

// GetSelectors returns the selectors
func (r ListProfilesByProjectIDRow) GetSelectors() []ProfileSelector {
return r.ProfilesWithSelectors
}

// LabelsFromFilter parses the filter string and populates the IncludeLabels and ExcludeLabels fields
func (lp *ListProfilesByProjectIDAndLabelParams) LabelsFromFilter(filter string) {
// If s does not contain sep and sep is not empty, Split returns a
Expand Down
70 changes: 0 additions & 70 deletions internal/db/profiles.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions internal/db/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,12 @@ func matchIdWithListLabelRow(t *testing.T, id uuid.UUID) func(r ListProfilesByPr
}
}

func matchIdWithListRow(t *testing.T, id uuid.UUID) func(r ListProfilesByProjectIDRow) bool {
t.Helper()

return func(r ListProfilesByProjectIDRow) bool {
return r.Profile.ID == id
}
}

func findRowWithLabels(t *testing.T, rows []ListProfilesByProjectIDAndLabelRow, id uuid.UUID) int {
t.Helper()

return slices.IndexFunc(rows, matchIdWithListLabelRow(t, id))
}

func findRow(t *testing.T, rows []ListProfilesByProjectIDRow, id uuid.UUID) int {
t.Helper()

return slices.IndexFunc(rows, matchIdWithListRow(t, id))
}

func TestProfileListWithSelectors(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -286,34 +272,6 @@ func TestProfileListWithSelectors(t *testing.T) {
require.Contains(t, rows[genSelIdx].ProfilesWithSelectors, genericSel)
})

t.Run("list profiles with selectors using the non-label list", func(t *testing.T) {
t.Parallel()

rows, err := testQueries.ListProfilesByProjectID(
context.Background(), randomEntities.proj.ID)
require.NoError(t, err)

require.Len(t, rows, 4)

noSelIdx := findRow(t, rows, noSelectors.ID)
require.True(t, noSelIdx >= 0, "noSelectors not found in rows")
require.Empty(t, rows[noSelIdx].ProfilesWithSelectors)

oneSelIdx := findRow(t, rows, oneSelectorProfile.ID)
require.True(t, oneSelIdx >= 0, "oneSelector not found in rows")
require.Len(t, rows[oneSelIdx].ProfilesWithSelectors, 1)
require.Contains(t, rows[oneSelIdx].ProfilesWithSelectors, oneSel)

multiSelIdx := findRow(t, rows, multiSelectorProfile.ID)
require.True(t, multiSelIdx >= 0, "multiSelectorProfile not found in rows")
require.Len(t, rows[multiSelIdx].ProfilesWithSelectors, 3)
require.Subset(t, rows[multiSelIdx].ProfilesWithSelectors, []ProfileSelector{mulitSel1, mulitSel2, mulitSel3})

genSelIdx := findRow(t, rows, genericSelectorProfile.ID)
require.Len(t, rows[genSelIdx].ProfilesWithSelectors, 1)
require.Contains(t, rows[genSelIdx].ProfilesWithSelectors, genericSel)
})

t.Run("Get profile by project and ID", func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/db/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c7a148

Please sign in to comment.