diff --git a/cmd/setup/40.go b/cmd/setup/40.go index 1b9bb5dab..d5f7f923f 100644 --- a/cmd/setup/40.go +++ b/cmd/setup/40.go @@ -52,6 +52,12 @@ func (mig *InitPushFunc) Execute(ctx context.Context, _ eventstore.Event) (err e return fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err) } } + // close idle connections to prevent them from using the old prepared statement with the wrong type + // and having wrong plan of `eventstore.command2`-type + for _, conn := range mig.dbClient.Pool.AcquireAllIdle(ctx) { + logging.OnError(ctx, conn.Conn().Close(ctx)).Debug("failed to close idle connection") + conn.Release() + } return nil } diff --git a/cmd/setup/64.go b/cmd/setup/64.go index 6a0e88a71..6a2191294 100644 --- a/cmd/setup/64.go +++ b/cmd/setup/64.go @@ -6,6 +6,7 @@ import ( _ "embed" "fmt" + "github.com/zitadel/zitadel/backend/v3/instrumentation/logging" "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/eventstore" ) @@ -26,7 +27,16 @@ func (mig *ChangePushPosition) Execute(ctx context.Context, _ eventstore.Event) } stmt := fmt.Sprintf(changePushPosition, inTxOrderType) _, err = mig.dbClient.ExecContext(ctx, stmt) - return err + if err != nil { + return err + } + // close idle connections to prevent them from using the old prepared statement with the wrong type + // and having wrong plan of `eventstore.command2`-type + for _, conn := range mig.dbClient.Pool.AcquireAllIdle(ctx) { + logging.OnError(ctx, conn.Conn().Close(ctx)).Debug("failed to close idle connection") + conn.Release() + } + return nil } func (mig *ChangePushPosition) String() string { diff --git a/cmd/setup/70.go b/cmd/setup/70.go index a50b880cc..edb816fad 100644 --- a/cmd/setup/70.go +++ b/cmd/setup/70.go @@ -5,6 +5,7 @@ import ( _ "embed" "fmt" + "github.com/zitadel/zitadel/backend/v3/instrumentation/logging" "github.com/zitadel/zitadel/internal/database" "github.com/zitadel/zitadel/internal/eventstore" ) @@ -26,7 +27,16 @@ func (mig *AddEventStoreCommandEnforceOwnerColumn) Execute(ctx context.Context, stmt := fmt.Sprintf(addEventStoreCommandEnforceOwnerColumn, inTxOrderType) _, err = mig.dbClient.ExecContext(ctx, stmt) - return err + if err != nil { + return err + } + // close idle connections to prevent them from using the old prepared statement with the wrong type + // and having wrong plan of `eventstore.command2`-type + for _, conn := range mig.dbClient.Pool.AcquireAllIdle(ctx) { + logging.OnError(ctx, conn.Conn().Close(ctx)).Debug("failed to close idle connection") + conn.Release() + } + return nil } func (mig *AddEventStoreCommandEnforceOwnerColumn) String() string { diff --git a/cmd/setup/setup.go b/cmd/setup/setup.go index bd5430d92..e2fe0467d 100644 --- a/cmd/setup/setup.go +++ b/cmd/setup/setup.go @@ -263,7 +263,6 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string) for _, step := range []migration.Migration{ steps.s14NewEventsTable, steps.s40InitPushFunc, - steps.s70AddEventStoreCommandEnforceOwner, steps.s1ProjectionTable, steps.s2AssetsTable, steps.s28AddFieldTable, @@ -312,6 +311,7 @@ func Setup(ctx context.Context, config *Config, steps *Steps, masterKey string) steps.s65FixUserMetadata5Index, steps.s67SyncMemberRoleFields, steps.s69CacheTablesLogged, + steps.s70AddEventStoreCommandEnforceOwner, } { setupErr = executeMigration(ctx, eventstoreClient, step, "migration failed") if setupErr != nil {