migrationx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package migrationx provides Kernel's SQL migration integration layer.

It intentionally keeps SQL as the source of truth. Proto describes API and access contracts; database structure lives in migrations/ and is applied or validated by Kernel boot.

Index

Constants

View Source
const (
	ModeDisabled    = "disabled"
	ModeDevApply    = "dev_apply"
	ModeApply       = "apply"
	ModeValidate    = "validate"
	ModeGORMDevAuto = "gorm_dev_auto"
)

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, db dbx.DB, cfg Config) error

Apply opens the configured migration directory and applies or validates it.

func ApplyMigrations

func ApplyMigrations(ctx context.Context, db dbx.DB, cfg Config, migrations []Migration) error

ApplyMigrations applies or validates a prepared migration set.

func Validate

func Validate(ctx context.Context, sqlDB *sql.DB, cfg Config, migrations []Migration) error

Validate checks pending and checksum drift without applying SQL.

Types

type Config

type Config struct {
	Enabled       bool   `json:"enabled" yaml:"enabled"`
	Engine        string `json:"engine" yaml:"engine"`
	Dir           string `json:"dir" yaml:"dir"`
	Table         string `json:"table" yaml:"table"`
	Mode          string `json:"mode" yaml:"mode"`
	FailOnPending bool   `json:"fail_on_pending" yaml:"fail_on_pending"`

	// AllowConcurrent explicitly allows startup-time applying migrations while
	// the deployment has more than one replica. Leave false for production unless
	// an external migration job or database advisory lock strategy is in place.
	AllowConcurrent bool `json:"allow_concurrent" yaml:"allow_concurrent"`
}

Config controls service startup migration behavior.

func (Config) Normalize

func (c Config) Normalize() Config

type Migration

type Migration struct {
	Version  string
	Name     string
	Path     string
	UpSQL    string
	DownSQL  string
	Checksum string
}

Migration is one discovered SQL migration.

func LoadDir

func LoadDir(fsys fs.FS, root string) ([]Migration, error)

LoadDir loads goose-compatible SQL migrations from an fs.FS.

Supported forms:

000001_create_skills.sql       with -- +goose Up / -- +goose Down sections
000001_create_skills.up.sql    split up file
000001_create_skills.down.sql  split down file

type Status

type Status struct {
	Version  string
	Name     string
	Applied  bool
	Checksum string
}

Status is one migration's observed state.

Jump to

Keyboard shortcuts

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