mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
feat(fields): add instance domain (#9000)
# Which Problems Are Solved Instance domains are only computed on read side. This can cause missing domains if calls are executed shortly after a instance domain (or instance) was added. # How the Problems Are Solved The instance domain is added to the fields table which is filled on command side. # Additional Changes - added setup step to compute instance domains - instance by host uses fields table instead of instance_domains table # Additional Context - part of https://github.com/zitadel/zitadel/issues/8999
This commit is contained in:
@@ -13,6 +13,10 @@ const (
|
||||
InstanceDomainAddedEventType = domainEventPrefix + "added"
|
||||
InstanceDomainPrimarySetEventType = domainEventPrefix + "primary.set"
|
||||
InstanceDomainRemovedEventType = domainEventPrefix + "removed"
|
||||
|
||||
InstanceDomainSearchType = "instance_domain"
|
||||
InstanceDomainSearchField = "domain"
|
||||
InstanceDomainObjectRevision = uint8(1)
|
||||
)
|
||||
|
||||
func NewAddInstanceDomainUniqueConstraint(domain string) *eventstore.UniqueConstraint {
|
||||
@@ -43,6 +47,30 @@ func (e *DomainAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return []*eventstore.UniqueConstraint{NewAddInstanceDomainUniqueConstraint(e.Domain)}
|
||||
}
|
||||
|
||||
func (e *DomainAddedEvent) Fields() []*eventstore.FieldOperation {
|
||||
return []*eventstore.FieldOperation{
|
||||
eventstore.SetField(
|
||||
e.Aggregate(),
|
||||
domainSearchObject(e.Domain),
|
||||
InstanceDomainSearchField,
|
||||
&eventstore.Value{
|
||||
Value: e.Domain,
|
||||
// TODO: (adlerhurst) ensure uniqueness if we go with fields table: https://github.com/zitadel/zitadel/issues/9009
|
||||
MustBeUnique: false,
|
||||
ShouldIndex: true,
|
||||
},
|
||||
|
||||
eventstore.FieldTypeInstanceID,
|
||||
eventstore.FieldTypeResourceOwner,
|
||||
eventstore.FieldTypeAggregateType,
|
||||
eventstore.FieldTypeAggregateID,
|
||||
eventstore.FieldTypeObjectType,
|
||||
eventstore.FieldTypeObjectID,
|
||||
eventstore.FieldTypeFieldName,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func NewDomainAddedEvent(ctx context.Context, aggregate *eventstore.Aggregate, domain string, generated bool) *DomainAddedEvent {
|
||||
return &DomainAddedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
@@ -118,6 +146,29 @@ func (e *DomainRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint
|
||||
return []*eventstore.UniqueConstraint{NewRemoveInstanceDomainUniqueConstraint(e.Domain)}
|
||||
}
|
||||
|
||||
func (e *DomainRemovedEvent) Fields() []*eventstore.FieldOperation {
|
||||
return []*eventstore.FieldOperation{
|
||||
eventstore.SetField(
|
||||
e.Aggregate(),
|
||||
domainSearchObject(e.Domain),
|
||||
InstanceDomainSearchField,
|
||||
&eventstore.Value{
|
||||
Value: e.Domain,
|
||||
MustBeUnique: true,
|
||||
ShouldIndex: true,
|
||||
},
|
||||
|
||||
eventstore.FieldTypeInstanceID,
|
||||
eventstore.FieldTypeResourceOwner,
|
||||
eventstore.FieldTypeAggregateType,
|
||||
eventstore.FieldTypeAggregateID,
|
||||
eventstore.FieldTypeObjectType,
|
||||
eventstore.FieldTypeObjectID,
|
||||
eventstore.FieldTypeFieldName,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func NewDomainRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate, domain string) *DomainRemovedEvent {
|
||||
return &DomainRemovedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
@@ -140,3 +191,11 @@ func DomainRemovedEventMapper(event eventstore.Event) (eventstore.Event, error)
|
||||
|
||||
return domainRemoved, nil
|
||||
}
|
||||
|
||||
func domainSearchObject(domain string) eventstore.Object {
|
||||
return eventstore.Object{
|
||||
Type: InstanceDomainSearchType,
|
||||
ID: domain,
|
||||
Revision: InstanceDomainObjectRevision,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user