feat(store): add totp columns, org totp policy and global scope

Orgs are created inside their own tenant scope, so signup needs no
system scope.

Refs #3

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-21 23:55:23 +01:00
1 parent caff396264
commit 99e9b1e57d
12 files changed
+203 -31

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ WHERE m.org_id = $1
ORDER BY u.email;
-- name: ListUserOrgs :many
SELECT o.id, o.slug, o.name, m.is_owner
SELECT o.id, o.slug, o.name, o.require_totp, m.is_owner
FROM memberships m
JOIN orgs o ON o.id = m.org_id
WHERE m.user_id = $1
+1 -1
View File
@@ -1,5 +1,5 @@
-- name: CreateOrg :one
INSERT INTO orgs (slug, name) VALUES ($1, $2)
INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3)
RETURNING *;
-- name: GetOrg :one
+15
View File
@@ -7,3 +7,18 @@ SELECT * FROM users WHERE id = $1;
-- name: GetUserByEmail :one
SELECT * FROM users WHERE email = $1;
-- name: AnyUserExists :one
SELECT EXISTS (SELECT 1 FROM users);
-- name: SetPasswordHash :exec
UPDATE users SET password_hash = $2, updated_at = now() WHERE id = $1;
-- name: EnableTOTP :exec
UPDATE users SET totp_secret = $2, totp_enabled_at = now(), updated_at = now() WHERE id = $1;
-- name: DisableTOTP :exec
UPDATE users SET totp_secret = NULL, totp_enabled_at = NULL, updated_at = now() WHERE id = $1;
-- name: DeleteUser :execrows
DELETE FROM users WHERE id = $1;