migrate

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoDB set to Options
	ErrNoDB = fmt.Errorf("no db")
	// ErrNoLogger set to Options
	ErrNoLogger = fmt.Errorf("no logger")
	// ErrDirNotExists when migration path not exists
	ErrDirNotExists = fmt.Errorf("migrations dir not exists")
	// ErrBothMigrateTypes when up or down migration file not found
	ErrBothMigrateTypes = errors.New("migration must have up and down files")
	// ErrPositiveSteps when steps < 0
	ErrPositiveSteps = errors.New("steps must be a positive number")
)

Functions

func CreateMigration

func CreateMigration(folder, name string) error

CreateMigration files

Types

type DB

type DB interface {
	RunInTransaction(fn func(*pg.Tx) error) error
	Exec(query interface{}, params ...interface{}) (orm.Result, error)
	ExecOne(query interface{}, params ...interface{}) (orm.Result, error)
	Query(model, query interface{}, params ...interface{}) (orm.Result, error)
	QueryOne(model, query interface{}, params ...interface{}) (orm.Result, error)
}

DB interface

type Migration

type Migration struct {
	Version   int64
	Name      string
	CreatedAt time.Time
	Up        func(DB) error
	Down      func(DB) error
}

Migration item

func (Migration) RealName

func (m Migration) RealName() string

RealName return formatted filename

type Migrations

type Migrations []*Migration

Migrations slice

type Migrator

type Migrator interface {
	Up(steps int) error
	Down(steps int) error
	List() (Migrations, error)
	Plan() (Migrations, error)
	Version() (int64, error)
}

Migrator interface

func New

func New(opts Options) (Migrator, error)

New creates new Migrator

type Options

type Options struct {
	// DB connection
	DB DB
	// Path to migrations files
	Path string
	// Logger
	Logger logger.Logger
}

Options for migrator

Jump to

Keyboard shortcuts

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