Chore: Fix SQL related Go variable naming (#28887)
* Chore: Fix variable naming Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -155,8 +155,8 @@ func addAlertMigrations(mg *Migrator) {
|
||||
Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true,
|
||||
}))
|
||||
|
||||
mg.AddMigration("Update uid column values in alert_notification", new(RawSqlMigration).
|
||||
Sqlite("UPDATE alert_notification SET uid=printf('%09d',id) WHERE uid IS NULL;").
|
||||
mg.AddMigration("Update uid column values in alert_notification", new(RawSQLMigration).
|
||||
SQLite("UPDATE alert_notification SET uid=printf('%09d',id) WHERE uid IS NULL;").
|
||||
Postgres("UPDATE alert_notification SET uid=lpad('' || id::text,9,'0') WHERE uid IS NULL;").
|
||||
Mysql("UPDATE alert_notification SET uid=lpad(id,9,'0') WHERE uid IS NULL;"))
|
||||
|
||||
@@ -173,7 +173,7 @@ func addAlertMigrations(mg *Migrator) {
|
||||
}))
|
||||
|
||||
// change column type of alert.settings
|
||||
mg.AddMigration("alter alert.settings to mediumtext", NewRawSqlMigration("").
|
||||
mg.AddMigration("alter alert.settings to mediumtext", NewRawSQLMigration("").
|
||||
Mysql("ALTER TABLE alert MODIFY settings MEDIUMTEXT;"))
|
||||
|
||||
mg.AddMigration("Add non-unique index alert_notification_state_alert_id", NewAddIndexMigration(alert_notification_state, &Index{
|
||||
|
||||
@@ -85,8 +85,8 @@ 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", NewRawSqlMigration(updateTextFieldSql))
|
||||
updateTextFieldSQL := "UPDATE annotation SET TEXT = '' WHERE alert_id > 0"
|
||||
mg.AddMigration("Update alert annotations and set TEXT to empty", NewRawSQLMigration(updateTextFieldSQL))
|
||||
|
||||
//
|
||||
// Add a 'created' & 'updated' column
|
||||
@@ -107,8 +107,8 @@ func addAnnotationMig(mg *Migrator) {
|
||||
//
|
||||
// Convert epoch saved as seconds to milliseconds
|
||||
//
|
||||
updateEpochSql := "UPDATE annotation SET epoch = (epoch*1000) where epoch < 9999999999"
|
||||
mg.AddMigration("Convert existing annotations from seconds to milliseconds", NewRawSqlMigration(updateEpochSql))
|
||||
updateEpochSQL := "UPDATE annotation SET epoch = (epoch*1000) where epoch < 9999999999"
|
||||
mg.AddMigration("Convert existing annotations from seconds to milliseconds", NewRawSQLMigration(updateEpochSQL))
|
||||
|
||||
//
|
||||
// 6.4: Make Regions a single annotation row
|
||||
@@ -119,7 +119,7 @@ func addAnnotationMig(mg *Migrator) {
|
||||
mg.AddMigration("Add index for epoch_end", NewAddIndexMigration(table, &Index{
|
||||
Cols: []string{"org_id", "epoch", "epoch_end"}, Type: IndexType,
|
||||
}))
|
||||
mg.AddMigration("Make epoch_end the same as epoch", NewRawSqlMigration("UPDATE annotation SET epoch_end = epoch"))
|
||||
mg.AddMigration("Make epoch_end the same as epoch", NewRawSQLMigration("UPDATE annotation SET epoch_end = epoch"))
|
||||
mg.AddMigration("Move region to single row", &AddMakeRegionSingleRowMigration{})
|
||||
|
||||
//
|
||||
@@ -154,7 +154,7 @@ type AddMakeRegionSingleRowMigration struct {
|
||||
MigrationBase
|
||||
}
|
||||
|
||||
func (m *AddMakeRegionSingleRowMigration) Sql(dialect Dialect) string {
|
||||
func (m *AddMakeRegionSingleRowMigration) SQL(dialect Dialect) string {
|
||||
return "code migration"
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ INSERT INTO dashboard_acl
|
||||
(-1,-1, 2,'Editor','2017-06-20','2017-06-20')
|
||||
`
|
||||
|
||||
mg.AddMigration("save default acl rules in dashboard_acl table", NewRawSqlMigration(rawSQL))
|
||||
mg.AddMigration("save default acl rules in dashboard_acl table", NewRawSQLMigration(rawSQL))
|
||||
|
||||
mg.AddMigration("delete acl rules for deleted dashboards and folders", NewRawSqlMigration(
|
||||
mg.AddMigration("delete acl rules for deleted dashboards and folders", NewRawSQLMigration(
|
||||
"DELETE FROM dashboard_acl WHERE dashboard_id NOT IN (SELECT id FROM dashboard) AND dashboard_id != -1"))
|
||||
}
|
||||
|
||||
@@ -90,7 +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", NewRawSqlMigration("").
|
||||
mg.AddMigration("alter dashboard.data to mediumtext v1", NewRawSQLMigration("").
|
||||
Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;"))
|
||||
|
||||
// add column to store updater of a dashboard
|
||||
@@ -155,8 +155,8 @@ func addDashboardMigration(mg *Migrator) {
|
||||
Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true,
|
||||
}))
|
||||
|
||||
mg.AddMigration("Update uid column values in dashboard", NewRawSqlMigration("").
|
||||
Sqlite("UPDATE dashboard SET uid=printf('%09d',id) WHERE uid IS NULL;").
|
||||
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::text,9,'0') WHERE uid IS NULL;").
|
||||
Mysql("UPDATE dashboard SET uid=lpad(id,9,'0') WHERE uid IS NULL;"))
|
||||
|
||||
@@ -220,9 +220,9 @@ func addDashboardMigration(mg *Migrator) {
|
||||
Type: IndexType,
|
||||
}))
|
||||
|
||||
mg.AddMigration("delete tags for deleted dashboards", NewRawSqlMigration(
|
||||
mg.AddMigration("delete tags for deleted dashboards", NewRawSQLMigration(
|
||||
"DELETE FROM dashboard_tag WHERE dashboard_id NOT IN (SELECT id FROM dashboard)"))
|
||||
|
||||
mg.AddMigration("delete stars for deleted dashboards", NewRawSqlMigration(
|
||||
mg.AddMigration("delete stars for deleted dashboards", NewRawSQLMigration(
|
||||
"DELETE FROM star WHERE dashboard_id NOT IN (SELECT id FROM dashboard)"))
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func addDashboardSnapshotMigrations(mg *Migrator) {
|
||||
addTableIndicesMigrations(mg, "v5", snapshotV5)
|
||||
|
||||
// change column type of dashboard
|
||||
mg.AddMigration("alter dashboard_snapshot to mediumtext v2", NewRawSqlMigration("").
|
||||
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{
|
||||
@@ -69,6 +69,6 @@ func addDashboardSnapshotMigrations(mg *Migrator) {
|
||||
Name: "dashboard_encrypted", Type: DB_Blob, Nullable: true,
|
||||
}))
|
||||
|
||||
mg.AddMigration("Change dashboard_encrypted column to MEDIUMBLOB", NewRawSqlMigration("").
|
||||
mg.AddMigration("Change dashboard_encrypted column to MEDIUMBLOB", NewRawSQLMigration("").
|
||||
Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard_encrypted MEDIUMBLOB;"))
|
||||
}
|
||||
|
||||
@@ -28,7 +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", NewRawSqlMigration(setVersionTo1WhereZeroSQL))
|
||||
mg.AddMigration("Set dashboard version to 1 where 0", NewRawSQLMigration(setVersionTo1WhereZeroSQL))
|
||||
|
||||
const rawSQL = `INSERT INTO dashboard_version
|
||||
(
|
||||
@@ -51,9 +51,9 @@ SELECT
|
||||
'',
|
||||
dashboard.data
|
||||
FROM dashboard;`
|
||||
mg.AddMigration("save existing dashboard data in dashboard_version table v1", NewRawSqlMigration(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", NewRawSqlMigration("").
|
||||
mg.AddMigration("alter dashboard_version.data to mediumtext v1", NewRawSQLMigration("").
|
||||
Mysql("ALTER TABLE dashboard_version MODIFY data MEDIUMTEXT;"))
|
||||
}
|
||||
|
||||
@@ -122,17 +122,17 @@ func addDataSourceMigration(mg *Migrator) {
|
||||
}))
|
||||
|
||||
const setVersionToOneWhereZero = `UPDATE data_source SET version = 1 WHERE version = 0`
|
||||
mg.AddMigration("Update initial version to 1", NewRawSqlMigration(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,
|
||||
}))
|
||||
|
||||
const migrateLoggingToLoki = `UPDATE data_source SET type = 'loki' WHERE type = 'logging'`
|
||||
mg.AddMigration("Migrate logging ds to loki ds", NewRawSqlMigration(migrateLoggingToLoki))
|
||||
mg.AddMigration("Migrate logging ds to loki ds", NewRawSQLMigration(migrateLoggingToLoki))
|
||||
|
||||
const setEmptyJSONWhereNullJSON = `UPDATE data_source SET json_data = '{}' WHERE json_data is null`
|
||||
mg.AddMigration("Update json_data with nulls", NewRawSqlMigration(setEmptyJSONWhereNullJSON))
|
||||
mg.AddMigration("Update json_data with nulls", NewRawSQLMigration(setEmptyJSONWhereNullJSON))
|
||||
|
||||
// add column uid for linking
|
||||
mg.AddMigration("Add uid column", NewAddColumnMigration(tableV2, &Column{
|
||||
@@ -142,8 +142,8 @@ func addDataSourceMigration(mg *Migrator) {
|
||||
// Initialize as id as that is unique already
|
||||
mg.AddMigration(
|
||||
"Update uid value",
|
||||
NewRawSqlMigration("").
|
||||
Sqlite("UPDATE data_source SET uid=printf('%09d',id);").
|
||||
NewRawSQLMigration("").
|
||||
SQLite("UPDATE data_source SET uid=printf('%09d',id);").
|
||||
Postgres("UPDATE data_source SET uid=lpad('' || id::text,9,'0');").
|
||||
Mysql("UPDATE data_source SET uid=lpad(id,9,'0');"),
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func TestMigrations(t *testing.T) {
|
||||
testDBs := []sqlutil.TestDB{
|
||||
sqlutil.Sqlite3TestDB(),
|
||||
sqlutil.SQLite3TestDB(),
|
||||
}
|
||||
|
||||
for _, testDB := range testDBs {
|
||||
|
||||
@@ -64,5 +64,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", NewRawSqlMigration(migrateReadOnlyViewersToViewers))
|
||||
mg.AddMigration("Migrate all Read Only Viewers to Viewers", NewRawSQLMigration(migrateReadOnlyViewersToViewers))
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ func addPreferencesMigrations(mg *Migrator) {
|
||||
Name: "team_id", Type: DB_BigInt, Nullable: true,
|
||||
}))
|
||||
|
||||
mg.AddMigration("Update team_id column values in preferences", NewRawSqlMigration("").
|
||||
Sqlite("UPDATE preferences SET team_id=0 WHERE team_id IS NULL;").
|
||||
mg.AddMigration("Update team_id column values in preferences", NewRawSQLMigration("").
|
||||
SQLite("UPDATE preferences SET team_id=0 WHERE team_id IS NULL;").
|
||||
Postgres("UPDATE preferences SET team_id=0 WHERE team_id IS NULL;").
|
||||
Mysql("UPDATE preferences SET team_id=0 WHERE team_id IS NULL;"))
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ type SetCreatedForOutstandingInvites struct {
|
||||
MigrationBase
|
||||
}
|
||||
|
||||
func (m *SetCreatedForOutstandingInvites) Sql(dialect Dialect) string {
|
||||
func (m *SetCreatedForOutstandingInvites) SQL(dialect Dialect) string {
|
||||
return "code migration"
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func addUserAuthMigrations(mg *Migrator) {
|
||||
// add indices
|
||||
addTableIndicesMigrations(mg, "v1", userAuthV1)
|
||||
|
||||
mg.AddMigration("alter user_auth.auth_id to length 190", NewRawSqlMigration("").
|
||||
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);"))
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ type AddMissingUserSaltAndRandsMigration struct {
|
||||
MigrationBase
|
||||
}
|
||||
|
||||
func (m *AddMissingUserSaltAndRandsMigration) Sql(dialect Dialect) string {
|
||||
func (m *AddMissingUserSaltAndRandsMigration) SQL(dialect Dialect) string {
|
||||
return "code migration"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user