Commit c1cff384 by Marcus Efraimsson

dashboard: change unique index for uid to include org_id

Make the max length of uid longer in case we want to change it later
#7883
parent 46e12967
...@@ -151,17 +151,16 @@ func addDashboardMigration(mg *Migrator) { ...@@ -151,17 +151,16 @@ func addDashboardMigration(mg *Migrator) {
Name: "has_acl", Type: DB_Bool, Nullable: false, Default: "0", Name: "has_acl", Type: DB_Bool, Nullable: false, Default: "0",
})) }))
// new uid column
mg.AddMigration("Add column uid in dashboard", NewAddColumnMigration(dashboardV2, &Column{ mg.AddMigration("Add column uid in dashboard", NewAddColumnMigration(dashboardV2, &Column{
Name: "uid", Type: DB_NVarchar, Length: 12, Nullable: true, Name: "uid", Type: DB_NVarchar, Length: 40, Nullable: true,
})) }))
mg.AddMigration("Set uid column values", new(RawSqlMigration). mg.AddMigration("Update uid column values in dashboard", new(RawSqlMigration).
Sqlite("UPDATE dashboard SET uid=printf('%09d',id) WHERE uid IS NULL;"). 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;"). 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;")) Mysql("UPDATE dashboard SET uid=lpad(id,9,'0') WHERE uid IS NULL;"))
mg.AddMigration("Add index for uid in dashboard", NewAddIndexMigration(dashboardV2, &Index{ mg.AddMigration("Add unique index dashboard_org_id_uid", NewAddIndexMigration(dashboardV2, &Index{
Cols: []string{"uid"}, Type: UniqueIndex, Cols: []string{"org_id", "uid"}, Type: UniqueIndex,
})) }))
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment