feat(eventstore): increase parallel write capabilities (#5940)

This implementation increases parallel write capabilities of the eventstore.
Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and  [06](https://zitadel.com/docs/support/advisory/a10006).
The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`.
If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
This commit is contained in:
Silvan
2023-10-19 12:19:10 +02:00
committed by GitHub
parent 259faba3f0
commit b5564572bc
791 changed files with 30326 additions and 43202 deletions

View File

@@ -7,17 +7,13 @@ import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/user"
)
type userProjection struct {
crdb.StatementHandler
}
const (
UserTable = "projections.users8"
UserHumanTable = UserTable + "_" + UserHumanSuffix
@@ -76,82 +72,87 @@ const (
NotifyPasswordSetCol = "password_set"
)
func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userProjection {
p := new(userProjection)
config.ProjectionName = UserTable
config.Reducers = p.reducers()
config.InitCheck = crdb.NewMultiTableCheck(
crdb.NewTable([]*crdb.Column{
crdb.NewColumn(UserIDCol, crdb.ColumnTypeText),
crdb.NewColumn(UserCreationDateCol, crdb.ColumnTypeTimestamp),
crdb.NewColumn(UserChangeDateCol, crdb.ColumnTypeTimestamp),
crdb.NewColumn(UserSequenceCol, crdb.ColumnTypeInt64),
crdb.NewColumn(UserStateCol, crdb.ColumnTypeEnum),
crdb.NewColumn(UserResourceOwnerCol, crdb.ColumnTypeText),
crdb.NewColumn(UserInstanceIDCol, crdb.ColumnTypeText),
crdb.NewColumn(UserUsernameCol, crdb.ColumnTypeText),
crdb.NewColumn(UserTypeCol, crdb.ColumnTypeEnum),
crdb.NewColumn(UserOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
},
crdb.NewPrimaryKey(UserInstanceIDCol, UserIDCol),
crdb.WithIndex(crdb.NewIndex("username", []string{UserUsernameCol})),
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{UserResourceOwnerCol})),
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{UserOwnerRemovedCol})),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(HumanUserIDCol, crdb.ColumnTypeText),
crdb.NewColumn(HumanUserInstanceIDCol, crdb.ColumnTypeText),
crdb.NewColumn(HumanFirstNameCol, crdb.ColumnTypeText),
crdb.NewColumn(HumanLastNameCol, crdb.ColumnTypeText),
crdb.NewColumn(HumanNickNameCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(HumanDisplayNameCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(HumanPreferredLanguageCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(HumanGenderCol, crdb.ColumnTypeEnum, crdb.Nullable()),
crdb.NewColumn(HumanAvatarURLCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(HumanEmailCol, crdb.ColumnTypeText),
crdb.NewColumn(HumanIsEmailVerifiedCol, crdb.ColumnTypeBool, crdb.Default(false)),
crdb.NewColumn(HumanPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(HumanIsPhoneVerifiedCol, crdb.ColumnTypeBool, crdb.Nullable()),
},
crdb.NewPrimaryKey(HumanUserInstanceIDCol, HumanUserIDCol),
UserHumanSuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(MachineUserIDCol, crdb.ColumnTypeText),
crdb.NewColumn(MachineUserInstanceIDCol, crdb.ColumnTypeText),
crdb.NewColumn(MachineNameCol, crdb.ColumnTypeText),
crdb.NewColumn(MachineDescriptionCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(MachineHasSecretCol, crdb.ColumnTypeBool, crdb.Default(false)),
crdb.NewColumn(MachineAccessTokenTypeCol, crdb.ColumnTypeEnum, crdb.Default(0)),
},
crdb.NewPrimaryKey(MachineUserInstanceIDCol, MachineUserIDCol),
UserMachineSuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(NotifyUserIDCol, crdb.ColumnTypeText),
crdb.NewColumn(NotifyInstanceIDCol, crdb.ColumnTypeText),
crdb.NewColumn(NotifyLastEmailCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(NotifyVerifiedEmailCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(NotifyLastPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(NotifyVerifiedPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
crdb.NewColumn(NotifyPasswordSetCol, crdb.ColumnTypeBool, crdb.Default(false)),
},
crdb.NewPrimaryKey(NotifyInstanceIDCol, NotifyUserIDCol),
UserNotifySuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
),
)
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
return p
type userProjection struct{}
func newUserProjection(ctx context.Context, config handler.Config) *handler.Handler {
return handler.NewHandler(ctx, &config, new(userProjection))
}
func (p *userProjection) reducers() []handler.AggregateReducer {
func (*userProjection) Name() string {
return UserTable
}
func (*userProjection) Init() *old_handler.Check {
return handler.NewMultiTableCheck(
handler.NewTable([]*handler.InitColumn{
handler.NewColumn(UserIDCol, handler.ColumnTypeText),
handler.NewColumn(UserCreationDateCol, handler.ColumnTypeTimestamp),
handler.NewColumn(UserChangeDateCol, handler.ColumnTypeTimestamp),
handler.NewColumn(UserSequenceCol, handler.ColumnTypeInt64),
handler.NewColumn(UserStateCol, handler.ColumnTypeEnum),
handler.NewColumn(UserResourceOwnerCol, handler.ColumnTypeText),
handler.NewColumn(UserInstanceIDCol, handler.ColumnTypeText),
handler.NewColumn(UserUsernameCol, handler.ColumnTypeText),
handler.NewColumn(UserTypeCol, handler.ColumnTypeEnum),
handler.NewColumn(UserOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
},
handler.NewPrimaryKey(UserInstanceIDCol, UserIDCol),
handler.WithIndex(handler.NewIndex("username", []string{UserUsernameCol})),
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserResourceOwnerCol})),
handler.WithIndex(handler.NewIndex("owner_removed", []string{UserOwnerRemovedCol})),
),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(HumanUserIDCol, handler.ColumnTypeText),
handler.NewColumn(HumanUserInstanceIDCol, handler.ColumnTypeText),
handler.NewColumn(HumanFirstNameCol, handler.ColumnTypeText),
handler.NewColumn(HumanLastNameCol, handler.ColumnTypeText),
handler.NewColumn(HumanNickNameCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(HumanDisplayNameCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(HumanPreferredLanguageCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(HumanGenderCol, handler.ColumnTypeEnum, handler.Nullable()),
handler.NewColumn(HumanAvatarURLCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(HumanEmailCol, handler.ColumnTypeText),
handler.NewColumn(HumanIsEmailVerifiedCol, handler.ColumnTypeBool, handler.Default(false)),
handler.NewColumn(HumanPhoneCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(HumanIsPhoneVerifiedCol, handler.ColumnTypeBool, handler.Nullable()),
},
handler.NewPrimaryKey(HumanUserInstanceIDCol, HumanUserIDCol),
UserHumanSuffix,
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(MachineUserIDCol, handler.ColumnTypeText),
handler.NewColumn(MachineUserInstanceIDCol, handler.ColumnTypeText),
handler.NewColumn(MachineNameCol, handler.ColumnTypeText),
handler.NewColumn(MachineDescriptionCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(MachineHasSecretCol, handler.ColumnTypeBool, handler.Default(false)),
handler.NewColumn(MachineAccessTokenTypeCol, handler.ColumnTypeEnum, handler.Default(0)),
},
handler.NewPrimaryKey(MachineUserInstanceIDCol, MachineUserIDCol),
UserMachineSuffix,
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(NotifyUserIDCol, handler.ColumnTypeText),
handler.NewColumn(NotifyInstanceIDCol, handler.ColumnTypeText),
handler.NewColumn(NotifyLastEmailCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(NotifyVerifiedEmailCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(NotifyLastPhoneCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(NotifyVerifiedPhoneCol, handler.ColumnTypeText, handler.Nullable()),
handler.NewColumn(NotifyPasswordSetCol, handler.ColumnTypeBool, handler.Default(false)),
},
handler.NewPrimaryKey(NotifyInstanceIDCol, NotifyUserIDCol),
UserNotifySuffix,
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
),
)
}
func (p *userProjection) Reducers() []handler.AggregateReducer {
return []handler.AggregateReducer{
{
Aggregate: user.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: user.UserV1AddedType,
Reduce: p.reduceHumanAdded,
@@ -292,7 +293,7 @@ func (p *userProjection) reducers() []handler.AggregateReducer {
},
{
Aggregate: org.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: org.OrgRemovedEventType,
Reduce: p.reduceOwnerRemoved,
@@ -301,7 +302,7 @@ func (p *userProjection) reducers() []handler.AggregateReducer {
},
{
Aggregate: instance.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(UserInstanceIDCol),
@@ -316,9 +317,9 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Ebynp", "reduce.wrong.event.type %s", user.HumanAddedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(UserIDCol, e.Aggregate().ID),
handler.NewCol(UserCreationDateCol, e.CreationDate()),
@@ -331,7 +332,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
},
),
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
@@ -344,9 +345,9 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
handler.NewCol(HumanEmailCol, e.EmailAddress),
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
@@ -354,7 +355,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -364,9 +365,9 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-xE53M", "reduce.wrong.event.type %s", user.HumanRegisteredType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(UserIDCol, e.Aggregate().ID),
handler.NewCol(UserCreationDateCol, e.CreationDate()),
@@ -379,7 +380,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
},
),
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
@@ -392,9 +393,9 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
handler.NewCol(HumanEmailCol, e.EmailAddress),
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
@@ -402,7 +403,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -412,7 +413,7 @@ func (p *userProjection) reduceHumanInitCodeAdded(event eventstore.Event) (*hand
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dvgws", "reduce.wrong.event.type %s", user.HumanInitialCodeAddedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserStateCol, domain.UserStateInitial),
@@ -429,7 +430,7 @@ func (p *userProjection) reduceHumanInitCodeSucceeded(event eventstore.Event) (*
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dfvwq", "reduce.wrong.event.type %s", user.HumanInitializedCheckSucceededType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserStateCol, domain.UserStateActive),
@@ -447,7 +448,7 @@ func (p *userProjection) reduceUserLocked(event eventstore.Event) (*handler.Stat
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-exyBF", "reduce.wrong.event.type %s", user.UserLockedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -467,7 +468,7 @@ func (p *userProjection) reduceUserUnlocked(event eventstore.Event) (*handler.St
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JIyRl", "reduce.wrong.event.type %s", user.UserUnlockedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -487,7 +488,7 @@ func (p *userProjection) reduceUserDeactivated(event eventstore.Event) (*handler
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-6BNjj", "reduce.wrong.event.type %s", user.UserDeactivatedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -507,7 +508,7 @@ func (p *userProjection) reduceUserReactivated(event eventstore.Event) (*handler
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-IoF6j", "reduce.wrong.event.type %s", user.UserReactivatedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -527,7 +528,7 @@ func (p *userProjection) reduceUserRemoved(event eventstore.Event) (*handler.Sta
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-BQB2t", "reduce.wrong.event.type %s", user.UserRemovedType)
}
return crdb.NewDeleteStatement(
return handler.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(UserIDCol, e.Aggregate().ID),
@@ -542,7 +543,7 @@ func (p *userProjection) reduceUserNameChanged(event eventstore.Event) (*handler
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QNKyV", "reduce.wrong.event.type %s", user.UserUserNameChangedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -562,7 +563,7 @@ func (p *userProjection) reduceDomainClaimed(event eventstore.Event) (*handler.S
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASwf3", "reduce.wrong.event.type %s", user.UserDomainClaimedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
@@ -606,9 +607,9 @@ func (p *userProjection) reduceHumanProfileChanged(event eventstore.Event) (*han
cols = append(cols, handler.NewCol(HumanGenderCol, *e.Gender))
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -618,13 +619,13 @@ func (p *userProjection) reduceHumanProfileChanged(event eventstore.Event) (*han
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
cols,
[]handler.Condition{
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
), nil
}
@@ -635,9 +636,9 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-xOGIA", "reduce.wrong.event.type %s", user.HumanPhoneChangedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -647,7 +648,7 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanPhoneCol, e.PhoneNumber),
handler.NewCol(HumanIsPhoneVerifiedCol, false),
@@ -656,9 +657,9 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
},
@@ -666,7 +667,7 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -677,9 +678,9 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JI4S1", "reduce.wrong.event.type %s", user.HumanPhoneRemovedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -689,7 +690,7 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanPhoneCol, nil),
handler.NewCol(HumanIsPhoneVerifiedCol, nil),
@@ -698,9 +699,9 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(NotifyLastPhoneCol, nil),
handler.NewCol(NotifyVerifiedPhoneCol, nil),
@@ -709,7 +710,7 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -720,9 +721,9 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-LBnqG", "reduce.wrong.event.type %s", user.HumanPhoneVerifiedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -732,7 +733,7 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanIsPhoneVerifiedCol, true),
},
@@ -740,17 +741,17 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
crdb.NewCopyCol(NotifyVerifiedPhoneCol, NotifyLastPhoneCol),
handler.NewCopyCol(NotifyVerifiedPhoneCol, NotifyLastPhoneCol),
},
[]handler.Condition{
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -761,9 +762,9 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KwiHa", "reduce.wrong.event.type %s", user.HumanEmailChangedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -773,7 +774,7 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanEmailCol, e.EmailAddress),
handler.NewCol(HumanIsEmailVerifiedCol, false),
@@ -782,9 +783,9 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(NotifyLastEmailCol, &sql.NullString{String: string(e.EmailAddress), Valid: e.EmailAddress != ""}),
},
@@ -792,7 +793,7 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -803,9 +804,9 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JzcDq", "reduce.wrong.event.type %s", user.HumanEmailVerifiedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -815,7 +816,7 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanIsEmailVerifiedCol, true),
},
@@ -823,17 +824,17 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
crdb.NewCopyCol(NotifyVerifiedEmailCol, NotifyLastEmailCol),
handler.NewCopyCol(NotifyVerifiedEmailCol, NotifyLastEmailCol),
},
[]handler.Condition{
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
),
), nil
}
@@ -844,9 +845,9 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-eDEdt", "reduce.wrong.event.type %s", user.HumanAvatarAddedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -856,7 +857,7 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanAvatarURLCol, e.StoreKey),
},
@@ -864,7 +865,7 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
), nil
}
@@ -875,9 +876,9 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KhETX", "reduce.wrong.event.type %s", user.HumanAvatarRemovedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -887,7 +888,7 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(HumanAvatarURLCol, nil),
},
@@ -895,7 +896,7 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserHumanSuffix),
handler.WithTableSuffix(UserHumanSuffix),
),
), nil
}
@@ -906,7 +907,7 @@ func (p *userProjection) reduceHumanPasswordChanged(event eventstore.Event) (*ha
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-jqXUY", "reduce.wrong.event.type %s", user.HumanPasswordChangedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(NotifyPasswordSetCol, true),
@@ -915,7 +916,7 @@ func (p *userProjection) reduceHumanPasswordChanged(event eventstore.Event) (*ha
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserNotifySuffix),
handler.WithTableSuffix(UserNotifySuffix),
), nil
}
@@ -924,9 +925,9 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x0p1n1i", "reduce.wrong.event.type %s", user.MachineSecretSetType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -936,7 +937,7 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(MachineHasSecretCol, true),
},
@@ -944,7 +945,7 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserMachineSuffix),
handler.WithTableSuffix(UserMachineSuffix),
),
), nil
}
@@ -955,9 +956,9 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x0p6n1i", "reduce.wrong.event.type %s", user.MachineSecretRemovedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -967,7 +968,7 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(MachineHasSecretCol, false),
},
@@ -975,7 +976,7 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserMachineSuffix),
handler.WithTableSuffix(UserMachineSuffix),
),
), nil
}
@@ -986,9 +987,9 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-q7ier", "reduce.wrong.event.type %s", user.MachineAddedEventType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(UserIDCol, e.Aggregate().ID),
handler.NewCol(UserCreationDateCol, e.CreationDate()),
@@ -1001,7 +1002,7 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
handler.NewCol(UserTypeCol, domain.UserTypeMachine),
},
),
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(MachineUserIDCol, e.Aggregate().ID),
handler.NewCol(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
@@ -1009,7 +1010,7 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
handler.NewCol(MachineDescriptionCol, &sql.NullString{String: e.Description, Valid: e.Description != ""}),
handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType),
},
crdb.WithTableSuffix(UserMachineSuffix),
handler.WithTableSuffix(UserMachineSuffix),
),
), nil
}
@@ -1031,12 +1032,12 @@ func (p *userProjection) reduceMachineChanged(event eventstore.Event) (*handler.
cols = append(cols, handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType))
}
if len(cols) == 0 {
return crdb.NewNoOpStatement(e), nil
return handler.NewNoOpStatement(e), nil
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(UserChangeDateCol, e.CreationDate()),
handler.NewCol(UserSequenceCol, e.Sequence()),
@@ -1046,13 +1047,13 @@ func (p *userProjection) reduceMachineChanged(event eventstore.Event) (*handler.
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
},
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
cols,
[]handler.Condition{
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(UserMachineSuffix),
handler.WithTableSuffix(UserMachineSuffix),
),
), nil
@@ -1064,7 +1065,7 @@ func (p *userProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.St
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-NCsdV", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
}
return crdb.NewDeleteStatement(
return handler.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),