handlers

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package handlers wires up route registrations for the peng server.

Each function in this package is a server.Handler. They take a *server.Request and return a server.Response without knowing whether the request arrived over IPC, HTTP, or MCP. RegisterMeta (below) groups the always-on housekeeping routes; further files in this package will register migration / schema / seed / session handlers as those land.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMeta

func RegisterMeta(m *server.Mux, d *Deps)

RegisterMeta installs /healthz, /readyz, /version, /info, /events against the mux. These work without a database connection and are the right smoke-test surface for verifying the transport stack.

func RegisterMigrations

func RegisterMigrations(m *server.Mux, d *Deps)

RegisterMigrations installs the migration handlers viz uses. Apply ops (up/down/redo/reset) are deferred to a later PR; they require a confirmation/diff dance that's separate from the read/edit surface viz needs for the migration pane.

func RegisterQueries

func RegisterQueries(m *server.Mux, d *Deps)

func RegisterQuery

func RegisterQuery(m *server.Mux, d *Deps)

RegisterQuery installs POST /query — arbitrary SQL execution against the configured live pool. Backs peng-tui's editor pane.

Not exposed as an MCP tool by default: arbitrary SQL from an LLM with `confirm: true` gating is still a footgun (read-only constraint is not enforced by peng; clients can use a SET TRANSACTION READ ONLY preamble if they want one).

func RegisterSchema

func RegisterSchema(m *server.Mux, d *Deps)

RegisterSchema installs the schema endpoints viz uses. Dump/apply/diff land in a later PR — viz currently only needs the typed model and the pending-migrations preview.

Types

type Deps

type Deps struct {
	Provider      Provider
	MigrationsDir string
	QueriesDir    string
	LiveDSN       string
	ScratchDSN    string
	Version       string
	Bus           *eventbus.Bus
}

Deps bundles the runtime services every handler may need. Handlers that don't use a field can ignore it; the dispatcher only needs the Deps to satisfy any one handler that does.

Phase 2 wires:

  • Provider for migration / schema / drift handlers.
  • MigrationsDir for create/read/write of migration files (the hoisted peng.CreateMigration takes a dir; pinning it here keeps handlers from re-reading peng.yaml on every request).
  • LiveDSN/ScratchDSN cached strings so /schema/preview doesn't have to chase the env on every call.
  • Version + Bus continue to back the meta handlers.

type Provider

type Provider interface {
	Status(ctx context.Context) ([]peng.MigrationStatus, error)
	Drift(ctx context.Context) (peng.DriftReport, error)
	SchemaModel(ctx context.Context) (*peng.Schema, error)
	SchemaPreview(ctx context.Context, liveDSN, scratchDSN string) (string, error)
	// SchemaPreviewModels returns the same diff text as SchemaPreview plus
	// typed before/after schema models. Used by peng-tui's diagram-diff
	// modal (Phase 4); other consumers can keep using SchemaPreview.
	SchemaPreviewModels(ctx context.Context, liveDSN, scratchDSN string) (diff string, before, after *peng.Schema, err error)
	Pool() *pgxpool.Pool
	Close()
}

Provider is the slice of *pg.Provider's API that the server handlers actually call. Keeping it as an interface lets tests stub it with a fake and keeps the handlers package free of the pg → pgx dep graph (handlers only need this shape; serve.go wires the concrete provider).

Jump to

Keyboard shortcuts

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