Stars: Move stars from preferences apiserver to a new collections apiserver (#114006)

This commit is contained in:
Ryan McKinley
2025-11-19 08:28:39 +03:00
committed by GitHub
parent e558c9af5d
commit 00329cab14
96 changed files with 3416 additions and 2380 deletions
@@ -26,52 +26,11 @@ func mustTemplate(filename string) *template.Template {
// Templates.
var (
sqlDashboardStarsQuery = mustTemplate("sql_dashboard_stars.sql")
sqlDashboardStarsRV = mustTemplate("sql_dashboard_stars_rv.sql")
sqlHistoryStarsQuery = mustTemplate("sql_history_stars.sql")
sqlHistoryStarsInsert = mustTemplate("sql_history_stars_insert.sql")
sqlHistoryStarsDelete = mustTemplate("sql_history_stars_delete.sql")
sqlPreferencesQuery = mustTemplate("sql_preferences_query.sql")
sqlPreferencesRV = mustTemplate("sql_preferences_rv.sql")
sqlTeams = mustTemplate("sql_teams.sql")
sqlPreferencesQuery = mustTemplate("sql_preferences_query.sql")
sqlPreferencesRV = mustTemplate("sql_preferences_rv.sql")
sqlTeams = mustTemplate("sql_teams.sql")
)
type starQuery struct {
sqltemplate.SQLTemplate
OrgID int64 // >= 1 if UserID != ""
UserUID string
UserID int64 // for stars
QueryUIDs []string
QueryUID string
StarTable string
UserTable string
QueryHistoryStarsTable string
QueryHistoryTable string
}
func (r starQuery) Validate() error {
if r.UserUID != "" && r.OrgID < 1 {
return fmt.Errorf("requests with a userid, must include an orgID")
}
return nil
}
func newStarQueryReq(sql *legacysql.LegacyDatabaseHelper, user string, orgId int64) starQuery {
return starQuery{
SQLTemplate: sqltemplate.New(sql.DialectForDriver()),
UserUID: user,
OrgID: orgId,
StarTable: sql.Table("star"),
UserTable: sql.Table("user"),
QueryHistoryStarsTable: sql.Table("query_history_star"),
QueryHistoryTable: sql.Table("query_history"),
}
}
type preferencesQuery struct {
sqltemplate.SQLTemplate
@@ -17,21 +17,6 @@ func TestStarsQueries(t *testing.T) {
},
}
getStarQuery := func(orgId int64, user string) sqltemplate.SQLTemplate {
v := newStarQueryReq(nodb, user, orgId)
v.SQLTemplate = mocks.NewTestingSQLTemplate()
return &v
}
getHistoryReq := func(orgId int64, userId int64, stars []string, star string) sqltemplate.SQLTemplate {
v := newStarQueryReq(nodb, "", orgId)
v.UserID = userId
v.QueryUIDs = stars
v.QueryUID = star
v.SQLTemplate = mocks.NewTestingSQLTemplate()
return &v
}
getPreferencesQuery := func(orgId int64, cb func(q *preferencesQuery)) sqltemplate.SQLTemplate {
v := newPreferencesQueryReq(nodb, orgId)
v.SQLTemplate = mocks.NewTestingSQLTemplate()
@@ -49,56 +34,6 @@ func TestStarsQueries(t *testing.T) {
RootDir: "testdata",
SQLTemplatesFS: sqlTemplatesFS,
Templates: map[*template.Template][]mocks.TemplateTestCase{
sqlDashboardStarsQuery: {
{
Name: "all",
Data: getStarQuery(0, ""),
},
{
Name: "org",
Data: getStarQuery(3, ""),
},
{
Name: "user",
Data: getStarQuery(3, "abc"),
},
},
sqlDashboardStarsRV: {
{
Name: "get",
Data: getStarQuery(0, ""),
},
},
sqlHistoryStarsQuery: {
{
Name: "user",
Data: getStarQuery(1, "abc"),
},
},
sqlHistoryStarsQuery: {
{
Name: "org",
Data: getStarQuery(1, ""),
},
},
sqlHistoryStarsInsert: {
{
Name: "add star",
Data: getHistoryReq(1, 3, nil, "XXX"),
},
},
sqlHistoryStarsDelete: {
{
Name: "remove star",
Data: getHistoryReq(1, 3, []string{"xxx", "yyy"}, ""),
},
},
sqlHistoryStarsDelete: {
{
Name: "remove all star",
Data: getHistoryReq(1, 3, nil, ""),
},
},
sqlPreferencesQuery: {
{
Name: "all",
-181
View File
@@ -12,20 +12,10 @@ import (
preferences "github.com/grafana/grafana/apps/preferences/pkg/apis/preferences/v1alpha1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
pref "github.com/grafana/grafana/pkg/services/preference"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/storage/legacysql"
"github.com/grafana/grafana/pkg/storage/unified/sql/sqltemplate"
)
type dashboardStars struct {
OrgID int64
UserUID string
First int64
Last int64
Dashboards []string
}
type preferenceModel struct {
ID int64
OrgID int64
@@ -49,177 +39,6 @@ func NewLegacySQL(db legacysql.LegacyDatabaseProvider) *LegacySQL {
return &LegacySQL{db: db, startup: time.Now()}
}
// NOTE: this does not support paging -- lets check if that will be a problem in cloud
func (s *LegacySQL) getDashboardStars(ctx context.Context, orgId int64, user string) ([]dashboardStars, int64, error) {
var max sql.NullString
sql, err := s.db(ctx)
if err != nil {
return nil, 0, err
}
req := newStarQueryReq(sql, user, orgId)
q, err := sqltemplate.Execute(sqlDashboardStarsQuery, req)
if err != nil {
return nil, 0, fmt.Errorf("execute template %q: %w", sqlDashboardStarsQuery.Name(), err)
}
sess := sql.DB.GetSqlxSession()
rows, err := sess.Query(ctx, q, req.GetArgs()...)
if err != nil {
return nil, 0, err
}
defer func() {
if rows != nil {
_ = rows.Close()
}
}()
stars := []dashboardStars{}
current := &dashboardStars{}
var orgID int64
var userUID string
var dashboardUID string
var updated time.Time
for rows.Next() {
err := rows.Scan(&orgID, &userUID, &dashboardUID, &updated)
if err != nil {
return nil, 0, err
}
if orgID != current.OrgID || userUID != current.UserUID {
if current.UserUID != "" {
stars = append(stars, *current)
}
current = &dashboardStars{
OrgID: orgID,
UserUID: userUID,
}
}
ts := updated.UnixMilli()
if ts > current.Last {
current.Last = ts
}
if ts < current.First || current.First == 0 {
current.First = ts
}
current.Dashboards = append(current.Dashboards, dashboardUID)
}
// Add the last value
if current.UserUID != "" {
stars = append(stars, *current)
}
// Find the RV unless it is a user query
if userUID == "" {
req.Reset()
q, err = sqltemplate.Execute(sqlDashboardStarsRV, req)
if err != nil {
return nil, 0, fmt.Errorf("execute template %q: %w", sqlPreferencesRV.Name(), err)
}
err = sess.Get(ctx, &max, q)
if err != nil {
return nil, 0, fmt.Errorf("unable to get RV %w", err)
}
if max.Valid && max.String != "" {
t, _ := time.Parse(time.RFC3339, max.String)
if !t.IsZero() {
updated = t
}
} else {
updated = s.startup
}
}
return stars, updated.UnixMilli(), err
}
func (s *LegacySQL) getHistoryStars(ctx context.Context, orgId int64, user string) (map[string][]string, error) {
sql, err := s.db(ctx)
if err != nil {
return nil, err
}
req := newStarQueryReq(sql, user, orgId)
q, err := sqltemplate.Execute(sqlHistoryStarsQuery, req)
if err != nil {
return nil, fmt.Errorf("execute template %q: %w", sqlHistoryStarsQuery.Name(), err)
}
sess := sql.DB.GetSqlxSession()
rows, err := sess.Query(ctx, q, req.GetArgs()...)
if err != nil {
return nil, err
}
defer func() {
if rows != nil {
_ = rows.Close()
}
}()
last := user
res := make(map[string][]string)
buffer := make([]string, 0, 10)
var uid string
for rows.Next() {
err := rows.Scan(&uid, &user)
if err != nil {
return nil, err
}
if user != last && len(buffer) > 0 {
res[last] = buffer
buffer = make([]string, 0, 10)
}
buffer = append(buffer, uid)
last = user
}
res[last] = buffer
return res, nil
}
func (s *LegacySQL) removeHistoryStar(ctx context.Context, user *user.User, stars []string) error {
sql, err := s.db(ctx)
if err != nil {
return err
}
req := newStarQueryReq(sql, "", user.OrgID)
req.UserID = user.ID
if len(stars) > 0 {
req.QueryUIDs = stars
}
q, err := sqltemplate.Execute(sqlHistoryStarsDelete, req)
if err != nil {
return fmt.Errorf("execute template %q: %w", sqlHistoryStarsDelete.Name(), err)
}
sess := sql.DB.GetSqlxSession()
_, err = sess.Exec(ctx, q, req.GetArgs()...)
return err
}
func (s *LegacySQL) addHistoryStar(ctx context.Context, user *user.User, star string) error {
sql, err := s.db(ctx)
if err != nil {
return err
}
req := newStarQueryReq(sql, "", user.OrgID)
req.UserID = user.ID
req.QueryUID = star
q, err := sqltemplate.Execute(sqlHistoryStarsDelete, req)
if err != nil {
return fmt.Errorf("execute template %q: %w", sqlHistoryStarsDelete.Name(), err)
}
sess := sql.DB.GetSqlxSession()
_, err = sess.Exec(ctx, q, req.GetArgs()...)
return err
}
// List all defined preferences in an org (valid for admin users only)
func (s *LegacySQL) listPreferences(ctx context.Context,
ns string, orgId int64,
@@ -1,10 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM {{ .Ident .StarTable }} as s
JOIN {{ .Ident .UserTable }} as u ON s.user_id = u.id
{{ if ge .OrgID 1 }}
WHERE s.org_id = {{ .Arg .OrgID }}
{{ if .UserUID }}
AND u.uid = {{ .Arg .UserUID }}
{{ end }}{{ end }}
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1 +0,0 @@
SELECT MAX(updated) FROM {{ .Ident .StarTable }}
@@ -1,9 +0,0 @@
SELECT s.query_uid, u.uid as user_uid
FROM {{ .Ident .QueryHistoryStarsTable }} as s
JOIN {{ .Ident .QueryHistoryTable }} as h ON s.query_uid = h.uid
JOIN {{ .Ident .UserTable }} as u ON s.user_id = u.id
WHERE s.org_id = {{ .Arg .OrgID }}
{{ if .UserUID }}
AND u.uid = {{ .Arg .UserUID }}
{{ end }}
ORDER BY s.org_id asc, s.user_id asc, s.query_uid asc
@@ -1,6 +0,0 @@
DELETE FROM {{ .Ident .QueryHistoryStarsTable }}
WHERE org_id = {{ .Arg .OrgID }}
AND user_id = {{ .Arg .UserID }}
{{ if .QueryUIDs }}
AND query_uid IN ({{ .ArgList .QueryUIDs }})
{{ end }}
@@ -1,4 +0,0 @@
INSERT INTO {{ .Ident .QueryHistoryStarsTable }}
( query_uid, user_id, org_id )
VALUES
( {{ .Arg .QueryUID }}, {{ .Arg .UserID }}, {{ .Arg .OrgID }} )
@@ -1,349 +0,0 @@
package legacy
import (
"context"
"fmt"
"math/rand"
"slices"
"strconv"
"strings"
"time"
apiserrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/utils/ptr"
authlib "github.com/grafana/authlib/types"
dashboardsV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
preferences "github.com/grafana/grafana/apps/preferences/pkg/apis/preferences/v1alpha1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/registry/apis/preferences/utils"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
"github.com/grafana/grafana/pkg/services/star"
"github.com/grafana/grafana/pkg/services/user"
)
var (
_ rest.Scoper = (*DashboardStarsStorage)(nil)
_ rest.SingularNameProvider = (*DashboardStarsStorage)(nil)
_ rest.Getter = (*DashboardStarsStorage)(nil)
_ rest.Lister = (*DashboardStarsStorage)(nil)
_ rest.Storage = (*DashboardStarsStorage)(nil)
_ rest.Creater = (*DashboardStarsStorage)(nil)
_ rest.Updater = (*DashboardStarsStorage)(nil)
_ rest.GracefulDeleter = (*DashboardStarsStorage)(nil)
_ rest.CollectionDeleter = (*DashboardStarsStorage)(nil)
)
func NewDashboardStarsStorage(
stars star.Service,
users user.Service,
namespacer request.NamespaceMapper,
sql *LegacySQL,
) *DashboardStarsStorage {
return &DashboardStarsStorage{
stars: stars,
users: users,
namespacer: namespacer,
sql: sql,
tableConverter: preferences.StarsResourceInfo.TableConverter(),
}
}
type DashboardStarsStorage struct {
namespacer request.NamespaceMapper
tableConverter rest.TableConvertor
sql *LegacySQL
stars star.Service
users user.Service
}
func (s *DashboardStarsStorage) New() runtime.Object {
return preferences.StarsKind().ZeroValue()
}
func (s *DashboardStarsStorage) Destroy() {}
func (s *DashboardStarsStorage) NamespaceScoped() bool {
return true // namespace == org
}
func (s *DashboardStarsStorage) GetSingularName() string {
return strings.ToLower(preferences.StarsKind().Kind())
}
func (s *DashboardStarsStorage) NewList() runtime.Object {
return preferences.StarsKind().ZeroListValue()
}
func (s *DashboardStarsStorage) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) {
return s.tableConverter.ConvertToTable(ctx, object, tableOptions)
}
func (s *DashboardStarsStorage) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) {
ns, err := request.NamespaceInfoFrom(ctx, false)
if err != nil {
return nil, err
}
if ns.Value == "" {
return nil, fmt.Errorf("cross cluster listing is not supported")
}
userInfo, err := identity.GetRequester(ctx)
if err != nil {
return nil, err
}
user := userInfo.GetIdentifier()
if userInfo.GetIdentityType() == authlib.TypeAccessPolicy {
user = "" // can see everything
}
list := &preferences.StarsList{}
found, rv, err := s.sql.getDashboardStars(ctx, ns.OrgID, user)
if err != nil {
return nil, err
}
history, err := s.sql.getHistoryStars(ctx, ns.OrgID, "")
if err != nil {
return nil, err
}
for _, v := range found {
list.Items = append(list.Items,
asStarsResource(s.namespacer(v.OrgID), &v, history[v.UserUID]))
}
if rv > 0 {
list.ResourceVersion = strconv.FormatInt(rv, 10)
}
return list, nil
}
func getNamespaceAndOwner(ctx context.Context, name string) (authlib.NamespaceInfo, utils.OwnerReference, error) {
info, err := request.NamespaceInfoFrom(ctx, true)
if err != nil {
return info, utils.OwnerReference{}, err
}
owner, ok := utils.ParseOwnerFromName(name)
if !ok {
return info, owner, fmt.Errorf("invalid name %w", err)
}
if owner.Owner != utils.UserResourceOwner {
return info, owner, fmt.Errorf("expecting name with prefix: %s-", utils.UserResourceOwner)
}
return info, owner, nil
}
func (s *DashboardStarsStorage) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
ns, owner, err := getNamespaceAndOwner(ctx, name)
if err != nil {
return nil, err
}
found, _, err := s.sql.getDashboardStars(ctx, ns.OrgID, owner.Identifier)
if err != nil {
return nil, err
}
history, err := s.sql.getHistoryStars(ctx, ns.OrgID, owner.Identifier)
if err != nil {
return nil, err
}
if len(found) == 0 || len(found[0].Dashboards) == 0 {
return nil, apiserrors.NewNotFound(preferences.StarsResourceInfo.GroupResource(), name)
}
obj := asStarsResource(ns.Value, &found[0], history[owner.Identifier])
return &obj, nil
}
func getStars(stars *preferences.Stars, gk schema.GroupKind) []string {
if stars == nil || len(stars.Spec.Resource) == 0 {
return []string{}
}
for _, r := range stars.Spec.Resource {
if r.Group == gk.Group && r.Kind == gk.Kind {
return r.Names
}
}
return []string{}
}
// Create implements rest.Creater.
func (s *DashboardStarsStorage) write(ctx context.Context, obj *preferences.Stars) (runtime.Object, error) {
ns, owner, err := getNamespaceAndOwner(ctx, obj.Name)
if err != nil {
return nil, err
}
user, err := s.users.GetByUID(ctx, &user.GetUserByUIDQuery{
UID: owner.Identifier,
})
if err != nil {
return nil, err
}
if user.OrgID != ns.OrgID {
return nil, fmt.Errorf("namespace mismatch")
}
stars := getStars(obj, schema.GroupKind{Group: "dashboard.grafana.app", Kind: "Dashboard"})
if len(stars) == 0 {
err = s.stars.DeleteByUser(ctx, user.ID)
return &preferences.Stars{ObjectMeta: metav1.ObjectMeta{
Name: obj.Name,
Namespace: obj.Namespace,
DeletionTimestamp: ptr.To(metav1.Now()),
}}, err
}
current, _, err := s.sql.getDashboardStars(ctx, ns.OrgID, owner.Identifier)
if err != nil {
return nil, err
}
changed := false
now := time.Now()
randID := now.UnixNano() + rand.Int63n(5000)
previous := make(map[string]bool)
if len(current) > 0 {
for _, v := range current[0].Dashboards {
previous[v] = true
}
}
for _, dashboard := range stars {
if previous[dashboard] {
delete(previous, dashboard)
continue // nothing needed
}
err = s.stars.Add(ctx, &star.StarDashboardCommand{
UserID: user.ID,
OrgID: user.OrgID,
DashboardUID: dashboard,
DashboardID: randID,
Updated: now,
})
if err != nil {
return nil, err
}
changed = true
randID++
}
for k := range previous {
err = s.stars.Delete(ctx, &star.UnstarDashboardCommand{
UserID: user.ID,
OrgID: user.OrgID,
DashboardUID: k,
})
if err != nil {
return nil, err
}
changed = true
}
// Apply history stars
stars = getStars(obj, schema.GroupKind{Group: "history.grafana.app", Kind: "Query"})
res, err := s.sql.getHistoryStars(ctx, user.OrgID, user.UID)
if err != nil {
return nil, err
}
history := res[user.UID]
if !slices.Equal(stars, history) {
changed = true
if len(stars) == 0 {
err = s.sql.removeHistoryStar(ctx, user, nil)
if err != nil {
return nil, err
}
} else {
added, removed, _ := preferences.Changes(history, stars)
if len(removed) > 0 {
_ = s.sql.removeHistoryStar(ctx, user, nil)
}
for _, v := range added {
_ = s.sql.addHistoryStar(ctx, user, v) // one at a time so duplicates do not fail everything
}
}
}
if changed {
return s.Get(ctx, obj.Name, &metav1.GetOptions{})
}
return obj, nil // nothing required
}
// Create implements rest.Creater.
func (s *DashboardStarsStorage) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
stars, ok := obj.(*preferences.Stars)
if !ok {
return nil, fmt.Errorf("expected stars object")
}
return s.write(ctx, stars)
}
// Update implements rest.Updater.
func (s *DashboardStarsStorage) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
old, err := s.Get(ctx, name, &metav1.GetOptions{})
if err != nil {
return nil, false, err
}
obj, err := objInfo.UpdatedObject(ctx, old)
if err != nil {
return nil, false, err
}
stars, ok := obj.(*preferences.Stars)
if !ok {
return nil, false, fmt.Errorf("expected stars object")
}
obj, err = s.write(ctx, stars)
return obj, false, err
}
// Delete implements rest.GracefulDeleter.
func (s *DashboardStarsStorage) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
obj, err := s.write(ctx, &preferences.Stars{ObjectMeta: metav1.ObjectMeta{Name: name}})
if err != nil {
return nil, false, err
}
return obj, true, err
}
// DeleteCollection implements rest.CollectionDeleter.
func (s *DashboardStarsStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) {
return nil, fmt.Errorf("not implemented yet")
}
func asStarsResource(ns string, v *dashboardStars, history []string) preferences.Stars {
stars := preferences.Stars{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("user-%s", v.UserUID),
Namespace: ns,
ResourceVersion: strconv.FormatInt(v.Last, 10),
CreationTimestamp: metav1.NewTime(time.UnixMilli(v.First)),
},
Spec: preferences.StarsSpec{
Resource: []preferences.StarsResource{{
Group: dashboardsV1.APIGroup,
Kind: "Dashboard",
Names: v.Dashboards,
}},
},
}
if len(history) > 0 {
stars.Spec.Resource = append(stars.Spec.Resource, preferences.StarsResource{
Group: "history.grafana.app",
Kind: "Query",
Names: history,
})
}
stars.Spec.Normalize()
return stars
}
@@ -1,5 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM `grafana`.`star` as s
JOIN `grafana`.`user` as u ON s.user_id = u.id
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,6 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM `grafana`.`star` as s
JOIN `grafana`.`user` as u ON s.user_id = u.id
WHERE s.org_id = 3
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,7 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM `grafana`.`star` as s
JOIN `grafana`.`user` as u ON s.user_id = u.id
WHERE s.org_id = 3
AND u.uid = 'abc'
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1 +0,0 @@
SELECT MAX(updated) FROM `grafana`.`star`
@@ -1,6 +0,0 @@
SELECT s.query_uid, u.uid as user_uid
FROM `grafana`.`query_history_star` as s
JOIN `grafana`.`query_history` as h ON s.query_uid = h.uid
JOIN `grafana`.`user` as u ON s.user_id = u.id
WHERE s.org_id = 1
ORDER BY s.org_id asc, s.user_id asc, s.query_uid asc
@@ -1,3 +0,0 @@
DELETE FROM `grafana`.`query_history_star`
WHERE org_id = 1
AND user_id = 3
@@ -1,4 +0,0 @@
INSERT INTO `grafana`.`query_history_star`
( query_uid, user_id, org_id )
VALUES
( 'XXX', 3, 1 )
@@ -1,5 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,6 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 3
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,7 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 3
AND u.uid = 'abc'
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1 +0,0 @@
SELECT MAX(updated) FROM "grafana"."star"
@@ -1,6 +0,0 @@
SELECT s.query_uid, u.uid as user_uid
FROM "grafana"."query_history_star" as s
JOIN "grafana"."query_history" as h ON s.query_uid = h.uid
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 1
ORDER BY s.org_id asc, s.user_id asc, s.query_uid asc
@@ -1,3 +0,0 @@
DELETE FROM "grafana"."query_history_star"
WHERE org_id = 1
AND user_id = 3
@@ -1,4 +0,0 @@
INSERT INTO "grafana"."query_history_star"
( query_uid, user_id, org_id )
VALUES
( 'XXX', 3, 1 )
@@ -1,5 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,6 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 3
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1,7 +0,0 @@
SELECT s.org_id, u.uid as user_uid, s.dashboard_uid, s.updated
FROM "grafana"."star" as s
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 3
AND u.uid = 'abc'
ORDER BY
s.org_id asc, s.user_id asc, s.updated asc
@@ -1 +0,0 @@
SELECT MAX(updated) FROM "grafana"."star"
@@ -1,6 +0,0 @@
SELECT s.query_uid, u.uid as user_uid
FROM "grafana"."query_history_star" as s
JOIN "grafana"."query_history" as h ON s.query_uid = h.uid
JOIN "grafana"."user" as u ON s.user_id = u.id
WHERE s.org_id = 1
ORDER BY s.org_id asc, s.user_id asc, s.query_uid asc
@@ -1,3 +0,0 @@
DELETE FROM "grafana"."query_history_star"
WHERE org_id = 1
AND user_id = 3
@@ -1,4 +0,0 @@
INSERT INTO "grafana"."query_history_star"
( query_uid, user_id, org_id )
VALUES
( 'XXX', 3, 1 )