ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m28s
ci / test (pull_request) Successful in 12m52s
ci / build (pull_request) Successful in 11m21s
ci / image (pull_request) Successful in 4m38s
A custom domain now needs a single record: a CNAME to <label>.<status page host>, where the label is derived from the page's domain token. The wildcard record of the status page host routes it, and since the target belongs to one page alone it also proves who set it up; a CNAME to the shared host would not, as any organization could then claim a domain pointing at the platform. The TXT record stays for domains whose CNAME cannot be seen, behind a proxy or without a subdomain. - The domain watch looks for the records of a new domain every minute for a quarter of an hour, then every ten minutes for two days, and verifies it on its own; "Check now" still works. - Verified domains are checked daily. When the record is gone the owners are told, and a week later the domain is switched off, so a record left behind cannot be taken over. Domains verified before keep working without checks. - The editor shows the CNAME record first, the TXT way for proxies and apex domains, how the domain was verified and when a missing record will switch it off. The API returns cname_record and domain_missing_since. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
740 lines
20 KiB
Go
740 lines
20 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: status_pages.sql
|
|
|
|
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const addStatusPageMonitor = `-- name: AddStatusPageMonitor :exec
|
|
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, group_id, label, position)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
`
|
|
|
|
type AddStatusPageMonitorParams struct {
|
|
PageID uuid.UUID
|
|
MonitorID uuid.UUID
|
|
OrgID uuid.UUID
|
|
Section string
|
|
GroupID *uuid.UUID
|
|
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.GroupID,
|
|
arg.Label,
|
|
arg.Position,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const clearStatusPageGroups = `-- name: ClearStatusPageGroups :exec
|
|
DELETE FROM status_page_groups WHERE page_id = $1
|
|
`
|
|
|
|
func (q *Queries) ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, clearStatusPageGroups, pageID)
|
|
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, show_component_details, domain_token, theme)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
|
|
`
|
|
|
|
type CreateStatusPageParams struct {
|
|
OrgID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
Description string
|
|
Published bool
|
|
ShowComponentDetails 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.ShowComponentDetails,
|
|
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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createStatusPageGroup = `-- name: CreateStatusPageGroup :one
|
|
INSERT INTO status_page_groups (page_id, org_id, parent_id, name, position)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id, page_id, org_id, parent_id, name, position, created_at, updated_at
|
|
`
|
|
|
|
type CreateStatusPageGroupParams struct {
|
|
PageID uuid.UUID
|
|
OrgID uuid.UUID
|
|
ParentID *uuid.UUID
|
|
Name string
|
|
Position int32
|
|
}
|
|
|
|
func (q *Queries) CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error) {
|
|
row := q.db.QueryRow(ctx, createStatusPageGroup,
|
|
arg.PageID,
|
|
arg.OrgID,
|
|
arg.ParentID,
|
|
arg.Name,
|
|
arg.Position,
|
|
)
|
|
var i StatusPageGroup
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PageID,
|
|
&i.OrgID,
|
|
&i.ParentID,
|
|
&i.Name,
|
|
&i.Position,
|
|
&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 deleteStatusPageGroup = `-- name: DeleteStatusPageGroup :execrows
|
|
DELETE FROM status_page_groups WHERE id = $1 AND page_id = $2
|
|
`
|
|
|
|
type DeleteStatusPageGroupParams struct {
|
|
ID uuid.UUID
|
|
PageID uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) DeleteStatusPageGroup(ctx context.Context, arg DeleteStatusPageGroupParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteStatusPageGroup, arg.ID, arg.PageID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const domainsToCheck = `-- name: DomainsToCheck :many
|
|
SELECT id, org_id, title, custom_domain::text AS domain, domain_token,
|
|
domain_verified_at, domain_failing_since
|
|
FROM status_pages
|
|
WHERE custom_domain IS NOT NULL
|
|
AND ($1::uuid IS NULL OR id = $1)
|
|
AND (
|
|
(domain_verified_at IS NULL AND domain_set_at > $2::timestamptz - interval '48 hours'
|
|
AND (domain_checked_at IS NULL OR domain_checked_at <= $2::timestamptz - CASE
|
|
WHEN domain_set_at > $2::timestamptz - interval '15 minutes' THEN interval '50 seconds'
|
|
ELSE interval '10 minutes' END))
|
|
OR (domain_verified_at IS NOT NULL AND domain_verify_method IS NOT NULL
|
|
AND (domain_checked_at IS NULL OR domain_checked_at <= $2::timestamptz - CASE
|
|
WHEN domain_failing_since IS NULL THEN interval '24 hours' ELSE interval '1 hour' END)))
|
|
ORDER BY domain_checked_at NULLS FIRST
|
|
LIMIT 500
|
|
`
|
|
|
|
type DomainsToCheckParams struct {
|
|
PageID *uuid.UUID
|
|
Now time.Time
|
|
}
|
|
|
|
type DomainsToCheckRow struct {
|
|
ID uuid.UUID
|
|
OrgID uuid.UUID
|
|
Title string
|
|
Domain string
|
|
DomainToken string
|
|
DomainVerifiedAt *time.Time
|
|
DomainFailingSince *time.Time
|
|
}
|
|
|
|
// System scope: domains due for a look at their DNS records. A new one is
|
|
// looked at every minute for a quarter of an hour, then every ten minutes
|
|
// for two days, after which only the verify button tries again. A verified
|
|
// one is checked daily, hourly once its record went missing.
|
|
func (q *Queries) DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error) {
|
|
rows, err := q.db.Query(ctx, domainsToCheck, arg.PageID, arg.Now)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []DomainsToCheckRow{}
|
|
for rows.Next() {
|
|
var i DomainsToCheckRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.OrgID,
|
|
&i.Title,
|
|
&i.Domain,
|
|
&i.DomainToken,
|
|
&i.DomainVerifiedAt,
|
|
&i.DomainFailingSince,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, 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, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method FROM status_pages
|
|
WHERE published AND suspended_at IS NULL
|
|
AND NOT EXISTS (SELECT 1 FROM orgs o WHERE o.id = status_pages.org_id AND o.suspended_at IS NOT NULL)
|
|
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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
)
|
|
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, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method 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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listStatusPageGroups = `-- name: ListStatusPageGroups :many
|
|
SELECT id, page_id, org_id, parent_id, name, position, created_at, updated_at FROM status_page_groups
|
|
WHERE page_id = $1
|
|
ORDER BY position, name, id
|
|
`
|
|
|
|
func (q *Queries) ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error) {
|
|
rows, err := q.db.Query(ctx, listStatusPageGroups, pageID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []StatusPageGroup{}
|
|
for rows.Next() {
|
|
var i StatusPageGroup
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PageID,
|
|
&i.OrgID,
|
|
&i.ParentID,
|
|
&i.Name,
|
|
&i.Position,
|
|
&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 listStatusPages = `-- name: ListStatusPages :many
|
|
SELECT id, org_id, slug, title, description, published, custom_domain, domain_token, domain_verified_at, theme, created_at, updated_at, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method 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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const markDomainUnconfirmed = `-- name: MarkDomainUnconfirmed :one
|
|
UPDATE status_pages SET
|
|
domain_checked_at = $1::timestamptz,
|
|
domain_failing_since = CASE WHEN domain_verified_at IS NULL THEN NULL
|
|
ELSE coalesce(domain_failing_since, $1::timestamptz) END
|
|
WHERE id = $2
|
|
RETURNING domain_failing_since
|
|
`
|
|
|
|
type MarkDomainUnconfirmedParams struct {
|
|
Now time.Time
|
|
ID uuid.UUID
|
|
}
|
|
|
|
// The record of a domain was not found. Returns since when it has not
|
|
// been, for a verified domain.
|
|
func (q *Queries) MarkDomainUnconfirmed(ctx context.Context, arg MarkDomainUnconfirmedParams) (*time.Time, error) {
|
|
row := q.db.QueryRow(ctx, markDomainUnconfirmed, arg.Now, arg.ID)
|
|
var domain_failing_since *time.Time
|
|
err := row.Scan(&domain_failing_since)
|
|
return domain_failing_since, err
|
|
}
|
|
|
|
const markDomainVerified = `-- name: MarkDomainVerified :exec
|
|
UPDATE status_pages SET
|
|
domain_verified_at = coalesce(domain_verified_at, $1::timestamptz),
|
|
domain_verify_method = $2::text,
|
|
domain_checked_at = $1::timestamptz,
|
|
domain_failing_since = NULL
|
|
WHERE id = $3
|
|
`
|
|
|
|
type MarkDomainVerifiedParams struct {
|
|
Now time.Time
|
|
Method string
|
|
ID uuid.UUID
|
|
}
|
|
|
|
// The domain's record was found: verified, or still in place.
|
|
func (q *Queries) MarkDomainVerified(ctx context.Context, arg MarkDomainVerifiedParams) error {
|
|
_, err := q.db.Exec(ctx, markDomainVerified, arg.Now, arg.Method, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const reparentStatusPageGroupChildren = `-- name: ReparentStatusPageGroupChildren :exec
|
|
UPDATE status_page_groups SET parent_id = $3, updated_at = now()
|
|
WHERE page_id = $1 AND parent_id = $2
|
|
`
|
|
|
|
type ReparentStatusPageGroupChildrenParams struct {
|
|
PageID uuid.UUID
|
|
ParentID *uuid.UUID
|
|
ParentID_2 *uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) ReparentStatusPageGroupChildren(ctx context.Context, arg ReparentStatusPageGroupChildrenParams) error {
|
|
_, err := q.db.Exec(ctx, reparentStatusPageGroupChildren, arg.PageID, arg.ParentID, arg.ParentID_2)
|
|
return err
|
|
}
|
|
|
|
const reparentStatusPageGroupMonitors = `-- name: ReparentStatusPageGroupMonitors :exec
|
|
UPDATE status_page_monitors SET group_id = $3
|
|
WHERE page_id = $1 AND group_id = $2
|
|
`
|
|
|
|
type ReparentStatusPageGroupMonitorsParams struct {
|
|
PageID uuid.UUID
|
|
GroupID *uuid.UUID
|
|
GroupID_2 *uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) ReparentStatusPageGroupMonitors(ctx context.Context, arg ReparentStatusPageGroupMonitorsParams) error {
|
|
_, err := q.db.Exec(ctx, reparentStatusPageGroupMonitors, arg.PageID, arg.GroupID, arg.GroupID_2)
|
|
return err
|
|
}
|
|
|
|
const servablePages = `-- name: ServablePages :many
|
|
SELECT p.slug, COALESCE(CASE WHEN p.domain_verified_at IS NOT NULL THEN p.custom_domain END, '')::text AS host
|
|
FROM status_pages p
|
|
JOIN orgs o ON o.id = p.org_id
|
|
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
|
|
AND CASE WHEN $1::uuid IS NULL
|
|
THEN NOT EXISTS (SELECT 1 FROM agents a WHERE a.org_id = p.org_id AND a.kind = 'statuspage' AND a.last_seen_at IS NOT NULL)
|
|
ELSE p.org_id = $1::uuid
|
|
END
|
|
ORDER BY p.slug
|
|
`
|
|
|
|
type ServablePagesRow struct {
|
|
Slug string
|
|
Host string
|
|
}
|
|
|
|
// System scope: the published pages a status page server serves, those
|
|
// of agent_org for an organization's server; the platform's leave the
|
|
// pages of organizations serving their own.
|
|
func (q *Queries) ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]ServablePagesRow, error) {
|
|
rows, err := q.db.Query(ctx, servablePages, agentOrg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ServablePagesRow{}
|
|
for rows.Next() {
|
|
var i ServablePagesRow
|
|
if err := rows.Scan(&i.Slug, &i.Host); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setStatusPageDomain = `-- name: SetStatusPageDomain :one
|
|
UPDATE status_pages SET
|
|
domain_verified_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verified_at END,
|
|
domain_verify_method = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_verify_method END,
|
|
domain_failing_since = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_failing_since END,
|
|
domain_checked_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_checked_at END,
|
|
domain_set_at = CASE WHEN custom_domain IS NOT DISTINCT FROM $1 THEN domain_set_at ELSE now() END,
|
|
custom_domain = $1,
|
|
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, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
|
|
`
|
|
|
|
type SetStatusPageDomainParams struct {
|
|
CustomDomain *string
|
|
ID uuid.UUID
|
|
}
|
|
|
|
// Changing the domain drops a previous verification and its checks.
|
|
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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const setStatusPageMonitorGroup = `-- name: SetStatusPageMonitorGroup :exec
|
|
UPDATE status_page_monitors SET group_id = $3, section = $4
|
|
WHERE page_id = $1 AND monitor_id = $2
|
|
`
|
|
|
|
type SetStatusPageMonitorGroupParams struct {
|
|
PageID uuid.UUID
|
|
MonitorID uuid.UUID
|
|
GroupID *uuid.UUID
|
|
Section string
|
|
}
|
|
|
|
func (q *Queries) SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error {
|
|
_, err := q.db.Exec(ctx, setStatusPageMonitorGroup,
|
|
arg.PageID,
|
|
arg.MonitorID,
|
|
arg.GroupID,
|
|
arg.Section,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const statusPageMonitors = `-- name: StatusPageMonitors :many
|
|
SELECT spm.monitor_id, spm.section, spm.group_id, spm.label, spm.position,
|
|
m.name AS monitor_name, m.enabled, m.group_id AS monitor_group_id,
|
|
m.type AS monitor_type, m.interval_seconds
|
|
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
|
|
GroupID *uuid.UUID
|
|
Label string
|
|
Position int32
|
|
MonitorName string
|
|
Enabled bool
|
|
MonitorGroupID *uuid.UUID
|
|
MonitorType string
|
|
IntervalSeconds int32
|
|
}
|
|
|
|
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.GroupID,
|
|
&i.Label,
|
|
&i.Position,
|
|
&i.MonitorName,
|
|
&i.Enabled,
|
|
&i.MonitorGroupID,
|
|
&i.MonitorType,
|
|
&i.IntervalSeconds,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const unverifyDomain = `-- name: UnverifyDomain :exec
|
|
UPDATE status_pages SET
|
|
domain_verified_at = NULL, domain_verify_method = NULL, domain_failing_since = NULL
|
|
WHERE id = $1
|
|
`
|
|
|
|
// A verified domain whose record stayed missing past the grace period.
|
|
func (q *Queries) UnverifyDomain(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, unverifyDomain, id)
|
|
return err
|
|
}
|
|
|
|
const updateStatusPage = `-- name: UpdateStatusPage :one
|
|
UPDATE status_pages
|
|
SET slug = $2,
|
|
title = $3,
|
|
description = $4,
|
|
published = $5,
|
|
show_component_details = $6,
|
|
theme = $7,
|
|
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, show_component_details, suspended_at, suspended_reason, domain_set_at, domain_checked_at, domain_failing_since, domain_verify_method
|
|
`
|
|
|
|
type UpdateStatusPageParams struct {
|
|
ID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
Description string
|
|
Published bool
|
|
ShowComponentDetails 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.ShowComponentDetails,
|
|
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,
|
|
&i.ShowComponentDetails,
|
|
&i.SuspendedAt,
|
|
&i.SuspendedReason,
|
|
&i.DomainSetAt,
|
|
&i.DomainCheckedAt,
|
|
&i.DomainFailingSince,
|
|
&i.DomainVerifyMethod,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateStatusPageGroup = `-- name: UpdateStatusPageGroup :one
|
|
UPDATE status_page_groups
|
|
SET name = $3, parent_id = $4, position = $5, updated_at = now()
|
|
WHERE id = $1 AND page_id = $2
|
|
RETURNING id, page_id, org_id, parent_id, name, position, created_at, updated_at
|
|
`
|
|
|
|
type UpdateStatusPageGroupParams struct {
|
|
ID uuid.UUID
|
|
PageID uuid.UUID
|
|
Name string
|
|
ParentID *uuid.UUID
|
|
Position int32
|
|
}
|
|
|
|
func (q *Queries) UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error) {
|
|
row := q.db.QueryRow(ctx, updateStatusPageGroup,
|
|
arg.ID,
|
|
arg.PageID,
|
|
arg.Name,
|
|
arg.ParentID,
|
|
arg.Position,
|
|
)
|
|
var i StatusPageGroup
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PageID,
|
|
&i.OrgID,
|
|
&i.ParentID,
|
|
&i.Name,
|
|
&i.Position,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|