feat: add tenant and user management with migrations, handlers, and tests
- Implemented tenant and user management features including: - Tenant creation and management with associated migrations. - User creation and management with associated migrations. - Tenant membership management with associated migrations. - Platform user roles management with associated migrations. - Quota management with associated migrations. - Article and template management with associated migrations. - Added HTTP handlers for templates and workspaces. - Created tests for protected and public routes. - Introduced a script to check tenant scope in SQL queries. - Documented task plan for backend completion and frontend foundation.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
-- name: CountArticlesByTenant :one
|
||||
SELECT COUNT(*) FROM articles
|
||||
WHERE tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|
||||
|
||||
-- name: CountPublishedArticlesByTenant :one
|
||||
SELECT COUNT(*) FROM articles
|
||||
WHERE tenant_id = sqlc.arg(tenant_id) AND publish_status = 'success' AND deleted_at IS NULL;
|
||||
|
||||
-- name: CountBrandsByTenant :one
|
||||
SELECT COUNT(*) FROM brands
|
||||
WHERE tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|
||||
|
||||
-- name: GetRecentArticles :many
|
||||
SELECT a.id, a.generate_status, a.publish_status, a.source_type, a.created_at,
|
||||
av.title, av.word_count, av.source_label,
|
||||
t.template_name
|
||||
FROM articles a
|
||||
LEFT JOIN article_versions av ON av.id = a.current_version_id
|
||||
LEFT JOIN article_templates t ON t.id = a.template_id
|
||||
WHERE a.tenant_id = sqlc.arg(tenant_id) AND a.deleted_at IS NULL
|
||||
ORDER BY a.created_at DESC
|
||||
LIMIT 10;
|
||||
|
||||
-- name: GetQuotaSummary :one
|
||||
SELECT COALESCE(
|
||||
(SELECT balance_after FROM tenant_quota_ledgers
|
||||
WHERE tenant_id = sqlc.arg(tenant_id) AND quota_type = 'article_generation'
|
||||
ORDER BY created_at DESC LIMIT 1), 0
|
||||
)::INT AS balance;
|
||||
|
||||
-- name: GetActivePlanForTenant :one
|
||||
SELECT p.plan_code, p.name AS plan_name, p.quota_policy_json,
|
||||
s.start_at, s.end_at
|
||||
FROM tenant_plan_subscriptions s
|
||||
JOIN plans p ON p.id = s.plan_id
|
||||
WHERE s.tenant_id = sqlc.arg(tenant_id) AND s.status = 'active' AND s.deleted_at IS NULL
|
||||
LIMIT 1;
|
||||
Reference in New Issue
Block a user