migrate

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTable = "schema_migrations"

Variables

This section is empty.

Functions

func ParseMigrationFileName

func ParseMigrationFileName(filename, dialect string) (version int, name string, direction string, ok bool)

Types

type Engine

type Engine struct {
	DB      db.Adapter
	Table   string
	Dialect string
}

Engine runs migration operations using a DB adapter.

func NewEngine

func NewEngine(adapter db.Adapter, dialect string) *Engine

func (*Engine) Down

func (e *Engine) Down(ctx context.Context, migrations []Migration, steps int) (int, error)

func (*Engine) Status

func (e *Engine) Status(ctx context.Context, migrations []Migration) ([]Status, error)

func (*Engine) Up

func (e *Engine) Up(ctx context.Context, migrations []Migration, steps int) (int, error)

type GeneratedMigration

type GeneratedMigration struct {
	Version  int
	Name     string
	UpPath   string
	DownPath string
	UpSQL    string
	DownSQL  string
}

GeneratedMigration holds generated migration metadata and SQL.

func GenerateFromModelFiles

func GenerateFromModelFiles(dir, dialect, name string, modelFiles []string) (GeneratedMigration, error)

GenerateFromModelFiles parses model structs from Go files and writes migration SQL files.

Exported struct types become tables. Fields and column options are inferred from `orm` tags using the same rules as orm.BuildCreateTableSQL.

type Migration

type Migration struct {
	Version int
	Name    string
	UpSQL   string
	DownSQL string
}

Migration is a single versioned SQL migration pair.

func Load

func Load(dir, dialect string) ([]Migration, error)

Load reads migrations from dir. Supported files: - 0001_init.up.sql - 0001_init.down.sql - 0001_init.pg.up.sql (dialect-specific)

type Status

type Status struct {
	Version int
	Name    string
	Applied bool
}

Status represents migration state in DB.

Jump to

Keyboard shortcuts

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