APIKeys: add API key migration to ensure fk is null (#46285)

This commit is contained in:
J Guerreiro 2022-03-07 14:58:20 +00:00 committed by GitHub
parent 0debf33c76
commit c6cae8411a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -182,7 +182,7 @@ func (hs *HTTPServer) declareFixedRoles() error {
},
},
},
Grants: []string{"Admin"},
Grants: []string{string(models.ROLE_ADMIN)},
}
orgReaderRole := ac.RoleRegistration{

View File

@ -1,6 +1,8 @@
package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
import (
. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)
func addApiKeyMigrations(mg *Migrator) {
apiKeyV1 := Table{
@ -86,4 +88,7 @@ func addApiKeyMigrations(mg *Migrator) {
mg.AddMigration("Add service account foreign key", NewAddColumnMigration(apiKeyV2, &Column{
Name: "service_account_id", Type: DB_BigInt, Nullable: true,
}))
mg.AddMigration("set service account foreign key to nil if 0", NewRawSQLMigration(
"UPDATE api_key SET service_account_id = NULL WHERE service_account_id = 0;"))
}