mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
move database-specific code into dialects (#11884)
This commit is contained in:
committed by
Torkel Ödegaard
parent
27e1c67453
commit
1dfff74da9
@@ -86,10 +86,7 @@ func addAnnotationMig(mg *Migrator) {
|
||||
// clear alert text
|
||||
//
|
||||
updateTextFieldSql := "UPDATE annotation SET TEXT = '' WHERE alert_id > 0"
|
||||
mg.AddMigration("Update alert annotations and set TEXT to empty", new(RawSqlMigration).
|
||||
Sqlite(updateTextFieldSql).
|
||||
Postgres(updateTextFieldSql).
|
||||
Mysql(updateTextFieldSql))
|
||||
mg.AddMigration("Update alert annotations and set TEXT to empty", NewRawSqlMigration(updateTextFieldSql))
|
||||
|
||||
//
|
||||
// Add a 'created' & 'updated' column
|
||||
@@ -111,8 +108,5 @@ func addAnnotationMig(mg *Migrator) {
|
||||
// Convert epoch saved as seconds to miliseconds
|
||||
//
|
||||
updateEpochSql := "UPDATE annotation SET epoch = (epoch*1000) where epoch < 9999999999"
|
||||
mg.AddMigration("Convert existing annotations from seconds to milliseconds", new(RawSqlMigration).
|
||||
Sqlite(updateEpochSql).
|
||||
Postgres(updateEpochSql).
|
||||
Mysql(updateEpochSql))
|
||||
mg.AddMigration("Convert existing annotations from seconds to milliseconds", NewRawSqlMigration(updateEpochSql))
|
||||
}
|
||||
|
||||
@@ -45,8 +45,5 @@ INSERT INTO dashboard_acl
|
||||
(-1,-1, 2,'Editor','2017-06-20','2017-06-20')
|
||||
`
|
||||
|
||||
mg.AddMigration("save default acl rules in dashboard_acl table", new(RawSqlMigration).
|
||||
Sqlite(rawSQL).
|
||||
Postgres(rawSQL).
|
||||
Mysql(rawSQL))
|
||||
mg.AddMigration("save default acl rules in dashboard_acl table", NewRawSqlMigration(rawSQL))
|
||||
}
|
||||
|
||||
@@ -90,9 +90,7 @@ func addDashboardMigration(mg *Migrator) {
|
||||
mg.AddMigration("drop table dashboard_v1", NewDropTableMigration("dashboard_v1"))
|
||||
|
||||
// change column type of dashboard.data
|
||||
mg.AddMigration("alter dashboard.data to mediumtext v1", new(RawSqlMigration).
|
||||
Sqlite("SELECT 0 WHERE 0;").
|
||||
Postgres("SELECT 0;").
|
||||
mg.AddMigration("alter dashboard.data to mediumtext v1", NewRawSqlMigration("").
|
||||
Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;"))
|
||||
|
||||
// add column to store updater of a dashboard
|
||||
@@ -157,7 +155,7 @@ func addDashboardMigration(mg *Migrator) {
|
||||
Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true,
|
||||
}))
|
||||
|
||||
mg.AddMigration("Update uid column values in dashboard", new(RawSqlMigration).
|
||||
mg.AddMigration("Update uid column values in dashboard", NewRawSqlMigration("").
|
||||
Sqlite("UPDATE dashboard SET uid=printf('%09d',id) WHERE uid IS NULL;").
|
||||
Postgres("UPDATE dashboard SET uid=lpad('' || id,9,'0') WHERE uid IS NULL;").
|
||||
Mysql("UPDATE dashboard SET uid=lpad(id,9,'0') WHERE uid IS NULL;"))
|
||||
|
||||
@@ -50,9 +50,7 @@ func addDashboardSnapshotMigrations(mg *Migrator) {
|
||||
addTableIndicesMigrations(mg, "v5", snapshotV5)
|
||||
|
||||
// change column type of dashboard
|
||||
mg.AddMigration("alter dashboard_snapshot to mediumtext v2", new(RawSqlMigration).
|
||||
Sqlite("SELECT 0 WHERE 0;").
|
||||
Postgres("SELECT 0;").
|
||||
mg.AddMigration("alter dashboard_snapshot to mediumtext v2", NewRawSqlMigration("").
|
||||
Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;"))
|
||||
|
||||
mg.AddMigration("Update dashboard_snapshot table charset", NewTableCharsetMigration("dashboard_snapshot", []*Column{
|
||||
|
||||
@@ -28,10 +28,7 @@ func addDashboardVersionMigration(mg *Migrator) {
|
||||
|
||||
// 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))
|
||||
mg.AddMigration("Set dashboard version to 1 where 0", NewRawSqlMigration(setVersionTo1WhereZeroSQL))
|
||||
|
||||
const rawSQL = `INSERT INTO dashboard_version
|
||||
(
|
||||
@@ -54,14 +51,9 @@ SELECT
|
||||
'',
|
||||
dashboard.data
|
||||
FROM dashboard;`
|
||||
mg.AddMigration("save existing dashboard data in dashboard_version table v1", new(RawSqlMigration).
|
||||
Sqlite(rawSQL).
|
||||
Postgres(rawSQL).
|
||||
Mysql(rawSQL))
|
||||
mg.AddMigration("save existing dashboard data in dashboard_version table v1", NewRawSqlMigration(rawSQL))
|
||||
|
||||
// change column type of dashboard_version.data
|
||||
mg.AddMigration("alter dashboard_version.data to mediumtext v1", new(RawSqlMigration).
|
||||
Sqlite("SELECT 0 WHERE 0;").
|
||||
Postgres("SELECT 0;").
|
||||
mg.AddMigration("alter dashboard_version.data to mediumtext v1", NewRawSqlMigration("").
|
||||
Mysql("ALTER TABLE dashboard_version MODIFY data MEDIUMTEXT;"))
|
||||
}
|
||||
|
||||
@@ -122,10 +122,7 @@ func addDataSourceMigration(mg *Migrator) {
|
||||
}))
|
||||
|
||||
const setVersionToOneWhereZero = `UPDATE data_source SET version = 1 WHERE version = 0`
|
||||
mg.AddMigration("Update initial version to 1", new(RawSqlMigration).
|
||||
Sqlite(setVersionToOneWhereZero).
|
||||
Postgres(setVersionToOneWhereZero).
|
||||
Mysql(setVersionToOneWhereZero))
|
||||
mg.AddMigration("Update initial version to 1", NewRawSqlMigration(setVersionToOneWhereZero))
|
||||
|
||||
mg.AddMigration("Add read_only data column", NewAddColumnMigration(tableV2, &Column{
|
||||
Name: "read_only", Type: DB_Bool, Nullable: true,
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestMigrations(t *testing.T) {
|
||||
x, err := xorm.NewEngine(testDB.DriverName, testDB.ConnStr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
sqlutil.CleanDB(x)
|
||||
NewDialect(x).CleanDB()
|
||||
|
||||
_, err = x.SQL(sql).Get(&r)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
@@ -85,8 +85,5 @@ func addOrgMigrations(mg *Migrator) {
|
||||
}))
|
||||
|
||||
const migrateReadOnlyViewersToViewers = `UPDATE org_user SET role = 'Viewer' WHERE role = 'Read Only Editor'`
|
||||
mg.AddMigration("Migrate all Read Only Viewers to Viewers", new(RawSqlMigration).
|
||||
Sqlite(migrateReadOnlyViewersToViewers).
|
||||
Postgres(migrateReadOnlyViewersToViewers).
|
||||
Mysql(migrateReadOnlyViewersToViewers))
|
||||
mg.AddMigration("Migrate all Read Only Viewers to Viewers", NewRawSqlMigration(migrateReadOnlyViewersToViewers))
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ func addUserAuthMigrations(mg *Migrator) {
|
||||
// add indices
|
||||
addTableIndicesMigrations(mg, "v1", userAuthV1)
|
||||
|
||||
mg.AddMigration("alter user_auth.auth_id to length 190", new(RawSqlMigration).
|
||||
Sqlite("SELECT 0 WHERE 0;").
|
||||
mg.AddMigration("alter user_auth.auth_id to length 190", NewRawSqlMigration("").
|
||||
Postgres("ALTER TABLE user_auth ALTER COLUMN auth_id TYPE VARCHAR(190);").
|
||||
Mysql("ALTER TABLE user_auth MODIFY auth_id VARCHAR(190);"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user