2015-02-24 11:46:34 +01:00
|
|
|
package migrations
|
|
|
|
|
|
2021-04-29 13:24:37 -04:00
|
|
|
import (
|
2023-10-24 10:04:45 +03:00
|
|
|
dashboardFolderMigrations "github.com/grafana/grafana/pkg/services/dashboards/database/migrations"
|
2023-05-25 15:38:30 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2021-11-11 14:02:53 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/accesscontrol"
|
2023-09-25 16:25:29 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/anonservice"
|
2023-10-04 10:37:27 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/signingkeys"
|
2023-11-08 10:50:01 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ssosettings"
|
2021-04-29 13:24:37 -04:00
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert"
|
|
|
|
|
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
|
|
|
)
|
2015-02-24 11:46:34 +01:00
|
|
|
|
|
|
|
|
// --- Migration Guide line ---
|
2021-05-06 16:29:29 +02:00
|
|
|
// 1. Never change a migration that is committed and pushed to main
|
2015-02-24 11:46:34 +01:00
|
|
|
// 2. Always add new migrations (to change or undo previous migrations)
|
2017-02-03 12:10:22 +01:00
|
|
|
// 3. Some migrations are not yet written (rename column, table, drop table, index etc)
|
2022-05-03 15:10:59 -08:00
|
|
|
// 4. Putting migrations behind feature flags is no longer recommended as broken
|
|
|
|
|
// migrations may not be caught by integration tests unless feature flags are
|
|
|
|
|
// specifically added
|
2015-02-24 11:46:34 +01:00
|
|
|
|
2021-08-25 15:11:22 +02:00
|
|
|
type OSSMigrations struct {
|
2024-01-28 15:22:45 -08:00
|
|
|
features featuremgmt.FeatureToggles
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-28 15:22:45 -08:00
|
|
|
func ProvideOSSMigrations(features featuremgmt.FeatureToggles) *OSSMigrations {
|
|
|
|
|
return &OSSMigrations{features}
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-28 15:22:45 -08:00
|
|
|
func (oss *OSSMigrations) AddMigration(mg *Migrator) {
|
2023-05-22 11:31:07 -07:00
|
|
|
mg.AddCreateMigration()
|
2015-02-24 11:46:34 +01:00
|
|
|
addUserMigrations(mg)
|
2015-07-16 17:59:11 +02:00
|
|
|
addTempUserMigrations(mg)
|
2015-02-24 11:46:34 +01:00
|
|
|
addStarMigrations(mg)
|
|
|
|
|
addOrgMigrations(mg)
|
2021-04-29 13:24:37 -04:00
|
|
|
addDashboardMigration(mg) // Do NOT add more migrations to this function.
|
2015-02-24 11:46:34 +01:00
|
|
|
addDataSourceMigration(mg)
|
|
|
|
|
addApiKeyMigrations(mg)
|
2015-03-21 08:53:16 -04:00
|
|
|
addDashboardSnapshotMigrations(mg)
|
2015-07-20 20:51:27 +08:00
|
|
|
addQuotaMigration(mg)
|
2016-01-10 21:37:11 +01:00
|
|
|
addAppSettingsMigration(mg)
|
2015-12-23 01:33:46 -06:00
|
|
|
addSessionMigration(mg)
|
2015-12-24 02:25:49 -08:00
|
|
|
addPlaylistMigrations(mg)
|
2016-03-04 01:29:46 -08:00
|
|
|
addPreferencesMigrations(mg)
|
2016-04-13 10:33:45 +02:00
|
|
|
addAlertMigrations(mg)
|
2016-08-01 10:07:00 +02:00
|
|
|
addAnnotationMig(mg)
|
2017-03-30 18:03:50 +02:00
|
|
|
addTestDataMigrations(mg)
|
History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
version, along with a dashboard version model and structs to represent
the queries and commands necessary for the dashboard version API
methods.
- API endpoints were created to support working with dashboard
versions.
- Methods were added to create, update, read, and destroy dashboard
versions in the database.
- Logic was added to compute the diff between two versions, and
display it to the user.
- The dashboard migration logic was updated to save a "Version
1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
are `version`, `created`, `created_by`, `message`. Default
is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
"dashboardId": <int>,
"version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
was added and vendored.
2017-05-24 19:14:39 -04:00
|
|
|
addDashboardVersionMigration(mg)
|
2017-12-08 18:25:45 +03:00
|
|
|
addTeamMigrations(mg)
|
2022-07-18 15:14:58 +02:00
|
|
|
addDashboardACLMigrations(mg) // Do NOT add more migrations to this function.
|
2017-10-07 10:31:39 +02:00
|
|
|
addTagMigration(mg)
|
2018-01-26 10:41:41 +01:00
|
|
|
addLoginAttemptMigrations(mg)
|
2018-02-08 17:13:58 -05:00
|
|
|
addUserAuthMigrations(mg)
|
2018-12-13 09:52:13 +01:00
|
|
|
addServerlockMigrations(mg)
|
2019-01-15 15:15:17 +01:00
|
|
|
addUserAuthTokenMigrations(mg)
|
2019-02-14 23:13:46 +01:00
|
|
|
addCacheMigration(mg)
|
2020-10-14 06:48:48 -04:00
|
|
|
addShortURLMigrations(mg)
|
2021-05-12 14:39:48 -04:00
|
|
|
ualert.AddTablesMigrations(mg)
|
2021-05-24 06:11:01 +02:00
|
|
|
addLibraryElementsMigrations(mg)
|
2021-12-23 09:43:53 -08:00
|
|
|
|
2023-10-12 13:43:10 +01:00
|
|
|
ualert.FixEarlyMigration(mg)
|
2021-10-01 15:39:57 +03:00
|
|
|
addSecretsMigration(mg)
|
2021-08-31 11:05:45 -04:00
|
|
|
addKVStoreMigrations(mg)
|
2021-10-04 16:33:55 +01:00
|
|
|
ualert.AddDashboardUIDPanelIDMigration(mg)
|
2021-11-11 14:02:53 +01:00
|
|
|
accesscontrol.AddMigration(mg)
|
2022-01-28 17:55:09 +01:00
|
|
|
addQueryHistoryMigrations(mg)
|
2022-02-01 14:57:26 +01:00
|
|
|
|
2023-04-19 16:34:19 +01:00
|
|
|
accesscontrol.AddDisabledMigrator(mg)
|
2022-05-26 11:21:02 +00:00
|
|
|
accesscontrol.AddTeamMembershipMigrations(mg)
|
|
|
|
|
accesscontrol.AddDashboardPermissionsMigrator(mg)
|
|
|
|
|
accesscontrol.AddAlertingPermissionsMigrator(mg)
|
|
|
|
|
|
2022-02-23 17:03:04 +01:00
|
|
|
addQueryHistoryStarMigrations(mg)
|
2022-02-22 10:47:42 +03:00
|
|
|
|
2022-07-25 15:19:07 +01:00
|
|
|
addCorrelationsMigrations(mg)
|
|
|
|
|
|
2022-04-27 12:29:39 +04:00
|
|
|
addEntityEventsTableMigration(mg)
|
2022-05-03 15:08:40 -08:00
|
|
|
|
|
|
|
|
addPublicDashboardMigration(mg)
|
2022-05-16 10:26:40 -07:00
|
|
|
addDbFileStorageMigration(mg)
|
2022-05-23 14:50:10 +00:00
|
|
|
|
2022-06-08 19:33:32 +02:00
|
|
|
accesscontrol.AddManagedPermissionsMigration(mg, accesscontrol.ManagedPermissionsMigrationID)
|
2022-06-01 15:29:37 +02:00
|
|
|
accesscontrol.AddManagedFolderAlertActionsMigration(mg)
|
2022-06-02 13:14:48 +01:00
|
|
|
accesscontrol.AddActionNameMigrator(mg)
|
2022-06-14 15:32:52 -04:00
|
|
|
addPlaylistUIDMigration(mg)
|
2022-06-22 10:52:46 -04:00
|
|
|
|
|
|
|
|
ualert.UpdateRuleGroupIndexMigration(mg)
|
2022-07-14 17:01:21 +01:00
|
|
|
accesscontrol.AddManagedFolderAlertActionsRepeatMigration(mg)
|
2022-09-20 18:31:08 +01:00
|
|
|
accesscontrol.AddAdminOnlyMigration(mg)
|
2022-10-12 15:18:07 +02:00
|
|
|
accesscontrol.AddSeedAssignmentMigrations(mg)
|
2022-11-03 08:57:20 +00:00
|
|
|
accesscontrol.AddManagedFolderAlertActionsRepeatFixedMigration(mg)
|
2023-10-12 00:30:50 +01:00
|
|
|
accesscontrol.AddManagedFolderLibraryPanelActionsMigration(mg)
|
2022-10-26 10:15:14 -04:00
|
|
|
|
2022-11-10 16:34:13 +01:00
|
|
|
AddExternalAlertmanagerToDatasourceMigration(mg)
|
|
|
|
|
|
2023-01-30 12:17:40 +02:00
|
|
|
addFolderMigrations(mg)
|
2023-09-25 16:25:29 +02:00
|
|
|
|
|
|
|
|
anonservice.AddMigration(mg)
|
2023-10-04 10:37:27 +02:00
|
|
|
signingkeys.AddMigration(mg)
|
2023-10-12 13:43:10 +01:00
|
|
|
|
|
|
|
|
ualert.MigrationServiceMigration(mg)
|
|
|
|
|
ualert.CreatedFoldersMigration(mg)
|
2023-10-24 10:04:45 +03:00
|
|
|
|
|
|
|
|
dashboardFolderMigrations.AddDashboardFolderMigrations(mg)
|
2023-11-08 10:50:01 +01:00
|
|
|
|
|
|
|
|
ssosettings.AddMigration(mg)
|
2023-11-30 10:25:59 -05:00
|
|
|
|
|
|
|
|
ualert.CreateOrgMigratedKVStoreEntries(mg)
|
2024-01-11 15:51:36 -05:00
|
|
|
|
2024-01-26 17:17:29 +00:00
|
|
|
// https://github.com/grafana/identity-access-team/issues/546: tracks removal of the feature toggle from the annotation permission migration
|
2024-01-28 15:22:45 -08:00
|
|
|
if oss.features != nil && oss.features.IsEnabledGlobally(featuremgmt.FlagAnnotationPermissionUpdate) {
|
|
|
|
|
accesscontrol.AddManagedDashboardAnnotationActionsMigration(mg)
|
2024-01-26 17:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-12 15:44:10 +01:00
|
|
|
addCloudMigrationsMigrations(mg)
|
|
|
|
|
|
2024-01-11 15:51:36 -05:00
|
|
|
addKVStoreMySQLValueTypeLongTextMigration(mg)
|
2024-02-15 09:45:10 -05:00
|
|
|
|
|
|
|
|
ualert.AddRuleNotificationSettingsColumns(mg)
|
2024-02-16 11:52:43 +00:00
|
|
|
|
|
|
|
|
accesscontrol.AddAlertingScopeRemovalMigration(mg)
|
2024-04-12 12:37:34 -04:00
|
|
|
|
|
|
|
|
accesscontrol.AddManagedFolderAlertingSilencesActionsMigrator(mg)
|
2015-02-24 11:46:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addStarMigrations(mg *Migrator) {
|
2015-02-24 18:32:29 +01:00
|
|
|
starV1 := Table{
|
|
|
|
|
Name: "star",
|
|
|
|
|
Columns: []*Column{
|
2015-03-07 16:23:22 +01:00
|
|
|
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
|
|
|
|
{Name: "user_id", Type: DB_BigInt, Nullable: false},
|
|
|
|
|
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
|
2015-02-24 18:32:29 +01:00
|
|
|
},
|
|
|
|
|
Indices: []*Index{
|
2015-03-07 16:23:22 +01:00
|
|
|
{Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
|
2015-02-24 18:32:29 +01:00
|
|
|
},
|
|
|
|
|
}
|
2015-02-24 11:46:34 +01:00
|
|
|
|
2015-02-24 18:32:29 +01:00
|
|
|
mg.AddMigration("create star table", NewAddTableMigration(starV1))
|
|
|
|
|
mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
|
2015-02-24 11:46:34 +01:00
|
|
|
}
|