2024-11-26 17:26:41 +02:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
_ "embed"
|
2024-12-18 17:48:22 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/zitadel/logging"
|
2024-11-26 17:26:41 +02:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-12-18 17:48:22 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
2024-11-26 17:26:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed 39.sql
|
|
|
|
deleteStaleOrgFields string
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeleteStaleOrgFields struct {
|
2024-12-18 17:48:22 +02:00
|
|
|
eventstore *eventstore.Eventstore
|
2024-11-26 17:26:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mig *DeleteStaleOrgFields) Execute(ctx context.Context, _ eventstore.Event) error {
|
2024-12-18 17:48:22 +02:00
|
|
|
instances, err := mig.eventstore.InstanceIDs(
|
|
|
|
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 (*DeleteStaleOrgFields) Check(map[string]any) bool {
|
|
|
|
return true
|
2024-11-26 17:26:41 +02:00
|
|
|
}
|
|
|
|
|
2024-12-18 17:48:22 +02:00
|
|
|
func (*DeleteStaleOrgFields) String() string {
|
|
|
|
return "repeatable_delete_stale_org_fields"
|
2024-11-26 17:26:41 +02:00
|
|
|
}
|