mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-10 04:13:40 +00:00
fix(setup): make step 39 repeatable (#9085)
# Which Problems Are Solved When downgrading zitadel and upgrading it again, it might be that orgs deleted in this period still have stale entries in the fields table. # How the Problems Are Solved - Make the cleanup repeatable - Scope the query by instance so that an index is used. (cherry picked from commit da706a8b30dca5ab4d7d96ae4225dcc9d55d85a5)
This commit is contained in:
parent
ded9491326
commit
47268c738a
@ -3,9 +3,12 @@ package setup
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zitadel/logging"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/database"
|
|
||||||
"github.com/zitadel/zitadel/internal/eventstore"
|
"github.com/zitadel/zitadel/internal/eventstore"
|
||||||
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -14,14 +17,35 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DeleteStaleOrgFields struct {
|
type DeleteStaleOrgFields struct {
|
||||||
dbClient *database.DB
|
eventstore *eventstore.Eventstore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mig *DeleteStaleOrgFields) Execute(ctx context.Context, _ eventstore.Event) error {
|
func (mig *DeleteStaleOrgFields) Execute(ctx context.Context, _ eventstore.Event) error {
|
||||||
_, err := mig.dbClient.ExecContext(ctx, deleteStaleOrgFields)
|
instances, err := mig.eventstore.InstanceIDs(
|
||||||
return err
|
ctx,
|
||||||
|
eventstore.NewSearchQueryBuilder(eventstore.ColumnsInstanceIDs).
|
||||||
|
OrderDesc().
|
||||||
|
AddQuery().
|
||||||
|
AggregateTypes("instance").
|
||||||
|
EventTypes(instance.InstanceAddedEventType).
|
||||||
|
Builder(),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i, instance := range instances {
|
||||||
|
logging.WithFields("instance_id", instance, "migration", mig.String(), "progress", fmt.Sprintf("%d/%d", i+1, len(instances))).Info("execute delete query")
|
||||||
|
if _, err := mig.eventstore.Client().ExecContext(ctx, deleteStaleOrgFields, instance); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mig *DeleteStaleOrgFields) String() string {
|
func (*DeleteStaleOrgFields) Check(map[string]any) bool {
|
||||||
return "39_delete_stale_org_fields"
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DeleteStaleOrgFields) String() string {
|
||||||
|
return "repeatable_delete_stale_org_fields"
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ WHERE aggregate_type = 'org'
|
|||||||
AND aggregate_id IN (
|
AND aggregate_id IN (
|
||||||
SELECT aggregate_id
|
SELECT aggregate_id
|
||||||
FROM eventstore.events2
|
FROM eventstore.events2
|
||||||
WHERE aggregate_type = 'org'
|
WHERE instance_id = $1
|
||||||
|
AND aggregate_type = 'org'
|
||||||
AND event_type = 'org.removed'
|
AND event_type = 'org.removed'
|
||||||
);
|
);
|
||||||
|
@ -127,7 +127,6 @@ type Steps struct {
|
|||||||
s37Apps7OIDConfigsBackChannelLogoutURI *Apps7OIDConfigsBackChannelLogoutURI
|
s37Apps7OIDConfigsBackChannelLogoutURI *Apps7OIDConfigsBackChannelLogoutURI
|
||||||
s38BackChannelLogoutNotificationStart *BackChannelLogoutNotificationStart
|
s38BackChannelLogoutNotificationStart *BackChannelLogoutNotificationStart
|
||||||
s40InitPushFunc *InitPushFunc
|
s40InitPushFunc *InitPushFunc
|
||||||
s39DeleteStaleOrgFields *DeleteStaleOrgFields
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustNewSteps(v *viper.Viper) *Steps {
|
func MustNewSteps(v *viper.Viper) *Steps {
|
||||||
|
@ -169,7 +169,6 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string)
|
|||||||
steps.s36FillV2Milestones = &FillV3Milestones{dbClient: queryDBClient, eventstore: eventstoreClient}
|
steps.s36FillV2Milestones = &FillV3Milestones{dbClient: queryDBClient, eventstore: eventstoreClient}
|
||||||
steps.s37Apps7OIDConfigsBackChannelLogoutURI = &Apps7OIDConfigsBackChannelLogoutURI{dbClient: esPusherDBClient}
|
steps.s37Apps7OIDConfigsBackChannelLogoutURI = &Apps7OIDConfigsBackChannelLogoutURI{dbClient: esPusherDBClient}
|
||||||
steps.s38BackChannelLogoutNotificationStart = &BackChannelLogoutNotificationStart{dbClient: esPusherDBClient, esClient: eventstoreClient}
|
steps.s38BackChannelLogoutNotificationStart = &BackChannelLogoutNotificationStart{dbClient: esPusherDBClient, esClient: eventstoreClient}
|
||||||
steps.s39DeleteStaleOrgFields = &DeleteStaleOrgFields{dbClient: esPusherDBClient}
|
|
||||||
steps.s40InitPushFunc = &InitPushFunc{dbClient: esPusherDBClient}
|
steps.s40InitPushFunc = &InitPushFunc{dbClient: esPusherDBClient}
|
||||||
|
|
||||||
err = projection.Create(ctx, projectionDBClient, eventstoreClient, config.Projections, nil, nil, nil)
|
err = projection.Create(ctx, projectionDBClient, eventstoreClient, config.Projections, nil, nil, nil)
|
||||||
@ -187,6 +186,9 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string)
|
|||||||
es: eventstoreClient,
|
es: eventstoreClient,
|
||||||
Version: build.Version(),
|
Version: build.Version(),
|
||||||
},
|
},
|
||||||
|
&DeleteStaleOrgFields{
|
||||||
|
eventstore: eventstoreClient,
|
||||||
|
},
|
||||||
&FillFieldsForInstanceDomains{
|
&FillFieldsForInstanceDomains{
|
||||||
eventstore: eventstoreClient,
|
eventstore: eventstoreClient,
|
||||||
},
|
},
|
||||||
@ -238,7 +240,6 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string)
|
|||||||
steps.s32AddAuthSessionID,
|
steps.s32AddAuthSessionID,
|
||||||
steps.s33SMSConfigs3TwilioAddVerifyServiceSid,
|
steps.s33SMSConfigs3TwilioAddVerifyServiceSid,
|
||||||
steps.s37Apps7OIDConfigsBackChannelLogoutURI,
|
steps.s37Apps7OIDConfigsBackChannelLogoutURI,
|
||||||
steps.s39DeleteStaleOrgFields,
|
|
||||||
} {
|
} {
|
||||||
mustExecuteMigration(ctx, eventstoreClient, step, "migration failed")
|
mustExecuteMigration(ctx, eventstoreClient, step, "migration failed")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user