feat(store): let regions and agents belong to the platform or one organization

Regions are identified by id so organizations can reuse keys. Triggers
keep agents in regions of the same owner and monitors in platform or own
regions. Platform admins are a user flag.

Refs #52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 01:36:02 +01:00
1 parent 7bb4afa04a
commit 607798d742
10 files changed
+442 -99

No files matched your search

+32 -3
View File
@@ -24,7 +24,7 @@ func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) {
const createUser = `-- name: CreateUser :one
INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4)
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin
`
type CreateUserParams struct {
@@ -53,6 +53,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
&i.TotpSecret,
&i.TotpEnabledAt,
&i.Locale,
&i.IsAdmin,
)
return i, err
}
@@ -93,7 +94,7 @@ func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error {
}
const getUser = `-- name: GetUser :one
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale FROM users WHERE id = $1
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin FROM users WHERE id = $1
`
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
@@ -110,12 +111,13 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
&i.TotpSecret,
&i.TotpEnabledAt,
&i.Locale,
&i.IsAdmin,
)
return i, err
}
const getUserByEmail = `-- name: GetUserByEmail :one
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale FROM users WHERE email = $1
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin FROM users WHERE email = $1
`
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
@@ -132,10 +134,20 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
&i.TotpSecret,
&i.TotpEnabledAt,
&i.Locale,
&i.IsAdmin,
)
return i, err
}
const makeAdmin = `-- name: MakeAdmin :exec
UPDATE users SET is_admin = true, updated_at = now() WHERE id = $1
`
func (q *Queries) MakeAdmin(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, makeAdmin, id)
return err
}
const setPasswordHash = `-- name: SetPasswordHash :exec
UPDATE users SET password_hash = $2, updated_at = now() WHERE id = $1
`
@@ -150,6 +162,23 @@ func (q *Queries) SetPasswordHash(ctx context.Context, arg SetPasswordHashParams
return err
}
const setUserAdmin = `-- name: SetUserAdmin :execrows
UPDATE users SET is_admin = $2, updated_at = now() WHERE email = $1
`
type SetUserAdminParams struct {
Email string
IsAdmin bool
}
func (q *Queries) SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) {
result, err := q.db.Exec(ctx, setUserAdmin, arg.Email, arg.IsAdmin)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const setUserLocale = `-- name: SetUserLocale :exec
UPDATE users SET locale = $2, updated_at = now() WHERE id = $1
`