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,8 +7,8 @@ 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/project"
@@ -67,91 +67,92 @@ const (
AppSAMLConfigColumnMetadataURL = "metadata_url"
)
type appProjection struct {
crdb.StatementHandler
type appProjection struct{}
func newAppProjection(ctx context.Context, config handler.Config) *handler.Handler {
return handler.NewHandler(ctx, &config, new(appProjection))
}
func newAppProjection(ctx context.Context, config crdb.StatementHandlerConfig) *appProjection {
p := new(appProjection)
config.ProjectionName = AppProjectionTable
config.Reducers = p.reducers()
config.InitCheck = crdb.NewMultiTableCheck(
crdb.NewTable([]*crdb.Column{
crdb.NewColumn(AppColumnID, crdb.ColumnTypeText),
crdb.NewColumn(AppColumnName, crdb.ColumnTypeText),
crdb.NewColumn(AppColumnProjectID, crdb.ColumnTypeText),
crdb.NewColumn(AppColumnCreationDate, crdb.ColumnTypeTimestamp),
crdb.NewColumn(AppColumnChangeDate, crdb.ColumnTypeTimestamp),
crdb.NewColumn(AppColumnResourceOwner, crdb.ColumnTypeText),
crdb.NewColumn(AppColumnInstanceID, crdb.ColumnTypeText),
crdb.NewColumn(AppColumnState, crdb.ColumnTypeEnum),
crdb.NewColumn(AppColumnSequence, crdb.ColumnTypeInt64),
crdb.NewColumn(AppColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
func (*appProjection) Name() string {
return AppProjectionTable
}
func (*appProjection) Init() *old_handler.Check {
return handler.NewMultiTableCheck(
handler.NewTable([]*handler.InitColumn{
handler.NewColumn(AppColumnID, handler.ColumnTypeText),
handler.NewColumn(AppColumnName, handler.ColumnTypeText),
handler.NewColumn(AppColumnProjectID, handler.ColumnTypeText),
handler.NewColumn(AppColumnCreationDate, handler.ColumnTypeTimestamp),
handler.NewColumn(AppColumnChangeDate, handler.ColumnTypeTimestamp),
handler.NewColumn(AppColumnResourceOwner, handler.ColumnTypeText),
handler.NewColumn(AppColumnInstanceID, handler.ColumnTypeText),
handler.NewColumn(AppColumnState, handler.ColumnTypeEnum),
handler.NewColumn(AppColumnSequence, handler.ColumnTypeInt64),
handler.NewColumn(AppColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
},
crdb.NewPrimaryKey(AppColumnInstanceID, AppColumnID),
crdb.WithIndex(crdb.NewIndex("project_id", []string{AppColumnProjectID})),
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AppColumnOwnerRemoved})),
handler.NewPrimaryKey(AppColumnInstanceID, AppColumnID),
handler.WithIndex(handler.NewIndex("project_id", []string{AppColumnProjectID})),
handler.WithIndex(handler.NewIndex("owner_removed", []string{AppColumnOwnerRemoved})),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(AppAPIConfigColumnAppID, crdb.ColumnTypeText),
crdb.NewColumn(AppAPIConfigColumnInstanceID, crdb.ColumnTypeText),
crdb.NewColumn(AppAPIConfigColumnClientID, crdb.ColumnTypeText),
crdb.NewColumn(AppAPIConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
crdb.NewColumn(AppAPIConfigColumnAuthMethod, crdb.ColumnTypeEnum),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(AppAPIConfigColumnAppID, handler.ColumnTypeText),
handler.NewColumn(AppAPIConfigColumnInstanceID, handler.ColumnTypeText),
handler.NewColumn(AppAPIConfigColumnClientID, handler.ColumnTypeText),
handler.NewColumn(AppAPIConfigColumnClientSecret, handler.ColumnTypeJSONB, handler.Nullable()),
handler.NewColumn(AppAPIConfigColumnAuthMethod, handler.ColumnTypeEnum),
},
crdb.NewPrimaryKey(AppAPIConfigColumnInstanceID, AppAPIConfigColumnAppID),
handler.NewPrimaryKey(AppAPIConfigColumnInstanceID, AppAPIConfigColumnAppID),
appAPITableSuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppAPIConfigColumnClientID})),
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
handler.WithIndex(handler.NewIndex("client_id", []string{AppAPIConfigColumnClientID})),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(AppOIDCConfigColumnAppID, crdb.ColumnTypeText),
crdb.NewColumn(AppOIDCConfigColumnInstanceID, crdb.ColumnTypeText),
crdb.NewColumn(AppOIDCConfigColumnVersion, crdb.ColumnTypeEnum),
crdb.NewColumn(AppOIDCConfigColumnClientID, crdb.ColumnTypeText),
crdb.NewColumn(AppOIDCConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnResponseTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnGrantTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnApplicationType, crdb.ColumnTypeEnum),
crdb.NewColumn(AppOIDCConfigColumnAuthMethodType, crdb.ColumnTypeEnum),
crdb.NewColumn(AppOIDCConfigColumnPostLogoutRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnDevMode, crdb.ColumnTypeBool),
crdb.NewColumn(AppOIDCConfigColumnAccessTokenType, crdb.ColumnTypeEnum),
crdb.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
crdb.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
crdb.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
crdb.NewColumn(AppOIDCConfigColumnClockSkew, crdb.ColumnTypeInt64, crdb.Default(0)),
crdb.NewColumn(AppOIDCConfigColumnAdditionalOrigins, crdb.ColumnTypeTextArray, crdb.Nullable()),
crdb.NewColumn(AppOIDCConfigColumnSkipNativeAppSuccessPage, crdb.ColumnTypeBool, crdb.Default(false)),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(AppOIDCConfigColumnAppID, handler.ColumnTypeText),
handler.NewColumn(AppOIDCConfigColumnInstanceID, handler.ColumnTypeText),
handler.NewColumn(AppOIDCConfigColumnVersion, handler.ColumnTypeEnum),
handler.NewColumn(AppOIDCConfigColumnClientID, handler.ColumnTypeText),
handler.NewColumn(AppOIDCConfigColumnClientSecret, handler.ColumnTypeJSONB, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnRedirectUris, handler.ColumnTypeTextArray, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnResponseTypes, handler.ColumnTypeEnumArray, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnGrantTypes, handler.ColumnTypeEnumArray, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnApplicationType, handler.ColumnTypeEnum),
handler.NewColumn(AppOIDCConfigColumnAuthMethodType, handler.ColumnTypeEnum),
handler.NewColumn(AppOIDCConfigColumnPostLogoutRedirectUris, handler.ColumnTypeTextArray, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnDevMode, handler.ColumnTypeBool),
handler.NewColumn(AppOIDCConfigColumnAccessTokenType, handler.ColumnTypeEnum),
handler.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, handler.ColumnTypeBool, handler.Default(false)),
handler.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, handler.ColumnTypeBool, handler.Default(false)),
handler.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, handler.ColumnTypeBool, handler.Default(false)),
handler.NewColumn(AppOIDCConfigColumnClockSkew, handler.ColumnTypeInt64, handler.Default(0)),
handler.NewColumn(AppOIDCConfigColumnAdditionalOrigins, handler.ColumnTypeTextArray, handler.Nullable()),
handler.NewColumn(AppOIDCConfigColumnSkipNativeAppSuccessPage, handler.ColumnTypeBool, handler.Default(false)),
},
crdb.NewPrimaryKey(AppOIDCConfigColumnInstanceID, AppOIDCConfigColumnAppID),
handler.NewPrimaryKey(AppOIDCConfigColumnInstanceID, AppOIDCConfigColumnAppID),
appOIDCTableSuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppOIDCConfigColumnClientID})),
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
handler.WithIndex(handler.NewIndex("client_id", []string{AppOIDCConfigColumnClientID})),
),
crdb.NewSuffixedTable([]*crdb.Column{
crdb.NewColumn(AppSAMLConfigColumnAppID, crdb.ColumnTypeText),
crdb.NewColumn(AppSAMLConfigColumnInstanceID, crdb.ColumnTypeText),
crdb.NewColumn(AppSAMLConfigColumnEntityID, crdb.ColumnTypeText),
crdb.NewColumn(AppSAMLConfigColumnMetadata, crdb.ColumnTypeBytes),
crdb.NewColumn(AppSAMLConfigColumnMetadataURL, crdb.ColumnTypeText),
handler.NewSuffixedTable([]*handler.InitColumn{
handler.NewColumn(AppSAMLConfigColumnAppID, handler.ColumnTypeText),
handler.NewColumn(AppSAMLConfigColumnInstanceID, handler.ColumnTypeText),
handler.NewColumn(AppSAMLConfigColumnEntityID, handler.ColumnTypeText),
handler.NewColumn(AppSAMLConfigColumnMetadata, handler.ColumnTypeBytes),
handler.NewColumn(AppSAMLConfigColumnMetadataURL, handler.ColumnTypeText),
},
crdb.NewPrimaryKey(AppSAMLConfigColumnInstanceID, AppSAMLConfigColumnAppID),
handler.NewPrimaryKey(AppSAMLConfigColumnInstanceID, AppSAMLConfigColumnAppID),
appSAMLTableSuffix,
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
crdb.WithIndex(crdb.NewIndex("entity_id", []string{AppSAMLConfigColumnEntityID})),
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
handler.WithIndex(handler.NewIndex("entity_id", []string{AppSAMLConfigColumnEntityID})),
),
)
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
return p
}
func (p *appProjection) reducers() []handler.AggregateReducer {
func (p *appProjection) Reducers() []handler.AggregateReducer {
return []handler.AggregateReducer{
{
Aggregate: project.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: project.ApplicationAddedType,
Reduce: p.reduceAppAdded,
@@ -212,7 +213,7 @@ func (p *appProjection) reducers() []handler.AggregateReducer {
},
{
Aggregate: org.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: org.OrgRemovedEventType,
Reduce: p.reduceOwnerRemoved,
@@ -221,7 +222,7 @@ func (p *appProjection) reducers() []handler.AggregateReducer {
},
{
Aggregate: instance.AggregateType,
EventRedusers: []handler.EventReducer{
EventReducers: []handler.EventReducer{
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(AppColumnInstanceID),
@@ -236,7 +237,7 @@ func (p *appProjection) reduceAppAdded(event eventstore.Event) (*handler.Stateme
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-1xYE6", "reduce.wrong.event.type %s", project.ApplicationAddedType)
}
return crdb.NewCreateStatement(
return handler.NewCreateStatement(
e,
[]handler.Column{
handler.NewCol(AppColumnID, e.AppID),
@@ -258,9 +259,9 @@ func (p *appProjection) reduceAppChanged(event eventstore.Event) (*handler.State
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ZJ8JA", "reduce.wrong.event.type %s", project.ApplicationChangedType)
}
if e.Name == "" {
return crdb.NewNoOpStatement(event), nil
return handler.NewNoOpStatement(event), nil
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(AppColumnName, e.Name),
@@ -279,7 +280,7 @@ func (p *appProjection) reduceAppDeactivated(event eventstore.Event) (*handler.S
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-MVWxZ", "reduce.wrong.event.type %s", project.ApplicationDeactivatedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(AppColumnState, domain.AppStateInactive),
@@ -298,7 +299,7 @@ func (p *appProjection) reduceAppReactivated(event eventstore.Event) (*handler.S
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-D0HZO", "reduce.wrong.event.type %s", project.ApplicationReactivatedType)
}
return crdb.NewUpdateStatement(
return handler.NewUpdateStatement(
e,
[]handler.Column{
handler.NewCol(AppColumnState, domain.AppStateActive),
@@ -317,7 +318,7 @@ func (p *appProjection) reduceAppRemoved(event eventstore.Event) (*handler.State
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.ApplicationRemovedType)
}
return crdb.NewDeleteStatement(
return handler.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(AppColumnID, e.AppID),
@@ -331,7 +332,7 @@ func (p *appProjection) reduceProjectRemoved(event eventstore.Event) (*handler.S
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DlUlO", "reduce.wrong.event.type %s", project.ProjectRemovedType)
}
return crdb.NewDeleteStatement(
return handler.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(AppColumnProjectID, e.Aggregate().ID),
@@ -345,9 +346,9 @@ func (p *appProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.S
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.APIConfigAddedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(AppAPIConfigColumnAppID, e.AppID),
handler.NewCol(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
@@ -355,9 +356,9 @@ func (p *appProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.S
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
handler.NewCol(AppAPIConfigColumnAuthMethod, e.AuthMethodType),
},
crdb.WithTableSuffix(appAPITableSuffix),
handler.WithTableSuffix(appAPITableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -383,19 +384,19 @@ func (p *appProjection) reduceAPIConfigChanged(event eventstore.Event) (*handler
cols = append(cols, handler.NewCol(AppAPIConfigColumnAuthMethod, *e.AuthMethodType))
}
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(
cols,
[]handler.Condition{
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(appAPITableSuffix),
handler.WithTableSuffix(appAPITableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -413,9 +414,9 @@ func (p *appProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*h
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ttb0I", "reduce.wrong.event.type %s", project.APIConfigSecretChangedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
},
@@ -423,9 +424,9 @@ func (p *appProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*h
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(appAPITableSuffix),
handler.WithTableSuffix(appAPITableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -443,33 +444,33 @@ func (p *appProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigAddedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(AppOIDCConfigColumnAppID, e.AppID),
handler.NewCol(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
handler.NewCol(AppOIDCConfigColumnVersion, e.Version),
handler.NewCol(AppOIDCConfigColumnClientID, e.ClientID),
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(e.RedirectUris)),
handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](e.ResponseTypes)),
handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](e.GrantTypes)),
handler.NewCol(AppOIDCConfigColumnRedirectUris, database.TextArray[string](e.RedirectUris)),
handler.NewCol(AppOIDCConfigColumnResponseTypes, database.Array[domain.OIDCResponseType](e.ResponseTypes)),
handler.NewCol(AppOIDCConfigColumnGrantTypes, database.Array[domain.OIDCGrantType](e.GrantTypes)),
handler.NewCol(AppOIDCConfigColumnApplicationType, e.ApplicationType),
handler.NewCol(AppOIDCConfigColumnAuthMethodType, e.AuthMethodType),
handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(e.PostLogoutRedirectUris)),
handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.TextArray[string](e.PostLogoutRedirectUris)),
handler.NewCol(AppOIDCConfigColumnDevMode, e.DevMode),
handler.NewCol(AppOIDCConfigColumnAccessTokenType, e.AccessTokenType),
handler.NewCol(AppOIDCConfigColumnAccessTokenRoleAssertion, e.AccessTokenRoleAssertion),
handler.NewCol(AppOIDCConfigColumnIDTokenRoleAssertion, e.IDTokenRoleAssertion),
handler.NewCol(AppOIDCConfigColumnIDTokenUserinfoAssertion, e.IDTokenUserinfoAssertion),
handler.NewCol(AppOIDCConfigColumnClockSkew, e.ClockSkew),
handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(e.AdditionalOrigins)),
handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.TextArray[string](e.AdditionalOrigins)),
handler.NewCol(AppOIDCConfigColumnSkipNativeAppSuccessPage, e.SkipNativeAppSuccessPage),
},
crdb.WithTableSuffix(appOIDCTableSuffix),
handler.WithTableSuffix(appOIDCTableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -493,13 +494,13 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
cols = append(cols, handler.NewCol(AppOIDCConfigColumnVersion, *e.Version))
}
if e.RedirectUris != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(*e.RedirectUris)))
cols = append(cols, handler.NewCol(AppOIDCConfigColumnRedirectUris, database.TextArray[string](*e.RedirectUris)))
}
if e.ResponseTypes != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](*e.ResponseTypes)))
cols = append(cols, handler.NewCol(AppOIDCConfigColumnResponseTypes, database.Array[domain.OIDCResponseType](*e.ResponseTypes)))
}
if e.GrantTypes != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](*e.GrantTypes)))
cols = append(cols, handler.NewCol(AppOIDCConfigColumnGrantTypes, database.Array[domain.OIDCGrantType](*e.GrantTypes)))
}
if e.ApplicationType != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnApplicationType, *e.ApplicationType))
@@ -508,7 +509,7 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAuthMethodType, *e.AuthMethodType))
}
if e.PostLogoutRedirectUris != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(*e.PostLogoutRedirectUris)))
cols = append(cols, handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.TextArray[string](*e.PostLogoutRedirectUris)))
}
if e.DevMode != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnDevMode, *e.DevMode))
@@ -529,27 +530,27 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
cols = append(cols, handler.NewCol(AppOIDCConfigColumnClockSkew, *e.ClockSkew))
}
if e.AdditionalOrigins != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(*e.AdditionalOrigins)))
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.TextArray[string](*e.AdditionalOrigins)))
}
if e.SkipNativeAppSuccessPage != nil {
cols = append(cols, handler.NewCol(AppOIDCConfigColumnSkipNativeAppSuccessPage, *e.SkipNativeAppSuccessPage))
}
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(
cols,
[]handler.Condition{
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(appOIDCTableSuffix),
handler.WithTableSuffix(appOIDCTableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -567,9 +568,9 @@ func (p *appProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigSecretChangedType)
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
},
@@ -577,9 +578,9 @@ func (p *appProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(appOIDCTableSuffix),
handler.WithTableSuffix(appOIDCTableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -598,7 +599,7 @@ func (p *appProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Sta
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Hyd1f", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
}
return crdb.NewDeleteStatement(
return handler.NewDeleteStatement(
e,
[]handler.Condition{
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
@@ -612,9 +613,9 @@ func (p *appProjection) reduceSAMLConfigAdded(event eventstore.Event) (*handler.
if !ok {
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GMHU1", "reduce.wrong.event.type")
}
return crdb.NewMultiStatement(
return handler.NewMultiStatement(
e,
crdb.AddCreateStatement(
handler.AddCreateStatement(
[]handler.Column{
handler.NewCol(AppSAMLConfigColumnAppID, e.AppID),
handler.NewCol(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
@@ -622,9 +623,9 @@ func (p *appProjection) reduceSAMLConfigAdded(event eventstore.Event) (*handler.
handler.NewCol(AppSAMLConfigColumnMetadata, e.Metadata),
handler.NewCol(AppSAMLConfigColumnMetadataURL, e.MetadataURL),
},
crdb.WithTableSuffix(appSAMLTableSuffix),
handler.WithTableSuffix(appSAMLTableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),
@@ -655,20 +656,20 @@ func (p *appProjection) reduceSAMLConfigChanged(event eventstore.Event) (*handle
}
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(
cols,
[]handler.Condition{
handler.NewCond(AppSAMLConfigColumnAppID, e.AppID),
handler.NewCond(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
},
crdb.WithTableSuffix(appSAMLTableSuffix),
handler.WithTableSuffix(appSAMLTableSuffix),
),
crdb.AddUpdateStatement(
handler.AddUpdateStatement(
[]handler.Column{
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
handler.NewCol(AppColumnSequence, e.Sequence()),