storage

package
v0.0.0-...-fe77c3d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckNotFound = errors.New("check not found")

ErrCheckNotFound is returned when a check is not found

View Source
var ErrComponentNotFound = errors.New("component not found")

ErrComponentNotFound is returned when a component is not found

Functions

func WithCheckSlug

func WithCheckSlug(checkSlug string) func(db *gorm.DB) *gorm.DB

WithCheckSlug scope filters by check slug

func WithComponentID

func WithComponentID(componentID uuid.UUID) func(db *gorm.DB) *gorm.DB

WithComponentID scope filters by component ID

func WithLatestPerCheck

func WithLatestPerCheck() func(db *gorm.DB) *gorm.DB

WithLatestPerCheck scope applies latest per check logic For PostgreSQL, uses DISTINCT ON; for SQLite, uses a subquery approach

func WithOrderByTimestamp

func WithOrderByTimestamp() func(db *gorm.DB) *gorm.DB

WithOrderByTimestamp scope orders by timestamp descending

func WithPagination

func WithPagination(limit, offset int) func(db *gorm.DB) *gorm.DB

WithPagination scope applies pagination

func WithPreloads

func WithPreloads() func(db *gorm.DB) *gorm.DB

WithPreloads scope adds necessary preloads

func WithSince

func WithSince(since time.Time) func(db *gorm.DB) *gorm.DB

WithSince scope filters by timestamp (since)

func WithStatus

func WithStatus(status CheckStatus) func(db *gorm.DB) *gorm.DB

WithStatus scope filters by check status

Types

type Check

type Check struct {
	ID          uuid.UUID `gorm:"type:uuid;primaryKey"`
	Slug        string    `gorm:"not null;uniqueIndex;size:100"`
	Name        string    `gorm:"not null;size:255"`
	Description string    `gorm:"type:text"`
	CreatedAt   time.Time `gorm:"autoCreateTime"`
	UpdatedAt   time.Time `gorm:"autoUpdateTime"`
}

Check represents a quality check that can be performed on components

func (*Check) BeforeCreate

func (c *Check) BeforeCreate(tx *gorm.DB) (err error)

type CheckReport

type CheckReport struct {
	ID          uuid.UUID   `gorm:"type:uuid;primaryKey"`
	CheckID     uuid.UUID   `gorm:"type:uuid;not null;index:idx_check_timestamp"`
	ComponentID uuid.UUID   `gorm:"type:uuid;not null;index:idx_component_check"`
	Status      CheckStatus `gorm:"type:varchar(20);not null;index:idx_check_status"`
	Timestamp   time.Time   `gorm:"not null;index:idx_check_timestamp"`
	Details     JSONB       `gorm:"type:jsonb"`
	Metadata    JSONB       `gorm:"type:jsonb"`
	CreatedAt   time.Time   `gorm:"autoCreateTime"`
	UpdatedAt   time.Time   `gorm:"autoUpdateTime"`

	// Relationships
	Check     Check
	Component Component
}

CheckReport represents a report of a check execution on a component

func (*CheckReport) BeforeCreate

func (cr *CheckReport) BeforeCreate(tx *gorm.DB) (err error)

type CheckStatus

type CheckStatus string

CheckStatus represents the status of a check execution

const (
	CheckStatusPass      CheckStatus = "pass"
	CheckStatusFail      CheckStatus = "fail"
	CheckStatusDisabled  CheckStatus = "disabled"
	CheckStatusSkipped   CheckStatus = "skipped"
	CheckStatusUnknown   CheckStatus = "unknown"
	CheckStatusError     CheckStatus = "error"
	CheckStatusCompleted CheckStatus = "completed"
)

type Component

type Component struct {
	ID          uuid.UUID `gorm:"type:uuid;primaryKey"`
	ComponentID string    `gorm:"not null;uniqueIndex"` // Unique identifier from manifest
	Name        string    `gorm:"not null"`
	Description string
	Maintainers StringArray `gorm:"type:jsonb"`
	Team        string

	// Relationships
	CheckReports []CheckReport
}

Component represents a component stored in the database.

func (*Component) BeforeCreate

func (c *Component) BeforeCreate(tx *gorm.DB) (err error)

type Config

type Config struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	DBName   string `yaml:"dbname"`
	SSLMode  string `yaml:"sslmode"`
}

func (Config) DSN

func (c Config) DSN() string

type CreateCheckReportInput

type CreateCheckReportInput struct {
	ComponentID      string
	CheckSlug        string
	CheckName        *string
	CheckDescription *string
	Status           CheckStatus
	Timestamp        time.Time
	Details          JSONB
	Metadata         JSONB
}

CreateCheckReportInput represents the input data for creating a check report

type JSONB

type JSONB map[string]interface{}

JSONB is a custom type to handle PostgreSQL JSONB fields This allows for flexible storage of JSON data with powerful querying capabilities using PostgreSQL's JSONB operators and functions

