mirror of
https://github.com/grafana/grafana.git
synced 2025-01-18 20:43:26 -06:00
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
This commit is contained in:
parent
5409f4c0eb
commit
7b5f7ed553
@ -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…
Reference in New Issue
Block a user