push 6 in 6 milestones

This commit is contained in:
Elio Bischof 2023-06-29 14:28:27 +02:00
parent ad13a65d1d
commit 3a338cdb44
No known key found for this signature in database
GPG Key ID: 7B383FDE4DDBF1BD
3 changed files with 39 additions and 23 deletions

View File

@ -290,7 +290,17 @@ func NewIsNullCond(column string) handler.Condition {
return handler.Condition{ return handler.Condition{
Name: column, Name: column,
ParameterOpt: func(string) string { ParameterOpt: func(string) string {
return fmt.Sprintf("%s IS NULL", column) return " IS NULL"
},
}
}
func NewNotEqualCond(column, value string) handler.Condition {
return handler.Condition{
Name: column,
Value: value,
ParameterOpt: func(param string) string {
return fmt.Sprintf(" != %s", param)
}, },
} }
} }

View File

@ -100,13 +100,13 @@ func NewProjectionHandler(
reduceScheduledPseudoEvent: reduceScheduledPseudoEvent, reduceScheduledPseudoEvent: reduceScheduledPseudoEvent,
} }
go func() { go func(subscribe bool) {
<-initialized <-initialized
if !h.reduceScheduledPseudoEvent { if subscribe {
go h.subscribe(ctx) go h.subscribe(ctx)
} }
go h.schedule(ctx) go h.schedule(ctx)
}() }(!h.reduceScheduledPseudoEvent)
return h return h
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"github.com/zitadel/zitadel/internal/repository/milestone" "github.com/zitadel/zitadel/internal/repository/milestone"
@ -127,14 +128,22 @@ func (p *milestoneProjection) reducePushed(event eventstore.Event) (*handler.Sta
if !ok { if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-XJGXK", "reduce.wrong.event.type %s", milestone.PushedEventType) return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-XJGXK", "reduce.wrong.event.type %s", milestone.PushedEventType)
} }
return crdb.NewUpdateStatement( if e.MilestoneType != milestone.InstanceDeleted {
return crdb.NewUpdateStatement(
event,
[]handler.Column{
handler.NewCol(MilestoneColumnPushedDate, event.CreationDate()),
},
[]handler.Condition{
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
handler.NewCond(MilestoneColumnType, e.MilestoneType),
},
), nil
}
return crdb.NewDeleteStatement(
event, event,
[]handler.Column{
handler.NewCol(MilestoneColumnPushedDate, event.CreationDate()),
},
[]handler.Condition{ []handler.Condition{
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
handler.NewCond(MilestoneColumnType, e.MilestoneType),
}, },
), nil ), nil
} }
@ -194,7 +203,6 @@ func (p *milestoneProjection) reduceProjectAdded(event eventstore.Event) (*handl
} }
func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*handler.Statement, error) { func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*handler.Statement, error) {
printEvent(event)
e, ok := event.(*user.UserTokenAddedEvent) e, ok := event.(*user.UserTokenAddedEvent)
if !ok { if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-3xhJ7", "reduce.wrong.event.type %s", user.UserTokenAddedType) return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-3xhJ7", "reduce.wrong.event.type %s", user.UserTokenAddedType)
@ -211,19 +219,17 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han
crdb.NewIsNullCond(MilestoneColumnReachedDate), crdb.NewIsNullCond(MilestoneColumnReachedDate),
}, },
), ),
/* crdb.AddUpdateStatement( crdb.AddUpdateStatement(
[]handler.Column{ []handler.Column{
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()), handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
}, },
[]handler.Condition{ []handler.Condition{
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID), handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication), handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication),
crdb.NewExpressionCond(func(param string) (clause string, needsParam bool) { crdb.NewNotEqualCond(MilestoneColumnIgnoredProject, strings.Split(e.ApplicationID, "@")[0]),
return fmt.Sprintf("%s") crdb.NewIsNullCond(MilestoneColumnReachedDate),
}), },
crdb.NewIsNullCond(MilestoneColumnReachedDate), ),
},
),*/
), nil ), nil
} }