func (JSONB) Delete

func (j JSONB) Delete(key string)

Delete removes a key from the JSONB map

func (JSONB) Get

func (j JSONB) Get(key string) (interface{}, bool)

Get retrieves a value from the JSONB map

func (JSONB) GormDBDataType

func (j JSONB) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType implements GormDBDataTypeInterface

func (JSONB) GormDataType

func (j JSONB) GormDataType() string

GormDataType implements GormDataTypeInterface

func (JSONB) Has

func (j JSONB) Has(key string) bool

Has checks if a key exists in the JSONB map

func (JSONB) Keys

func (j JSONB) Keys() []string

Keys returns all keys in the JSONB map

func (*JSONB) Scan

func (j *JSONB) Scan(value interface{}) error

Scan implements sql.Scanner interface for database retrieval

func (JSONB) Set

func (j JSONB) Set(key string, value interface{})

Set sets a value in the JSONB map

func (JSONB) Value

func (j JSONB) Value() (driver.Value, error)

Value implements driver.Valuer interface for database storage

type Repository

type Repository struct {
	DB *gorm.DB
}

func ConnectAndMigrate

func ConnectAndMigrate(ctx context.Context, dsn string) (*Repository, error)

func (*Repository) CreateCheck

func (r *Repository) CreateCheck(ctx context.Context, check Check) error

func (*Repository) CreateCheckReportFromSubmission

func (r *Repository) CreateCheckReportFromSubmission(ctx context.Context, input CreateCheckReportInput) (uuid.UUID, error)

CreateCheckReportFromSubmission creates a check report from API submission data

func (*Repository) CreateComponent

func (r *Repository) CreateComponent(ctx context.Context, component Component) error

CreateComponent creates a new component

func (*Repository) GetCheckBySlug

func (r *Repository) GetCheckBySlug(ctx context.Context, slug string) (*Check, error)

Check methods - only what's needed for handlers

func (*Repository) GetCheckReportsForComponentWithPagination

func (r *Repository) GetCheckReportsForComponentWithPagination(ctx context.Context, componentID string, status *CheckStatus, checkSlug *string, since *time.Time, limit int, offset int, latestPerCheck bool) ([]CheckReport, int64, error)

GetCheckReportsForComponentWithPagination retrieves check reports for a component with database-level filtering, pagination, and latest per check

func (*Repository) GetComponentByID

func (r *Repository) GetComponentByID(ctx context.Context, componentID string) (*Component, error)

GetComponentByID returns a component by its unique identifier

func (*Repository) GetComponents

func (r *Repository) GetComponents(ctx context.Context) ([]Component, error)

Component methods

func (*Repository) GetComponentsByTeam

func (r *Repository) GetComponentsByTeam(ctx context.Context, team string) ([]Component, error)

GetComponentsByTeam returns all components owned by a specific team

func (*Repository) GetOrCreateCheckBySlug

func (r *Repository) GetOrCreateCheckBySlug(ctx context.Context, slug string, name *string, description *string) (uuid.UUID, error)

GetOrCreateCheckBySlug auto-creates a check if it doesn't exist, returns CheckID

func (*Repository) HealthCheck

func (r *Repository) HealthCheck(ctx context.Context) error

HealthCheck implements the health.Checker interface

func (*Repository) Migrate

func (r *Repository) Migrate(ctx context.Context) error

func (*Repository) Name

func (r *Repository) Name() string

type StringArray

type StringArray []string

StringArray is a custom type to handle PostgreSQL JSONB arrays This allows for powerful querying capabilities using PostgreSQL's JSONB operators: - ? : Check if a string exists in the array - ?| : Check if any of the strings exist in the array - ?& : Check if all of the strings exist in the array Example queries:

WHERE maintainers ? 'alice@company.com'                    -- Find components maintained by alice
WHERE maintainers ?| '["alice@company.com", "bob@company.com"]' -- Find components maintained by either alice or bob
WHERE maintainers ?& '["alice@company.com", "bob@company.com"]' -- Find components maintained by both alice and bob

func (StringArray) Contains

func (sa StringArray) Contains(value string) bool

Contains checks if the array contains a specific string

func (StringArray) ContainsAny

func (sa StringArray) ContainsAny(values []string) bool

ContainsAny checks if the array contains any of the provided strings

func (StringArray) GormDBDataType

func (sa StringArray) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType implements GormDBDataTypeInterface

func (StringArray) GormDataType

func (sa StringArray) GormDataType() string

GormDataType implements GormDataTypeInterface

func (*StringArray) Scan

func (sa *StringArray) Scan(value interface{}) error

Scan implements sql.Scanner interface for database retrieval

func (StringArray) Value

func (sa StringArray) Value() (driver.Value, error)

Value implements driver.Valuer interface for database storage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL