migrate

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2018 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Simple PostgreSQL migrator

CircleCI

  • up / down migrations
  • list of applied migrations
  • list of planned migrations
  • version (number) of latest applied migration
  • version (name) of latest applied migration

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoDB set to Options
	ErrNoDB = fmt.Errorf("no db")
	// 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

func SetTableName

func SetTableName(name string)

SetTableName for migrations

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 Logger

type Logger interface {
	Infof(format string, args ...interface{})
}

Logger interface for migrator

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)
	VersionName() (string, 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
}

Options for migrator

Jump to

Keyboard shortcuts

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