dbmigrator

package module
v0.0.0-...-2a89022 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2015 License: MIT Imports: 9 Imported by: 0

README

go-dbmigrator

Yet another database migrator for Go.

Documentation

Overview

Package dbmigrator is yet another library to migrate database schemas.

It saves the current migration version directly in the database. There is also support for the go-bindata program.

Index

Constants

This section is empty.

Variables

View Source
var ErrCorruptDatabase = errors.New("failed to retrieve migration version from setting table (database not empty)")

ErrCorruptDatabase is returned when the setting table does not have the migration_version key or another database error occured while retrieving the migration version.

View Source
var ErrNoMigrationFiles = errors.New("migration directory does not contain any valid migration files")

ErrNoMigrationFiles is returned when there are no files in the directory that match the required filename pattern.

Functions

This section is empty.

Types

type MigrationConfig

type MigrationConfig struct {
	Asset                       func(name string) ([]byte, error)
	AssetDir                    func(name string) ([]string, error)
	AssetInfo                   func(name string) (os.FileInfo, error)
	DataSourceName              string
	DriverName                  string
	MigrationsPath              string
	Quiet                       bool
	SettingTableCreateStatement string
}

MigrationConfig contains the configuration for the migrator. The use of Asset, AssetDir and AssetInfo functions is optional, but if you set a value for either of them, you have to set values for all of them. If you leave SettingTableCreateStatement empty, the default create statement will be used.

type Migrator

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

Migrator contains the migrations to apply to the database.

func NewMigrator

func NewMigrator(config MigrationConfig) (Migrator, error)

NewMigrator returns a new migrator. It reads all migrations (files) in the migration path that match the "YYYY-MM-DD hhmmss *.sql" filename format and sorts them.

func (*Migrator) Migrate

func (m *Migrator) Migrate() error

Migrate applies all new migrations to the database. After each successful migration it will update the "migration_version" key in the setting table to the corresponding migration version. If there is an error while applying a migration, the operation is canceled (but not rolled back).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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