Commit 7b5f7ed5 by Torkel Ödegaard

dashboard_history: SQL did not work when using MySQL, fixes to dashboard version…

dashboard_history: SQL did not work when using MySQL, fixes to dashboard version numbering, so inserts start at 1, added migration to fix old dashboards with version 0
parent 5409f4c0
...@@ -64,6 +64,9 @@ func GetDashboard(c *middleware.Context) { ...@@ -64,6 +64,9 @@ func GetDashboard(c *middleware.Context) {
creator = getUserLogin(dash.CreatedBy) creator = getUserLogin(dash.CreatedBy)
} }
// make sure db version is in sync with json model version
dash.Data.Set("version", dash.Version)
dto := dtos.DashboardFullWithMeta{ dto := dtos.DashboardFullWithMeta{
Dashboard: dash.Data, Dashboard: dash.Data,
Meta: dtos.DashboardMeta{ Meta: dtos.DashboardMeta{
......
...@@ -74,6 +74,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error { ...@@ -74,6 +74,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
affectedRows := int64(0) affectedRows := int64(0)
if dash.Id == 0 { if dash.Id == 0 {
dash.Version = 1
metrics.M_Models_Dashboard_Insert.Inc(1) metrics.M_Models_Dashboard_Insert.Inc(1)
dash.Data.Set("version", dash.Version) dash.Data.Set("version", dash.Version)
affectedRows, err = sess.Insert(dash) affectedRows, err = sess.Insert(dash)
......
...@@ -33,10 +33,10 @@ func GetDashboardVersions(query *m.GetDashboardVersionsQuery) error { ...@@ -33,10 +33,10 @@ func GetDashboardVersions(query *m.GetDashboardVersionsQuery) error {
dashboard_version.created, dashboard_version.created,
dashboard_version.created_by as created_by_id, dashboard_version.created_by as created_by_id,
dashboard_version.message, dashboard_version.message,
dashboard_version.data, dashboard_version.data,`+
"user".login as created_by`). dialect.Quote("user")+`.login as created_by`).
Join("LEFT", "user", `dashboard_version.created_by = "user".id`). Join("LEFT", "user", `dashboard_version.created_by = `+dialect.Quote("user")+`.id`).
Join("LEFT", "dashboard", `dashboard.id = "dashboard_version".dashboard_id`). Join("LEFT", "dashboard", `dashboard.id = dashboard_version.dashboard_id`).
Where("dashboard_version.dashboard_id=? AND dashboard.org_id=?", query.DashboardId, query.OrgId). Where("dashboard_version.dashboard_id=? AND dashboard.org_id=?", query.DashboardId, query.OrgId).
OrderBy("dashboard_version.version DESC"). OrderBy("dashboard_version.version DESC").
Limit(query.Limit, query.Start). Limit(query.Limit, query.Start).
......
...@@ -26,6 +26,13 @@ func addDashboardVersionMigration(mg *Migrator) { ...@@ -26,6 +26,13 @@ func addDashboardVersionMigration(mg *Migrator) {
mg.AddMigration("add index dashboard_version.dashboard_id", NewAddIndexMigration(dashboardVersionV1, dashboardVersionV1.Indices[0])) mg.AddMigration("add index dashboard_version.dashboard_id", NewAddIndexMigration(dashboardVersionV1, dashboardVersionV1.Indices[0]))
mg.AddMigration("add unique index dashboard_version.dashboard_id and dashboard_version.version", NewAddIndexMigration(dashboardVersionV1, dashboardVersionV1.Indices[1])) mg.AddMigration("add unique index dashboard_version.dashboard_id and dashboard_version.version", NewAddIndexMigration(dashboardVersionV1, dashboardVersionV1.Indices[1]))
// before new dashboards where created with version 0, now they are always inserted with version 1
const setVersionTo1WhereZeroSQL = `UPDATE dashboard SET version = 1 WHERE version = 0`
mg.AddMigration("Set dashboard version to 1 where 0", new(RawSqlMigration).
Sqlite(setVersionTo1WhereZeroSQL).
Postgres(setVersionTo1WhereZeroSQL).
Mysql(setVersionTo1WhereZeroSQL))
const rawSQL = `INSERT INTO dashboard_version const rawSQL = `INSERT INTO dashboard_version
( (
dashboard_id, dashboard_id,
......
...@@ -168,7 +168,7 @@ export class NavModelSrv { ...@@ -168,7 +168,7 @@ export class NavModelSrv {
}); });
menu.push({ menu.push({
title: 'Version History', title: 'Version history',
icon: 'fa fa-fw fa-history', icon: 'fa fa-fw fa-history',
clickHandler: () => dashNavCtrl.openEditView('history') clickHandler: () => dashNavCtrl.openEditView('history')
}); });
......
<div class="tabbed-view-header"> <div class="tabbed-view-header">
<h2 class="tabbed-view-title"> <h2 class="tabbed-view-title">
Version History Version history
</h2> </h2>
<ul class="gf-tabs"> <ul class="gf-tabs">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment