doctor

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 11 Imported by: 0

README

doctor

Health checks for melange authorization infrastructure.

Responsibility

Validates that the authorization system is properly configured by checking:

  • Schema File - Exists, parses correctly, no cyclic dependencies
  • Migration State - Tracking table exists, schema is in sync
  • Generated Functions - All expected functions present, no orphans
  • Tuples Source - melange_tuples view exists with correct columns
  • Data Health - Tuples reference valid types and relations

Architecture Role

cmd/melange doctor
       │
       └── internal/doctor
               │
               ├── pkg/parser (schema parsing)
               ├── pkg/schema (validation)
               ├── pkg/migrator (migration state)
               └── internal/sqlgen (function analysis)

The doctor command provides diagnostic output for troubleshooting authorization issues.

Output

Produces a Report with categorized check results:

  • StatusPass - Check passed
  • StatusWarn - Non-critical issue
  • StatusFail - Critical issue that will cause failures

Each failing check includes a FixHint suggesting remediation steps.

Key Checks

Category Validates
Schema File File exists, syntax valid, no cycles
Migration State Tracking table, schema checksum match
Generated Functions Dispatchers present, no missing/orphan functions
Tuples Source View exists, required columns present
Data Health Tuple types and relations match schema

Documentation

Overview

Package doctor provides health checks for melange authorization infrastructure.

The doctor command validates that the authorization system is properly configured by checking schema files, database state, generated functions, and data health.

Example usage:

d := doctor.New(db, "schemas")
report, err := d.Run(ctx)
if err != nil {
	log.Fatal(err)
}
report.Print(os.Stdout, true) // verbose=true

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	// Category groups related checks (e.g., "schema", "functions", "tuples").
	Category string

	// Name is a short identifier for the check.
	Name string

	// Status is the check outcome.
	Status Status

	// Message is a human-readable description of the result.
	Message string

	// Details provides additional information for verbose output.
	Details string

	// FixHint suggests how to resolve issues.
	FixHint string
}

CheckResult represents the outcome of a single health check.

type Doctor

type Doctor struct {
	// contains filtered or unexported fields
}

Doctor performs health checks on the melange authorization infrastructure.

func New

func New(db *sql.DB, schemaPath string) *Doctor

New creates a new Doctor instance.

func (*Doctor) Run

func (d *Doctor) Run(ctx context.Context) (*Report, error)

Run executes all health checks and returns a report.

type Report

type Report struct {
	Checks []CheckResult

	// Summary counts.
	Passed   int
	Warnings int
	Errors   int
}

Report contains all health check results.

func (*Report) AddCheck

func (r *Report) AddCheck(check CheckResult)

AddCheck adds a check result and updates summary counts.

func (*Report) HasErrors

func (r *Report) HasErrors() bool

HasErrors returns true if any check failed.

func (*Report) Print

func (r *Report) Print(w io.Writer, verbose bool)

Print writes the report to the given writer.

type Status

type Status int

Status represents the result of a health check.

const (
	// StatusPass indicates the check passed.
	StatusPass Status = iota
	// StatusWarn indicates a non-critical issue.
	StatusWarn
	// StatusFail indicates a critical issue that will cause failures.
	StatusFail
)

func (Status) Symbol

func (s Status) Symbol() string

Symbol returns a status indicator symbol for terminal output.

type TuplesInfo

type TuplesInfo struct {
	Exists     bool
	RelKind    string // 'r' = table, 'v' = view, 'm' = materialized view
	RelKindStr string // human-readable
	Columns    []string
	RowCount   int64 // -1 if unknown/expensive to compute
}

TuplesInfo contains information about the melange_tuples relation.

Jump to

Keyboard shortcuts

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