Dashboards: Add apiVersion to dashboard table (#100845)
This commit is contained in:
@@ -486,6 +486,7 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
CreatedBy: dash.UpdatedBy,
|
||||
Message: cmd.Message,
|
||||
Data: dash.Data,
|
||||
APIVersion: cmd.APIVersion,
|
||||
}
|
||||
|
||||
// insert version entry
|
||||
|
||||
@@ -26,13 +26,14 @@ const (
|
||||
|
||||
// Dashboard model
|
||||
type Dashboard struct {
|
||||
ID int64 `xorm:"pk autoincr 'id'"`
|
||||
UID string `xorm:"uid"`
|
||||
Slug string
|
||||
OrgID int64 `xorm:"org_id"`
|
||||
GnetID int64 `xorm:"gnet_id"`
|
||||
Version int
|
||||
PluginID string `xorm:"plugin_id"`
|
||||
ID int64 `xorm:"pk autoincr 'id'"`
|
||||
UID string `xorm:"uid"`
|
||||
Slug string
|
||||
OrgID int64 `xorm:"org_id"`
|
||||
GnetID int64 `xorm:"gnet_id"`
|
||||
Version int
|
||||
PluginID string `xorm:"plugin_id"`
|
||||
APIVersion string `xorm:"api_version"`
|
||||
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
@@ -138,6 +139,7 @@ func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
|
||||
dash.OrgID = cmd.OrgID
|
||||
dash.PluginID = cmd.PluginID
|
||||
dash.IsFolder = cmd.IsFolder
|
||||
dash.APIVersion = cmd.APIVersion
|
||||
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.Dashboard).Inc()
|
||||
// nolint:staticcheck
|
||||
dash.FolderID = cmd.FolderID
|
||||
@@ -202,6 +204,8 @@ type SaveDashboardCommand struct {
|
||||
OrgID int64 `json:"-" xorm:"org_id"`
|
||||
RestoredFrom int `json:"-"`
|
||||
PluginID string `json:"-" xorm:"plugin_id"`
|
||||
APIVersion string `json:"-" xorm:"api_version"`
|
||||
|
||||
// Deprecated: use FolderUID instead
|
||||
FolderID int64 `json:"folderId" xorm:"folder_id"`
|
||||
FolderUID string `json:"folderUid" xorm:"folder_uid"`
|
||||
|
||||
@@ -1787,13 +1787,13 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex
|
||||
switch query.Type {
|
||||
case "":
|
||||
// When no type specified, search for dashboards
|
||||
request.Options.Key, err = resource.AsResourceKey(namespace, dashboard.DASHBOARD_RESOURCE)
|
||||
request.Options.Key, err = resource.AsResourceKey(namespace, dashboardv0alpha1.DASHBOARD_RESOURCE)
|
||||
// Currently a search query is across folders and dashboards
|
||||
if err == nil {
|
||||
federate, err = resource.AsResourceKey(namespace, folderv0alpha1.RESOURCE)
|
||||
}
|
||||
case searchstore.TypeDashboard, searchstore.TypeAnnotation:
|
||||
request.Options.Key, err = resource.AsResourceKey(namespace, dashboard.DASHBOARD_RESOURCE)
|
||||
request.Options.Key, err = resource.AsResourceKey(namespace, dashboardv0alpha1.DASHBOARD_RESOURCE)
|
||||
case searchstore.TypeFolder, searchstore.TypeAlertFolder:
|
||||
request.Options.Key, err = resource.AsResourceKey(namespace, folderv0alpha1.RESOURCE)
|
||||
default:
|
||||
@@ -1954,13 +1954,14 @@ func (dr *DashboardServiceImpl) UnstructuredToLegacyDashboard(ctx context.Contex
|
||||
}
|
||||
|
||||
out := dashboards.Dashboard{
|
||||
OrgID: orgID,
|
||||
ID: obj.GetDeprecatedInternalID(), // nolint:staticcheck
|
||||
UID: uid,
|
||||
Slug: obj.GetSlug(),
|
||||
FolderUID: obj.GetFolder(),
|
||||
Version: dashVersion,
|
||||
Data: simplejson.NewFromAny(spec),
|
||||
OrgID: orgID,
|
||||
ID: obj.GetDeprecatedInternalID(), // nolint:staticcheck
|
||||
UID: uid,
|
||||
Slug: obj.GetSlug(),
|
||||
FolderUID: obj.GetFolder(),
|
||||
Version: dashVersion,
|
||||
Data: simplejson.NewFromAny(spec),
|
||||
APIVersion: strings.TrimPrefix(item.GetAPIVersion(), dashboardv0alpha1.GROUP+"/"),
|
||||
}
|
||||
|
||||
out.Created = obj.GetCreationTimestamp().Time
|
||||
|
||||
@@ -17,11 +17,12 @@ var (
|
||||
// fixtures that insert DashboardVersions directly into a database which must be
|
||||
// refactored first.
|
||||
type DashboardVersion struct {
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'" db:"id"`
|
||||
DashboardID int64 `json:"dashboardId" xorm:"dashboard_id" db:"dashboard_id"`
|
||||
ParentVersion int `json:"parentVersion" db:"parent_version"`
|
||||
RestoredFrom int `json:"restoredFrom" db:"restored_from"`
|
||||
Version int `json:"version" db:"version"`
|
||||
ID int64 `json:"id" xorm:"pk autoincr 'id'" db:"id"`
|
||||
DashboardID int64 `json:"dashboardId" xorm:"dashboard_id" db:"dashboard_id"`
|
||||
ParentVersion int `json:"parentVersion" db:"parent_version"`
|
||||
RestoredFrom int `json:"restoredFrom" db:"restored_from"`
|
||||
Version int `json:"version" db:"version"`
|
||||
APIVersion string `json:"apiVersion" xorm:"api_version" db:"api_version"`
|
||||
|
||||
Created time.Time `json:"created" db:"created"`
|
||||
CreatedBy int64 `json:"createdBy" db:"created_by"`
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apis/dashboard"
|
||||
dashboard "github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
|
||||
@@ -3,8 +3,9 @@ package migrations
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"xorm.io/xorm"
|
||||
|
||||
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
)
|
||||
|
||||
func addDashboardMigration(mg *Migrator) {
|
||||
@@ -256,6 +257,10 @@ func addDashboardMigration(mg *Migrator) {
|
||||
}))
|
||||
|
||||
mg.AddMigration("Add missing dashboard_uid and org_id to dashboard_tag", &FillDashbordUIDAndOrgIDMigration{})
|
||||
|
||||
mg.AddMigration("Add apiVersion for dashboard", NewAddColumnMigration(dashboardV2, &Column{
|
||||
Name: "api_version", Type: DB_Varchar, Length: 16, Nullable: true,
|
||||
}))
|
||||
}
|
||||
|
||||
type FillDashbordUIDAndOrgIDMigration struct {
|
||||
|
||||
@@ -56,4 +56,8 @@ FROM dashboard;`
|
||||
// change column type of dashboard_version.data
|
||||
mg.AddMigration("alter dashboard_version.data to mediumtext v1", NewRawSQLMigration("").
|
||||
Mysql("ALTER TABLE dashboard_version MODIFY data MEDIUMTEXT;"))
|
||||
|
||||
mg.AddMigration("Add apiVersion for dashboard_version", NewAddColumnMigration(dashboardVersionV1, &Column{
|
||||
Name: "api_version", Type: DB_Varchar, Length: 16, Nullable: true,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user