diff --git a/internal/query/app.go b/internal/query/app.go index 2fe6dd15a9..c5bb8e39f3 100644 --- a/internal/query/app.go +++ b/internal/query/app.go @@ -279,6 +279,7 @@ func (q *Queries) AppBySAMLEntityID(ctx context.Context, entityID string) (*App, query, args, err := stmt.Where( sq.Eq{ AppSAMLConfigColumnEntityID.identifier(): entityID, + AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(), }, ).ToSql() if err != nil { @@ -292,10 +293,13 @@ func (q *Queries) AppBySAMLEntityID(ctx context.Context, entityID string) (*App, func (q *Queries) ProjectByClientID(ctx context.Context, appID string) (*Project, error) { stmt, scan := prepareProjectByAppQuery() query, args, err := stmt.Where( - sq.Or{ - sq.Eq{AppOIDCConfigColumnClientID.identifier(): appID}, - sq.Eq{AppAPIConfigColumnClientID.identifier(): appID}, - sq.Eq{AppSAMLConfigColumnAppID.identifier(): appID}, + sq.And{ + sq.Eq{AppColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID()}, + sq.Or{ + sq.Eq{AppOIDCConfigColumnClientID.identifier(): appID}, + sq.Eq{AppAPIConfigColumnClientID.identifier(): appID}, + sq.Eq{AppSAMLConfigColumnAppID.identifier(): appID}, + }, }, ).ToSql() if err != nil { diff --git a/internal/query/projection/action.go b/internal/query/projection/action.go index 05fd15b0ef..6d706511a6 100644 --- a/internal/query/projection/action.go +++ b/internal/query/projection/action.go @@ -145,6 +145,7 @@ func (p *actionProjection) reduceActionChanged(event eventstore.Event) (*handler values, []handler.Condition{ handler.NewCond(ActionIDCol, e.Aggregate().ID), + handler.NewCond(ActionInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -163,6 +164,7 @@ func (p *actionProjection) reduceActionDeactivated(event eventstore.Event) (*han }, []handler.Condition{ handler.NewCond(ActionIDCol, e.Aggregate().ID), + handler.NewCond(ActionInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -181,6 +183,7 @@ func (p *actionProjection) reduceActionReactivated(event eventstore.Event) (*han }, []handler.Condition{ handler.NewCond(ActionIDCol, e.Aggregate().ID), + handler.NewCond(ActionInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -194,6 +197,7 @@ func (p *actionProjection) reduceActionRemoved(event eventstore.Event) (*handler e, []handler.Condition{ handler.NewCond(ActionIDCol, e.Aggregate().ID), + handler.NewCond(ActionInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/action_test.go b/internal/query/projection/action_test.go index 44116604e0..a6a702cccf 100644 --- a/internal/query/projection/action_test.go +++ b/internal/query/projection/action_test.go @@ -76,13 +76,14 @@ func TestActionProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, name, script) = ($1, $2, $3, $4) WHERE (id = $5)", + expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, name, script) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "name2", "name2(){}", "agg-id", + "instance-id", }, }, }, @@ -106,12 +107,13 @@ func TestActionProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)", + expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.ActionStateInactive, "agg-id", + "instance-id", }, }, }, @@ -135,12 +137,13 @@ func TestActionProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4)", + expectedStmt: "UPDATE projections.actions2 SET (change_date, sequence, action_state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.ActionStateActive, "agg-id", + "instance-id", }, }, }, @@ -164,9 +167,10 @@ func TestActionProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.actions2 WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.actions2 WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/app_test.go b/internal/query/projection/app_test.go index 256e27d2b5..0bfa9edfe3 100644 --- a/internal/query/projection/app_test.go +++ b/internal/query/projection/app_test.go @@ -25,7 +25,7 @@ func TestAppProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "project.reduceAppAdded", + name: "project reduceAppAdded", args: args{ event: getEvent(testEvent( repository.EventType(project.ApplicationAddedType), @@ -62,7 +62,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAppChanged", + name: "project reduceAppChanged", args: args{ event: getEvent(testEvent( repository.EventType(project.ApplicationChangedType), @@ -95,7 +95,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAppDeactivated", + name: "project reduceAppDeactivated", args: args{ event: getEvent(testEvent( repository.EventType(project.ApplicationDeactivatedType), @@ -127,7 +127,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAppReactivated", + name: "project reduceAppReactivated", args: args{ event: getEvent(testEvent( repository.EventType(project.ApplicationReactivatedType), @@ -159,7 +159,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAppRemoved", + name: "project reduceAppRemoved", args: args{ event: getEvent(testEvent( repository.EventType(project.ApplicationRemovedType), @@ -188,7 +188,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceProjectRemoved", + name: "project reduceProjectRemoved", args: args{ event: getEvent(testEvent( repository.EventType(project.ProjectRemovedType), @@ -215,7 +215,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -241,7 +241,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAPIConfigAdded", + name: "project reduceAPIConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(project.APIConfigAddedType), @@ -285,7 +285,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAPIConfigChanged", + name: "project reduceAPIConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(project.APIConfigChangedType), @@ -328,7 +328,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAPIConfigChanged noop", + name: "project reduceAPIConfigChanged noop", args: args{ event: getEvent(testEvent( repository.EventType(project.APIConfigChangedType), @@ -349,7 +349,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceAPIConfigSecretChanged", + name: "project reduceAPIConfigSecretChanged", args: args{ event: getEvent(testEvent( repository.EventType(project.APIConfigSecretChangedType), @@ -389,7 +389,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceOIDCConfigAdded", + name: "project reduceOIDCConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(project.OIDCConfigAddedType), @@ -459,7 +459,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceOIDCConfigChanged", + name: "project reduceOIDCConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(project.OIDCConfigChangedType), @@ -525,7 +525,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceOIDCConfigChanged noop", + name: "project reduceOIDCConfigChanged noop", args: args{ event: getEvent(testEvent( repository.EventType(project.OIDCConfigChangedType), @@ -546,7 +546,7 @@ func TestAppProjection_reduces(t *testing.T) { }, }, { - name: "project.reduceOIDCConfigSecretChanged", + name: "project reduceOIDCConfigSecretChanged", args: args{ event: getEvent(testEvent( repository.EventType(project.OIDCConfigSecretChangedType), diff --git a/internal/query/projection/authn_key.go b/internal/query/projection/authn_key.go index 4930ba6e78..305d391142 100644 --- a/internal/query/projection/authn_key.go +++ b/internal/query/projection/authn_key.go @@ -194,7 +194,10 @@ func (p *authNKeyProjection) reduceAuthNKeyEnabledChanged(event eventstore.Event return crdb.NewUpdateStatement( event, []handler.Column{handler.NewCol(AuthNKeyEnabledCol, enabled)}, - []handler.Condition{handler.NewCond(AuthNKeyObjectIDCol, appID)}, + []handler.Condition{ + handler.NewCond(AuthNKeyObjectIDCol, appID), + handler.NewCond(AuthNKeyInstanceIDCol, event.Aggregate().InstanceID), + }, ), nil } @@ -216,6 +219,9 @@ func (p *authNKeyProjection) reduceAuthNKeyRemoved(event eventstore.Event) (*han } return crdb.NewDeleteStatement( event, - []handler.Condition{condition}, + []handler.Condition{ + condition, + handler.NewCond(AuthNKeyInstanceIDCol, event.Aggregate().InstanceID), + }, ), nil } diff --git a/internal/query/projection/authn_key_test.go b/internal/query/projection/authn_key_test.go index d7fa8bdeb3..d4912fbe4e 100644 --- a/internal/query/projection/authn_key_test.go +++ b/internal/query/projection/authn_key_test.go @@ -112,9 +112,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "keyId", + "instance-id", }, }, }, @@ -157,10 +158,11 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2)", + expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ false, "appId", + "instance-id", }, }, }, @@ -184,10 +186,11 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2)", + expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "appId", + "instance-id", }, }, }, @@ -211,9 +214,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "keyId", + "instance-id", }, }, }, @@ -282,10 +286,11 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2)", + expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ false, "appId", + "instance-id", }, }, }, @@ -309,10 +314,11 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2)", + expectedStmt: "UPDATE projections.authn_keys SET enabled = $1 WHERE (object_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ true, "appId", + "instance-id", }, }, }, @@ -336,9 +342,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "keyId", + "instance-id", }, }, }, @@ -362,9 +369,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (object_id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (object_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "appId", + "instance-id", }, }, }, @@ -388,9 +396,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -414,9 +423,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "keyId", + "instance-id", }, }, }, @@ -440,9 +450,10 @@ func TestAuthNKeyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1)", + expectedStmt: "DELETE FROM projections.authn_keys WHERE (aggregate_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/custom_text.go b/internal/query/projection/custom_text.go index 38200704d5..0ec0096fcc 100644 --- a/internal/query/projection/custom_text.go +++ b/internal/query/projection/custom_text.go @@ -151,6 +151,7 @@ func (p *customTextProjection) reduceRemoved(event eventstore.Event) (*handler.S handler.NewCond(CustomTextTemplateCol, customTextEvent.Template), handler.NewCond(CustomTextKeyCol, customTextEvent.Key), handler.NewCond(CustomTextLanguageCol, customTextEvent.Language.String()), + handler.NewCond(CustomTextInstanceIDCol, customTextEvent.Aggregate().InstanceID), }), nil } @@ -170,5 +171,6 @@ func (p *customTextProjection) reduceTemplateRemoved(event eventstore.Event) (*h handler.NewCond(CustomTextAggregateIDCol, customTextEvent.Aggregate().ID), handler.NewCond(CustomTextTemplateCol, customTextEvent.Template), handler.NewCond(CustomTextLanguageCol, customTextEvent.Language.String()), + handler.NewCond(CustomTextInstanceIDCol, customTextEvent.Aggregate().InstanceID), }), nil } diff --git a/internal/query/projection/custom_text_test.go b/internal/query/projection/custom_text_test.go index d98e939745..577132fd01 100644 --- a/internal/query/projection/custom_text_test.go +++ b/internal/query/projection/custom_text_test.go @@ -22,7 +22,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "org.reduceSet", + name: "org reduceSet", args: args{ event: getEvent(testEvent( repository.EventType(org.CustomTextSetEventType), @@ -62,7 +62,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceRemoved", + name: "org reduceRemoved", reduce: (&customTextProjection{}).reduceRemoved, args: args{ event: getEvent(testEvent( @@ -82,12 +82,13 @@ func TestCustomTextProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)", + expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ "agg-id", "InitCode", "Text", "en", + "instance-id", }, }, }, @@ -95,7 +96,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceTemplateRemoved", + name: "org reduceTemplateRemoved", reduce: (&customTextProjection{}).reduceTemplateRemoved, args: args{ event: getEvent(testEvent( @@ -115,11 +116,12 @@ func TestCustomTextProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)", + expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "agg-id", "InitCode", "en", + "instance-id", }, }, }, @@ -127,7 +129,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -153,7 +155,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "iam.reduceAdded", + name: "instance reduceAdded", reduce: (&customTextProjection{}).reduceSet, args: args{ event: getEvent(testEvent( @@ -193,7 +195,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "iam.reduceRemoved", + name: "instance reduceRemoved", reduce: (&customTextProjection{}).reduceRemoved, args: args{ event: getEvent(testEvent( @@ -213,12 +215,13 @@ func TestCustomTextProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4)", + expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (key = $3) AND (language = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ "agg-id", "InitCode", "Text", "en", + "instance-id", }, }, }, @@ -226,7 +229,7 @@ func TestCustomTextProjection_reduces(t *testing.T) { }, }, { - name: "iam.reduceTemplateRemoved", + name: "instance reduceTemplateRemoved", reduce: (&customTextProjection{}).reduceTemplateRemoved, args: args{ event: getEvent(testEvent( @@ -246,11 +249,12 @@ func TestCustomTextProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3)", + expectedStmt: "DELETE FROM projections.custom_texts WHERE (aggregate_id = $1) AND (template = $2) AND (language = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "agg-id", "InitCode", "en", + "instance-id", }, }, }, diff --git a/internal/query/projection/debug_notification.go b/internal/query/projection/debug_notification.go index 0ee1e9fa18..9eff62ee8d 100644 --- a/internal/query/projection/debug_notification.go +++ b/internal/query/projection/debug_notification.go @@ -147,6 +147,7 @@ func (p *debugNotificationProviderProjection) reduceDebugNotificationProviderCha []handler.Condition{ handler.NewCond(DebugNotificationProviderAggIDCol, providerEvent.Aggregate().ID), handler.NewCond(DebugNotificationProviderTypeCol, providerType), + handler.NewCond(DebugNotificationProviderInstanceIDCol, providerEvent.Aggregate().InstanceID), }, ), nil } @@ -170,6 +171,7 @@ func (p *debugNotificationProviderProjection) reduceDebugNotificationProviderRem []handler.Condition{ handler.NewCond(DebugNotificationProviderAggIDCol, providerEvent.Aggregate().ID), handler.NewCond(DebugNotificationProviderTypeCol, providerType), + handler.NewCond(DebugNotificationProviderInstanceIDCol, providerEvent.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/debug_notification_provider_test.go b/internal/query/projection/debug_notification_provider_test.go index 79446f7593..ec22287e5f 100644 --- a/internal/query/projection/debug_notification_provider_test.go +++ b/internal/query/projection/debug_notification_provider_test.go @@ -22,7 +22,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "instance.reduceNotificationProviderFileAdded", + name: "instance reduceNotificationProviderFileAdded", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded, args: args{ event: getEvent(testEvent( @@ -58,7 +58,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceNotificationProviderFileChanged", + name: "instance reduceNotificationProviderFileChanged", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged, args: args{ event: getEvent(testEvent( @@ -76,13 +76,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)", + expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), true, "agg-id", domain.NotificationProviderTypeFile, + "instance-id", }, }, }, @@ -90,7 +91,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceNotificationProviderFileRemoved", + name: "instance reduceNotificationProviderFileRemoved", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved, args: args{ event: getEvent(testEvent( @@ -106,10 +107,11 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)", + expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "agg-id", domain.NotificationProviderTypeFile, + "instance-id", }, }, }, @@ -117,7 +119,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceNotificationProviderLogAdded", + name: "instance reduceNotificationProviderLogAdded", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded, args: args{ event: getEvent(testEvent( @@ -153,7 +155,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceNotificationProviderLogChanged", + name: "instance reduceNotificationProviderLogChanged", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged, args: args{ event: getEvent(testEvent( @@ -171,13 +173,14 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5)", + expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), true, "agg-id", domain.NotificationProviderTypeLog, + "instance-id", }, }, }, @@ -185,7 +188,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceNotificationProviderLogRemoved", + name: "instance reduceNotificationProviderLogRemoved", reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved, args: args{ event: getEvent(testEvent( @@ -201,10 +204,11 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2)", + expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "agg-id", domain.NotificationProviderTypeLog, + "instance-id", }, }, }, @@ -212,7 +216,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/domain_policy.go b/internal/query/projection/domain_policy.go index fd88e73110..54053317d5 100644 --- a/internal/query/projection/domain_policy.go +++ b/internal/query/projection/domain_policy.go @@ -155,6 +155,7 @@ func (p *domainPolicyProjection) reduceChanged(event eventstore.Event) (*handler cols, []handler.Condition{ handler.NewCond(DomainPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(DomainPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }), nil } @@ -167,5 +168,6 @@ func (p *domainPolicyProjection) reduceRemoved(event eventstore.Event) (*handler policyEvent, []handler.Condition{ handler.NewCond(DomainPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(DomainPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }), nil } diff --git a/internal/query/projection/domain_policy_test.go b/internal/query/projection/domain_policy_test.go index d0e72bf766..eada1a6f19 100644 --- a/internal/query/projection/domain_policy_test.go +++ b/internal/query/projection/domain_policy_test.go @@ -23,7 +23,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "org.reduceAdded", + name: "org reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.DomainPolicyAddedEventType), @@ -63,7 +63,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceChanged", + name: "org reduceChanged", reduce: (&domainPolicyProjection{}).reduceChanged, args: args{ event: getEvent(testEvent( @@ -83,7 +83,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.domain_policies SET (change_date, sequence, user_login_must_be_domain, validate_org_domains, smtp_sender_address_matches_instance_domain) = ($1, $2, $3, $4, $5) WHERE (id = $6)", + expectedStmt: "UPDATE projections.domain_policies SET (change_date, sequence, user_login_must_be_domain, validate_org_domains, smtp_sender_address_matches_instance_domain) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -91,6 +91,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { true, true, "agg-id", + "instance-id", }, }, }, @@ -98,7 +99,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceRemoved", + name: "org reduceRemoved", reduce: (&domainPolicyProjection{}).reduceRemoved, args: args{ event: getEvent(testEvent( @@ -114,9 +115,10 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.domain_policies WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.domain_policies WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -124,7 +126,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -150,7 +152,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceAdded", + name: "instance reduceAdded", reduce: (&domainPolicyProjection{}).reduceAdded, args: args{ event: getEvent(testEvent( @@ -190,7 +192,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceChanged", + name: "instance reduceChanged", reduce: (&domainPolicyProjection{}).reduceChanged, args: args{ event: getEvent(testEvent( @@ -210,7 +212,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.domain_policies SET (change_date, sequence, user_login_must_be_domain, validate_org_domains, smtp_sender_address_matches_instance_domain) = ($1, $2, $3, $4, $5) WHERE (id = $6)", + expectedStmt: "UPDATE projections.domain_policies SET (change_date, sequence, user_login_must_be_domain, validate_org_domains, smtp_sender_address_matches_instance_domain) = ($1, $2, $3, $4, $5) WHERE (id = $6) AND (instance_id = $7)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -218,6 +220,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) { true, true, "agg-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/flow.go b/internal/query/projection/flow.go index 78f61999a4..08750e588a 100644 --- a/internal/query/projection/flow.go +++ b/internal/query/projection/flow.go @@ -87,6 +87,7 @@ func (p *flowProjection) reduceTriggerActionsSetEventType(event eventstore.Event handler.NewCond(FlowTypeCol, e.FlowType), handler.NewCond(FlowTriggerTypeCol, e.TriggerType), handler.NewCond(FlowResourceOwnerCol, e.Aggregate().ResourceOwner), + handler.NewCond(FlowInstanceIDCol, e.Aggregate().InstanceID), }, ) for i, id := range e.ActionIDs { @@ -116,6 +117,7 @@ func (p *flowProjection) reduceFlowClearedEventType(event eventstore.Event) (*ha []handler.Condition{ handler.NewCond(FlowTypeCol, e.FlowType), handler.NewCond(FlowResourceOwnerCol, e.Aggregate().ResourceOwner), + handler.NewCond(FlowInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/flow_test.go b/internal/query/projection/flow_test.go index faadcc985e..e7834c5d94 100644 --- a/internal/query/projection/flow_test.go +++ b/internal/query/projection/flow_test.go @@ -39,11 +39,12 @@ func TestFlowProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1) AND (trigger_type = $2) AND (resource_owner = $3)", + expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1) AND (trigger_type = $2) AND (resource_owner = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ domain.FlowTypeExternalAuthentication, domain.TriggerTypePostAuthentication, "ro-id", + "instance-id", }, }, { @@ -93,10 +94,11 @@ func TestFlowProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.flows_triggers WHERE (flow_type = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ domain.FlowTypeExternalAuthentication, "ro-id", + "instance-id", }, }, }, @@ -104,7 +106,7 @@ func TestFlowProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/idp_login_policy_link.go b/internal/query/projection/idp_login_policy_link.go index 213fb72c8a..8f33f90d21 100644 --- a/internal/query/projection/idp_login_policy_link.go +++ b/internal/query/projection/idp_login_policy_link.go @@ -159,6 +159,7 @@ func (p *idpLoginPolicyLinkProjection) reduceRemoved(event eventstore.Event) (*h []handler.Condition{ handler.NewCond(IDPLoginPolicyLinkIDPIDCol, idp.IDPConfigID), handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, idp.Aggregate().ID), + handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -179,6 +180,7 @@ func (p *idpLoginPolicyLinkProjection) reduceCascadeRemoved(event eventstore.Eve []handler.Condition{ handler.NewCond(IDPLoginPolicyLinkIDPIDCol, idp.IDPConfigID), handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, idp.Aggregate().ID), + handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, idp.Aggregate().InstanceID), }, ), nil } @@ -199,6 +201,7 @@ func (p *idpLoginPolicyLinkProjection) reduceIDPConfigRemoved(event eventstore.E []handler.Condition{ handler.NewCond(IDPLoginPolicyLinkIDPIDCol, idpID), handler.NewCond(IDPLoginPolicyLinkResourceOwnerCol, event.Aggregate().ResourceOwner), + handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -211,6 +214,7 @@ func (p *idpLoginPolicyLinkProjection) reduceOrgRemoved(event eventstore.Event) return crdb.NewDeleteStatement(e, []handler.Condition{ handler.NewCond(IDPLoginPolicyLinkResourceOwnerCol, e.Aggregate().ID), + handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } @@ -223,6 +227,7 @@ func (p *idpLoginPolicyLinkProjection) reducePolicyRemoved(event eventstore.Even return crdb.NewDeleteStatement(e, []handler.Condition{ handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, e.Aggregate().ID), + handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/idp_login_policy_link_test.go b/internal/query/projection/idp_login_policy_link_test.go index ee61e4ea24..1c963e7077 100644 --- a/internal/query/projection/idp_login_policy_link_test.go +++ b/internal/query/projection/idp_login_policy_link_test.go @@ -23,7 +23,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "iam.reduceAdded", + name: "iam reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.LoginPolicyIDPProviderAddedEventType), @@ -59,7 +59,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "iam.reduceRemoved", + name: "iam reduceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.LoginPolicyIDPProviderRemovedEventType), @@ -78,10 +78,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", + "instance-id", }, }, }, @@ -89,7 +90,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "iam.reduceCascadeRemoved", + name: "iam reduceCascadeRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.LoginPolicyIDPProviderCascadeRemovedEventType), @@ -108,10 +109,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", + "instance-id", }, }, }, @@ -119,7 +121,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceAdded", + name: "org reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.LoginPolicyIDPProviderAddedEventType), @@ -155,7 +157,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceRemoved", + name: "org reduceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.LoginPolicyIDPProviderRemovedEventType), @@ -174,10 +176,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", + "instance-id", }, }, }, @@ -185,7 +188,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -211,7 +214,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceCascadeRemoved", + name: "org reduceCascadeRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.LoginPolicyIDPProviderCascadeRemovedEventType), @@ -230,10 +233,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (aggregate_id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", + "instance-id", }, }, }, @@ -257,9 +261,10 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (resource_owner = $1)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (resource_owner = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -283,9 +288,10 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (aggregate_id = $1)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (aggregate_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -293,7 +299,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "org.IDPConfigRemovedEvent", + name: "org IDPConfigRemovedEvent", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigRemovedEventType), @@ -311,10 +317,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "ro-id", + "instance-id", }, }, }, @@ -322,7 +329,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { }, }, { - name: "iam.IDPConfigRemovedEvent", + name: "iam IDPConfigRemovedEvent", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigRemovedEventType), @@ -340,10 +347,11 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.idp_login_policy_links3 WHERE (idp_id = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "ro-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/idp_test.go b/internal/query/projection/idp_test.go index 8f5c46e91d..f19b268388 100644 --- a/internal/query/projection/idp_test.go +++ b/internal/query/projection/idp_test.go @@ -24,7 +24,7 @@ func TestIDPProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "instance.reduceIDPAdded", + name: "instance reduceIDPAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigAddedEventType), @@ -66,7 +66,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIDPChanged", + name: "instance reduceIDPChanged", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigChangedEventType), @@ -103,7 +103,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIDPDeactivated", + name: "instance reduceIDPDeactivated", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigDeactivatedEventType), @@ -135,7 +135,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIDPReactivated", + name: "instance reduceIDPReactivated", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigReactivatedEventType), @@ -167,7 +167,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIDPRemoved", + name: "instance reduceIDPRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigRemovedEventType), @@ -196,7 +196,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -222,7 +222,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceOIDCConfigAdded", + name: "instance reduceOIDCConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPOIDCConfigAddedEventType), @@ -281,7 +281,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceOIDCConfigChanged", + name: "instance reduceOIDCConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPOIDCConfigChangedEventType), @@ -339,7 +339,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceOIDCConfigChanged: no op", + name: "instance reduceOIDCConfigChanged: no op", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPOIDCConfigChangedEventType), @@ -358,7 +358,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceJWTConfigAdded", + name: "instance reduceJWTConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPJWTConfigAddedEventType), @@ -405,7 +405,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceJWTConfigChanged", + name: "instance reduceJWTConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPJWTConfigChangedEventType), @@ -451,7 +451,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceJWTConfigChanged: no op", + name: "instance reduceJWTConfigChanged: no op", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPJWTConfigChangedEventType), @@ -470,7 +470,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIDPAdded", + name: "org reduceIDPAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigAddedEventType), @@ -512,7 +512,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIDPChanged", + name: "org reduceIDPChanged", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigChangedEventType), @@ -549,7 +549,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIDPDeactivated", + name: "org reduceIDPDeactivated", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigDeactivatedEventType), @@ -581,7 +581,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIDPReactivated", + name: "org reduceIDPReactivated", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigReactivatedEventType), @@ -613,7 +613,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIDPRemoved", + name: "org reduceIDPRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigRemovedEventType), @@ -642,7 +642,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceOIDCConfigAdded", + name: "org reduceOIDCConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPOIDCConfigAddedEventType), @@ -701,7 +701,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceOIDCConfigChanged", + name: "org reduceOIDCConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPOIDCConfigChangedEventType), @@ -759,7 +759,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceOIDCConfigChanged: no op", + name: "org reduceOIDCConfigChanged: no op", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPOIDCConfigChangedEventType), @@ -778,7 +778,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceJWTConfigAdded", + name: "org reduceJWTConfigAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPJWTConfigAddedEventType), @@ -825,7 +825,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceJWTConfigChanged", + name: "org reduceJWTConfigChanged", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPJWTConfigChangedEventType), @@ -871,7 +871,7 @@ func TestIDPProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceJWTConfigChanged: no op", + name: "org reduceJWTConfigChanged: no op", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPJWTConfigChangedEventType), diff --git a/internal/query/projection/idp_user_link.go b/internal/query/projection/idp_user_link.go index d045f24c67..f4ccfe266a 100644 --- a/internal/query/projection/idp_user_link.go +++ b/internal/query/projection/idp_user_link.go @@ -137,6 +137,7 @@ func (p *idpUserLinkProjection) reduceRemoved(event eventstore.Event) (*handler. handler.NewCond(IDPUserLinkIDPIDCol, e.IDPConfigID), handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID), handler.NewCond(IDPUserLinkExternalUserIDCol, e.ExternalUserID), + handler.NewCond(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } @@ -152,6 +153,7 @@ func (p *idpUserLinkProjection) reduceCascadeRemoved(event eventstore.Event) (*h handler.NewCond(IDPUserLinkIDPIDCol, e.IDPConfigID), handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID), handler.NewCond(IDPUserLinkExternalUserIDCol, e.ExternalUserID), + handler.NewCond(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } @@ -165,6 +167,7 @@ func (p *idpUserLinkProjection) reduceOrgRemoved(event eventstore.Event) (*handl return crdb.NewDeleteStatement(e, []handler.Condition{ handler.NewCond(IDPUserLinkResourceOwnerCol, e.Aggregate().ID), + handler.NewCond(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } @@ -178,6 +181,7 @@ func (p *idpUserLinkProjection) reduceUserRemoved(event eventstore.Event) (*hand return crdb.NewDeleteStatement(e, []handler.Condition{ handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID), + handler.NewCond(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } @@ -198,6 +202,7 @@ func (p *idpUserLinkProjection) reduceIDPConfigRemoved(event eventstore.Event) ( []handler.Condition{ handler.NewCond(IDPUserLinkIDPIDCol, idpID), handler.NewCond(IDPUserLinkResourceOwnerCol, event.Aggregate().ResourceOwner), + handler.NewCond(IDPUserLinkInstanceIDCol, event.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/idp_user_link_test.go b/internal/query/projection/idp_user_link_test.go index a72eaaa8c0..925352bb79 100644 --- a/internal/query/projection/idp_user_link_test.go +++ b/internal/query/projection/idp_user_link_test.go @@ -80,11 +80,12 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", "external-user-id", + "instance-id", }, }, }, @@ -111,11 +112,12 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (user_id = $2) AND (external_user_id = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ "idp-config-id", "agg-id", "external-user-id", + "instance-id", }, }, }, @@ -139,9 +141,10 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (resource_owner = $1)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (resource_owner = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -149,7 +152,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -191,9 +194,10 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (user_id = $1)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (user_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -201,7 +205,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { }, }, { - name: "org.IDPConfigRemovedEvent", + name: "org IDPConfigRemovedEvent", args: args{ event: getEvent(testEvent( repository.EventType(org.IDPConfigRemovedEventType), @@ -219,10 +223,11 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "ro-id", + "instance-id", }, }, }, @@ -230,7 +235,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { }, }, { - name: "iam.IDPConfigRemovedEvent", + name: "iam IDPConfigRemovedEvent", args: args{ event: getEvent(testEvent( repository.EventType(instance.IDPConfigRemovedEventType), @@ -248,10 +253,11 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.idp_user_links2 WHERE (idp_id = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "idp-config-id", "ro-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/instance_domain.go b/internal/query/projection/instance_domain.go index 1511abd7d7..18eded8cc9 100644 --- a/internal/query/projection/instance_domain.go +++ b/internal/query/projection/instance_domain.go @@ -41,6 +41,7 @@ func newInstanceDomainProjection(ctx context.Context, config crdb.StatementHandl crdb.NewColumn(InstanceDomainIsPrimaryCol, crdb.ColumnTypeBool), }, crdb.NewPrimaryKey(InstanceDomainInstanceIDCol, InstanceDomainDomainCol), + crdb.WithIndex(crdb.NewIndex("instance_domain", []string{InstanceDomainDomainCol})), ), ) p.StatementHandler = crdb.NewStatementHandler(ctx, config) diff --git a/internal/query/projection/instance_domain_test.go b/internal/query/projection/instance_domain_test.go index 68eb2e1f77..0106bbe85a 100644 --- a/internal/query/projection/instance_domain_test.go +++ b/internal/query/projection/instance_domain_test.go @@ -80,7 +80,7 @@ func TestInstanceDomainProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/instance_member_test.go b/internal/query/projection/instance_member_test.go index debfb8bf84..d8cf81c760 100644 --- a/internal/query/projection/instance_member_test.go +++ b/internal/query/projection/instance_member_test.go @@ -23,7 +23,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "instance.MemberAddedType", + name: "instance MemberAddedType", args: args{ event: getEvent(testEvent( repository.EventType(instance.MemberAddedEventType), @@ -59,7 +59,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { }, }, { - name: "instance.MemberChangedType", + name: "instance MemberChangedType", args: args{ event: getEvent(testEvent( repository.EventType(instance.MemberChangedEventType), @@ -78,11 +78,12 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.instance_members2 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (user_id = $4)", + expectedStmt: "UPDATE projections.instance_members2 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (instance_id = $4) AND (user_id = $5)", expectedArgs: []interface{}{ database.StringArray{"role", "changed"}, anyArg{}, uint64(15), + "instance-id", "user-id", }, }, @@ -91,7 +92,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { }, }, { - name: "instance.MemberCascadeRemovedType", + name: "instance MemberCascadeRemovedType", args: args{ event: getEvent(testEvent( repository.EventType(instance.MemberCascadeRemovedEventType), @@ -109,8 +110,9 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.instance_members2 WHERE (user_id = $1)", + expectedStmt: "DELETE FROM projections.instance_members2 WHERE (instance_id = $1) AND (user_id = $2)", expectedArgs: []interface{}{ + "instance-id", "user-id", }, }, @@ -119,7 +121,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { }, }, { - name: "instance.MemberRemovedType", + name: "instance MemberRemovedType", args: args{ event: getEvent(testEvent( repository.EventType(instance.MemberRemovedEventType), @@ -137,8 +139,9 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.instance_members2 WHERE (user_id = $1)", + expectedStmt: "DELETE FROM projections.instance_members2 WHERE (instance_id = $1) AND (user_id = $2)", expectedArgs: []interface{}{ + "instance-id", "user-id", }, }, @@ -147,7 +150,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { }, }, { - name: "user.UserRemoved", + name: "user UserRemoved", args: args{ event: getEvent(testEvent( repository.EventType(user.UserRemovedType), @@ -163,8 +166,9 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.instance_members2 WHERE (user_id = $1)", + expectedStmt: "DELETE FROM projections.instance_members2 WHERE (instance_id = $1) AND (user_id = $2)", expectedArgs: []interface{}{ + "instance-id", "agg-id", }, }, @@ -173,7 +177,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/key_test.go b/internal/query/projection/key_test.go index a915b8fc2b..54b1539027 100644 --- a/internal/query/projection/key_test.go +++ b/internal/query/projection/key_test.go @@ -101,7 +101,7 @@ func TestKeyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/label_policy.go b/internal/query/projection/label_policy.go index 08d4e2ea41..f4203d1cd5 100644 --- a/internal/query/projection/label_policy.go +++ b/internal/query/projection/label_policy.go @@ -312,6 +312,7 @@ func (p *labelPolicyProjection) reduceChanged(event eventstore.Event) (*handler. []handler.Condition{ handler.NewCond(LabelPolicyIDCol, policyEvent.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -324,6 +325,7 @@ func (p *labelPolicyProjection) reduceRemoved(event eventstore.Event) (*handler. policyEvent, []handler.Condition{ handler.NewCond(LabelPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -425,6 +427,7 @@ func (p *labelPolicyProjection) reduceLogoAdded(event eventstore.Event) (*handle []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -453,6 +456,7 @@ func (p *labelPolicyProjection) reduceLogoRemoved(event eventstore.Event) (*hand []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -481,6 +485,7 @@ func (p *labelPolicyProjection) reduceIconAdded(event eventstore.Event) (*handle []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -509,6 +514,7 @@ func (p *labelPolicyProjection) reduceIconRemoved(event eventstore.Event) (*hand []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -533,6 +539,7 @@ func (p *labelPolicyProjection) reduceFontAdded(event eventstore.Event) (*handle []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -557,6 +564,7 @@ func (p *labelPolicyProjection) reduceFontRemoved(event eventstore.Event) (*hand []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -582,5 +590,6 @@ func (p *labelPolicyProjection) reduceAssetsRemoved(event eventstore.Event) (*ha []handler.Condition{ handler.NewCond(LabelPolicyIDCol, event.Aggregate().ID), handler.NewCond(LabelPolicyStateCol, domain.LabelPolicyStatePreview), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } diff --git a/internal/query/projection/label_policy_test.go b/internal/query/projection/label_policy_test.go index 50616f5abc..ae638fb697 100644 --- a/internal/query/projection/label_policy_test.go +++ b/internal/query/projection/label_policy_test.go @@ -23,7 +23,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "org.reduceAdded", + name: "org reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyAddedEventType), @@ -67,7 +67,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceChanged", + name: "org reduceChanged", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyChangedEventType), @@ -83,7 +83,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (state = $8)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (state = $8) AND (instance_id = $9)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -93,6 +93,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { "#ffffff", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -100,7 +101,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceRemoved", + name: "org reduceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyRemovedEventType), @@ -116,9 +117,10 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.label_policies WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.label_policies WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -126,7 +128,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -152,7 +154,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceActivated", + name: "org reduceActivated", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyActivatedEventType), @@ -183,7 +185,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceLogoAdded light", + name: "org reduceLogoAdded light", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyLogoAddedEventType), @@ -199,13 +201,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/logo.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -213,7 +216,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceLogoAdded dark", + name: "org reduceLogoAdded dark", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyLogoDarkAddedEventType), @@ -229,13 +232,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/logo.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -243,7 +247,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIconAdded light", + name: "org reduceIconAdded light", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyIconAddedEventType), @@ -259,13 +263,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/icon.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -273,7 +278,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIconAdded dark", + name: "org reduceIconAdded dark", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyIconDarkAddedEventType), @@ -289,13 +294,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/icon.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -303,7 +309,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceLogoRemoved light", + name: "org reduceLogoRemoved light", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyLogoRemovedEventType), @@ -319,13 +325,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -333,7 +340,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceLogoRemoved dark", + name: "org reduceLogoRemoved dark", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyLogoDarkRemovedEventType), @@ -349,13 +356,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -363,7 +371,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIconRemoved light", + name: "org reduceIconRemoved light", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyIconRemovedEventType), @@ -379,13 +387,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -393,7 +402,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceIconRemoved dark", + name: "org reduceIconRemoved dark", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyIconDarkRemovedEventType), @@ -409,13 +418,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -423,7 +433,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceFontAdded", + name: "org reduceFontAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyFontAddedEventType), @@ -439,13 +449,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/font.ttf", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -453,7 +464,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceFontRemoved", + name: "org reduceFontRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyFontRemovedEventType), @@ -469,13 +480,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -483,7 +495,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceAssetsRemoved", + name: "org reduceAssetsRemoved", args: args{ event: getEvent(testEvent( repository.EventType(org.LabelPolicyAssetsRemovedEventType), @@ -499,7 +511,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9) AND (instance_id = $10)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -510,6 +522,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -517,7 +530,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceAdded", + name: "instance reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyAddedEventType), @@ -561,7 +574,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceChanged", + name: "instance reduceChanged", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyChangedEventType), @@ -577,7 +590,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (id = $14) AND (state = $15)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_primary_color, light_background_color, light_warn_color, light_font_color, dark_primary_color, dark_background_color, dark_warn_color, dark_font_color, hide_login_name_suffix, should_error_popup, watermark_disabled) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (id = $14) AND (state = $15) AND (instance_id = $16)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -594,6 +607,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { true, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -601,7 +615,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceActivated", + name: "instance reduceActivated", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyActivatedEventType), @@ -632,7 +646,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceLogoAdded light", + name: "instance reduceLogoAdded light", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyLogoAddedEventType), @@ -648,13 +662,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/logo.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -662,7 +677,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceLogoAdded dark", + name: "instance reduceLogoAdded dark", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyLogoDarkAddedEventType), @@ -678,13 +693,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/logo.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -692,7 +708,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIconAdded light", + name: "instance reduceIconAdded light", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyIconAddedEventType), @@ -708,13 +724,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/icon.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -722,7 +739,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIconAdded dark", + name: "instance reduceIconAdded dark", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyIconDarkAddedEventType), @@ -738,13 +755,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/icon.png", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -752,7 +770,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceLogoRemoved light", + name: "instance reduceLogoRemoved light", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyLogoRemovedEventType), @@ -768,13 +786,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -782,7 +801,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceLogoRemoved dark", + name: "instance reduceLogoRemoved dark", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyLogoDarkRemovedEventType), @@ -798,13 +817,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_logo_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -812,7 +832,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIconRemoved light", + name: "instance reduceIconRemoved light", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyIconRemovedEventType), @@ -828,13 +848,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -842,7 +863,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceIconRemoved dark", + name: "instance reduceIconRemoved dark", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyIconDarkRemovedEventType), @@ -858,13 +879,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, dark_icon_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -872,7 +894,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceFontAdded", + name: "instance reduceFontAdded", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyFontAddedEventType), @@ -888,13 +910,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), "/path/to/font.ttf", "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -902,7 +925,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceFontRemoved", + name: "instance reduceFontRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyFontRemovedEventType), @@ -918,13 +941,14 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, font_url) = ($1, $2, $3) WHERE (id = $4) AND (state = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, @@ -932,7 +956,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceAssetsRemoved", + name: "instance reduceAssetsRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.LabelPolicyAssetsRemovedEventType), @@ -948,7 +972,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9)", + expectedStmt: "UPDATE projections.label_policies SET (change_date, sequence, light_logo_url, light_icon_url, dark_logo_url, dark_icon_url, font_url) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8) AND (state = $9) AND (instance_id = $10)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -959,6 +983,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) { nil, "agg-id", domain.LabelPolicyStatePreview, + "instance-id", }, }, }, diff --git a/internal/query/projection/lockout_policy.go b/internal/query/projection/lockout_policy.go index 5130b4df90..62ef6eba94 100644 --- a/internal/query/projection/lockout_policy.go +++ b/internal/query/projection/lockout_policy.go @@ -149,6 +149,7 @@ func (p *lockoutPolicyProjection) reduceChanged(event eventstore.Event) (*handle cols, []handler.Condition{ handler.NewCond(LockoutPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } @@ -161,5 +162,6 @@ func (p *lockoutPolicyProjection) reduceRemoved(event eventstore.Event) (*handle policyEvent, []handler.Condition{ handler.NewCond(LockoutPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LabelPolicyInstanceIDCol, event.Aggregate().InstanceID), }), nil } diff --git a/internal/query/projection/lockout_policy_test.go b/internal/query/projection/lockout_policy_test.go index d1792d1b5f..0fe107cda4 100644 --- a/internal/query/projection/lockout_policy_test.go +++ b/internal/query/projection/lockout_policy_test.go @@ -23,7 +23,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "org.reduceAdded", + name: "org reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.LockoutPolicyAddedEventType), @@ -61,7 +61,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceChanged", + name: "org reduceChanged", reduce: (&lockoutPolicyProjection{}).reduceChanged, args: args{ event: getEvent(testEvent( @@ -80,13 +80,14 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)", + expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), uint64(10), true, "agg-id", + "instance-id", }, }, }, @@ -94,7 +95,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceRemoved", + name: "org reduceRemoved", reduce: (&lockoutPolicyProjection{}).reduceRemoved, args: args{ event: getEvent(testEvent( @@ -110,9 +111,10 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.lockout_policies WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.lockout_policies WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -120,7 +122,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), @@ -146,7 +148,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceAdded", + name: "instance reduceAdded", reduce: (&lockoutPolicyProjection{}).reduceAdded, args: args{ event: getEvent(testEvent( @@ -184,7 +186,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceChanged", + name: "instance reduceChanged", reduce: (&lockoutPolicyProjection{}).reduceChanged, args: args{ event: getEvent(testEvent( @@ -203,13 +205,14 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5)", + expectedStmt: "UPDATE projections.lockout_policies SET (change_date, sequence, max_password_attempts, show_failure) = ($1, $2, $3, $4) WHERE (id = $5) AND (instance_id = $6)", expectedArgs: []interface{}{ anyArg{}, uint64(15), uint64(10), true, "agg-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/login_name.go b/internal/query/projection/login_name.go index 49a916d6c5..5d121fd9d9 100644 --- a/internal/query/projection/login_name.go +++ b/internal/query/projection/login_name.go @@ -256,6 +256,7 @@ func (p *loginNameProjection) reduceUserRemoved(event eventstore.Event) (*handle event, []handler.Condition{ handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID), + handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameUserSuffix), ), nil @@ -274,6 +275,7 @@ func (p *loginNameProjection) reduceUserNameChanged(event eventstore.Event) (*ha }, []handler.Condition{ handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID), + handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameUserSuffix), ), nil @@ -292,6 +294,7 @@ func (p *loginNameProjection) reduceUserDomainClaimed(event eventstore.Event) (* }, []handler.Condition{ handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID), + handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameUserSuffix), ), nil @@ -349,6 +352,7 @@ func (p *loginNameProjection) reduceDomainPolicyChanged(event eventstore.Event) }, []handler.Condition{ handler.NewCond(LoginNamePoliciesResourceOwnerCol, policyEvent.Aggregate().ResourceOwner), + handler.NewCond(LoginNamePoliciesInstanceIDCol, policyEvent.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNamePolicySuffix), ), nil @@ -364,6 +368,7 @@ func (p *loginNameProjection) reduceDomainPolicyRemoved(event eventstore.Event) event, []handler.Condition{ handler.NewCond(LoginNamePoliciesResourceOwnerCol, e.Aggregate().ResourceOwner), + handler.NewCond(LoginNamePoliciesInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNamePolicySuffix), ), nil @@ -401,6 +406,7 @@ func (p *loginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h []handler.Condition{ handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner), handler.NewCond(LoginNameDomainIsPrimaryCol, true), + handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameDomainSuffix), ), @@ -411,6 +417,7 @@ func (p *loginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h []handler.Condition{ handler.NewCond(LoginNameDomainNameCol, e.Domain), handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner), + handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameDomainSuffix), ), @@ -428,6 +435,7 @@ func (p *loginNameProjection) reduceDomainRemoved(event eventstore.Event) (*hand []handler.Condition{ handler.NewCond(LoginNameDomainNameCol, e.Domain), handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner), + handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID), }, crdb.WithTableSuffix(loginNameDomainSuffix), ), nil diff --git a/internal/query/projection/login_name_test.go b/internal/query/projection/login_name_test.go index c18961e508..b213e89352 100644 --- a/internal/query/projection/login_name_test.go +++ b/internal/query/projection/login_name_test.go @@ -23,7 +23,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "user.HumanAddedType", + name: "user HumanAddedType", args: args{ event: getEvent(testEvent( repository.EventType(user.HumanAddedType), @@ -54,7 +54,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "user.HumanRegisteredType", + name: "user HumanRegisteredType", args: args{ event: getEvent(testEvent( repository.EventType(user.HumanRegisteredType), @@ -85,7 +85,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "user.MachineAddedEventType", + name: "user MachineAddedEventType", args: args{ event: getEvent(testEvent( repository.EventType(user.MachineAddedEventType), @@ -116,7 +116,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "user.UserRemovedType", + name: "user UserRemovedType", args: args{ event: getEvent(testEvent( repository.EventType(user.UserRemovedType), @@ -132,9 +132,10 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.login_names_users WHERE (id = $1)", + expectedStmt: "DELETE FROM projections.login_names_users WHERE (id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -142,7 +143,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "user.UserUserNameChangedType", + name: "user UserUserNameChangedType", args: args{ event: getEvent(testEvent( repository.EventType(user.UserUserNameChangedType), @@ -160,10 +161,11 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_names_users SET user_name = $1 WHERE (id = $2)", + expectedStmt: "UPDATE projections.login_names_users SET user_name = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "changed", "agg-id", + "instance-id", }, }, }, @@ -171,7 +173,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "user.UserDomainClaimedType", + name: "user UserDomainClaimedType", args: args{ event: getEvent(testEvent( repository.EventType(user.UserDomainClaimedType), @@ -189,10 +191,11 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_names_users SET user_name = $1 WHERE (id = $2)", + expectedStmt: "UPDATE projections.login_names_users SET user_name = $1 WHERE (id = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "claimed", "agg-id", + "instance-id", }, }, }, @@ -200,7 +203,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainPolicyAddedEventType", + name: "org OrgDomainPolicyAddedEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.DomainPolicyAddedEventType), @@ -231,7 +234,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainPolicyChangedEventType", + name: "org OrgDomainPolicyChangedEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.DomainPolicyChangedEventType), @@ -249,10 +252,11 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_names_policies SET must_be_domain = $1 WHERE (resource_owner = $2)", + expectedStmt: "UPDATE projections.login_names_policies SET must_be_domain = $1 WHERE (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ false, "ro-id", + "instance-id", }, }, }, @@ -260,7 +264,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainPolicyChangedEventType no change", + name: "org OrgDomainPolicyChangedEventType no change", args: args{ event: getEvent(testEvent( repository.EventType(org.DomainPolicyChangedEventType), @@ -279,7 +283,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainPolicyRemovedEventType", + name: "org OrgDomainPolicyRemovedEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.DomainPolicyRemovedEventType), @@ -295,9 +299,10 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.login_names_policies WHERE (resource_owner = $1)", + expectedStmt: "DELETE FROM projections.login_names_policies WHERE (resource_owner = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "ro-id", + "instance-id", }, }, }, @@ -305,7 +310,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainVerifiedEventType", + name: "org OrgDomainVerifiedEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.OrgDomainVerifiedEventType), @@ -335,7 +340,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainRemovedEventType", + name: "org OrgDomainRemovedEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.OrgDomainRemovedEventType), @@ -353,10 +358,11 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.login_names_domains WHERE (name = $1) AND (resource_owner = $2)", + expectedStmt: "DELETE FROM projections.login_names_domains WHERE (name = $1) AND (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ "remove", "ro-id", + "instance-id", }, }, }, @@ -364,7 +370,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "org.OrgDomainPrimarySetEventType", + name: "org OrgDomainPrimarySetEventType", args: args{ event: getEvent(testEvent( repository.EventType(org.OrgDomainPrimarySetEventType), @@ -382,19 +388,21 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_names_domains SET is_primary = $1 WHERE (resource_owner = $2) AND (is_primary = $3)", + expectedStmt: "UPDATE projections.login_names_domains SET is_primary = $1 WHERE (resource_owner = $2) AND (is_primary = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ false, "ro-id", true, + "instance-id", }, }, { - expectedStmt: "UPDATE projections.login_names_domains SET is_primary = $1 WHERE (name = $2) AND (resource_owner = $3)", + expectedStmt: "UPDATE projections.login_names_domains SET is_primary = $1 WHERE (name = $2) AND (resource_owner = $3) AND (instance_id = $4)", expectedArgs: []interface{}{ true, "primary", "ro-id", + "instance-id", }, }, }, @@ -402,7 +410,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "iam.OrgDomainPolicyAddedEventType", + name: "iam OrgDomainPolicyAddedEventType", args: args{ event: getEvent(testEvent( repository.EventType(instance.DomainPolicyAddedEventType), @@ -433,7 +441,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "iam.OrgDomainPolicyChangedEventType", + name: "iam OrgDomainPolicyChangedEventType", args: args{ event: getEvent(testEvent( repository.EventType(instance.DomainPolicyChangedEventType), @@ -451,10 +459,11 @@ func TestLoginNameProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_names_policies SET must_be_domain = $1 WHERE (resource_owner = $2)", + expectedStmt: "UPDATE projections.login_names_policies SET must_be_domain = $1 WHERE (resource_owner = $2) AND (instance_id = $3)", expectedArgs: []interface{}{ false, "ro-id", + "instance-id", }, }, }, @@ -462,7 +471,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "iam.OrgDomainPolicyChangedEventType no change", + name: "iam OrgDomainPolicyChangedEventType no change", args: args{ event: getEvent(testEvent( repository.EventType(instance.DomainPolicyChangedEventType), @@ -481,7 +490,7 @@ func TestLoginNameProjection_reduces(t *testing.T) { }, }, { - name: "instance.reduceInstanceRemoved", + name: "instance reduceInstanceRemoved", args: args{ event: getEvent(testEvent( repository.EventType(instance.InstanceRemovedEventType), diff --git a/internal/query/projection/login_policy.go b/internal/query/projection/login_policy.go index cf992d2c84..114f8f142f 100644 --- a/internal/query/projection/login_policy.go +++ b/internal/query/projection/login_policy.go @@ -263,6 +263,7 @@ func (p *loginPolicyProjection) reduceLoginPolicyChanged(event eventstore.Event) cols, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }, ), nil } @@ -287,6 +288,7 @@ func (p *loginPolicyProjection) reduceMFAAdded(event eventstore.Event) (*handler }, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }, ), nil } @@ -311,6 +313,7 @@ func (p *loginPolicyProjection) reduceMFARemoved(event eventstore.Event) (*handl }, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }, ), nil } @@ -324,6 +327,7 @@ func (p *loginPolicyProjection) reduceLoginPolicyRemoved(event eventstore.Event) e, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, e.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, e.Aggregate().InstanceID), }, ), nil } @@ -348,6 +352,7 @@ func (p *loginPolicyProjection) reduce2FAAdded(event eventstore.Event) (*handler }, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }, ), nil } @@ -372,6 +377,7 @@ func (p *loginPolicyProjection) reduce2FARemoved(event eventstore.Event) (*handl }, []handler.Condition{ handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID), + handler.NewCond(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID), }, ), nil } diff --git a/internal/query/projection/login_policy_test.go b/internal/query/projection/login_policy_test.go index b98a410757..071fa3659f 100644 --- a/internal/query/projection/login_policy_test.go +++ b/internal/query/projection/login_policy_test.go @@ -121,7 +121,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, ignore_unknown_usernames, allow_domain_discovery, disable_login_with_email, disable_login_with_phone, default_redirect_uri, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) WHERE (aggregate_id = $19)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, ignore_unknown_usernames, allow_domain_discovery, disable_login_with_email, disable_login_with_phone, default_redirect_uri, password_check_lifetime, external_login_check_lifetime, mfa_init_skip_lifetime, second_factor_check_lifetime, multi_factor_check_lifetime) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) WHERE (aggregate_id = $19) AND (instance_id = $20)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -142,6 +142,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { time.Millisecond * 10, time.Millisecond * 10, "agg-id", + "instance-id", }, }, }, @@ -167,12 +168,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.MultiFactorTypeU2FWithPIN, "agg-id", + "instance-id", }, }, }, @@ -198,12 +200,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.MultiFactorTypeU2FWithPIN, "agg-id", + "instance-id", }, }, }, @@ -227,9 +230,10 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "DELETE FROM projections.login_policies3 WHERE (aggregate_id = $1)", + expectedStmt: "DELETE FROM projections.login_policies3 WHERE (aggregate_id = $1) AND (instance_id = $2)", expectedArgs: []interface{}{ "agg-id", + "instance-id", }, }, }, @@ -255,12 +259,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.SecondFactorTypeU2F, "agg-id", + "instance-id", }, }, }, @@ -286,12 +291,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.SecondFactorTypeU2F, "agg-id", + "instance-id", }, }, }, @@ -391,7 +397,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, ignore_unknown_usernames, allow_domain_discovery, disable_login_with_email, disable_login_with_phone, default_redirect_uri) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (aggregate_id = $14)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, allow_register, allow_username_password, allow_external_idps, force_mfa, passwordless_type, hide_password_reset, ignore_unknown_usernames, allow_domain_discovery, disable_login_with_email, disable_login_with_phone, default_redirect_uri) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) WHERE (aggregate_id = $14) AND (instance_id = $15)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -407,6 +413,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { true, "https://example.com/redirect", "agg-id", + "instance-id", }, }, }, @@ -432,12 +439,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_append(multi_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.MultiFactorTypeU2FWithPIN, "agg-id", + "instance-id", }, }, }, @@ -463,12 +471,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, multi_factors) = ($1, $2, array_remove(multi_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.MultiFactorTypeU2FWithPIN, "agg-id", + "instance-id", }, }, }, @@ -494,12 +503,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_append(second_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.SecondFactorTypeU2F, "agg-id", + "instance-id", }, }, }, @@ -525,12 +535,13 @@ func TestLoginPolicyProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.login_policies3 SET (change_date, sequence, second_factors) = ($1, $2, array_remove(second_factors, $3)) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), domain.SecondFactorTypeU2F, "agg-id", + "instance-id", }, }, }, diff --git a/internal/query/projection/mail_template.go b/internal/query/projection/mail_template.go index 8bc939381e..d8e8cd8108 100644 --- a/internal/query/projection/mail_template.go +++ b/internal/query/projection/mail_template.go @@ -140,6 +140,7 @@ func (p *mailTemplateProjection) reduceChanged(event eventstore.Event) (*handler cols, []handler.Condition{ handler.NewCond(MailTemplateAggregateIDCol, policyEvent.Aggregate().ID), + handler.NewCond(MailTemplateInstanceIDCol, policyEvent.Aggregate().InstanceID), }), nil } @@ -152,5 +153,6 @@ func (p *mailTemplateProjection) reduceRemoved(event eventstore.Event) (*handler policyEvent, []handler.Condition{ handler.NewCond(MailTemplateAggregateIDCol, policyEvent.Aggregate().ID), + handler.NewCond(MailTemplateInstanceIDCol, policyEvent.Aggregate().InstanceID), }), nil } diff --git a/internal/query/projection/mail_template_test.go b/internal/query/projection/mail_template_test.go index 25f744148c..047af571b8 100644 --- a/internal/query/projection/mail_template_test.go +++ b/internal/query/projection/mail_template_test.go @@ -23,7 +23,7 @@ func TestMailTemplateProjection_reduces(t *testing.T) { want wantReduce }{ { - name: "org.reduceAdded", + name: "org reduceAdded", args: args{ event: getEvent(testEvent( repository.EventType(org.MailTemplateAddedEventType), @@ -58,7 +58,7 @@ func TestMailTemplateProjection_reduces(t *testing.T) { }, }, { - name: "org.reduceChanged", + name: "org reduceChanged", reduce: (&mailTemplateProjection{}).reduceChanged, args: args{ event: getEvent(testEvent( @@ -76,12 +76,13 @@ func TestMailTemplateProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.mail_templates SET (change_date, sequence, template) = ($1, $2, $3) WHERE (aggregate_id = $4)", + expectedStmt: "UPDATE projections.mail_templates SET (change_date, sequence, template) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (instance_id = $5)", expectedArgs: []interface{}{ anyArg{}, uint64(15), []byte("