feat: support tickets between accounts and platform admins
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m0s
ci / test (pull_request) Successful in 12m1s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m9s

Accounts open tickets under Support and admins answer them under Admin →
Support tickets.

- A ticket is open while it waits for the admins and answered while it
  waits for the account. Either side can close or reopen it, and a reply
  reopens it.
- The admins are mailed about new tickets and replies, and the account
  about answers.
- A ticket can name the active organization and point at a monitor,
  notification channel, alert group, status page or incident in it.
  Each must be something the account can read.
- Next to the conversation, admins see the account at a glance: state,
  sign-in, organizations with their limits and usage, and open tickets.
- Admins switch support off and limit how many tickets an account has
  open at once.
- Suspended accounts and those yet to accept the terms reach support too;
  a suspended account opens one ticket.
- Tickets are part of the account export and are deleted with the
  account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-24 18:01:50 +01:00
1 parent 9fc3c6b050
commit f3d402705e
25 files changed
+5296 -451

No files matched your search

+24
View File
@@ -441,6 +441,30 @@ type StatusPageMonitor struct {
GroupID *uuid.UUID
}
type SupportMessage struct {
ID uuid.UUID
TicketID uuid.UUID
AuthorID *uuid.UUID
FromStaff bool
Body string
CreatedAt time.Time
}
type SupportTicket struct {
ID uuid.UUID
UserID uuid.UUID
OrgID *uuid.UUID
MonitorID *uuid.UUID
ChannelID *uuid.UUID
AlertGroupID *uuid.UUID
StatusPageID *uuid.UUID
IncidentID *uuid.UUID
Subject string
Status string
CreatedAt time.Time
UpdatedAt time.Time
}
type User struct {
ID uuid.UUID
Email string
+24
View File
@@ -22,6 +22,8 @@ type Querier interface {
AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error)
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error
AddSupportMessage(ctx context.Context, arg AddSupportMessageParams) (SupportMessage, error)
AdminEmails(ctx context.Context) ([]string, error)
// System scope: organizations with their usage, limit overrides and owner,
// matching search in name, slug or owner email; newest first, a page from a
// keyset cursor.
@@ -50,10 +52,12 @@ type Querier interface {
ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error
ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error
CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error)
CountOpenSupportTickets(ctx context.Context, userID uuid.UUID) (int64, error)
CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error)
CountOwners(ctx context.Context, orgID uuid.UUID) (int64, error)
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error)
CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error)
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
// Ways the account can sign in besides platform identities.
CountUserSignIns(ctx context.Context, id uuid.UUID) (int32, error)
@@ -77,6 +81,7 @@ type Querier interface {
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error)
CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error)
CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error)
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error)
@@ -160,6 +165,7 @@ type Querier interface {
GetRole(ctx context.Context, id uuid.UUID) (Role, error)
GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error)
GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error)
GetSupportTicket(ctx context.Context, id uuid.UUID) (GetSupportTicketRow, error)
GetUser(ctx context.Context, id uuid.UUID) (User, error)
GetUserByEmail(ctx context.Context, email string) (User, error)
// System scope: the monitor a ping token belongs to.
@@ -234,9 +240,14 @@ type Querier interface {
ListSSOProviders(ctx context.Context) ([]SsoProvider, error)
ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error)
ListStatusPages(ctx context.Context) ([]StatusPage, error)
// Every account's tickets for the admins, those waiting for them first.
ListSupportTickets(ctx context.Context, status *string) ([]ListSupportTicketsRow, error)
ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error)
ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error)
ListUserPlatformIdentities(ctx context.Context, userID uuid.UUID) ([]ListUserPlatformIdentitiesRow, error)
// The tickets row-level security lets the account see, newest activity
// first.
ListUserSupportTickets(ctx context.Context, userID uuid.UUID) ([]SupportTicket, error)
// Row-level security limits this to platform regions and the scope's org;
// the org's own regions come first.
ListVisibleRegions(ctx context.Context) ([]Region, error)
@@ -333,6 +344,7 @@ type Querier interface {
// Changing the domain drops a previous verification.
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error
SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error)
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error)
@@ -346,6 +358,18 @@ type Querier interface {
StorageGet(ctx context.Context, arg StorageGetParams) (StorageGetRow, error)
StorageList(ctx context.Context, arg StorageListParams) ([]StorageListRow, error)
StoragePut(ctx context.Context, arg StoragePutParams) error
SupportMessages(ctx context.Context, ticketID uuid.UUID) ([]SupportMessagesRow, error)
SupportOptionsAlertGroups(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsAlertGroupsRow, error)
SupportOptionsChannels(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsChannelsRow, error)
SupportOptionsIncidents(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsIncidentsRow, error)
SupportOptionsMonitors(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsMonitorsRow, error)
SupportOptionsStatusPages(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsStatusPagesRow, error)
// Whether everything a new ticket points at belongs to org; run in the
// organization's scope so only what the account may see counts.
SupportReferencesExist(ctx context.Context, arg SupportReferencesExistParams) (*bool, error)
// The names of what a ticket points at, for showing it.
SupportTicketReferences(ctx context.Context, id uuid.UUID) (SupportTicketReferencesRow, error)
SupportTicketStatus(ctx context.Context, id uuid.UUID) (string, error)
SuspendOrg(ctx context.Context, arg SuspendOrgParams) (SuspendOrgRow, error)
SuspendStatusPage(ctx context.Context, arg SuspendStatusPageParams) (SuspendStatusPageRow, error)
SuspendUser(ctx context.Context, arg SuspendUserParams) (SuspendUserRow, error)
+97
View File
@@ -0,0 +1,97 @@
-- name: CreateSupportTicket :one
INSERT INTO support_tickets (user_id, org_id, subject, monitor_id, channel_id, alert_group_id, status_page_id, incident_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;
-- name: SupportReferencesExist :one
-- Whether everything a new ticket points at belongs to org; run in the
-- organization's scope so only what the account may see counts.
SELECT (sqlc.narg(monitor_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM monitors m WHERE m.id = sqlc.narg(monitor_id) AND m.org_id = sqlc.arg(org_id)::uuid))
AND (sqlc.narg(channel_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM notification_channels c WHERE c.id = sqlc.narg(channel_id) AND c.org_id = sqlc.arg(org_id)::uuid))
AND (sqlc.narg(alert_group_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM alert_groups g WHERE g.id = sqlc.narg(alert_group_id) AND g.org_id = sqlc.arg(org_id)::uuid))
AND (sqlc.narg(status_page_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM status_pages p WHERE p.id = sqlc.narg(status_page_id) AND p.org_id = sqlc.arg(org_id)::uuid))
AND (sqlc.narg(incident_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM incidents i WHERE i.id = sqlc.narg(incident_id) AND i.org_id = sqlc.arg(org_id)::uuid))
AS ok;
-- name: SupportTicketReferences :one
-- The names of what a ticket points at, for showing it.
SELECT o.name AS org_name, o.slug AS org_slug,
m.name AS monitor_name, m.type AS monitor_type,
ch.name AS channel_name, ch.type AS channel_type,
ag.name AS alert_group_name,
sp.title AS status_page_title, sp.slug AS status_page_slug,
i.title AS incident_title, i.started_at AS incident_started_at, im.name AS incident_monitor
FROM support_tickets t
LEFT JOIN orgs o ON o.id = t.org_id
LEFT JOIN monitors m ON m.id = t.monitor_id
LEFT JOIN notification_channels ch ON ch.id = t.channel_id
LEFT JOIN alert_groups ag ON ag.id = t.alert_group_id
LEFT JOIN status_pages sp ON sp.id = t.status_page_id
LEFT JOIN incidents i ON i.id = t.incident_id
LEFT JOIN monitors im ON im.id = i.monitor_id
WHERE t.id = $1;
-- name: SupportOptionsMonitors :many
SELECT id, name FROM monitors WHERE org_id = $1 ORDER BY lower(name) LIMIT 500;
-- name: SupportOptionsChannels :many
SELECT id, name, type FROM notification_channels WHERE org_id = $1 ORDER BY lower(name) LIMIT 500;
-- name: SupportOptionsAlertGroups :many
SELECT id, name FROM alert_groups WHERE org_id = $1 ORDER BY lower(name) LIMIT 500;
-- name: SupportOptionsStatusPages :many
SELECT id, title FROM status_pages WHERE org_id = $1 ORDER BY lower(title) LIMIT 500;
-- name: SupportOptionsIncidents :many
SELECT i.id, i.title, i.started_at, m.name AS monitor_name
FROM incidents i JOIN monitors m ON m.id = i.monitor_id
WHERE i.org_id = $1 ORDER BY i.started_at DESC LIMIT 50;
-- name: AddSupportMessage :one
INSERT INTO support_messages (ticket_id, author_id, from_staff, body) VALUES ($1, $2, $3, $4)
RETURNING *;
-- name: SetSupportTicketStatus :execrows
UPDATE support_tickets SET status = $2, updated_at = now() WHERE id = $1;
-- name: GetSupportTicket :one
SELECT t.*, u.email AS user_email, o.name AS org_name
FROM support_tickets t
JOIN users u ON u.id = t.user_id
LEFT JOIN orgs o ON o.id = t.org_id
WHERE t.id = $1;
-- name: ListUserSupportTickets :many
-- The tickets row-level security lets the account see, newest activity
-- first.
SELECT * FROM support_tickets WHERE user_id = $1 ORDER BY updated_at DESC LIMIT 200;
-- name: ListSupportTickets :many
-- Every account's tickets for the admins, those waiting for them first.
SELECT t.*, u.email AS user_email, o.name AS org_name
FROM support_tickets t
JOIN users u ON u.id = t.user_id
LEFT JOIN orgs o ON o.id = t.org_id
WHERE sqlc.narg(status)::text IS NULL OR t.status = sqlc.narg(status)::text
ORDER BY t.status = 'open' DESC, t.updated_at DESC
LIMIT 200;
-- name: SupportMessages :many
SELECT m.*, coalesce(u.email, '')::text AS author_email
FROM support_messages m
LEFT JOIN users u ON u.id = m.author_id
WHERE m.ticket_id = $1
ORDER BY m.created_at, m.id;
-- name: AdminEmails :many
SELECT email FROM users WHERE is_admin AND disabled_at IS NULL ORDER BY email;
-- name: CountOpenSupportTickets :one
SELECT count(*) FROM support_tickets WHERE user_id = $1 AND status <> 'closed';
-- name: CountSupportTicketsSince :one
SELECT count(*) FROM support_tickets WHERE user_id = $1 AND created_at >= $2;
-- name: SupportTicketStatus :one
SELECT status FROM support_tickets WHERE id = $1;
+607
View File
@@ -0,0 +1,607 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: support.sql
package store
import (
"context"
"time"
"github.com/google/uuid"
)
const addSupportMessage = `-- name: AddSupportMessage :one
INSERT INTO support_messages (ticket_id, author_id, from_staff, body) VALUES ($1, $2, $3, $4)
RETURNING id, ticket_id, author_id, from_staff, body, created_at
`
type AddSupportMessageParams struct {
TicketID uuid.UUID
AuthorID *uuid.UUID
FromStaff bool
Body string
}
func (q *Queries) AddSupportMessage(ctx context.Context, arg AddSupportMessageParams) (SupportMessage, error) {
row := q.db.QueryRow(ctx, addSupportMessage,
arg.TicketID,
arg.AuthorID,
arg.FromStaff,
arg.Body,
)
var i SupportMessage
err := row.Scan(
&i.ID,
&i.TicketID,
&i.AuthorID,
&i.FromStaff,
&i.Body,
&i.CreatedAt,
)
return i, err
}
const adminEmails = `-- name: AdminEmails :many
SELECT email FROM users WHERE is_admin AND disabled_at IS NULL ORDER BY email
`
func (q *Queries) AdminEmails(ctx context.Context) ([]string, error) {
rows, err := q.db.Query(ctx, adminEmails)
if err != nil {
return nil, err
}
defer rows.Close()
items := []string{}
for rows.Next() {
var email string
if err := rows.Scan(&email); err != nil {
return nil, err
}
items = append(items, email)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const countOpenSupportTickets = `-- name: CountOpenSupportTickets :one
SELECT count(*) FROM support_tickets WHERE user_id = $1 AND status <> 'closed'
`
func (q *Queries) CountOpenSupportTickets(ctx context.Context, userID uuid.UUID) (int64, error) {
row := q.db.QueryRow(ctx, countOpenSupportTickets, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const countSupportTicketsSince = `-- name: CountSupportTicketsSince :one
SELECT count(*) FROM support_tickets WHERE user_id = $1 AND created_at >= $2
`
type CountSupportTicketsSinceParams struct {
UserID uuid.UUID
CreatedAt time.Time
}
func (q *Queries) CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error) {
row := q.db.QueryRow(ctx, countSupportTicketsSince, arg.UserID, arg.CreatedAt)
var count int64
err := row.Scan(&count)
return count, err
}
const createSupportTicket = `-- name: CreateSupportTicket :one
INSERT INTO support_tickets (user_id, org_id, subject, monitor_id, channel_id, alert_group_id, status_page_id, incident_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, user_id, org_id, monitor_id, channel_id, alert_group_id, status_page_id, incident_id, subject, status, created_at, updated_at
`
type CreateSupportTicketParams struct {
UserID uuid.UUID
OrgID *uuid.UUID
Subject string
MonitorID *uuid.UUID
ChannelID *uuid.UUID
AlertGroupID *uuid.UUID
StatusPageID *uuid.UUID
IncidentID *uuid.UUID
}
func (q *Queries) CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error) {
row := q.db.QueryRow(ctx, createSupportTicket,
arg.UserID,
arg.OrgID,
arg.Subject,
arg.MonitorID,
arg.ChannelID,
arg.AlertGroupID,
arg.StatusPageID,
arg.IncidentID,
)
var i SupportTicket
err := row.Scan(
&i.ID,
&i.UserID,
&i.OrgID,
&i.MonitorID,
&i.ChannelID,
&i.AlertGroupID,
&i.StatusPageID,
&i.IncidentID,
&i.Subject,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getSupportTicket = `-- name: GetSupportTicket :one
SELECT t.id, t.user_id, t.org_id, t.monitor_id, t.channel_id, t.alert_group_id, t.status_page_id, t.incident_id, t.subject, t.status, t.created_at, t.updated_at, u.email AS user_email, o.name AS org_name
FROM support_tickets t
JOIN users u ON u.id = t.user_id
LEFT JOIN orgs o ON o.id = t.org_id
WHERE t.id = $1
`
type GetSupportTicketRow struct {
ID uuid.UUID
UserID uuid.UUID
OrgID *uuid.UUID
MonitorID *uuid.UUID
ChannelID *uuid.UUID
AlertGroupID *uuid.UUID
StatusPageID *uuid.UUID
IncidentID *uuid.UUID
Subject string
Status string
CreatedAt time.Time
UpdatedAt time.Time
UserEmail string
OrgName *string
}
func (q *Queries) GetSupportTicket(ctx context.Context, id uuid.UUID) (GetSupportTicketRow, error) {
row := q.db.QueryRow(ctx, getSupportTicket, id)
var i GetSupportTicketRow
err := row.Scan(
&i.ID,
&i.UserID,
&i.OrgID,
&i.MonitorID,
&i.ChannelID,
&i.AlertGroupID,
&i.StatusPageID,
&i.IncidentID,
&i.Subject,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.UserEmail,
&i.OrgName,
)
return i, err
}
const listSupportTickets = `-- name: ListSupportTickets :many
SELECT t.id, t.user_id, t.org_id, t.monitor_id, t.channel_id, t.alert_group_id, t.status_page_id, t.incident_id, t.subject, t.status, t.created_at, t.updated_at, u.email AS user_email, o.name AS org_name
FROM support_tickets t
JOIN users u ON u.id = t.user_id
LEFT JOIN orgs o ON o.id = t.org_id
WHERE $1::text IS NULL OR t.status = $1::text
ORDER BY t.status = 'open' DESC, t.updated_at DESC
LIMIT 200
`
type ListSupportTicketsRow struct {
ID uuid.UUID
UserID uuid.UUID
OrgID *uuid.UUID
MonitorID *uuid.UUID
ChannelID *uuid.UUID
AlertGroupID *uuid.UUID
StatusPageID *uuid.UUID
IncidentID *uuid.UUID
Subject string
Status string
CreatedAt time.Time
UpdatedAt time.Time
UserEmail string
OrgName *string
}
// Every account's tickets for the admins, those waiting for them first.
func (q *Queries) ListSupportTickets(ctx context.Context, status *string) ([]ListSupportTicketsRow, error) {
rows, err := q.db.Query(ctx, listSupportTickets, status)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListSupportTicketsRow{}
for rows.Next() {
var i ListSupportTicketsRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.OrgID,
&i.MonitorID,
&i.ChannelID,
&i.AlertGroupID,
&i.StatusPageID,
&i.IncidentID,
&i.Subject,
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.UserEmail,
&i.OrgName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUserSupportTickets = `-- name: ListUserSupportTickets :many
SELECT id, user_id, org_id, monitor_id, channel_id, alert_group_id, status_page_id, incident_id, subject, status, created_at, updated_at FROM support_tickets WHERE user_id = $1 ORDER BY updated_at DESC LIMIT 200
`
// The tickets row-level security lets the account see, newest activity
// first.
func (q *Queries) ListUserSupportTickets(ctx context.Context, userID uuid.UUID) ([]SupportTicket, error) {
rows, err := q.db.Query(ctx, listUserSupportTickets, userID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportTicket{}
for rows.Next() {
var i SupportTicket
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.OrgID,
&i.MonitorID,
&i.ChannelID,
&i.AlertGroupID,
&i.StatusPageID,
&i.IncidentID,
&i.Subject,
&i.Status,
&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 setSupportTicketStatus = `-- name: SetSupportTicketStatus :execrows
UPDATE support_tickets SET status = $2, updated_at = now() WHERE id = $1
`
type SetSupportTicketStatusParams struct {
ID uuid.UUID
Status string
}
func (q *Queries) SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error) {
result, err := q.db.Exec(ctx, setSupportTicketStatus, arg.ID, arg.Status)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const supportMessages = `-- name: SupportMessages :many
SELECT m.id, m.ticket_id, m.author_id, m.from_staff, m.body, m.created_at, coalesce(u.email, '')::text AS author_email
FROM support_messages m
LEFT JOIN users u ON u.id = m.author_id
WHERE m.ticket_id = $1
ORDER BY m.created_at, m.id
`
type SupportMessagesRow struct {
ID uuid.UUID
TicketID uuid.UUID
AuthorID *uuid.UUID
FromStaff bool
Body string
CreatedAt time.Time
AuthorEmail string
}
func (q *Queries) SupportMessages(ctx context.Context, ticketID uuid.UUID) ([]SupportMessagesRow, error) {
rows, err := q.db.Query(ctx, supportMessages, ticketID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportMessagesRow{}
for rows.Next() {
var i SupportMessagesRow
if err := rows.Scan(
&i.ID,
&i.TicketID,
&i.AuthorID,
&i.FromStaff,
&i.Body,
&i.CreatedAt,
&i.AuthorEmail,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportOptionsAlertGroups = `-- name: SupportOptionsAlertGroups :many
SELECT id, name FROM alert_groups WHERE org_id = $1 ORDER BY lower(name) LIMIT 500
`
type SupportOptionsAlertGroupsRow struct {
ID uuid.UUID
Name string
}
func (q *Queries) SupportOptionsAlertGroups(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsAlertGroupsRow, error) {
rows, err := q.db.Query(ctx, supportOptionsAlertGroups, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportOptionsAlertGroupsRow{}
for rows.Next() {
var i SupportOptionsAlertGroupsRow
if err := rows.Scan(&i.ID, &i.Name); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportOptionsChannels = `-- name: SupportOptionsChannels :many
SELECT id, name, type FROM notification_channels WHERE org_id = $1 ORDER BY lower(name) LIMIT 500
`
type SupportOptionsChannelsRow struct {
ID uuid.UUID
Name string
Type string
}
func (q *Queries) SupportOptionsChannels(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsChannelsRow, error) {
rows, err := q.db.Query(ctx, supportOptionsChannels, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportOptionsChannelsRow{}
for rows.Next() {
var i SupportOptionsChannelsRow
if err := rows.Scan(&i.ID, &i.Name, &i.Type); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportOptionsIncidents = `-- name: SupportOptionsIncidents :many
SELECT i.id, i.title, i.started_at, m.name AS monitor_name
FROM incidents i JOIN monitors m ON m.id = i.monitor_id
WHERE i.org_id = $1 ORDER BY i.started_at DESC LIMIT 50
`
type SupportOptionsIncidentsRow struct {
ID uuid.UUID
Title string
StartedAt time.Time
MonitorName string
}
func (q *Queries) SupportOptionsIncidents(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsIncidentsRow, error) {
rows, err := q.db.Query(ctx, supportOptionsIncidents, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportOptionsIncidentsRow{}
for rows.Next() {
var i SupportOptionsIncidentsRow
if err := rows.Scan(
&i.ID,
&i.Title,
&i.StartedAt,
&i.MonitorName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportOptionsMonitors = `-- name: SupportOptionsMonitors :many
SELECT id, name FROM monitors WHERE org_id = $1 ORDER BY lower(name) LIMIT 500
`
type SupportOptionsMonitorsRow struct {
ID uuid.UUID
Name string
}
func (q *Queries) SupportOptionsMonitors(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsMonitorsRow, error) {
rows, err := q.db.Query(ctx, supportOptionsMonitors, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportOptionsMonitorsRow{}
for rows.Next() {
var i SupportOptionsMonitorsRow
if err := rows.Scan(&i.ID, &i.Name); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportOptionsStatusPages = `-- name: SupportOptionsStatusPages :many
SELECT id, title FROM status_pages WHERE org_id = $1 ORDER BY lower(title) LIMIT 500
`
type SupportOptionsStatusPagesRow struct {
ID uuid.UUID
Title string
}
func (q *Queries) SupportOptionsStatusPages(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsStatusPagesRow, error) {
rows, err := q.db.Query(ctx, supportOptionsStatusPages, orgID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []SupportOptionsStatusPagesRow{}
for rows.Next() {
var i SupportOptionsStatusPagesRow
if err := rows.Scan(&i.ID, &i.Title); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const supportReferencesExist = `-- name: SupportReferencesExist :one
SELECT ($1::uuid IS NULL OR EXISTS (SELECT 1 FROM monitors m WHERE m.id = $1 AND m.org_id = $2::uuid))
AND ($3::uuid IS NULL OR EXISTS (SELECT 1 FROM notification_channels c WHERE c.id = $3 AND c.org_id = $2::uuid))
AND ($4::uuid IS NULL OR EXISTS (SELECT 1 FROM alert_groups g WHERE g.id = $4 AND g.org_id = $2::uuid))
AND ($5::uuid IS NULL OR EXISTS (SELECT 1 FROM status_pages p WHERE p.id = $5 AND p.org_id = $2::uuid))
AND ($6::uuid IS NULL OR EXISTS (SELECT 1 FROM incidents i WHERE i.id = $6 AND i.org_id = $2::uuid))
AS ok
`
type SupportReferencesExistParams struct {
MonitorID *uuid.UUID
OrgID uuid.UUID
ChannelID *uuid.UUID
AlertGroupID *uuid.UUID
StatusPageID *uuid.UUID
IncidentID *uuid.UUID
}
// Whether everything a new ticket points at belongs to org; run in the
// organization's scope so only what the account may see counts.
func (q *Queries) SupportReferencesExist(ctx context.Context, arg SupportReferencesExistParams) (*bool, error) {
row := q.db.QueryRow(ctx, supportReferencesExist,
arg.MonitorID,
arg.OrgID,
arg.ChannelID,
arg.AlertGroupID,
arg.StatusPageID,
arg.IncidentID,
)
var ok *bool
err := row.Scan(&ok)
return ok, err
}
const supportTicketReferences = `-- name: SupportTicketReferences :one
SELECT o.name AS org_name, o.slug AS org_slug,
m.name AS monitor_name, m.type AS monitor_type,
ch.name AS channel_name, ch.type AS channel_type,
ag.name AS alert_group_name,
sp.title AS status_page_title, sp.slug AS status_page_slug,
i.title AS incident_title, i.started_at AS incident_started_at, im.name AS incident_monitor
FROM support_tickets t
LEFT JOIN orgs o ON o.id = t.org_id
LEFT JOIN monitors m ON m.id = t.monitor_id
LEFT JOIN notification_channels ch ON ch.id = t.channel_id
LEFT JOIN alert_groups ag ON ag.id = t.alert_group_id
LEFT JOIN status_pages sp ON sp.id = t.status_page_id
LEFT JOIN incidents i ON i.id = t.incident_id
LEFT JOIN monitors im ON im.id = i.monitor_id
WHERE t.id = $1
`
type SupportTicketReferencesRow struct {
OrgName *string
OrgSlug *string
MonitorName *string
MonitorType *string
ChannelName *string
ChannelType *string
AlertGroupName *string
StatusPageTitle *string
StatusPageSlug *string
IncidentTitle *string
IncidentStartedAt *time.Time
IncidentMonitor *string
}
// The names of what a ticket points at, for showing it.
func (q *Queries) SupportTicketReferences(ctx context.Context, id uuid.UUID) (SupportTicketReferencesRow, error) {
row := q.db.QueryRow(ctx, supportTicketReferences, id)
var i SupportTicketReferencesRow
err := row.Scan(
&i.OrgName,
&i.OrgSlug,
&i.MonitorName,
&i.MonitorType,
&i.ChannelName,
&i.ChannelType,
&i.AlertGroupName,
&i.StatusPageTitle,
&i.StatusPageSlug,
&i.IncidentTitle,
&i.IncidentStartedAt,
&i.IncidentMonitor,
)
return i, err
}
const supportTicketStatus = `-- name: SupportTicketStatus :one
SELECT status FROM support_tickets WHERE id = $1
`
func (q *Queries) SupportTicketStatus(ctx context.Context, id uuid.UUID) (string, error) {
row := q.db.QueryRow(ctx, supportTicketStatus, id)
var status string
err := row.Scan(&status)
return status, err
}