mirror of
https://github.com/zitadel/zitadel.git
synced 2026-07-25 18:28:00 +00:00
# Which Problems Are Solved During the setup step we saw rare cases which caused setup to fail after executing steps 40, 64 and 70. # How the Problems Are Solved Close currently open database connections so that they fetch the correct type mapping for the `eventstore.command2` database type. # Additional Changes Ensure correct order of setup steps 64 and 70. # Additional Context None --------- Co-authored-by: Livio Spring <9405495+livio-a@users.noreply.github.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
_ "embed"
|
|
"fmt"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/instrumentation/logging"
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
var (
|
|
//go:embed 64.sql
|
|
changePushPosition string
|
|
)
|
|
|
|
type ChangePushPosition struct {
|
|
dbClient *database.DB
|
|
}
|
|
|
|
func (mig *ChangePushPosition) Execute(ctx context.Context, _ eventstore.Event) error {
|
|
inTxOrderType, err := inTxOrderType(ctx, mig.dbClient)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
stmt := fmt.Sprintf(changePushPosition, inTxOrderType)
|
|
_, err = mig.dbClient.ExecContext(ctx, stmt)
|
|
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 {
|
|
return "64_change_push_position"
|
|
}
|
|
|
|
func inTxOrderType(ctx context.Context, client *database.DB) (typeName string, err error) {
|
|
err = client.QueryRowContext(ctx, func(row *sql.Row) error {
|
|
return row.Scan(&typeName)
|
|
}, `SELECT data_type FROM information_schema.columns WHERE table_schema = 'eventstore' AND table_name = 'events2' AND column_name = 'in_tx_order'`)
|
|
if err != nil {
|
|
return "", fmt.Errorf("get in_tx_order_type: %w", err)
|
|
}
|
|
return typeName, nil
|
|
}
|