migrate

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2014 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UNIQUE int = iota
	PRIMARYKEY
	AUTOINCREMENT
	NULL
	NOTNULL
)

Variables

View Source
var AddGitlabColumns = &rev20140328201430{}
View Source
var AddOpenInvitationColumn = &rev20140310104446{}
View Source
var GitHubEnterpriseSupport = &Rev3{}
View Source
var RenamePrivelegedToPrivileged = &Rev1{}
View Source
var SaveDroneYml = &rev20140522205400{}
View Source
var SetupIndices = &rev2nd{}
View Source
var SetupTables = &rev1st{}

Functions

This section is empty.

Types

type DriverBuilder added in v0.2.1

type DriverBuilder func(tx *sql.Tx) *MigrationDriver

DriverBuilder is a constructor for MigrationDriver

var Driver DriverBuilder

type Migration

type Migration struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB) *Migration

func (*Migration) Add

func (m *Migration) Add(rev ...Revision) *Migration

Add the Revision to the list of migrations.

func (*Migration) All

func (m *Migration) All() *Migration

All is called to collect all migration scripts and adds them to Revision list. New Revision should be added here ordered by its revision number.

func (*Migration) Migrate

func (m *Migration) Migrate() error

Migrate executes the full list of migrations.

func (*Migration) MigrateTo

func (m *Migration) MigrateTo(target int64) error

MigrateTo executes all database migration until you are at the specified revision number. If the revision number is less than the current revision, then we will downgrade.

type MigrationDriver

type MigrationDriver struct {
	Operation
	T  *columnType
	Tx *sql.Tx
}

MigrationDriver drives migration script by injecting transaction object (*sql.Tx), `Operation` implementation and column type helper.

func MySQL added in v0.2.1

func MySQL(tx *sql.Tx) *MigrationDriver

func PostgreSQL added in v0.2.1

func PostgreSQL(tx *sql.Tx) *MigrationDriver

func SQLite

func SQLite(tx *sql.Tx) *MigrationDriver

type Operation

type Operation interface {

	// CreateTable may be used to create a table named `tableName`
	// with its columns specification listed in `args` as an array of string
	CreateTable(tableName string, args []string) (sql.Result, error)

	// RenameTable simply rename table from `tableName` to `newName`
	RenameTable(tableName, newName string) (sql.Result, error)

	// DropTable drops table named `tableName`
	DropTable(tableName string) (sql.Result, error)

	// AddColumn adds single new column to `tableName`, columnSpec is
	// a standard column definition (column name included) which may looks like this:
	//
	//     mg.AddColumn("example", "email VARCHAR(255) UNIQUE")
	//
	// it's equivalent to:
	//
	//     mg.AddColumn("example", mg.T.String("email", UNIQUE))
	//
	AddColumn(tableName, columnSpec string) (sql.Result, error)

	// ChangeColumn may be used to change the type of a column
	// `newType` should always specify the column's new type even
	// if the type is not meant to be change. Eg.
	//
	//     mg.ChangeColumn("example", "name", "VARCHAR(255) UNIQUE")
	//
	ChangeColumn(tableName, columnName, newType string) (sql.Result, error)

	// DropColumns drops a list of columns
	DropColumns(tableName string, columnsToDrop ...string) (sql.Result, error)

	// RenameColumns will rename columns listed in `columnChanges`
	RenameColumns(tableName string, columnChanges map[string]string) (sql.Result, error)

	// AddIndex adds index on `tableName` indexed by `columns`
	AddIndex(tableName string, columns []string, flags ...string) (sql.Result, error)

	// DropIndex drops index indexed by `columns` from `tableName`
	DropIndex(tableName string, columns []string) (sql.Result, error)
}

Operation interface covers basic migration operations. Implementation details is specific for each database, see migrate/sqlite.go for implementation reference.

type Rev1

type Rev1 struct{}

func (*Rev1) Down

func (r *Rev1) Down(mg *MigrationDriver) error

func (*Rev1) Revision

func (r *Rev1) Revision() int64

func (*Rev1) Up

func (r *Rev1) Up(mg *MigrationDriver) error

type Rev3

type Rev3 struct{}

func (*Rev3) Down

func (r *Rev3) Down(mg *MigrationDriver) error

func (*Rev3) Revision

func (r *Rev3) Revision() int64

func (*Rev3) Up

func (r *Rev3) Up(mg *MigrationDriver) error

type Revision

type Revision interface {
	Up(mg *MigrationDriver) error
	Down(mg *MigrationDriver) error
	Revision() int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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