migrator

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package migrator is a public pzero runtime API for PostgreSQL schema migration execution and service commands backed by pgx.

Index

Constants

View Source
const MigrationDir = "desc/sql_migration"

Variables

View Source
var (
	DefaultXMigrationsTable = "schema_migrations"
	DefaultSource           = "file://desc/sql_migration"
)

Functions

func NewCommand

func NewCommand(loadSQLConf SQLConfigLoader) *cobra.Command

NewCommand builds a migrate command for a service root command. The service root must expose an inherited string flag named "config".

func WithSource

func WithSource(source string) opts.Opt[Options]

func WithSourceAppendDriver

func WithSourceAppendDriver(sourceAppendDriver bool) opts.Opt[Options]

func WithXMigrationsTable

func WithXMigrationsTable(xMigrationsTable string) opts.Opt[Options]

Types

type Migrator

type Migrator interface {
	// Up looks at the currently active migration version
	// and will migrate all the way up (default applying all up migrations).
	Up(steps ...uint) error

	// Down looks at the currently active migration version
	// and will migrate all the way down (default applying all down migrations).
	Down(steps ...uint) error

	// Goto looks at the currently active migration version,
	// then migrates either up or down to the specified version.
	Goto(version uint) error

	// Force sets a migration version and clears the dirty state without
	// running migrations.
	Force(version int) error

	// Version returns the currently active migration version.
	// If no migration has been applied, yet, it will return ErrNilVersion.
	Version() (version uint, dirty bool, err error)

	// Close source and database, return source error and database error
	Close() (error, error)
}

func New

func New(sqlConf sqlx.SqlConf, op ...opts.Opt[Options]) (Migrator, error)

type Options

type Options struct {
	Source             string
	SourceAppendDriver bool
	XMigrationsTable   string
}

func (Options) DefaultOptions

func (d Options) DefaultOptions() Options

type SQLConfigLoader

type SQLConfigLoader func(configPath string) (sqlx.SqlConf, error)

Jump to

Keyboard shortcuts

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