fix: instance remove (#4602)

This commit is contained in:
Livio Spring
2022-10-26 13:06:48 +00:00
committed by GitHub
parent 001636f2b4
commit d721f725fd
89 changed files with 655 additions and 121 deletions
+1 -1
View File
@@ -179,7 +179,7 @@ func TestActionProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ActionInstanceIDCol),
+1 -1
View File
@@ -220,7 +220,7 @@ func TestAppProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(AppColumnInstanceID),
+1 -1
View File
@@ -226,7 +226,7 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(AuthNKeyInstanceIDCol),
@@ -132,7 +132,7 @@ func TestCustomTextProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(CustomTextInstanceIDCol),
@@ -217,7 +217,7 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(DebugNotificationProviderInstanceIDCol),
@@ -129,7 +129,7 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(DomainPolicyInstanceIDCol),
+1 -1
View File
@@ -109,7 +109,7 @@ func TestFlowProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(FlowInstanceIDCol),
@@ -190,7 +190,7 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(IDPUserLinkInstanceIDCol),
+1 -1
View File
@@ -201,7 +201,7 @@ func TestIDPProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(IDPInstanceIDCol),
@@ -154,7 +154,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(IDPUserLinkInstanceIDCol),
@@ -85,7 +85,7 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(InstanceDomainInstanceIDCol),
@@ -178,7 +178,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
+1 -1
View File
@@ -56,7 +56,7 @@ func TestInstanceProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(InstanceColumnID),
+1 -1
View File
@@ -106,7 +106,7 @@ func TestKeyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(KeyColumnInstanceID),
@@ -131,7 +131,7 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(LabelPolicyInstanceIDCol),
@@ -125,7 +125,7 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(LockoutPolicyInstanceIDCol),
+30 -1
View File
@@ -213,7 +213,7 @@ func (p *loginNameProjection) reducers() []handler.AggregateReducer {
},
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(LoginNameUserInstanceIDCol),
Reduce: p.reduceInstanceRemoved,
},
},
},
@@ -432,3 +432,32 @@ func (p *loginNameProjection) reduceDomainRemoved(event eventstore.Event) (*hand
crdb.WithTableSuffix(loginNameDomainSuffix),
), nil
}
func (p *loginNameProjection) reduceInstanceRemoved(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.InstanceRemovedEvent)
if !ok {
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASeg3", "reduce.wrong.event.type %s", instance.InstanceRemovedEventType)
}
return crdb.NewMultiStatement(
event,
crdb.AddDeleteStatement(
[]handler.Condition{
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().ID),
},
crdb.WithTableSuffix(loginNameDomainSuffix),
),
crdb.AddDeleteStatement(
[]handler.Condition{
handler.NewCond(LoginNamePoliciesInstanceIDCol, e.Aggregate().ID),
},
crdb.WithTableSuffix(loginNamePolicySuffix),
),
crdb.AddDeleteStatement(
[]handler.Condition{
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().ID),
},
crdb.WithTableSuffix(loginNameUserSuffix),
),
), nil
}
+15 -3
View File
@@ -486,10 +486,10 @@ func TestLoginNameProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(LoginNameUserInstanceIDCol),
reduce: (&loginNameProjection{}).reduceInstanceRemoved,
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
@@ -497,7 +497,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.login_names WHERE (instance_id = $1)",
expectedStmt: "DELETE FROM projections.login_names_domains WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
{
expectedStmt: "DELETE FROM projections.login_names_policies WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
{
expectedStmt: "DELETE FROM projections.login_names_users WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
@@ -543,7 +543,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(LoginPolicyInstanceIDCol),
@@ -82,11 +82,6 @@ func (p *mailTemplateProjection) reducers() []handler.AggregateReducer {
Event: instance.MailTemplateChangedEventType,
Reduce: p.reduceChanged,
},
},
},
{
Aggregate: instance.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(MailTemplateInstanceIDCol),
@@ -120,7 +120,7 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MailTemplateInstanceIDCol),
@@ -336,7 +336,7 @@ func TestMessageTextProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MessageTextInstanceIDCol),
@@ -66,11 +66,6 @@ func (p *oidcSettingsProjection) reducers() []handler.AggregateReducer {
Event: instance.OIDCSettingsChangedEventType,
Reduce: p.reduceOIDCSettingsChanged,
},
},
},
{
Aggregate: instance.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(OIDCSettingsColumnInstanceID),
@@ -94,7 +94,7 @@ func TestOIDCSettingsProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(OIDCSettingsColumnInstanceID),
+1 -1
View File
@@ -194,7 +194,7 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(OrgDomainInstanceIDCol),
+1 -1
View File
@@ -208,7 +208,7 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
+10
View File
@@ -7,6 +7,7 @@ import (
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
)
@@ -73,6 +74,15 @@ func (p *orgMetadataProjection) reducers() []handler.AggregateReducer {
},
},
},
{
Aggregate: instance.AggregateType,
EventRedusers: []handler.EventReducer{
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(OrgMetadataColumnInstanceID),
},
},
},
}
}
@@ -7,6 +7,7 @@ import (
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
)
@@ -137,6 +138,32 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
},
},
},
{
name: "reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.org_metadata WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
+1 -1
View File
@@ -194,7 +194,7 @@ func TestOrgProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(OrgColumnInstanceID),
@@ -125,7 +125,7 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(AgePolicyInstanceIDCol),
@@ -137,7 +137,7 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ComplexityPolicyInstanceIDCol),
@@ -128,7 +128,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(PrivacyPolicyInstanceIDCol),
@@ -216,7 +216,7 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
@@ -55,7 +55,7 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ProjectGrantColumnInstanceID),
@@ -209,7 +209,7 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
@@ -53,7 +53,7 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ProjectRoleColumnInstanceID),
+1 -1
View File
@@ -54,7 +54,7 @@ func TestProjectProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ProjectColumnInstanceID),
@@ -76,6 +76,10 @@ func (p *secretGeneratorProjection) reducers() []handler.AggregateReducer {
Event: instance.SecretGeneratorRemovedEventType,
Reduce: p.reduceSecretGeneratorRemoved,
},
{
Event: instance.InstanceRemovedEventType,
Reduce: reduceInstanceRemovedHelper(SecretGeneratorColumnInstanceID),
},
},
},
}
@@ -122,6 +122,32 @@ func TestSecretGeneratorProjection_reduces(t *testing.T) {
},
},
},
{
name: "reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.secret_generators2 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
+1 -1
View File
@@ -271,7 +271,7 @@ func TestSMSProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(SMSColumnInstanceID),
+1 -1
View File
@@ -151,7 +151,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(SMTPConfigColumnInstanceID),
@@ -244,7 +244,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(UserAuthMethodInstanceIDCol),
+1 -1
View File
@@ -159,7 +159,7 @@ func TestUserGrantProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(UserGrantInstanceID),
@@ -144,7 +144,7 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(UserMetadataColumnInstanceID),
@@ -115,7 +115,7 @@ func TestPersonalAccessTokenProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(PersonalAccessTokenColumnInstanceID),
+1 -1
View File
@@ -1623,7 +1623,7 @@ func TestUserProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(UserInstanceIDCol),