feat: projections auto create their tables (#3324)

* begin init checks for projections

* first projection checks

* debug notification providers with query fixes

* more projections and first index

* more projections

* more projections

* finish projections

* fix tests (remove db name)

* create tables in setup

* fix logging / error handling

* add tenant to views

* rename tenant to instance_id

* add instance_id to all projections

* add instance_id to all queries

* correct instance_id on projections

* add instance_id to failed_events

* use separate context for instance

* implement features projection

* implement features projection

* remove unique constraint from setup when migration failed

* add error to failed setup event

* add instance_id to primary keys

* fix IAM projection

* remove old migrations folder

* fix keysFromYAML test
This commit is contained in:
Livio Amstutz
2022-03-23 09:02:39 +01:00
committed by GitHub
parent 9e13b70a3d
commit 56b916a2b0
400 changed files with 6508 additions and 8890 deletions

View File

@@ -23,7 +23,7 @@ type Aggregate struct {
editorService string
editorUser string
resourceOwner string
tenant string
instanceID string
Events []*Event
Precondition *precondition
}
@@ -56,7 +56,7 @@ func (a *Aggregate) AppendEvent(typ EventType, payload interface{}) (*Aggregate,
EditorService: a.editorService,
EditorUser: a.editorUser,
ResourceOwner: a.resourceOwner,
Tenant: a.tenant,
InstanceID: a.instanceID,
}
a.Events = append(a.Events, e)

View File

@@ -18,9 +18,10 @@ type option func(*Aggregate)
func (c *AggregateCreator) NewAggregate(ctx context.Context, id string, typ AggregateType, version Version, previousSequence uint64, opts ...option) (*Aggregate, error) {
ctxData := authz.GetCtxData(ctx)
instance := authz.GetInstance(ctx)
editorUser := ctxData.UserID
resourceOwner := ctxData.OrgID
tenant := ctxData.TenantID
instanceID := instance.ID
aggregate := &Aggregate{
ID: id,
@@ -31,7 +32,7 @@ func (c *AggregateCreator) NewAggregate(ctx context.Context, id string, typ Aggr
editorService: c.serviceName,
editorUser: editorUser,
resourceOwner: resourceOwner,
tenant: tenant,
instanceID: instanceID,
}
for _, opt := range opts {

View File

@@ -28,7 +28,7 @@ type Event struct {
EditorService string
EditorUser string
ResourceOwner string
Tenant string
InstanceID string
}
func eventData(i interface{}) ([]byte, error) {

View File

@@ -11,5 +11,5 @@ const (
Field_EditorUser
Field_EventType
Field_CreationDate
Field_Tenant
Field_InstanceID
)

View File

@@ -8,7 +8,7 @@ type ObjectRoot struct {
AggregateID string `json:"-"`
Sequence uint64 `json:"-"`
ResourceOwner string `json:"-"`
Tenant string `json:"-"`
InstanceID string `json:"-"`
CreationDate time.Time `json:"-"`
ChangeDate time.Time `json:"-"`
}
@@ -22,8 +22,8 @@ func (o *ObjectRoot) AppendEvent(event *Event) {
if o.ResourceOwner == "" {
o.ResourceOwner = event.ResourceOwner
}
if o.Tenant == "" {
o.Tenant = event.Tenant
if o.InstanceID == "" {
o.InstanceID = event.InstanceID
}
o.ChangeDate = event.CreationDate

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/errors"
)
@@ -17,7 +18,7 @@ type SearchQueryFactory struct {
sequenceTo uint64
eventTypes []EventType
resourceOwner string
tenant string
instanceID string
creationDate time.Time
}
@@ -63,8 +64,8 @@ func FactoryFromSearchQuery(query *SearchQuery) *SearchQueryFactory {
}
case Field_ResourceOwner:
factory = factory.ResourceOwner(filter.value.(string))
case Field_Tenant:
factory = factory.Tenant(filter.value.(string))
case Field_InstanceID:
factory = factory.InstanceID(filter.value.(string))
case Field_EventType:
factory = factory.EventTypes(filter.value.([]EventType)...)
case Field_EditorService, Field_EditorUser:
@@ -123,8 +124,8 @@ func (factory *SearchQueryFactory) ResourceOwner(resourceOwner string) *SearchQu
return factory
}
func (factory *SearchQueryFactory) Tenant(tenant string) *SearchQueryFactory {
factory.tenant = tenant
func (factory *SearchQueryFactory) InstanceID(instanceID string) *SearchQueryFactory {
factory.instanceID = instanceID
return factory
}
@@ -159,7 +160,7 @@ func (factory *SearchQueryFactory) Build() (*searchQuery, error) {
factory.sequenceToFilter,
factory.eventTypeFilter,
factory.resourceOwnerFilter,
factory.tenantFilter,
factory.instanceIDFilter,
factory.creationDateNewerFilter,
} {
if filter := f(); filter != nil {
@@ -231,11 +232,11 @@ func (factory *SearchQueryFactory) resourceOwnerFilter() *Filter {
return NewFilter(Field_ResourceOwner, factory.resourceOwner, Operation_Equals)
}
func (factory *SearchQueryFactory) tenantFilter() *Filter {
if factory.tenant == "" {
func (factory *SearchQueryFactory) instanceIDFilter() *Filter {
if factory.instanceID == "" {
return nil
}
return NewFilter(Field_Tenant, factory.tenant, Operation_Equals)
return NewFilter(Field_InstanceID, factory.instanceID, Operation_Equals)
}
func (factory *SearchQueryFactory) creationDateNewerFilter() *Filter {

View File

@@ -69,8 +69,8 @@ func (q *SearchQuery) ResourceOwnerFilter(resourceOwner string) *SearchQuery {
return q.setFilter(NewFilter(Field_ResourceOwner, resourceOwner, Operation_Equals))
}
func (q *SearchQuery) TenantFilter(tenant string) *SearchQuery {
return q.setFilter(NewFilter(Field_Tenant, tenant, Operation_Equals))
func (q *SearchQuery) InstanceIDFilter(instanceID string) *SearchQuery {
return q.setFilter(NewFilter(Field_InstanceID, instanceID, Operation_Equals))
}
func (q *SearchQuery) CreationDateNewerFilter(time time.Time) *SearchQuery {