mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
fix: instance remove (#4602)
This commit is contained in:
@@ -92,6 +92,8 @@ const (
|
||||
|
||||
uniqueDelete = `DELETE FROM eventstore.unique_constraints
|
||||
WHERE unique_type = $1 and unique_field = $2 and instance_id = $3`
|
||||
uniqueDeleteInstance = `DELETE FROM eventstore.unique_constraints
|
||||
WHERE instance_id = $1`
|
||||
)
|
||||
|
||||
type CRDB struct {
|
||||
@@ -193,7 +195,7 @@ func (db *CRDB) handleUniqueConstraints(ctx context.Context, tx *sql.Tx, uniqueC
|
||||
return caos_errs.ThrowAlreadyExists(err, "SQL-M0dsf", uniqueConstraint.ErrorMessage)
|
||||
}
|
||||
|
||||
return caos_errs.ThrowInternal(err, "SQL-dM9ds", "unable to create unique constraint ")
|
||||
return caos_errs.ThrowInternal(err, "SQL-dM9ds", "unable to create unique constraint")
|
||||
}
|
||||
case repository.UniqueConstraintRemoved:
|
||||
_, err := tx.ExecContext(ctx, uniqueDelete, uniqueConstraint.UniqueType, uniqueConstraint.UniqueField, uniqueConstraint.InstanceID)
|
||||
@@ -201,7 +203,14 @@ func (db *CRDB) handleUniqueConstraints(ctx context.Context, tx *sql.Tx, uniqueC
|
||||
logging.WithFields(
|
||||
"unique_type", uniqueConstraint.UniqueType,
|
||||
"unique_field", uniqueConstraint.UniqueField).WithError(err).Info("delete unique constraint failed")
|
||||
return caos_errs.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraint ")
|
||||
return caos_errs.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraint")
|
||||
}
|
||||
case repository.UniqueConstraintInstanceRemoved:
|
||||
_, err := tx.ExecContext(ctx, uniqueDeleteInstance, uniqueConstraint.InstanceID)
|
||||
if err != nil {
|
||||
logging.WithFields(
|
||||
"instance_id", uniqueConstraint.InstanceID).WithError(err).Info("delete instance unique constraints failed")
|
||||
return caos_errs.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraints of instance")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -379,24 +379,28 @@ func TestCRDB_Push_OneAggregate(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "push 1 event and add asset",
|
||||
name: "push 1 event and remove instance unique constraints",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
events: []*repository.Event{
|
||||
generateEvent(t, "12"),
|
||||
},
|
||||
uniqueConstraints: generateRemoveInstanceUniqueConstraints(t, "instanceID"),
|
||||
uniqueDataType: "usernames",
|
||||
uniqueDataField: "testremove",
|
||||
uniqueDataInstanceID: "instanceID",
|
||||
},
|
||||
res: res{
|
||||
wantErr: false,
|
||||
eventsRes: eventsRes{
|
||||
pushedEventsCount: 1,
|
||||
assetCount: 1,
|
||||
uniqueCount: 0,
|
||||
aggID: []string{"12"},
|
||||
aggType: repository.AggregateType(t.Name()),
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "push 1 event and remove asset",
|
||||
name: "push 1 event and add asset",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
events: []*repository.Event{
|
||||
@@ -407,11 +411,28 @@ func TestCRDB_Push_OneAggregate(t *testing.T) {
|
||||
wantErr: false,
|
||||
eventsRes: eventsRes{
|
||||
pushedEventsCount: 1,
|
||||
assetCount: 0,
|
||||
assetCount: 1,
|
||||
aggID: []string{"13"},
|
||||
aggType: repository.AggregateType(t.Name()),
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "push 1 event and remove asset",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
events: []*repository.Event{
|
||||
generateEvent(t, "14"),
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
wantErr: false,
|
||||
eventsRes: eventsRes{
|
||||
pushedEventsCount: 1,
|
||||
assetCount: 0,
|
||||
aggID: []string{"14"},
|
||||
aggType: repository.AggregateType(t.Name()),
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -1201,3 +1222,13 @@ func generateRemoveUniqueConstraint(t *testing.T, table, uniqueField string) *re
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func generateRemoveInstanceUniqueConstraints(t *testing.T, instanceID string) *repository.UniqueConstraint {
|
||||
t.Helper()
|
||||
e := &repository.UniqueConstraint{
|
||||
InstanceID: instanceID,
|
||||
Action: repository.UniqueConstraintInstanceRemoved,
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
Reference in New Issue
Block a user