feat(store): add incidents, notification channels and delivery outbox

At most one open incident per monitor is enforced by a partial unique
index.

Refs #15, #16

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-22 01:23:37 +01:00
1 parent 4b4e134bfd
commit ffef63e586
9 files changed
+770 -11

No files matched your search

+21
View File
@@ -16,6 +16,9 @@ type Querier interface {
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error)
AnyUserExists(ctx context.Context) (bool, error)
// System scope. Leases due rows for five minutes so a crashed sender's rows
// come back; SKIP LOCKED lets every API replica work the outbox.
ClaimNotifications(ctx context.Context, max int32) ([]uuid.UUID, error)
// Shortens tokens that would outlive a newly set maximum lifetime.
ClampAPITokenExpiry(ctx context.Context, arg ClampAPITokenExpiryParams) (int64, error)
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
@@ -23,6 +26,7 @@ type Querier interface {
CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) (ApiToken, error)
CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error)
CreateAssignment(ctx context.Context, arg CreateAssignmentParams) (RoleAssignment, error)
CreateChannel(ctx context.Context, arg CreateChannelParams) (NotificationChannel, error)
CreateIdentity(ctx context.Context, arg CreateIdentityParams) error
CreateInvitation(ctx context.Context, arg CreateInvitationParams) (Invitation, error)
CreateMonitor(ctx context.Context, arg CreateMonitorParams) (Monitor, error)
@@ -33,6 +37,7 @@ type Querier interface {
DeleteAPIToken(ctx context.Context, id uuid.UUID) (int64, error)
DeleteAgent(ctx context.Context, id uuid.UUID) (int64, error)
DeleteAssignment(ctx context.Context, id uuid.UUID) (int64, error)
DeleteChannel(ctx context.Context, id uuid.UUID) (int64, error)
DeleteInvitation(ctx context.Context, id uuid.UUID) (int64, error)
DeleteMonitor(ctx context.Context, id uuid.UUID) (int64, error)
DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID) error
@@ -43,10 +48,12 @@ type Querier interface {
DeleteUser(ctx context.Context, id uuid.UUID) (int64, error)
DisableTOTP(ctx context.Context, id uuid.UUID) error
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
GetAPIToken(ctx context.Context, id uuid.UUID) (ApiToken, error)
GetAPITokenByHash(ctx context.Context, tokenHash []byte) (ApiToken, error)
GetAgentByHash(ctx context.Context, tokenHash []byte) (Agent, error)
GetAssignment(ctx context.Context, id uuid.UUID) (RoleAssignment, error)
GetChannel(ctx context.Context, id uuid.UUID) (NotificationChannel, error)
GetIdentity(ctx context.Context, arg GetIdentityParams) (UserIdentity, error)
GetInvitation(ctx context.Context, id uuid.UUID) (Invitation, error)
GetInvitationByHash(ctx context.Context, tokenHash []byte) (GetInvitationByHashRow, error)
@@ -66,13 +73,17 @@ type Querier interface {
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
// Newest result per monitor and region in the org.
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
ListAPITokens(ctx context.Context, arg ListAPITokensParams) ([]ListAPITokensRow, error)
ListAgents(ctx context.Context) ([]Agent, error)
ListAssignments(ctx context.Context, orgID uuid.UUID) ([]ListAssignmentsRow, error)
ListChannels(ctx context.Context) ([]NotificationChannel, error)
ListEnabledChannelIDs(ctx context.Context, orgID uuid.UUID) ([]uuid.UUID, error)
// System scope: every enabled monitor with its regions, for reconciling the
// schedule.
ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEnabledMonitorsForScheduleRow, error)
ListEnabledSSOProviders(ctx context.Context) ([]ListEnabledSSOProvidersRow, error)
ListIncidents(ctx context.Context) ([]ListIncidentsRow, error)
ListMonitors(ctx context.Context) ([]Monitor, error)
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
ListOrgs(ctx context.Context) ([]Org, error)
@@ -83,20 +94,30 @@ type Querier interface {
ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error)
ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error)
MarkInvitationAccepted(ctx context.Context, id uuid.UUID) (int64, error)
MarkNotificationFailed(ctx context.Context, arg MarkNotificationFailedParams) error
MarkNotificationSent(ctx context.Context, id uuid.UUID) error
// Every role a member holds, with the scope it applies to.
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]string, error)
// System scope: monitors to hand to a checker of region, skipping ones that
// were disabled, deleted or moved out of the region since dispatch.
MonitorsForJobs(ctx context.Context, arg MonitorsForJobsParams) ([]Monitor, error)
// System scope: monitors a checker of region may report, with every region
// they are assigned to, for evaluation.
MonitorsForResults(ctx context.Context, arg MonitorsForResultsParams) ([]MonitorsForResultsRow, error)
// System scope.
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error)
RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error)
RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error)
ResolveIncident(ctx context.Context, arg ResolveIncidentParams) (Incident, error)
SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
TouchAPIToken(ctx context.Context, id uuid.UUID) error
TouchAgent(ctx context.Context, arg TouchAgentParams) error
TouchIdentity(ctx context.Context, arg TouchIdentityParams) error
UpdateChannel(ctx context.Context, arg UpdateChannelParams) (NotificationChannel, error)
UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (Monitor, error)
UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams) (Org, error)
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)