Remove use of dialect.LikeStr (#104460)

* Fix TestIntegrationUpdatingProvisionionedDashboards* tests when running on Spanner by fixing case-insensitive search for dashboard title.

* Fix use of case-insensitive LIKE when running on Spanner.

* Fix use of LikeStr in anonstore.

* Fix use of LikeStr in ngalert/store and org/orgimpl.

* Fix use of LikeStr in queryhistory search.

* Fix use of LikeStr in serviceaccounts.

* Fix use of LikeStr in serviceaccounts.

* Fix use of LikeStr in services/team.

* Remove LikeStr method.
This commit is contained in:
Peter Štibraný
2025-05-02 11:23:57 +03:00
committed by GitHub
parent d7ebaafa94
commit e85acf047a
16 changed files with 82 additions and 51 deletions
+5 -5
View File
@@ -186,8 +186,6 @@ func (ss *xormStore) Search(ctx context.Context, query *team.SearchTeamsQuery) (
Teams: make([]*team.TeamDTO, 0),
}
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
queryWithWildcards := "%" + query.Query + "%"
var sql bytes.Buffer
params := make([]any, 0)
@@ -201,8 +199,9 @@ func (ss *xormStore) Search(ctx context.Context, query *team.SearchTeamsQuery) (
params = append(params, query.OrgID)
if query.Query != "" {
sql.WriteString(` and team.name ` + ss.db.GetDialect().LikeStr() + ` ?`)
params = append(params, queryWithWildcards)
like, param := ss.db.GetDialect().LikeOperator("team.name", true, query.Query, true)
sql.WriteString(" and " + like)
params = append(params, param)
}
if query.Name != "" {
@@ -250,7 +249,8 @@ func (ss *xormStore) Search(ctx context.Context, query *team.SearchTeamsQuery) (
countSess.Where("team.org_id=?", query.OrgID)
if query.Query != "" {
countSess.Where(`name `+ss.db.GetDialect().LikeStr()+` ?`, queryWithWildcards)
like, param := ss.db.GetDialect().LikeOperator("name", true, query.Query, true)
countSess.Where(like, param)
}
if query.Name != "" {
+2 -1
View File
@@ -243,7 +243,8 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
})
t.Run("Should be able to search for teams", func(t *testing.T) {
query := &team.SearchTeamsQuery{OrgID: testOrgID, Query: "group", Page: 1, SignedInUser: testUser}
// Use mixed-case to test case-insensitive search.
query := &team.SearchTeamsQuery{OrgID: testOrgID, Query: "GrOuP", Page: 1, SignedInUser: testUser}
queryResult, err := teamSvc.SearchTeams(context.Background(), query)
require.NoError(t, err)
require.Equal(t, len(queryResult.Teams), 2)