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 @@
|
|||||||
|
-- +goose Up
|
||||||
|
CREATE TABLE status_pages (
|
||||||
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
org_id uuid NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
|
||||||
|
-- Pages without a custom domain are served at /<slug>, so slugs are
|
||||||
|
-- unique across organizations.
|
||||||
|
slug citext NOT NULL UNIQUE CHECK (slug ~ '^[a-z0-9][a-z0-9-]{1,62}$'),
|
||||||
|
title text NOT NULL CHECK (length(title) BETWEEN 1 AND 200),
|
||||||
|
description text NOT NULL DEFAULT '' CHECK (length(description) <= 2000),
|
||||||
|
published boolean NOT NULL DEFAULT false,
|
||||||
|
custom_domain citext UNIQUE CHECK (custom_domain ~ '^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?$'),
|
||||||
|
-- Proves control of custom_domain via a TXT record.
|
||||||
|
domain_token text NOT NULL,
|
||||||
|
domain_verified_at timestamptz,
|
||||||
|
theme jsonb NOT NULL DEFAULT '{}',
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
UNIQUE (id, org_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE monitors ADD CONSTRAINT monitors_id_org_key UNIQUE (id, org_id);
|
||||||
|
|
||||||
|
-- Composite foreign keys keep pages from listing monitors of other
|
||||||
|
-- organizations; foreign keys are checked regardless of row-level security.
|
||||||
|
CREATE TABLE status_page_monitors (
|
||||||
|
page_id uuid NOT NULL,
|
||||||
|
monitor_id uuid NOT NULL,
|
||||||
|
org_id uuid NOT NULL,
|
||||||
|
section text NOT NULL DEFAULT '' CHECK (length(section) <= 100),
|
||||||
|
label text NOT NULL DEFAULT '' CHECK (length(label) <= 200),
|
||||||
|
position integer NOT NULL DEFAULT 0,
|
||||||
|
PRIMARY KEY (page_id, monitor_id),
|
||||||
|
FOREIGN KEY (page_id, org_id) REFERENCES status_pages (id, org_id) ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (monitor_id, org_id) REFERENCES monitors (id, org_id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE status_pages ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE status_pages FORCE ROW LEVEL SECURITY;
|
||||||
|
CREATE POLICY status_pages_tenant ON status_pages FOR ALL
|
||||||
|
USING (app_scope_system() OR org_id = app_org_id())
|
||||||
|
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||||
|
|
||||||
|
ALTER TABLE status_page_monitors ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE status_page_monitors FORCE ROW LEVEL SECURITY;
|
||||||
|
CREATE POLICY status_page_monitors_tenant ON status_page_monitors FOR ALL
|
||||||
|
USING (app_scope_system() OR org_id = app_org_id())
|
||||||
|
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DROP TABLE status_page_monitors;
|
||||||
|
ALTER TABLE monitors DROP CONSTRAINT monitors_id_org_key;
|
||||||
|
DROP TABLE status_pages;
|
||||||
@@ -52,6 +52,52 @@ func (q *Queries) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]D
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dailyBucketsForMonitors = `-- name: DailyBucketsForMonitors :many
|
||||||
|
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count
|
||||||
|
FROM check_results_1d
|
||||||
|
WHERE org_id = $1 AND monitor_id = ANY ($3::uuid[]) AND bucket >= $2
|
||||||
|
GROUP BY monitor_id, bucket
|
||||||
|
ORDER BY monitor_id, bucket
|
||||||
|
`
|
||||||
|
|
||||||
|
type DailyBucketsForMonitorsParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Bucket interface{}
|
||||||
|
Ids []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
type DailyBucketsForMonitorsRow struct {
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
Bucket time.Time
|
||||||
|
Total int64
|
||||||
|
OkCount int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, dailyBucketsForMonitors, arg.OrgID, arg.Bucket, arg.Ids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []DailyBucketsForMonitorsRow{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i DailyBucketsForMonitorsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.MonitorID,
|
||||||
|
&i.Bucket,
|
||||||
|
&i.Total,
|
||||||
|
&i.OkCount,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const hourlyBuckets = `-- name: HourlyBuckets :many
|
const hourlyBuckets = `-- name: HourlyBuckets :many
|
||||||
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
|
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
|
||||||
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms
|
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms
|
||||||
|
|||||||
@@ -137,6 +137,45 @@ func (q *Queries) GetChannel(ctx context.Context, id uuid.UUID) (NotificationCha
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
|
||||||
|
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents
|
||||||
|
WHERE monitor_id = ANY ($1::uuid[]) AND (resolved_at IS NULL OR resolved_at > $2)
|
||||||
|
ORDER BY started_at DESC
|
||||||
|
LIMIT 50
|
||||||
|
`
|
||||||
|
|
||||||
|
type IncidentsForMonitorsParams struct {
|
||||||
|
Ids []uuid.UUID
|
||||||
|
Since *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error) {
|
||||||
|
rows, err := q.db.Query(ctx, incidentsForMonitors, arg.Ids, arg.Since)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []Incident{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i Incident
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.OrgID,
|
||||||
|
&i.MonitorID,
|
||||||
|
&i.StartedAt,
|
||||||
|
&i.ResolvedAt,
|
||||||
|
&i.Cause,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const listChannels = `-- name: ListChannels :many
|
const listChannels = `-- name: ListChannels :many
|
||||||
SELECT id, org_id, name, type, config, enabled, created_at, updated_at FROM notification_channels ORDER BY name
|
SELECT id, org_id, name, type, config, enabled, created_at, updated_at FROM notification_channels ORDER BY name
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -206,6 +206,30 @@ type SsoProvider struct {
|
|||||||
DefaultRoleID *uuid.UUID
|
DefaultRoleID *uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StatusPage struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Slug string
|
||||||
|
Title string
|
||||||
|
Description string
|
||||||
|
Published bool
|
||||||
|
CustomDomain *string
|
||||||
|
DomainToken string
|
||||||
|
DomainVerifiedAt *time.Time
|
||||||
|
Theme []byte
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusPageMonitor struct {
|
||||||
|
PageID uuid.UUID
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Section string
|
||||||
|
Label string
|
||||||
|
Position int32
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Email string
|
Email string
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type Querier interface {
|
|||||||
APITokenOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
|
APITokenOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
|
||||||
AddMembership(ctx context.Context, arg AddMembershipParams) error
|
AddMembership(ctx context.Context, arg AddMembershipParams) error
|
||||||
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
|
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
|
||||||
|
AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error
|
||||||
AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error)
|
AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error)
|
||||||
AnyUserExists(ctx context.Context) (bool, error)
|
AnyUserExists(ctx context.Context) (bool, error)
|
||||||
// System scope. Leases due rows for five minutes so a crashed sender's rows
|
// System scope. Leases due rows for five minutes so a crashed sender's rows
|
||||||
@@ -21,6 +22,7 @@ type Querier interface {
|
|||||||
ClaimNotifications(ctx context.Context, max int32) ([]uuid.UUID, error)
|
ClaimNotifications(ctx context.Context, max int32) ([]uuid.UUID, error)
|
||||||
// Shortens tokens that would outlive a newly set maximum lifetime.
|
// Shortens tokens that would outlive a newly set maximum lifetime.
|
||||||
ClampAPITokenExpiry(ctx context.Context, arg ClampAPITokenExpiryParams) (int64, error)
|
ClampAPITokenExpiry(ctx context.Context, arg ClampAPITokenExpiryParams) (int64, error)
|
||||||
|
ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error
|
||||||
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
||||||
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||||
CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) (ApiToken, error)
|
CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) (ApiToken, error)
|
||||||
@@ -34,8 +36,10 @@ type Querier interface {
|
|||||||
CreateRegion(ctx context.Context, arg CreateRegionParams) (Region, error)
|
CreateRegion(ctx context.Context, arg CreateRegionParams) (Region, error)
|
||||||
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
||||||
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
|
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
|
||||||
|
CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error)
|
||||||
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
|
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
|
||||||
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
|
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
|
||||||
|
DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error)
|
||||||
DeleteAPIToken(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteAPIToken(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteAgent(ctx context.Context, arg DeleteAgentParams) (int64, error)
|
DeleteAgent(ctx context.Context, arg DeleteAgentParams) (int64, error)
|
||||||
DeleteAssignment(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteAssignment(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
@@ -48,12 +52,16 @@ type Querier interface {
|
|||||||
DeleteRegion(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteRegion(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteRole(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteRole(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteSSOProvider(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteSSOProvider(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
|
DeleteStatusPage(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)
|
DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
DisableTOTP(ctx context.Context, id uuid.UUID) error
|
DisableTOTP(ctx context.Context, id uuid.UUID) error
|
||||||
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
||||||
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
||||||
// An empty name names a new region after its key and keeps an existing name.
|
// An empty name names a new region after its key and keeps an existing name.
|
||||||
EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRegionParams) (Region, error)
|
EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRegionParams) (Region, error)
|
||||||
|
// System scope: resolves a request to a page by verified custom domain or
|
||||||
|
// by slug.
|
||||||
|
FindPublishedPage(ctx context.Context, arg FindPublishedPageParams) (StatusPage, error)
|
||||||
GetAPIToken(ctx context.Context, id uuid.UUID) (ApiToken, error)
|
GetAPIToken(ctx context.Context, id uuid.UUID) (ApiToken, error)
|
||||||
GetAPITokenByHash(ctx context.Context, tokenHash []byte) (ApiToken, error)
|
GetAPITokenByHash(ctx context.Context, tokenHash []byte) (ApiToken, error)
|
||||||
// System scope.
|
// System scope.
|
||||||
@@ -70,10 +78,12 @@ type Querier interface {
|
|||||||
GetRegion(ctx context.Context, id uuid.UUID) (Region, error)
|
GetRegion(ctx context.Context, id uuid.UUID) (Region, error)
|
||||||
GetRole(ctx context.Context, id uuid.UUID) (Role, error)
|
GetRole(ctx context.Context, id uuid.UUID) (Role, error)
|
||||||
GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error)
|
GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error)
|
||||||
|
GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error)
|
||||||
GetUser(ctx context.Context, id uuid.UUID) (User, error)
|
GetUser(ctx context.Context, id uuid.UUID) (User, error)
|
||||||
GetUserByEmail(ctx context.Context, email string) (User, error)
|
GetUserByEmail(ctx context.Context, email string) (User, error)
|
||||||
// Per monitor and hour since $2, across all regions.
|
// Per monitor and hour since $2, across all regions.
|
||||||
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
||||||
|
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
|
||||||
// check_results and its aggregates have no row-level security (see
|
// check_results and its aggregates have no row-level security (see
|
||||||
// migration 00013). Every query here must filter by org_id.
|
// migration 00013). Every query here must filter by org_id.
|
||||||
InsertCheckResults(ctx context.Context, arg []InsertCheckResultsParams) (int64, error)
|
InsertCheckResults(ctx context.Context, arg []InsertCheckResultsParams) (int64, error)
|
||||||
@@ -101,12 +111,14 @@ type Querier interface {
|
|||||||
ListPlatformRegions(ctx context.Context) ([]Region, error)
|
ListPlatformRegions(ctx context.Context) ([]Region, error)
|
||||||
ListRoles(ctx context.Context) ([]Role, error)
|
ListRoles(ctx context.Context) ([]Role, error)
|
||||||
ListSSOProviders(ctx context.Context) ([]SsoProvider, error)
|
ListSSOProviders(ctx context.Context) ([]SsoProvider, error)
|
||||||
|
ListStatusPages(ctx context.Context) ([]StatusPage, error)
|
||||||
ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error)
|
ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error)
|
||||||
ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error)
|
ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error)
|
||||||
// Row-level security limits this to platform regions and the scope's org;
|
// Row-level security limits this to platform regions and the scope's org;
|
||||||
// the org's own regions come first.
|
// the org's own regions come first.
|
||||||
ListVisibleRegions(ctx context.Context) ([]Region, error)
|
ListVisibleRegions(ctx context.Context) ([]Region, error)
|
||||||
MakeAdmin(ctx context.Context, id uuid.UUID) error
|
MakeAdmin(ctx context.Context, id uuid.UUID) error
|
||||||
|
MarkDomainVerified(ctx context.Context, id uuid.UUID) error
|
||||||
MarkInvitationAccepted(ctx context.Context, id uuid.UUID) (int64, error)
|
MarkInvitationAccepted(ctx context.Context, id uuid.UUID) (int64, error)
|
||||||
MarkNotificationFailed(ctx context.Context, arg MarkNotificationFailedParams) error
|
MarkNotificationFailed(ctx context.Context, arg MarkNotificationFailedParams) error
|
||||||
MarkNotificationSent(ctx context.Context, id uuid.UUID) error
|
MarkNotificationSent(ctx context.Context, id uuid.UUID) error
|
||||||
@@ -130,8 +142,11 @@ type Querier interface {
|
|||||||
RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error)
|
RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error)
|
||||||
ResolveIncident(ctx context.Context, arg ResolveIncidentParams) (Incident, error)
|
ResolveIncident(ctx context.Context, arg ResolveIncidentParams) (Incident, error)
|
||||||
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
|
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
|
||||||
|
// Changing the domain drops a previous verification.
|
||||||
|
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
|
||||||
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
|
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
|
||||||
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
|
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
|
||||||
|
StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]StatusPageMonitorsRow, error)
|
||||||
TouchAPIToken(ctx context.Context, id uuid.UUID) error
|
TouchAPIToken(ctx context.Context, id uuid.UUID) error
|
||||||
TouchAgent(ctx context.Context, arg TouchAgentParams) error
|
TouchAgent(ctx context.Context, arg TouchAgentParams) error
|
||||||
TouchIdentity(ctx context.Context, arg TouchIdentityParams) error
|
TouchIdentity(ctx context.Context, arg TouchIdentityParams) error
|
||||||
@@ -140,6 +155,7 @@ type Querier interface {
|
|||||||
UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams) (Org, error)
|
UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams) (Org, error)
|
||||||
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
||||||
UpdateSSOProvider(ctx context.Context, arg UpdateSSOProviderParams) (SsoProvider, error)
|
UpdateSSOProvider(ctx context.Context, arg UpdateSSOProviderParams) (SsoProvider, error)
|
||||||
|
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
||||||
// Uptime per monitor from the hourly aggregate, including the not yet
|
// Uptime per monitor from the hourly aggregate, including the not yet
|
||||||
// materialized most recent hours (real-time aggregation).
|
// materialized most recent hours (real-time aggregation).
|
||||||
UptimeSince(ctx context.Context, arg UptimeSinceParams) ([]UptimeSinceRow, error)
|
UptimeSince(ctx context.Context, arg UptimeSinceParams) ([]UptimeSinceRow, error)
|
||||||
|
|||||||
@@ -48,3 +48,10 @@ FROM check_results_1d
|
|||||||
WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3
|
WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3
|
||||||
GROUP BY bucket
|
GROUP BY bucket
|
||||||
ORDER BY bucket;
|
ORDER BY bucket;
|
||||||
|
|
||||||
|
-- name: DailyBucketsForMonitors :many
|
||||||
|
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count
|
||||||
|
FROM check_results_1d
|
||||||
|
WHERE org_id = $1 AND monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND bucket >= $2
|
||||||
|
GROUP BY monitor_id, bucket
|
||||||
|
ORDER BY monitor_id, bucket;
|
||||||
@@ -83,3 +83,9 @@ SELECT * FROM incidents WHERE resolved_at IS NULL;
|
|||||||
|
|
||||||
-- name: MonitorIncidents :many
|
-- name: MonitorIncidents :many
|
||||||
SELECT * FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20;
|
SELECT * FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20;
|
||||||
|
|
||||||
|
-- name: IncidentsForMonitors :many
|
||||||
|
SELECT * FROM incidents
|
||||||
|
WHERE monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND (resolved_at IS NULL OR resolved_at > sqlc.arg(since))
|
||||||
|
ORDER BY started_at DESC
|
||||||
|
LIMIT 50;
|
||||||
@@ -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)));
|
||||||
@@ -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