migrator

package module
v0.0.0-...-7acf401 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2019 License: MIT Imports: 14 Imported by: 0

README

Flow Migrator

Database Migrations for Go made simple
Evolve your database schema easily and reliably accross all your instances and environments.

Simple, focused and powerful.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// MigrationsTableName holds default table name for migrations
	//
	// Default value is "schema_migration"
	MigrationsTableName = "schema_migration"
)

Functions

This section is empty.

Types

type FileMigrator

type FileMigrator struct {
	Migrator
	Path string
}

FileMigrator is Migrator implementation for SQL files stored on file system

func NewFileMigrator

func NewFileMigrator(path string, dialect string, db db.Store) FileMigrator

NewFileMigrator - creates Migrations for files

type Migration

type Migration struct {

	//Version of the migration
	//
	// for example 2`018051570142`
	Version string

	// Name of the migration
	//
	// for exmample `initial`
	Name string

	// Direction of the migration
	//
	// for example `up`
	Direction string

	// Content of migration
	//
	// Content holds migration SQL query
	Content string
}

Migration handles data for a given database migration

func (Migration) Run

func (m Migration) Run(conn db.Store) error

Run executes the migration.

Returns error if Content is not defined, and returns result from SQL execution (error)

type Migrations

type Migrations []Migration

Migrations collection

func (Migrations) Len

func (m Migrations) Len() int

Len returns number of migrations

func (Migrations) Less

func (m Migrations) Less(i, j int) bool

Less checks if migration version at index i is lesss than migration at index j

func (Migrations) Swap

func (m Migrations) Swap(i, j int)

Swap migrations at index i and j

type Migrator

type Migrator struct {
	Migrations map[string]Migrations
	// contains filtered or unexported fields
}

Migrator forms the basis of all migration systems.Migrator it does the actual heavy lifting of running migrations

func (Migrator) Down

func (m Migrator) Down(step int) error

Down runs pending `down` migrations and rolls back the database by the specified number of steps

func (Migrator) Reset

func (m Migrator) Reset() error

Reset executes all `down` migrations followed by the `up` migrations

func (Migrator) Status

func (m Migrator) Status() error

Status prints out the status of applied/Pending migrations

func (Migrator) Up

func (m Migrator) Up() error

Up runs pending `up` migrations and applies them to the database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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