zitadel/internal/repository/iam/migrate_unique_constraints.go
Fabi 667cc30291
feat: asset storage (#1696)
* feat: remove assets

* feat: minio implementation

* fix: remove assets from tests

* feat: minio implementation

* feat: Env vars

* fix: sprintf

* fix: sprintf

* Update internal/eventstore/repository/repository.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: error handling

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2021-05-03 10:15:50 +02:00

59 lines
1.7 KiB
Go

package iam
import (
"context"
"github.com/caos/zitadel/internal/domain"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/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.EventReader, error) {
return &MigrateUniqueConstraintEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}