CloudMigrations: Make table sort case insensitive (#103898)
* case insensitive sort * fix for all db types * add comment * add unit test * add a TODO to fix later
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/secrets"
|
||||
secretskv "github.com/grafana/grafana/pkg/services/secrets/kvstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -434,7 +435,13 @@ func (ss *sqlStore) getSnapshotResources(ctx context.Context, snapshotUid string
|
||||
if errorsOnly {
|
||||
sess.Where("status = ?", cloudmigration.ItemStatusError)
|
||||
}
|
||||
return sess.OrderBy(fmt.Sprintf("%s %s", col, dir)).Find(&resources, &cloudmigration.CloudMigrationResource{
|
||||
// TODO: It would be better if the query builder supported a case-insensitive flag for the .OrderBy() method
|
||||
orderByClause := fmt.Sprintf("lower(%s) %s", col, dir)
|
||||
if ss.db.GetDBType() == migrator.Postgres || // Postgres does not support lower() in ORDER BY -- sorts by case-insensitive by default
|
||||
params.SortColumn == cloudmigration.SortColumnID { // Don't apply a string sort to a numeric column
|
||||
orderByClause = fmt.Sprintf("%s %s", col, dir)
|
||||
}
|
||||
return sess.OrderBy(orderByClause).Find(&resources, &cloudmigration.CloudMigrationResource{
|
||||
SnapshotUID: snapshotUid,
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user