mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
fe1337536f
* fix(db): add additional connection pool for projection spooling * use correct connection pool for projections --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package setup
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/database/dialect"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
old_es "github.com/zitadel/zitadel/internal/eventstore/repository/sql"
|
|
new_es "github.com/zitadel/zitadel/internal/eventstore/v3"
|
|
"github.com/zitadel/zitadel/internal/migration"
|
|
)
|
|
|
|
func NewCleanup() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "cleanup",
|
|
Short: "cleans up migration if they got stuck",
|
|
Long: `cleans up migration if they got stuck`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
config := MustNewConfig(viper.GetViper())
|
|
Cleanup(config)
|
|
},
|
|
}
|
|
}
|
|
|
|
func Cleanup(config *Config) {
|
|
ctx := context.Background()
|
|
|
|
logging.Info("cleanup started")
|
|
|
|
queryDBClient, err := database.Connect(config.Database, false, dialect.DBPurposeQuery)
|
|
logging.OnError(err).Fatal("unable to connect to database")
|
|
esPusherDBClient, err := database.Connect(config.Database, false, dialect.DBPurposeEventPusher)
|
|
logging.OnError(err).Fatal("unable to connect to database")
|
|
|
|
config.Eventstore.Pusher = new_es.NewEventstore(esPusherDBClient)
|
|
config.Eventstore.Querier = old_es.NewCRDB(queryDBClient)
|
|
es := eventstore.NewEventstore(config.Eventstore)
|
|
migration.RegisterMappers(es)
|
|
|
|
step, err := migration.LatestStep(ctx, es)
|
|
logging.OnError(err).Fatal("unable to query latest migration")
|
|
|
|
if step.BaseEvent.EventType != migration.StartedType {
|
|
logging.Info("there is no stuck migration please run `zitadel setup`")
|
|
return
|
|
}
|
|
|
|
logging.WithFields("name", step.Name).Info("cleanup migration")
|
|
|
|
err = migration.CancelStep(ctx, es, step)
|
|
logging.OnError(err).Fatal("cleanup migration failed please retry")
|
|
}
|