mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-30 19:12:16 +00:00
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:
co-authored by
Marco Ardizzone
parent
6d90a120a6
commit
f138082b64
@@ -15,6 +15,11 @@ type TextArray[T ~string] pgtype.FlatArray[T]
|
||||
|
||||
// Scan implements the [database/sql.Scanner] interface.
|
||||
func (s *TextArray[T]) Scan(src any) error {
|
||||
if src == nil {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var typedArray []string
|
||||
err := pgtype.NewMap().SQLScanner(&typedArray).Scan(src)
|
||||
if err != nil {
|
||||
@@ -29,6 +34,46 @@ func (s *TextArray[T]) Scan(src any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s TextArray[T]) Dimensions() []pgtype.ArrayDimension {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return []pgtype.ArrayDimension{{Length: int32(len(s)), LowerBound: 1}}
|
||||
}
|
||||
|
||||
func (s TextArray[T]) Index(i int) any {
|
||||
return s[i]
|
||||
}
|
||||
|
||||
func (s TextArray[T]) IndexType() any {
|
||||
var el T
|
||||
return el
|
||||
}
|
||||
|
||||
func (s *TextArray[T]) SetDimensions(dimensions []pgtype.ArrayDimension) error {
|
||||
if dimensions == nil {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
elementCount := 1
|
||||
for _, dimension := range dimensions {
|
||||
elementCount *= int(dimension.Length)
|
||||
}
|
||||
|
||||
*s = make(TextArray[T], elementCount)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s TextArray[T]) ScanIndex(i int) any {
|
||||
return &s[i]
|
||||
}
|
||||
|
||||
func (s TextArray[T]) ScanIndexType() any {
|
||||
return new(T)
|
||||
}
|
||||
|
||||
// Value implements the [database/sql/driver.Valuer] interface.
|
||||
func (s TextArray[T]) Value() (driver.Value, error) {
|
||||
if len(s) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user