2021-02-15 12:31:24 +00:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-02-15 12:31:24 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
2021-02-15 12:31:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
UniqueConstraintsMigratedEventType eventstore.EventType = "iam.unique.constraints.migrated"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MigrateUniqueConstraintEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
uniqueConstraintMigrations []*domain.UniqueConstraintMigration `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAddMigrateUniqueConstraint(uniqueMigration *domain.UniqueConstraintMigration) *eventstore.EventUniqueConstraint {
|
|
|
|
return eventstore.NewAddEventUniqueConstraint(
|
|
|
|
uniqueMigration.UniqueType,
|
|
|
|
uniqueMigration.UniqueField,
|
|
|
|
uniqueMigration.ErrorMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *MigrateUniqueConstraintEvent) Data() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *MigrateUniqueConstraintEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
constraints := make([]*eventstore.EventUniqueConstraint, len(e.uniqueConstraintMigrations))
|
|
|
|
for i, uniqueMigration := range e.uniqueConstraintMigrations {
|
|
|
|
constraints[i] = NewAddMigrateUniqueConstraint(uniqueMigration)
|
|
|
|
}
|
|
|
|
return constraints
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewMigrateUniqueConstraintEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
uniqueConstraintMigrations []*domain.UniqueConstraintMigration) *MigrateUniqueConstraintEvent {
|
2021-02-15 12:31:24 +00:00
|
|
|
return &MigrateUniqueConstraintEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2021-02-15 12:31:24 +00:00
|
|
|
UniqueConstraintsMigratedEventType,
|
|
|
|
),
|
|
|
|
uniqueConstraintMigrations: uniqueConstraintMigrations,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func MigrateUniqueConstraintEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-02-15 12:31:24 +00:00
|
|
|
return &MigrateUniqueConstraintEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|