database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package database opens the PostgreSQL pool and applies the embedded migrations. capsa owns its schema: the binary is the only thing that creates or changes tables, at every start.

Index

Constants

View Source
const (
	StatusOK      = "ok"
	StatusWarning = "warning"
	StatusFailed  = "failed"
)

Check statuses.

View Source
const MigrationsTable = "schema_migrations"

MigrationsTable is the ledger of applied migrations in the database.

View Source
const MinVectorVersion = "0.7.0"

MinVectorVersion is the pgvector the schema needs: halfvec arrived in 0.7.0.

Variables

This section is empty.

Functions

func EnsureDatabase

func EnsureDatabase(ctx context.Context, dsn string) error

EnsureDatabase creates the database of the DSN when it does not exist yet. Tests use it for their scratch databases; the server does not: its database is the operator's.

func MigrateUp

func MigrateUp(ctx context.Context, dsn string, logger *slog.Logger) error

MigrateUp applies the embedded migrations and makes sure the pgvector extension is in place. A dirty ledger (a migration interrupted halfway) is reported, never forced: someone has to look at the database first.

func Open

func Open(ctx context.Context, dsn string) (*pgxpool.Pool, error)

Open connects to the database and verifies the connection answers.

Types

type Check

type Check struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	// Fix is what to do about it, when the status is not ok.
	Fix string `json:"fix,omitempty"`
}

Check is one line of the doctor's report.

type Report

type Report struct {
	Checks []Check `json:"checks"`
	Ready  bool    `json:"ready"`
}

Report is what the doctor found. Ready means the server can start against this database as it is.

func Doctor

func Doctor(ctx context.Context, dsn string, fix bool, logger *slog.Logger) (Report, error)

Doctor examines the database the way the server will use it: reachable, PostgreSQL 13 or newer, the pgvector extension present on the server, new enough, created in this database, and this role allowed to create tables. With fix it creates the extension when the server has it and the role may. The report comes back whatever is found; the error is for failures of the examination itself.

Jump to

Keyboard shortcuts

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