pgmgr

package
v0.0.0-...-d2b24f2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DOWN = iota
	UP
)

Migration directions

View Source
const (
	MIGRATION = "migration"
	ROLLBACK  = "rollback"
)

Migration directions used for error message building

Variables

This section is empty.

Functions

func Create

func Create(c *Config) error

Create creates the database specified by the configuration.

func CreateMigration

func CreateMigration(c *Config, name string, noTransaction bool) error

CreateMigration generates new, empty migration files.

func Drop

func Drop(c *Config) error

Drop drops the database specified by the configuration.

func Dump

func Dump(c *Config) error

Dump dumps the schema and contents of the database to the dump file.

func Initialize

func Initialize(c *Config) error

Initialize creates the schema_migrations table if necessary.

func Load

func Load(c *Config) error

Load loads the database from the dump file using psql.

func LoadConfig

func LoadConfig(config *Config, ctx argumentContext) error

LoadConfig reads the config file, applies CLI arguments as overrides, and returns an error if the configuration is invalid.

func Migrate

func Migrate(c *Config) error

Migrate applies un-applied migrations in the specified MigrationFolder.

func Rollback

func Rollback(c *Config) error

Rollback un-applies the latest migration, if possible.

func Version

func Version(c *Config) (int64, error)

Version returns the highest version number stored in the database. This is not necessarily enough info to uniquely identify the version, since there may be backdated migrations which have not yet applied.

Types

type Config

type Config struct {
	// connection
	Username string
	Password string
	Database string
	Host     string
	Port     int
	URL      string
	SslMode  string

	// filepaths
	DumpFile        string `json:"dump-file"`
	MigrationFolder string `json:"migration-folder"`

	// options
	MigrationTable string   `json:"migration-table"`
	SeedTables     []string `json:"seed-tables"`
	ColumnType     string   `json:"column-type"`
	Format         string
}

Config stores the options used by pgmgr.

type Migration

type Migration struct {
	Filename string
	Version  int64
}

Migration stores a single migration's version and filename.

func (Migration) WrapInTransaction

func (m Migration) WrapInTransaction() bool

WrapInTransaction returns whether the migration should be run within a transaction.

Jump to

Keyboard shortcuts

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