fix(storage): add indexes for auth.tokens (#5259)

* fix(storage): add indexes for `auth.tokens`

* refactor: naming
This commit is contained in:
Silvan 2023-02-21 15:46:47 +01:00 committed by GitHub
parent c5d0c109da
commit 94116fa04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

25
cmd/setup/08.go Normal file
View File

@ -0,0 +1,25 @@
package setup
import (
"context"
"database/sql"
_ "embed"
)
var (
//go:embed 08.sql
tokenIndexes08 string
)
type AuthTokenIndexes struct {
dbClient *sql.DB
}
func (mig *AuthTokenIndexes) Execute(ctx context.Context) error {
_, err := mig.dbClient.ExecContext(ctx, tokenIndexes08)
return err
}
func (mig *AuthTokenIndexes) String() string {
return "08_auth_token_indexes"
}

5
cmd/setup/08.sql Normal file
View File

@ -0,0 +1,5 @@
CREATE INDEX IF NOT EXISTS inst_refresh_tkn_idx ON auth.tokens(instance_id, refresh_token_id);
CREATE INDEX IF NOT EXISTS inst_app_tkn_idx ON auth.tokens(instance_id, application_id);
CREATE INDEX IF NOT EXISTS inst_ro_tkn_idx ON auth.tokens(instance_id, resource_owner);
DROP INDEX IF EXISTS auth.tokens@user_user_agent_idx;
CREATE INDEX IF NOT EXISTS inst_usr_agnt_tkn_idx ON auth.tokens(instance_id, user_id, user_agent_id);

View File

@ -63,6 +63,7 @@ type Steps struct {
s5LastFailed *LastFailed
s6OwnerRemoveColumns *OwnerRemoveColumns
s7LogstoreTables *LogstoreTables
s8AuthTokens *AuthTokenIndexes
}
type encryptionKeyConfig struct {

View File

@ -85,6 +85,7 @@ func Setup(config *Config, steps *Steps, masterKey string) {
steps.s5LastFailed = &LastFailed{dbClient: dbClient}
steps.s6OwnerRemoveColumns = &OwnerRemoveColumns{dbClient: dbClient}
steps.s7LogstoreTables = &LogstoreTables{dbClient: dbClient, username: config.Database.Username(), dbType: config.Database.Type()}
steps.s8AuthTokens = &AuthTokenIndexes{dbClient: dbClient}
err = projection.Create(ctx, dbClient, eventstoreClient, config.Projections, nil, nil)
logging.OnError(err).Fatal("unable to start projections")
@ -116,6 +117,8 @@ func Setup(config *Config, steps *Steps, masterKey string) {
logging.OnError(err).Fatal("unable to migrate step 6")
err = migration.Migrate(ctx, eventstoreClient, steps.s7LogstoreTables)
logging.OnError(err).Fatal("unable to migrate step 7")
err = migration.Migrate(ctx, eventstoreClient, steps.s8AuthTokens)
logging.OnError(err).Fatal("unable to migrate step 8")
for _, repeatableStep := range repeatableSteps {
err = migration.Migrate(ctx, eventstoreClient, repeatableStep)