From 6b588f4c93dfe2b497b9e4fe956dff2c4870cfe4 Mon Sep 17 00:00:00 2001 From: Gabriel MABILLE Date: Wed, 7 May 2025 13:40:32 +0200 Subject: [PATCH] Migrations: Make sure users uid are set (#104996) * Migrations: Make sure default admin has a uid * Account for all users not only id 1 * Add spanner * Wrong migration to add spanner * Fix spanner mig --- pkg/services/sqlstore/migrations/user_mig.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/services/sqlstore/migrations/user_mig.go b/pkg/services/sqlstore/migrations/user_mig.go index 348bf7c5ef1..c3766de1ba3 100644 --- a/pkg/services/sqlstore/migrations/user_mig.go +++ b/pkg/services/sqlstore/migrations/user_mig.go @@ -151,6 +151,12 @@ func addUserMigrations(mg *Migrator) { Postgres("UPDATE `user` SET uid='u' || lpad('' || id::text,9,'0') WHERE uid IS NULL;"). Mysql("UPDATE user SET uid=concat('u',lpad(id,9,'0')) WHERE uid IS NULL;")) + mg.AddMigration("Make sure users uid are set", NewRawSQLMigration(""). + SQLite("UPDATE user SET uid=printf('u%09d',id) WHERE uid is NULL OR uid = '';"). + Postgres("UPDATE `user` SET uid='u' || lpad('' || id::text,9,'0') WHERE uid is NULL OR uid = '';"). + Mysql("UPDATE user SET uid=concat('u',lpad(id,9,'0')) WHERE uid is NULL OR uid = '';"). + Spanner("UPDATE user SET uid=concat('u',lpad(CAST(id AS STRING),9,'0')) WHERE uid IS NULL OR uid = '';")) + mg.AddMigration("Add unique index user_uid", NewAddIndexMigration(userV2, &Index{ Cols: []string{"uid"}, Type: UniqueIndex, }))