From 69e657b2969025ac4f11cc6505babec25aa32ba4 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> Date: Wed, 21 May 2025 17:44:44 +0300 Subject: [PATCH] SQLStore: Add index on is_service_account and last_seen_at columns in user table. (#105727) Add index on is_service_account and last_seen_at columns in user table. --- pkg/services/sqlstore/migrations/user_mig.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/services/sqlstore/migrations/user_mig.go b/pkg/services/sqlstore/migrations/user_mig.go index c3766de1ba3..0d3ced3fbb8 100644 --- a/pkg/services/sqlstore/migrations/user_mig.go +++ b/pkg/services/sqlstore/migrations/user_mig.go @@ -129,8 +129,8 @@ func addUserMigrations(mg *Migrator) { Cols: []string{"login", "email"}, })) - //Service accounts are lightweight users with restricted permissions. They support API keys - //and provisioning and tasks like alarms and reports. + // Service accounts are lightweight users with restricted permissions. They support API keys + // and provisioning and tasks like alarms and reports. // Issues in this migration: is_service_account should be nullable mg.AddMigration("Add is_service_account column to user", NewAddColumnMigration(userV2, &Column{ Name: "is_service_account", Type: DB_Bool, Nullable: false, Default: "0", @@ -178,6 +178,10 @@ func addUserMigrations(mg *Migrator) { mg.AddMigration(usermig.LowerCaseUserLoginAndEmail, &usermig.UsersLowerCaseLoginAndEmail{}) // Users login and email should be in lower case - 2, fix for creating users not lowering login and email mg.AddMigration(usermig.LowerCaseUserLoginAndEmail+"2", &usermig.UsersLowerCaseLoginAndEmail{}) + + mg.AddMigration("Add index on user.is_service_account and user.last_seen_at", NewAddIndexMigration(userV2, &Index{ + Cols: []string{"is_service_account", "last_seen_at"}, Type: IndexType, + })) } const migSQLITEisServiceAccountNullable = `ALTER TABLE user ADD COLUMN tmp_service_account BOOLEAN DEFAULT 0;