migrate

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package migrate owns OtelContext's ordered main-database schema contract.

Index

Constants

View Source
const (
	// LedgerTable is shared by main storage and GraphRAG migrations.
	LedgerTable = "otelcontext_schema_migrations"
	// CurrentVersion is the exact relational schema version required by this binary.
	CurrentVersion = 3
)
View Source
const (
	ExitOK           = 0
	ExitUsage        = 2
	ExitEmpty        = 10
	ExitUnmanaged    = 11
	ExitBehind       = 12
	ExitAhead        = 13
	ExitDirty        = 14
	ExitIncompatible = 15
	ExitUnverified   = 16
)

Exit codes are stable so deployment scripts do not need to parse prose.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB, driver string, options storage.MigrateOptions) error

AutoMigrate is the single development and preview-driver schema owner. It deliberately does not stamp the versioned ledger: operators must validate and baseline a database before changing to DB_AUTOMIGRATE=false.

func NormalizeDriver

func NormalizeDriver(driver string) string

NormalizeDriver returns the canonical driver name used by the registry.

func SchemaFingerprint

func SchemaFingerprint(ctx context.Context, db *gorm.DB, driver string, version int) (string, error)

SchemaFingerprint hashes the required tables, columns, keys, and indexes. It deliberately excludes optional search indexes and the migration ledger.

func SupportsVersioned

func SupportsVersioned(driver string) bool

SupportsVersioned reports whether this driver has promoted migration definitions.

Types

type Applied

type Applied struct {
	Version     int
	Name        string
	Checksum    string
	StartedAt   time.Time
	CompletedAt *time.Time
	Dirty       bool
}

Applied records one ledger entry without exposing the database row type.

type BaselineResult

type BaselineResult struct {
	Release           string
	RecordedVersion   int
	BeforeFingerprint string
	AfterFingerprint  string
	Status            Status
}

BaselineResult records the no-repair bridge from a published release.

func Baseline

func Baseline(ctx context.Context, db *gorm.DB, driver, release string) (BaselineResult, error)

Baseline validates a frozen released structure and records it without repair.

type State

type State string

State is the operator-visible compatibility state of the main database.

const (
	StateEmpty        State = "empty"
	StateUnmanaged    State = "unmanaged"
	StateExact        State = "exact"
	StateBehind       State = "behind"
	StateAhead        State = "ahead"
	StateDirty        State = "dirty"
	StateIncompatible State = "incompatible"
	StateUnverified   State = "unverified"
)

type StateError

type StateError struct {
	Operation string
	Status    Status
}

StateError carries the read-only status that made an operation fail closed.

func (*StateError) Error

func (e *StateError) Error() string

type Status

type Status struct {
	Driver          string
	State           State
	ExpectedVersion int
	ActualVersion   int
	Fingerprint     string
	Detail          string
	Applied         []Applied
}

Status is the complete read-only compatibility result for the main database.

func Inspect

func Inspect(ctx context.Context, db *gorm.DB, driver string) (Status, error)

Inspect reads the ledger and required relational structure without mutating it. A migration can commit between those two reads, so managed states are retried unless the ledger still matches the snapshot used for structural validation.

func RequireExact

func RequireExact(ctx context.Context, db *gorm.DB, driver string) (Status, error)

RequireExact performs the production startup compatibility gate.

func Up

func Up(ctx context.Context, db *gorm.DB, driver string) (Status, error)

Up installs an empty supported database or applies every pending migration.

func (Status) Description

func (s Status) Description() string

Description returns a compact stable line for logs and command output.

func (Status) ExitCode

func (s Status) ExitCode() int

ExitCode maps a state to its stable command exit code.

func (Status) Usable

func (s Status) Usable() bool

Usable reports whether this binary can safely use the inspected schema.

Jump to

Keyboard shortcuts

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