feat: instance domain APIs with relational tables (#11051)

# Which Problems Are Solved

This PR implements the endpoints listed in
https://github.com/zitadel/zitadel/issues/10444 .

# How the Problems Are Solved

The implementation follows the same pattern as the Instance one. The
`Add` and `Remove` are implementing the `Commander` interface, while
`List` Domains endpoints are implementing the `Querier` interace.

The PR adds also some forgotten calls to the relational logic for the
Instance API. The commits are identifiable by the label `instance:`
prepended to them. This is the complete list: bafce01b0 , 6fe7257ab ,
e27bc9c34 , 8133ede73 , fde667953 , a3e1135ed , ee1a6f9c1

# Additional Context

- Closes #10444

---------

Co-authored-by: Elio Bischof <[email protected]>
Co-authored-by: Lebogang Phoshoko <[email protected]>
Co-authored-by: Wim Van Laer <[email protected]>
Co-authored-by: Max Peintner <[email protected]>
Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
Marco A.
2025-12-17 12:01:09 +01:00
committed by GitHub
co-authored by Elio Bischof Lebogang Phoshoko Wim Van Laer Max Peintner Gayathri Vijayan
parent d79bfe6eba
commit b339a3e696
49 changed files with 5670 additions and 1466 deletions
+20 -15
View File
@@ -11,8 +11,9 @@ import (
)
type UpdateInstanceCommand struct {
ID string `json:"id"`
Name string `json:"name"`
ID string `json:"id"`
Name string `json:"name"`
ShouldSkipUpdate bool `json:"should_skip_update"`
}
// RequiresTransaction implements [Transactional].
@@ -20,6 +21,10 @@ func (u *UpdateInstanceCommand) RequiresTransaction() {}
// Events implements Commander.
func (u *UpdateInstanceCommand) Events(ctx context.Context, _ *InvokeOpts) ([]eventstore.Command, error) {
if u.ShouldSkipUpdate {
return nil, nil
}
return []eventstore.Command{
instance.NewInstanceChangedEvent(ctx, &instance.NewAggregate(u.ID).Aggregate, u.Name),
}, nil
@@ -39,6 +44,10 @@ func NewUpdateInstanceCommand(id, name string) *UpdateInstanceCommand {
// Execute implements [Commander]
func (u *UpdateInstanceCommand) Execute(ctx context.Context, opts *InvokeOpts) (err error) {
if u.ShouldSkipUpdate {
return
}
instanceRepo := opts.instanceRepo
updateCount, err := instanceRepo.Update(
@@ -48,16 +57,14 @@ func (u *UpdateInstanceCommand) Execute(ctx context.Context, opts *InvokeOpts) (
database.NewChange(instanceRepo.NameColumn(), u.Name),
)
if err != nil {
return err
return zerrors.ThrowInternal(err, "DOM-PkVMNR", "Errors.Instance.Update")
}
if updateCount == 0 {
err = zerrors.ThrowNotFound(nil, "DOM-ghfov1", "Errors.Instance.NotFound")
return err
return zerrors.ThrowNotFound(nil, "DOM-ghfov1", "Errors.Instance.NotFound")
}
if updateCount > 1 {
err = zerrors.ThrowInternal(NewMultipleObjectsUpdatedError(1, updateCount), "DOM-HlrNmD", "unexpected number of rows updated")
return err
return zerrors.ThrowInternal(NewMultipleObjectsUpdatedError(1, updateCount), "DOM-HlrNmD", "Errors.Instance.UpdateMismatch")
}
return err
@@ -71,26 +78,24 @@ func (u *UpdateInstanceCommand) String() string {
// Validate implements [Commander]
func (u *UpdateInstanceCommand) Validate(ctx context.Context, opts *InvokeOpts) error {
if u.ID = strings.TrimSpace(u.ID); u.ID == "" {
return zerrors.ThrowInvalidArgument(nil, "DOM-wSs6kG", "invalid instance ID")
return zerrors.ThrowInvalidArgument(nil, "DOM-wSs6kG", "Errors.Instance.ID")
}
if u.Name = strings.TrimSpace(u.Name); u.Name == "" {
return zerrors.ThrowInvalidArgument(nil, "DOM-FPJcLC", "invalid instance name")
return zerrors.ThrowInvalidArgument(nil, "DOM-FPJcLC", "Errors.Instance.Name")
}
if authZErr := opts.Permissions.CheckInstancePermission(ctx, InstanceWritePermission); authZErr != nil {
return zerrors.ThrowPermissionDenied(authZErr, "DOM-M5ObLP", "permission denied")
return zerrors.ThrowPermissionDenied(authZErr, "DOM-M5ObLP", "Errors.PermissionDenied")
}
instanceRepo := opts.instanceRepo
instance, err := instanceRepo.Get(ctx, opts.DB(), database.WithCondition(instanceRepo.IDCondition(u.ID)))
if err != nil {
return err
return zerrors.ThrowInternal(err, "DOM-j05Hdo", "Errors.Instance.Get")
}
if instance.Name == u.Name {
err = zerrors.ThrowPreconditionFailed(nil, "DOM-5MrT21", "Errors.Instance.NotChanged")
return err
}
u.ShouldSkipUpdate = instance.Name == u.Name
return nil
}