Documentation
¶
Index ¶
- Constants
- Variables
- type AlertFilters
- type AlertRepository
- type AlreadyExistsError
- type DatabaseError
- type EscalationPolicyRepository
- type GroupingRuleRepository
- type IncidentFilters
- type IncidentRepository
- type LocalSessionRepository
- type NotFoundError
- type Pagination
- type PostMortemCommentRepository
- type PostMortemRepository
- type PostMortemTemplateRepository
- type RoutingRuleRepository
- type ScheduleRepository
- type SlackConfigRepository
- type SystemSettingsRepository
- type TeamsConfigRepository
- type TelegramConfigRepository
- type TimelineRepository
- type UserRepository
- type ValidationError
Constants ¶
const ( KeyInstanceName = "instance.name" KeyTimezone = "instance.timezone" KeyOpenAIAPIKey = "ai.openai_api_key" KeyInstanceID = "instance.id" KeyTelemetryOptOut = "telemetry.opt_out" // Multi-provider AI connector keys (OPE-113) KeyAIProvider = "ai.provider" KeyAnthropicAPIKey = "ai.anthropic_api_key" KeyOllamaBaseURL = "ai.ollama_base_url" KeyOllamaModel = "ai.ollama_model" )
Variables ¶
var ( ErrNotFound = errors.New("resource not found") ErrAlreadyExists = errors.New("resource already exists") ErrInvalidInput = errors.New("invalid input") ErrDatabase = errors.New("database error") )
Common repository errors
Functions ¶
This section is empty.
Types ¶
type AlertFilters ¶
type AlertFilters struct {
Source string
Status models.AlertStatus
Severity models.AlertSeverity
}
AlertFilters holds filter options for listing alerts
type AlertRepository ¶
type AlertRepository interface {
Create(alert *models.Alert) error
GetByID(id uuid.UUID) (*models.Alert, error)
GetByExternalID(source, externalID string) (*models.Alert, error)
List(filters AlertFilters, pagination Pagination) ([]models.Alert, int64, error)
Update(alert *models.Alert) error
}
AlertRepository defines the interface for alert data access
func NewAlertRepository ¶
func NewAlertRepository(db *gorm.DB) AlertRepository
NewAlertRepository creates a new alert repository
type AlreadyExistsError ¶
AlreadyExistsError represents a duplicate resource error
func (*AlreadyExistsError) Error ¶
func (e *AlreadyExistsError) Error() string
func (*AlreadyExistsError) Is ¶
func (e *AlreadyExistsError) Is(target error) bool
type DatabaseError ¶
DatabaseError wraps database errors
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
func (*DatabaseError) Is ¶
func (e *DatabaseError) Is(target error) bool
func (*DatabaseError) Unwrap ¶
func (e *DatabaseError) Unwrap() error
type EscalationPolicyRepository ¶
type EscalationPolicyRepository interface {
// CreatePolicy persists a new escalation policy (without tiers).
CreatePolicy(policy *models.EscalationPolicy) error
// GetPolicyByID retrieves a policy by ID (without tiers).
GetPolicyByID(id uuid.UUID) (*models.EscalationPolicy, error)
// GetPolicyWithTiers retrieves a policy and eagerly loads its tiers in
// ascending tier_index order.
GetPolicyWithTiers(id uuid.UUID) (*models.EscalationPolicy, error)
// GetAllPolicies retrieves all policies ordered by name (without tiers).
GetAllPolicies() ([]models.EscalationPolicy, error)
// GetAllPoliciesWithTiers retrieves all policies with their tiers eagerly
// loaded using a single IN query. Use this for list endpoints to avoid N+1.
GetAllPoliciesWithTiers() ([]models.EscalationPolicy, error)
// GetEnabledPolicies retrieves only enabled policies.
// This is the hot-path query used by the routing engine.
GetEnabledPolicies() ([]models.EscalationPolicy, error)
// UpdatePolicy updates mutable fields on an existing policy.
UpdatePolicy(policy *models.EscalationPolicy) error
// DeletePolicy deletes a policy and cascades to its tiers and states.
DeletePolicy(id uuid.UUID) error
// CreateTier adds a new tier to an existing policy.
CreateTier(tier *models.EscalationTier) error
// GetTiersByPolicy retrieves all tiers for a policy in ascending tier_index order.
GetTiersByPolicy(policyID uuid.UUID) ([]models.EscalationTier, error)
// UpdateTier persists changes to an existing escalation tier.
UpdateTier(tier *models.EscalationTier) error
// DeleteTier removes a single tier by ID.
DeleteTier(id uuid.UUID) error
// CreateState creates a new escalation state for an alert.
// Returns ErrAlreadyExists if a state for this alert already exists.
CreateState(state *models.EscalationState) error
// GetStateByAlert retrieves the escalation state for a specific alert.
GetStateByAlert(alertID uuid.UUID) (*models.EscalationState, error)
// GetStateByIncident retrieves the active escalation state for a manually escalated incident.
GetStateByIncident(incidentID uuid.UUID) (*models.EscalationState, error)
// GetActiveStates retrieves all escalation states that are still in progress
// (not acknowledged and not completed) for worker polling.
GetActiveStates() ([]models.EscalationState, error)
// UpdateState persists changes to an escalation state row (tier advancement,
// last_notified_at, status transitions).
UpdateState(state *models.EscalationState) error
// RecordAcknowledgment marks an escalation state as acknowledged and updates
// the alert's acknowledgment_status in a single transaction.
RecordAcknowledgment(alertID uuid.UUID, by string, via models.AcknowledgmentVia) error
// ListSeverityRules returns all severity → policy mappings.
ListSeverityRules() ([]models.EscalationSeverityRule, error)
// GetSeverityRule returns the rule for a specific severity, or nil if unset.
GetSeverityRule(severity string) (*models.EscalationSeverityRule, error)
// UpsertSeverityRule creates or updates the escalation policy for a severity level.
UpsertSeverityRule(severity string, policyID uuid.UUID) (*models.EscalationSeverityRule, error)
// DeleteSeverityRule removes the escalation rule for a severity level.
DeleteSeverityRule(severity string) error
}
EscalationPolicyRepository defines operations for managing escalation policies, tiers, and per-alert escalation state.
func NewEscalationPolicyRepository ¶
func NewEscalationPolicyRepository(db *gorm.DB) EscalationPolicyRepository
NewEscalationPolicyRepository creates a new escalation policy repository.
type GroupingRuleRepository ¶
type GroupingRuleRepository interface {
// Create creates a new grouping rule
Create(rule *models.GroupingRule) error
// GetByID retrieves a grouping rule by its ID
GetByID(id uuid.UUID) (*models.GroupingRule, error)
// GetAll retrieves all grouping rules ordered by priority (ascending)
GetAll() ([]models.GroupingRule, error)
// GetEnabled retrieves only enabled grouping rules ordered by priority
// This is the most common query - used by the grouping engine
GetEnabled() ([]models.GroupingRule, error)
// Update updates an existing grouping rule
Update(rule *models.GroupingRule) error
// Delete soft-deletes a grouping rule by ID
Delete(id uuid.UUID) error
// CheckPriorityConflict checks if another rule already uses this priority
// Returns the conflicting rule if one exists, nil otherwise
CheckPriorityConflict(priority int, excludeID uuid.UUID) (*models.GroupingRule, error)
}
GroupingRuleRepository defines operations for managing grouping rules
func NewGroupingRuleRepository ¶
func NewGroupingRuleRepository(db *gorm.DB) GroupingRuleRepository
NewGroupingRuleRepository creates a new grouping rule repository
type IncidentFilters ¶
type IncidentFilters struct {
Status models.IncidentStatus
Severity models.IncidentSeverity
StartDate *time.Time
EndDate *time.Time
ResolvedSince *time.Time // filters on resolved_at >= value
}
IncidentFilters holds filter options for listing incidents
type IncidentRepository ¶
type IncidentRepository interface {
Create(incident *models.Incident) error
GetByID(id uuid.UUID) (*models.Incident, error)
GetByNumber(number int) (*models.Incident, error)
GetBySlackChannelID(channelID string) (*models.Incident, error)
GetBySlackMessageTS(messageTS string) (*models.Incident, error)
GetByTeamsChannelID(channelID string) (*models.Incident, error)
GetByTeamsConversationID(conversationID string) (*models.Incident, error)
List(filters IncidentFilters, pagination Pagination) ([]models.Incident, int64, error)
Update(incident *models.Incident) error
UpdateStatus(id uuid.UUID, status models.IncidentStatus) error
UpdateSlackChannel(id uuid.UUID, channelID, channelName string) error
UpdateSlackMessageTS(id uuid.UUID, messageTS string) error
UpdateTeamsChannel(id uuid.UUID, channelID, channelName string) error
UpdateTeamsConversationID(id uuid.UUID, conversationID string) error
UpdateTeamsActivityID(id uuid.UUID, activityID string) error
UpdateTeamsPostingIDs(id uuid.UUID, conversationID, activityID string) error
LinkAlert(incidentID, alertID uuid.UUID, linkedByType, linkedByID string) error
GetAlerts(incidentID uuid.UUID) ([]models.Alert, error)
GetIncidentByAlertID(alertID uuid.UUID) (*models.Incident, error)
UpdateAISummary(id uuid.UUID, summary string, generatedAt time.Time) error
}
IncidentRepository defines the interface for incident data access
func NewIncidentRepository ¶
func NewIncidentRepository(db *gorm.DB) IncidentRepository
NewIncidentRepository creates a new incident repository
type LocalSessionRepository ¶
type LocalSessionRepository interface {
Create(userID uuid.UUID) (*models.LocalSession, error)
GetByToken(token string) (*models.LocalSession, error)
DeleteByToken(token string) error
DeleteByUserID(userID uuid.UUID) error
DeleteExpired() error
}
LocalSessionRepository manages local session tokens.
func NewLocalSessionRepository ¶
func NewLocalSessionRepository(db *gorm.DB) LocalSessionRepository
type NotFoundError ¶
type NotFoundError struct {
Resource string
ID interface{}
}
NotFoundError represents a resource not found error
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Is ¶
func (e *NotFoundError) Is(target error) bool
type Pagination ¶
Pagination holds pagination parameters
type PostMortemCommentRepository ¶
type PostMortemCommentRepository interface {
ListByPostMortemID(postMortemID uuid.UUID) ([]models.PostMortemComment, error)
Create(comment *models.PostMortemComment) error
GetByID(id uuid.UUID) (*models.PostMortemComment, error)
Delete(id uuid.UUID) error
}
func NewPostMortemCommentRepository ¶
func NewPostMortemCommentRepository(db *gorm.DB) PostMortemCommentRepository
type PostMortemRepository ¶
type PostMortemRepository interface {
GetByIncidentID(incidentID uuid.UUID) (*models.PostMortem, error)
GetByID(id uuid.UUID) (*models.PostMortem, error)
Create(pm *models.PostMortem) error
// Upsert inserts pm or, if a post-mortem for the same incident already exists,
// overwrites its AI-generated fields. Safe for concurrent callers.
Upsert(pm *models.PostMortem) error
Update(pm *models.PostMortem) error
ListActionItems(postMortemID uuid.UUID) ([]models.ActionItem, error)
GetActionItemByID(id uuid.UUID) (*models.ActionItem, error)
CreateActionItem(item *models.ActionItem) error
UpdateActionItem(item *models.ActionItem) error
DeleteActionItem(id uuid.UUID) error
}
PostMortemRepository provides data access for post-mortems and their action items.
func NewPostMortemRepository ¶
func NewPostMortemRepository(db *gorm.DB) PostMortemRepository
type PostMortemTemplateRepository ¶
type PostMortemTemplateRepository interface {
List() ([]models.PostMortemTemplate, error)
GetByID(id uuid.UUID) (*models.PostMortemTemplate, error)
Create(tmpl *models.PostMortemTemplate) error
Update(tmpl *models.PostMortemTemplate) error
Delete(id uuid.UUID) error
}
PostMortemTemplateRepository provides data access for post-mortem templates.
func NewPostMortemTemplateRepository ¶
func NewPostMortemTemplateRepository(db *gorm.DB) PostMortemTemplateRepository
type RoutingRuleRepository ¶
type RoutingRuleRepository interface {
// Create creates a new routing rule
Create(rule *models.RoutingRule) error
// GetByID retrieves a routing rule by its ID
GetByID(id uuid.UUID) (*models.RoutingRule, error)
// GetAll retrieves all routing rules ordered by priority (ascending)
GetAll() ([]models.RoutingRule, error)
// GetEnabled retrieves only enabled routing rules ordered by priority.
// This is the hot-path query — called by the routing engine on every alert.
GetEnabled() ([]models.RoutingRule, error)
// Update updates an existing routing rule
Update(rule *models.RoutingRule) error
// Delete deletes a routing rule by ID
Delete(id uuid.UUID) error
// CheckPriorityConflict checks if another rule already uses this priority.
// Returns the conflicting rule if one exists, nil otherwise.
CheckPriorityConflict(priority int, excludeID uuid.UUID) (*models.RoutingRule, error)
// Reorder reassigns priorities in bulk using the supplied ordered slice of IDs.
// Priorities become 10, 20, 30 … (multiples of 10) to leave room for future inserts.
// Runs inside a single transaction. IDs not present in the slice are unchanged.
Reorder(ids []uuid.UUID) error
// GetMaxPriority returns the highest priority value currently in use (0 if no rules exist).
GetMaxPriority() (int, error)
}
RoutingRuleRepository defines operations for managing routing rules
func NewRoutingRuleRepository ¶
func NewRoutingRuleRepository(db *gorm.DB) RoutingRuleRepository
NewRoutingRuleRepository creates a new routing rule repository
type ScheduleRepository ¶
type ScheduleRepository interface {
// Create persists a new schedule. Layers/participants must be created separately.
Create(schedule *models.Schedule) error
// GetByID returns the schedule row only (no layers). Use GetWithLayers for full data.
GetByID(id uuid.UUID) (*models.Schedule, error)
// GetAll returns all schedules ordered by name, without layers.
GetAll() ([]models.Schedule, error)
// Update saves name, description, timezone, notification_channel, and updated_at.
Update(schedule *models.Schedule) error
// Delete removes a schedule and cascades to layers, participants, overrides.
Delete(id uuid.UUID) error
// GetWithLayers returns the schedule plus all layers (ordered by order_index)
// plus all participants per layer (ordered by order_index).
// Executes 3 queries: schedule, layers, participants.
GetWithLayers(id uuid.UUID) (*models.Schedule, error)
// CreateLayer adds a new layer to a schedule.
CreateLayer(layer *models.ScheduleLayer) error
// DeleteLayer removes a layer (cascades to participants).
DeleteLayer(layerID uuid.UUID) error
// UpdateLayer updates layer metadata and optionally replaces participants atomically.
// A nil participants pointer means "leave participants untouched".
// A non-nil pointer (even pointing to an empty slice) replaces all participants.
UpdateLayer(layer *models.ScheduleLayer, participants *[]models.ScheduleParticipant) error
// CreateParticipantsBulk bulk-inserts participants for a layer.
CreateParticipantsBulk(participants []models.ScheduleParticipant) error
// CreateOverride adds an override to a schedule.
CreateOverride(override *models.ScheduleOverride) error
// DeleteOverride removes an override by ID.
DeleteOverride(overrideID uuid.UUID) error
// GetActiveOverrides returns all overrides for a schedule that cover `at`.
// "Cover" means start_time <= at < end_time.
// Results are ordered by start_time DESC so the most-recently-starting override is first.
GetActiveOverrides(scheduleID uuid.UUID, at time.Time) ([]models.ScheduleOverride, error)
// GetOverridesInWindow returns all overrides for a schedule that overlap [from, to).
// Used by GetTimeline to collect all overrides in the requested window.
GetOverridesInWindow(scheduleID uuid.UUID, from, to time.Time) ([]models.ScheduleOverride, error)
// ListUpcomingOverrides returns all overrides for a schedule whose end_time is in the future,
// ordered by start_time ASC. Used by the UI override management table.
ListUpcomingOverrides(scheduleID uuid.UUID) ([]models.ScheduleOverride, error)
// GetHolidayCountries returns the country codes configured for this schedule.
GetHolidayCountries(scheduleID uuid.UUID) ([]string, error)
// SetHolidayCountries atomically replaces the holiday country config for a schedule.
// Removed countries have their holiday rows purged. Returns the added codes.
SetHolidayCountries(scheduleID uuid.UUID, countries []string) (added []string, removed []string, err error)
// UpsertHolidays inserts or ignores holiday rows (unique on schedule_id+country+date).
UpsertHolidays(holidays []models.ScheduleHoliday) error
// ListHolidays returns holidays for a schedule within [from, to) ordered by date.
ListHolidays(scheduleID uuid.UUID, from, to time.Time) ([]models.ScheduleHoliday, error)
// DeleteHolidaysByCountry removes all holidays for a schedule+country pair.
DeleteHolidaysByCountry(scheduleID uuid.UUID, countryCode string) error
// ListSchedulesWithHolidays returns all schedules that have at least one
// holiday country configured, with HolidayCountries populated.
ListSchedulesWithHolidays() ([]models.Schedule, error)
CreateUnavailability(u *models.ScheduleUnavailability) error
// given scheduleID so that cross-schedule deletions are rejected.
DeleteUnavailability(scheduleID, id uuid.UUID) error
// end_date is today or in the future, ordered by start_date ASC.
ListUnavailabilities(scheduleID uuid.UUID) ([]models.ScheduleUnavailability, error)
// given date window [from, to). Used by the evaluator to determine who may
// be skipped during timeline construction.
GetUnavailabilitiesInWindow(scheduleID uuid.UUID, from, to time.Time) ([]models.ScheduleUnavailability, error)
}
ScheduleRepository defines all database operations for schedules.
func NewScheduleRepository ¶
func NewScheduleRepository(db *gorm.DB) ScheduleRepository
NewScheduleRepository creates a new schedule repository.
type SlackConfigRepository ¶
type SlackConfigRepository interface {
Get() (*models.SlackConfig, error) // nil, nil if not configured
Save(cfg *models.SlackConfig) error
Delete() error
}
SlackConfigRepository manages Slack integration configuration.
func NewSlackConfigRepository ¶
func NewSlackConfigRepository(db *gorm.DB) SlackConfigRepository
NewSlackConfigRepository creates a new SlackConfigRepository.
type SystemSettingsRepository ¶
type SystemSettingsRepository interface {
// GetGlobalFallbackPolicyID returns the configured global escalation fallback
// policy, or nil if none is set.
GetGlobalFallbackPolicyID() (*uuid.UUID, error)
// SetGlobalFallbackPolicyID persists the global fallback policy. Pass nil to
// clear the setting.
SetGlobalFallbackPolicyID(id *uuid.UUID) error
// GetString returns the string value for the given key, or "" if not set.
GetString(key string) (string, error)
// SetString persists a string value for the given key.
SetString(key, value string) error
// GetInstanceID returns the persistent anonymous instance UUID, or "" on first boot.
GetInstanceID() (string, error)
// SetInstanceID persists the anonymous instance UUID.
SetInstanceID(id string) error
// GetTelemetryOptOut returns true if the admin has disabled telemetry via the UI.
GetTelemetryOptOut() (bool, error)
// SetTelemetryOptOut persists the admin's telemetry preference.
SetTelemetryOptOut(disabled bool) error
}
SystemSettingsRepository manages system-wide configuration stored in the system_settings key-value table.
func NewSystemSettingsRepository ¶
func NewSystemSettingsRepository(db *gorm.DB) SystemSettingsRepository
NewSystemSettingsRepository creates a new SystemSettingsRepository.
type TeamsConfigRepository ¶
type TeamsConfigRepository interface {
Get() (*models.TeamsConfig, error) // nil, nil if not configured
Save(cfg *models.TeamsConfig) error
Delete() error
}
TeamsConfigRepository manages Teams integration configuration.
func NewTeamsConfigRepository ¶
func NewTeamsConfigRepository(db *gorm.DB) TeamsConfigRepository
type TelegramConfigRepository ¶
type TelegramConfigRepository interface {
Get() (*models.TelegramConfig, error) // nil, nil if not configured
Save(cfg *models.TelegramConfig) error
Delete() error
}
TelegramConfigRepository manages Telegram bot configuration.
func NewTelegramConfigRepository ¶
func NewTelegramConfigRepository(db *gorm.DB) TelegramConfigRepository
type TimelineRepository ¶
type TimelineRepository interface {
Create(entry *models.TimelineEntry) error
CreateBulk(entries []models.TimelineEntry) error
GetByIncidentID(incidentID uuid.UUID, pagination Pagination) ([]models.TimelineEntry, int64, error)
}
TimelineRepository defines the interface for timeline entry data access
func NewTimelineRepository ¶
func NewTimelineRepository(db *gorm.DB) TimelineRepository
NewTimelineRepository creates a new timeline repository
type UserRepository ¶
type UserRepository interface {
GetBySubject(subject string) (*models.User, error)
GetByEmail(email string) (*models.User, error)
Upsert(ctx context.Context, user *models.User) error
UpdateLastLogin(id uuid.UUID, at time.Time) error
// CreateLocal creates a new locally-authenticated user with a bcrypt password hash.
CreateLocal(user *models.User) error
// ListAll returns all users ordered by created_at ASC.
ListAll() ([]models.User, error)
// GetByID retrieves a user by primary key.
GetByID(id uuid.UUID) (*models.User, error)
// Update saves changed fields (name, role, password_hash) for a user.
Update(user *models.User) error
// Count returns the total number of active (non-deactivated) users.
Count() (int64, error)
// CountByRole returns the number of active users with the given role.
CountByRole(role models.UserRole) (int64, error)
// Deactivate soft-deletes a user by setting auth_source='deactivated'.
Deactivate(id uuid.UUID) error
// CreateAgent inserts an AI agent user. No password hash is set.
CreateAgent(user *models.User) error
// SetActive enables or disables a user (used for agent on/off toggle).
SetActive(id uuid.UUID, active bool) error
// ListAgents returns all users with auth_source='ai', including inactive ones.
// The coordinator must additionally check the Active flag before dispatching work.
ListAgents() ([]models.User, error)
// GetBySlackUserID retrieves a user by their Slack user ID (e.g. "U01234ABCDE").
GetBySlackUserID(slackUserID string) (*models.User, error)
// GetByTeamsUserID retrieves a user by their Azure AD Object ID.
GetByTeamsUserID(teamsUserID string) (*models.User, error)
// RestoreAgent resets a previously-deactivated AI agent back to auth_source='ai', active=true.
RestoreAgent(id uuid.UUID) error
}
UserRepository defines the data access interface for users.
func NewUserRepository ¶
func NewUserRepository(db *gorm.DB) UserRepository
type ValidationError ¶
ValidationError represents invalid input error
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Is ¶
func (e *ValidationError) Is(target error) bool
Source Files
¶
- alert_repository.go
- errors.go
- escalation_policy_repository.go
- grouping_rule_repository.go
- incident_repository.go
- local_session_repository.go
- post_mortem_comment_repository.go
- post_mortem_repository.go
- post_mortem_template_repository.go
- routing_rule_repository.go
- schedule_repository.go
- slack_config_repository.go
- system_settings_repository.go
- teams_config_repository.go
- telegram_config_repository.go
- timeline_repository.go
- user_repository.go