ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m59s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Canceled after 1m1s
With thousands of monitors on a status page the editor was tens of megabytes, as every row carried the options of all groups, and importing the monitor groups updated each monitor in its own statement. - The monitors of the editor are shown 50 at a time. All rows stay in the form, as saving replaces the page's monitors. - Rows carry their own group only and get the other options from the row template once shown or focused. - The filter matches a monitor's name and group path only, no longer the names of the groups in its select. - The import creates the groups one nesting level at a time and files all monitors in one statement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
788 lines
22 KiB
Go
788 lines
22 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, subscriptions)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
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, subscriptions
|
|
`
|
|
|
|
type CreateStatusPageParams struct {
|
|
OrgID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
Description string
|
|
Published bool
|
|
ShowComponentDetails bool
|
|
DomainToken string
|
|
Theme []byte
|
|
Subscriptions bool
|
|
}
|
|
|
|
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,
|
|
arg.Subscriptions,
|
|
)
|
|
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,
|
|
&i.Subscriptions,
|
|
)
|
|
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 createStatusPageGroups = `-- name: CreateStatusPageGroups :exec
|
|
INSERT INTO status_page_groups (id, page_id, org_id, parent_id, name, position)
|
|
SELECT v.id, $1, $2, nullif(v.parent_id, '00000000-0000-0000-0000-000000000000'::uuid), v.name, v.position
|
|
FROM (SELECT unnest($3::uuid[]) AS id, unnest($4::uuid[]) AS parent_id,
|
|
unnest($5::text[]) AS name, unnest($6::int[]) AS position) AS v
|
|
`
|
|
|
|
type CreateStatusPageGroupsParams struct {
|
|
PageID uuid.UUID
|
|
OrgID uuid.UUID
|
|
Ids []uuid.UUID
|
|
ParentIds []uuid.UUID
|
|
Names []string
|
|
Positions []int32
|
|
}
|
|
|
|
// Creates many groups of a page at once, with ids the caller chose. Parents
|
|
// must exist before their children are created; a nil parent id (all
|
|
// zeros) means none.
|
|
func (q *Queries) CreateStatusPageGroups(ctx context.Context, arg CreateStatusPageGroupsParams) error {
|
|
_, err := q.db.Exec(ctx, createStatusPageGroups,
|
|
arg.PageID,
|
|
arg.OrgID,
|
|
arg.Ids,
|
|
arg.ParentIds,
|
|
arg.Names,
|
|
arg.Positions,
|
|
)
|
|
return 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, subscriptions 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,
|
|
&i.Subscriptions,
|
|
)
|
|
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, subscriptions 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,
|
|
&i.Subscriptions,
|
|
)
|
|
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, subscriptions 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,
|
|
&i.Subscriptions,
|
|
); 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, p.org_id
|
|
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
|
|
OrgID uuid.UUID
|
|
}
|
|
|
|
// 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, &i.OrgID); 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, subscriptions
|
|
`
|
|
|
|
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,
|
|
&i.Subscriptions,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const setStatusPageMonitorGroups = `-- name: SetStatusPageMonitorGroups :exec
|
|
UPDATE status_page_monitors spm
|
|
SET group_id = nullif(v.group_id, '00000000-0000-0000-0000-000000000000'::uuid), section = v.section
|
|
FROM (SELECT unnest($2::uuid[]) AS monitor_id, unnest($3::uuid[]) AS group_id,
|
|
unnest($4::text[]) AS section) AS v
|
|
WHERE spm.page_id = $1 AND spm.monitor_id = v.monitor_id
|
|
`
|
|
|
|
type SetStatusPageMonitorGroupsParams struct {
|
|
PageID uuid.UUID
|
|
MonitorIds []uuid.UUID
|
|
GroupIds []uuid.UUID
|
|
Sections []string
|
|
}
|
|
|
|
// Files many monitors of a page at once; a nil group id (all zeros) files
|
|
// a monitor under none.
|
|
func (q *Queries) SetStatusPageMonitorGroups(ctx context.Context, arg SetStatusPageMonitorGroupsParams) error {
|
|
_, err := q.db.Exec(ctx, setStatusPageMonitorGroups,
|
|
arg.PageID,
|
|
arg.MonitorIds,
|
|
arg.GroupIds,
|
|
arg.Sections,
|
|
)
|
|
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,
|
|
subscriptions = $8,
|
|
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, subscriptions
|
|
`
|
|
|
|
type UpdateStatusPageParams struct {
|
|
ID uuid.UUID
|
|
Slug string
|
|
Title string
|
|
Description string
|
|
Published bool
|
|
ShowComponentDetails bool
|
|
Theme []byte
|
|
Subscriptions bool
|
|
}
|
|
|
|
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,
|
|
arg.Subscriptions,
|
|
)
|
|
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,
|
|
&i.Subscriptions,
|
|
)
|
|
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
|
|
}
|