feat(store): add status pages and their components
Composite foreign keys keep pages from listing monitors of other organizations, independent of row-level security. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
b831478143
commit
d820547e8c
9 files changed
+570
No files matched your search
@@ -0,0 +1,52 @@
|
||||
-- name: CreateStatusPage :one
|
||||
INSERT INTO status_pages (org_id, slug, title, description, published, domain_token, theme)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateStatusPage :one
|
||||
UPDATE status_pages SET slug = $2, title = $3, description = $4, published = $5, theme = $6, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: SetStatusPageDomain :one
|
||||
-- Changing the domain drops a previous verification.
|
||||
UPDATE status_pages SET
|
||||
custom_domain = sqlc.narg(custom_domain),
|
||||
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM sqlc.narg(custom_domain) THEN domain_verified_at END,
|
||||
updated_at = now()
|
||||
WHERE id = sqlc.arg(id)
|
||||
RETURNING *;
|
||||
|
||||
-- name: MarkDomainVerified :exec
|
||||
UPDATE status_pages SET domain_verified_at = now() WHERE id = $1;
|
||||
|
||||
-- name: GetStatusPage :one
|
||||
SELECT * FROM status_pages WHERE id = $1;
|
||||
|
||||
-- name: ListStatusPages :many
|
||||
SELECT * FROM status_pages ORDER BY title;
|
||||
|
||||
-- name: DeleteStatusPage :execrows
|
||||
DELETE FROM status_pages WHERE id = $1;
|
||||
|
||||
-- name: StatusPageMonitors :many
|
||||
SELECT spm.monitor_id, spm.section, spm.label, spm.position, m.name AS monitor_name, m.enabled
|
||||
FROM status_page_monitors spm
|
||||
JOIN monitors m ON m.id = spm.monitor_id
|
||||
WHERE spm.page_id = $1
|
||||
ORDER BY spm.position, m.name;
|
||||
|
||||
-- name: ClearStatusPageMonitors :exec
|
||||
DELETE FROM status_page_monitors WHERE page_id = $1;
|
||||
|
||||
-- name: AddStatusPageMonitor :exec
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
||||
|
||||
-- name: FindPublishedPage :one
|
||||
-- System scope: resolves a request to a page by verified custom domain or
|
||||
-- by slug.
|
||||
SELECT * FROM status_pages
|
||||
WHERE published
|
||||
AND ((sqlc.narg(host)::citext IS NOT NULL AND custom_domain = sqlc.narg(host) AND domain_verified_at IS NOT NULL)
|
||||
OR (sqlc.narg(slug)::citext IS NOT NULL AND slug = sqlc.narg(slug)));
|
||||
Reference in new issue
Block a user