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,328 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: status_pages.sql
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addStatusPageMonitor = `-- name: AddStatusPageMonitor :exec
|
||||
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, label, position)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
type AddStatusPageMonitorParams struct {
|
||||
PageID uuid.UUID
|
||||
MonitorID uuid.UUID
|
||||
OrgID uuid.UUID
|
||||
Section string
|
||||
Label string
|
||||
Position int32
|
||||
}
|
||||
|
||||
func (q *Queries) AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error {
|
||||
_, err := q.db.Exec(ctx, addStatusPageMonitor,
|
||||
arg.PageID,
|
||||
arg.MonitorID,
|
||||
arg.OrgID,
|
||||
arg.Section,
|
||||
arg.Label,
|
||||
arg.Position,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearStatusPageMonitors = `-- name: ClearStatusPageMonitors :exec
|
||||
DELETE FROM status_page_monitors WHERE page_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, clearStatusPageMonitors, pageID)
|
||||
return err
|
||||
}
|
||||
|
||||
const createStatusPage = `-- 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 id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateStatusPageParams struct {
|
||||
OrgID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
DomainToken string
|
||||
Theme []byte
|
||||
}
|
||||
|
||||
func (q *Queries) CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error) {
|
||||
row := q.db.QueryRow(ctx, createStatusPage,
|
||||
arg.OrgID,
|
||||
arg.Slug,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Published,
|
||||
arg.DomainToken,
|
||||
arg.Theme,
|
||||
)
|
||||
var i StatusPage
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteStatusPage = `-- name: DeleteStatusPage :execrows
|
||||
DELETE FROM status_pages WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteStatusPage(ctx context.Context, id uuid.UUID) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteStatusPage, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const findPublishedPage = `-- name: FindPublishedPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages
|
||||
WHERE published
|
||||
AND (($1::citext IS NOT NULL AND custom_domain = $1 AND domain_verified_at IS NOT NULL)
|
||||
OR ($2::citext IS NOT NULL AND slug = $2))
|
||||
`
|
||||
|
||||
type FindPublishedPageParams struct {
|
||||
Host *string
|
||||
Slug *string
|
||||
}
|
||||
|
||||
// System scope: resolves a request to a page by verified custom domain or
|
||||
// by slug.
|
||||
func (q *Queries) FindPublishedPage(ctx context.Context, arg FindPublishedPageParams) (StatusPage, error) {
|
||||
row := q.db.QueryRow(ctx, findPublishedPage, arg.Host, arg.Slug)
|
||||
var i StatusPage
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getStatusPage = `-- name: GetStatusPage :one
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error) {
|
||||
row := q.db.QueryRow(ctx, getStatusPage, id)
|
||||
var i StatusPage
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listStatusPages = `-- name: ListStatusPages :many
|
||||
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at FROM status_pages ORDER BY title
|
||||
`
|
||||
|
||||
func (q *Queries) ListStatusPages(ctx context.Context) ([]StatusPage, error) {
|
||||
rows, err := q.db.Query(ctx, listStatusPages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []StatusPage{}
|
||||
for rows.Next() {
|
||||
var i StatusPage
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const markDomainVerified = `-- name: MarkDomainVerified :exec
|
||||
UPDATE status_pages SET domain_verified_at = now() WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) MarkDomainVerified(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, markDomainVerified, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const setStatusPageDomain = `-- name: SetStatusPageDomain :one
|
||||
UPDATE status_pages SET
|
||||
custom_domain = $1,
|
||||
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verified_at END,
|
||||
updated_at = now()
|
||||
WHERE id = $2
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
`
|
||||
|
||||
type SetStatusPageDomainParams struct {
|
||||
CustomDomain *string
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
// Changing the domain drops a previous verification.
|
||||
func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error) {
|
||||
row := q.db.QueryRow(ctx, setStatusPageDomain, arg.CustomDomain, arg.ID)
|
||||
var i StatusPage
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const statusPageMonitors = `-- 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
|
||||
`
|
||||
|
||||
type StatusPageMonitorsRow struct {
|
||||
MonitorID uuid.UUID
|
||||
Section string
|
||||
Label string
|
||||
Position int32
|
||||
MonitorName string
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
func (q *Queries) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]StatusPageMonitorsRow, error) {
|
||||
rows, err := q.db.Query(ctx, statusPageMonitors, pageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []StatusPageMonitorsRow{}
|
||||
for rows.Next() {
|
||||
var i StatusPageMonitorsRow
|
||||
if err := rows.Scan(
|
||||
&i.MonitorID,
|
||||
&i.Section,
|
||||
&i.Label,
|
||||
&i.Position,
|
||||
&i.MonitorName,
|
||||
&i.Enabled,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateStatusPage = `-- name: UpdateStatusPage :one
|
||||
UPDATE status_pages SET slug = $2, title = $3, description = $4, published = $5, theme = $6, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateStatusPageParams struct {
|
||||
ID uuid.UUID
|
||||
Slug string
|
||||
Title string
|
||||
Description string
|
||||
Published bool
|
||||
Theme []byte
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error) {
|
||||
row := q.db.QueryRow(ctx, updateStatusPage,
|
||||
arg.ID,
|
||||
arg.Slug,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Published,
|
||||
arg.Theme,
|
||||
)
|
||||
var i StatusPage
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.Slug,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Published,
|
||||
&i.CustomDomain,
|
||||
&i.DomainToken,
|
||||
&i.DomainVerifiedAt,
|
||||
&i.Theme,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in new issue
Block a user