feat: add administrator repository (#11803)

Introduces the `administrators` relational table and repository layer
for the v3 backend, unifying instance, organization, project, and
project-grant membership into a single scoped model.

Closes #10220

## Changes

- **Domain**: `Administrator` struct, `AdministratorScope` enum,
`AdministratorRepository` interface with typed CRUD, column, condition,
and change helpers. Generated enumer and GoMock.
- **Migration** (`016`): `zitadel.administrators` table with a generated
`id`, scope-alignment check constraint, cascading foreign keys, and a
child `administrator_roles` table.
- **Repository**: CTE-based role mutations (`AddRole`, `RemoveRole`,
`SetRoles`) for atomicity. Roles aggregated via `ARRAY_AGG`.
- **Projection**: Event reducers for
`member.added/changed/removed/cascade_removed` across all four admin
scopes.
- **Fixes**: `Rows.Close()` error wrapping; `TextArray` nil-safe scan +
full `pgtype` array interface; `authorization` and `projectGrant` scan
helpers fixed for `ARRAY_AGG` under `database/sql`; removed unused `ctx`
parameter from `callReduce`.

---------

Co-authored-by: Marco Ardizzone <[email protected]>
This commit is contained in:
Silvan
2026-03-18 10:24:09 +01:00
committed by GitHub
co-authored by Marco Ardizzone
parent 6d90a120a6
commit f138082b64
21 changed files with 3513 additions and 46 deletions
@@ -44,7 +44,7 @@ func TestInstanceDomainReducers(t *testing.T) {
domainAddedEvt := instance.NewDomainAddedEvent(ctx, &instance.NewAggregate("123").Aggregate, domainName, false)
// Test
res := callReduce(t, ctx, rawTx, handler, domainAddedEvt)
res := callReduce(t, rawTx, handler, domainAddedEvt)
require.True(t, res)
// Verify
@@ -85,7 +85,7 @@ func TestInstanceDomainReducers(t *testing.T) {
domainPrimarySetEvt := instance.NewDomainPrimarySetEvent(ctx, &instance.NewAggregate("123").Aggregate, domainName)
// Test
res := callReduce(t, ctx, rawTx, handler, domainPrimarySetEvt)
res := callReduce(t, rawTx, handler, domainPrimarySetEvt)
require.True(t, res)
// Verify
@@ -127,7 +127,7 @@ func TestInstanceDomainReducers(t *testing.T) {
domainRemovedEvt := instance.NewDomainRemovedEvent(ctx, &instance.NewAggregate("123").Aggregate, domainName)
// Test
res := callReduce(t, ctx, rawTx, handler, domainRemovedEvt)
res := callReduce(t, rawTx, handler, domainRemovedEvt)
require.True(t, res)
// Verify
@@ -150,7 +150,7 @@ func TestInstanceDomainReducers(t *testing.T) {
trustedDomainAddedEvt := instance.NewTrustedDomainAddedEvent(ctx, &instance.NewAggregate("123").Aggregate, domainName)
// Test
res := callReduce(t, ctx, rawTx, handler, trustedDomainAddedEvt)
res := callReduce(t, rawTx, handler, trustedDomainAddedEvt)
require.True(t, res)
// Verify
@@ -185,7 +185,7 @@ func TestInstanceDomainReducers(t *testing.T) {
trustedDomainRemovedEvt := instance.NewTrustedDomainRemovedEvent(ctx, &instance.NewAggregate("123").Aggregate, domainName)
// Test
res := callReduce(t, ctx, rawTx, handler, trustedDomainRemovedEvt)
res := callReduce(t, rawTx, handler, trustedDomainRemovedEvt)
require.True(t, res)
// Verify