mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package instance
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
func NewMigrateUniqueConstraintEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
uniqueConstraintMigrations []*domain.UniqueConstraintMigration) *MigrateUniqueConstraintEvent {
|
|
return &MigrateUniqueConstraintEvent{
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
UniqueConstraintsMigratedEventType,
|
|
),
|
|
uniqueConstraintMigrations: uniqueConstraintMigrations,
|
|
}
|
|
}
|
|
|
|
func MigrateUniqueConstraintEventMapper(event *repository.Event) (eventstore.Event, error) {
|
|
return &MigrateUniqueConstraintEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}, nil
|
|
}
|