mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
fix: unique constraints on instance domain events (#3635)
This commit is contained in:
@@ -19,14 +19,14 @@ const (
|
||||
)
|
||||
|
||||
func NewAddInstanceDomainUniqueConstraint(orgDomain string) *eventstore.EventUniqueConstraint {
|
||||
return eventstore.NewAddEventUniqueConstraint(
|
||||
return eventstore.NewAddGlobalEventUniqueConstraint(
|
||||
UniqueInstanceDomain,
|
||||
orgDomain,
|
||||
"Errors.Instance.Domain.AlreadyExists")
|
||||
}
|
||||
|
||||
func NewRemoveInstanceDomainUniqueConstraint(orgDomain string) *eventstore.EventUniqueConstraint {
|
||||
return eventstore.NewRemoveEventUniqueConstraint(
|
||||
return eventstore.NewRemoveGlobalEventUniqueConstraint(
|
||||
UniqueInstanceDomain,
|
||||
orgDomain)
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ func RegisterEventMappers(es *eventstore.Eventstore) {
|
||||
RegisterFilterEventMapper(SMTPConfigAddedEventType, SMTPConfigAddedEventMapper).
|
||||
RegisterFilterEventMapper(SMTPConfigChangedEventType, SMTPConfigChangedEventMapper).
|
||||
RegisterFilterEventMapper(SMTPConfigPasswordChangedEventType, SMTPConfigPasswordChangedEventMapper).
|
||||
RegisterFilterEventMapper(UniqueConstraintsMigratedEventType, MigrateUniqueConstraintEventMapper).
|
||||
RegisterFilterEventMapper(SMSConfigTwilioAddedEventType, SMSConfigTwilioAddedEventMapper).
|
||||
RegisterFilterEventMapper(SMSConfigTwilioChangedEventType, SMSConfigTwilioChangedEventMapper).
|
||||
RegisterFilterEventMapper(SMSConfigTwilioTokenChangedEventType, SMSConfigTwilioTokenChangedEventMapper).
|
||||
|
@@ -1,59 +0,0 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user