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

pull/8569/head
Torkel Ödegaard 9 years ago
parent 5409f4c0eb
commit 7b5f7ed553
  1. 3
      pkg/api/dashboard.go
  2. 1
      pkg/services/sqlstore/dashboard.go
  3. 8
      pkg/services/sqlstore/dashboard_version.go
  4. 7
      pkg/services/sqlstore/migrations/dashboard_version_mig.go
  5. 2
      public/app/core/nav_model_srv.ts
  6. 2
      public/app/features/dashboard/history/history.html

@ -64,6 +64,9 @@ func GetDashboard(c *middleware.Context) {
creator = getUserLogin(dash.CreatedBy)
}
// make sure db version is in sync with json model version
dash.Data.Set("version", dash.Version)
dto := dtos.DashboardFullWithMeta{
Dashboard: dash.Data,
Meta: dtos.DashboardMeta{

@ -74,6 +74,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
affectedRows := int64(0)
if dash.Id == 0 {
dash.Version = 1
metrics.M_Models_Dashboard_Insert.Inc(1)
dash.Data.Set("version", dash.Version)
affectedRows, err = sess.Insert(dash)

@ -33,10 +33,10 @@ func GetDashboardVersions(query *m.GetDashboardVersionsQuery) error {
dashboard_version.created,
dashboard_version.created_by as created_by_id,
dashboard_version.message,
dashboard_version.data,
"user".login as created_by`).
Join("LEFT", "user", `dashboard_version.created_by = "user".id`).
Join("LEFT", "dashboard", `dashboard.id = "dashboard_version".dashboard_id`).
dashboard_version.data,`+
dialect.Quote("user")+`.login as created_by`).
Join("LEFT", "user", `dashboard_version.created_by = `+dialect.Quote("user")+`.id`).
Join("LEFT", "dashboard", `dashboard.id = dashboard_version.dashboard_id`).
Where("dashboard_version.dashboard_id=? AND dashboard.org_id=?", query.DashboardId, query.OrgId).
OrderBy("dashboard_version.version DESC").
Limit(query.Limit, query.Start).

@ -26,6 +26,13 @@ func addDashboardVersionMigration(mg *Migrator) {
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]))
// 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
(
dashboard_id,

@ -168,7 +168,7 @@ export class NavModelSrv {
});
menu.push({
title: 'Version History',
title: 'Version history',
icon: 'fa fa-fw fa-history',
clickHandler: () => dashNavCtrl.openEditView('history')
});

@ -1,6 +1,6 @@
<div class="tabbed-view-header">
<h2 class="tabbed-view-title">
Version History
Version history
</h2>
<ul class="gf-tabs">

Loading…
Cancel
Save