mirror of
https://github.com/zitadel/zitadel.git
synced 2025-10-09 11:12:01 +00:00
migrate instances projection
This commit is contained in:
26
cmd/setup/21.go
Normal file
26
cmd/setup/21.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed 18.sql
|
||||
addLimitFieldsToInstances string
|
||||
)
|
||||
|
||||
type AddLimitFieldsToInstances struct {
|
||||
dbClient *database.DB
|
||||
}
|
||||
|
||||
func (mig *AddLimitFieldsToInstances) Execute(ctx context.Context) error {
|
||||
_, err := mig.dbClient.ExecContext(ctx, addLimitFieldsToInstances)
|
||||
return err
|
||||
}
|
||||
|
||||
func (mig *AddLimitFieldsToInstances) String() string {
|
||||
return "21_add_limit_fields_to_instances"
|
||||
}
|
5
cmd/setup/21.sql
Normal file
5
cmd/setup/21.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE IF EXISTS projections.instances
|
||||
ADD COLUMN IF NOT EXISTS audit_log_retention INTERVAL,
|
||||
ADD COLUMN IF NOT EXISTS block BOOLEAN;
|
||||
;
|
||||
|
@@ -78,6 +78,7 @@ type Steps struct {
|
||||
s18AddLowerFieldsToLoginNames *AddLowerFieldsToLoginNames
|
||||
s19AddCurrentStatesIndex *AddCurrentSequencesIndex
|
||||
s20AddByUserSessionIndex *AddByUserIndexToSession
|
||||
s21AddLimitFieldsToInstances *AddLimitFieldsToInstances
|
||||
}
|
||||
|
||||
type encryptionKeyConfig struct {
|
||||
|
@@ -111,6 +111,7 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
||||
steps.s18AddLowerFieldsToLoginNames = &AddLowerFieldsToLoginNames{dbClient: queryDBClient}
|
||||
steps.s19AddCurrentStatesIndex = &AddCurrentSequencesIndex{dbClient: queryDBClient}
|
||||
steps.s20AddByUserSessionIndex = &AddByUserIndexToSession{dbClient: queryDBClient}
|
||||
steps.s21AddLimitFieldsToInstances = &AddLimitFieldsToInstances{dbClient: queryDBClient}
|
||||
|
||||
err = projection.Create(ctx, projectionDBClient, eventstoreClient, config.Projections, nil, nil, nil)
|
||||
logging.OnError(err).Fatal("unable to start projections")
|
||||
@@ -165,9 +166,11 @@ func Setup(config *Config, steps *Steps, masterKey string) {
|
||||
logging.OnError(err).Fatalf("unable to migrate repeatable step: %s", repeatableStep.String())
|
||||
}
|
||||
|
||||
// This step is executed after the repeatable steps because it adds fields to the login_names3 projection
|
||||
// These steps are executed after the repeatable steps because they add fields to tables
|
||||
err = migration.Migrate(ctx, eventstoreClient, steps.s18AddLowerFieldsToLoginNames)
|
||||
logging.WithFields("name", steps.s18AddLowerFieldsToLoginNames.String()).OnError(err).Fatal("migration failed")
|
||||
err = migration.Migrate(ctx, eventstoreClient, steps.s21AddLimitFieldsToInstances)
|
||||
logging.WithFields("name", steps.s21AddLimitFieldsToInstances.String()).OnError(err).Fatal("migration failed")
|
||||
}
|
||||
|
||||
func readStmt(fs embed.FS, folder, typ, filename string) (string, error) {
|
||||
|
@@ -248,6 +248,9 @@ func (p *instanceProjection) reduceLimitsSet(event eventstore.Event) (*handler.S
|
||||
if e.Block != nil {
|
||||
updateCols = append(updateCols, handler.NewCol(InstanceColumnBlock, *e.Block))
|
||||
}
|
||||
if len(updateCols) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
updateCols,
|
||||
|
@@ -69,7 +69,6 @@ var (
|
||||
AuthRequestProjection *handler.Handler
|
||||
MilestoneProjection *handler.Handler
|
||||
QuotaProjection *quotaProjection
|
||||
LimitsProjection *handler.Handler
|
||||
RestrictionsProjection *handler.Handler
|
||||
)
|
||||
|
||||
@@ -247,7 +246,6 @@ func newProjectionsList() {
|
||||
AuthRequestProjection,
|
||||
MilestoneProjection,
|
||||
QuotaProjection.handler,
|
||||
LimitsProjection,
|
||||
RestrictionsProjection,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user