Files
nexarch/internal/migration/role/map.go
T
patrickandClaude Sonnet 5.5 5b8c20777d refactor: Pruefgate-Pakete nach Funktion benannt, migration* gruppiert
- dms/ai/workflow: qa0x-Pakete nach internal/gates/<thema> verschoben, Paketname = Thema
- internal/migration{acl,audit,...} -> internal/migration/{acl,audit,...}
- Importpfade, Gate-Skripte und zwei relative Migrationspfade angepasst
- keine Logikaenderung; mail-Gates bewusst unveraendert (pfadabhaengig)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 12:44:21 +01:00

65 lines
1.7 KiB
Go

package migrationrole
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
// MapEntry ist eine Zeile der role_migration_map, angereichert um die
// Zieldaten aus dem verknuepften user_migration_map-Eintrag.
type MapEntry struct {
ID int64
UserMigrationMapID int64
SourceSystem string
SourceRole string
GrantedBy string
ApprovedBy *string
NexarchTenantID string
NexarchUserID string
}
// MapStore kapselt den lesenden Zugriff auf role_migration_map in der
// Registry-Datenbank.
type MapStore struct {
pool *pgxpool.Pool
}
func NewMapStore(pool *pgxpool.Pool) *MapStore {
return &MapStore{pool: pool}
}
// Approved liefert ausschliesslich Zeilen mit gesetztem approved_at, verknuepft
// mit dem zugehoerigen user_migration_map-Eintrag fuer Tenant-/User-ID.
func (s *MapStore) Approved(ctx context.Context) ([]MapEntry, error) {
rows, err := s.pool.Query(ctx, `
SELECT r.id, r.user_migration_map_id, r.source_system, r.source_role, r.granted_by, r.approved_by,
u.nexarch_tenant_id, u.nexarch_user_id
FROM role_migration_map r
JOIN user_migration_map u ON u.id = r.user_migration_map_id
WHERE r.approved_at IS NOT NULL
ORDER BY r.id
`)
if err != nil {
return nil, fmt.Errorf("freigegebene role-map lesen: %w", err)
}
defer rows.Close()
var out []MapEntry
for rows.Next() {
var e MapEntry
var grantedBy *string
if err := rows.Scan(&e.ID, &e.UserMigrationMapID, &e.SourceSystem, &e.SourceRole, &grantedBy, &e.ApprovedBy,
&e.NexarchTenantID, &e.NexarchUserID); err != nil {
return nil, fmt.Errorf("role-map-eintrag lesen: %w", err)
}
if grantedBy != nil {
e.GrantedBy = *grantedBy
}
out = append(out, e)
}
return out, rows.Err()
}