mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix(projections): delete app on remove project event (#2772)
* fix(projections): delete app on remove project event * test(projection): project removed event in app * more effitient mig
This commit is contained in:
parent
b43362ad15
commit
7a5cb80569
@ -56,6 +56,10 @@ func (p *AppProjection) reducers() []handler.AggregateReducer {
|
||||
Event: project.ApplicationRemovedType,
|
||||
Reduce: p.reduceAppRemoved,
|
||||
},
|
||||
{
|
||||
Event: project.ProjectRemovedType,
|
||||
Reduce: p.reduceProjectRemoved,
|
||||
},
|
||||
{
|
||||
Event: project.APIConfigAddedType,
|
||||
Reduce: p.reduceAPIConfigAdded,
|
||||
@ -213,6 +217,20 @@ func (p *AppProjection) reduceAppRemoved(event eventstore.EventReader) (*handler
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *AppProjection) reduceProjectRemoved(event eventstore.EventReader) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.ProjectRemovedEvent)
|
||||
if !ok {
|
||||
logging.LogWithFields("HANDL-ZxQnj", "seq", event.Sequence(), "expectedType", project.ProjectRemovedType).Error("wrong event type")
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-DlUlO", "reduce.wrong.event.type")
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppColumnProjectID, e.Aggregate().ID),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *AppProjection) reduceAPIConfigAdded(event eventstore.EventReader) (*handler.Statement, error) {
|
||||
e, ok := event.(*project.APIConfigAddedEvent)
|
||||
if !ok {
|
||||
|
@ -186,6 +186,33 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "project.reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&AppProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
projection: AppProjectionTable,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM zitadel.projections.apps WHERE (project_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "project.reduceAPIConfigAdded",
|
||||
args: args{
|
||||
|
6
migrations/cockroach/V1.97__delete_apps.sql
Normal file
6
migrations/cockroach/V1.97__delete_apps.sql
Normal file
@ -0,0 +1,6 @@
|
||||
DELETE FROM zitadel.projections.apps
|
||||
WHERE project_id IN (
|
||||
SELECT aggregate_id
|
||||
FROM eventstore.events
|
||||
WHERE aggregate_type = 'project' AND event_type = 'project.removed'
|
||||
);
|
Loading…
Reference in New Issue
Block a user