pqmigrate

package module
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2019 License: MIT Imports: 17 Imported by: 0

README

pqmigrate

FOSSA Status

Migration utility for postgres databases

License

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AllInOneTx      bool   // Perform all database operations in the same transaction
	BaseDirectory   string // Directory where the sql files are stored
	DBUrl           string // Postgresql url `psql://<user>:<pwd>@<host>:<port>/<db_name>`
	Logger          Logger // If set the logger will be used instead of standard out
	MigrationsTable string // Name of migrations table in database
	Debug           bool   // Show debug info
	DryRun          bool   // Perform all database operations but don't commit
}

Config options for the library

type ConfirmCB

type ConfirmCB func(prompt string) bool

ConfirmCB simple confirm function for potentially dangerous operations. if return value is true the operation will be performed, else abort.

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
	Warn(args ...interface{})
	Print(args ...interface{})
	Error(args ...interface{})
	Inf(args ...interface{})
	DBG(args ...interface{})
	Ok(args ...interface{})
}

Logger interface for using other loggers than stdout.

type PQMigrate added in v1.0.0

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

PQMigrate utility for managing common postgresql operations

func New

func New(config Config) *PQMigrate

New creates a new PQMigrate instance.

func (*PQMigrate) CreateDB added in v1.0.0

func (ctx *PQMigrate) CreateDB(cb ConfirmCB) error

CreateDB ensures that the database specified in the postgres url exists. If not it creates it. This probably won't work if you don't have full access to the postgres server.

func (*PQMigrate) CreateMigration added in v1.0.0

func (ctx *PQMigrate) CreateMigration(name string) error

CreateMigration creates a new migration file with specified name

func (*PQMigrate) DropDB added in v1.0.0

func (ctx *PQMigrate) DropDB(cb ConfirmCB) error

DropDB drops the database specified in the postgres url. This probably won't work if you don't have full access to the postgres server.

func (*PQMigrate) DumpDBFull added in v1.0.0

func (ctx *PQMigrate) DumpDBFull(fname *string) error

DumpDBFull dumps database schema and content to a file named `dump_<timestamp-unix>.sql`

func (*PQMigrate) DumpDBSchema added in v1.0.0

func (ctx *PQMigrate) DumpDBSchema() ([]byte, error)

DumpDBSchema dumps the database schema without owner information.

func (*PQMigrate) DumpDBSchemaToFile added in v1.0.0

func (ctx *PQMigrate) DumpDBSchemaToFile(fname *string) error

DumpDBSchemaToFile dumps database schema and performed database migrations to files named `schema_<timestamp-unix>.sql` and `migrations_<timestamp-unix>.sql`.

func (*PQMigrate) DumpDBSchemaToFileWithName added in v1.0.0

func (ctx *PQMigrate) DumpDBSchemaToFileWithName(schemaName, migrationsName string) error

DumpDBSchemaToFileWithName calls `DumpDBSchema` and writes output to specified file.

func (*PQMigrate) Finish added in v1.0.0

func (ctx *PQMigrate) Finish() error

Finish commits lingering database transaction (if all in one transaction specified) and closes database handle.

func (*PQMigrate) LoadDBSchema added in v1.0.0

func (ctx *PQMigrate) LoadDBSchema(schemaName string, cb ConfirmCB) error

LoadDBSchema loads specified schema and inserts migrations from matching migrations file if found next to the schema sql.

func (*PQMigrate) LoadFullDump added in v1.0.0

func (ctx *PQMigrate) LoadFullDump(dumpName string) error

func (*PQMigrate) MigrateDown added in v1.0.0

func (ctx *PQMigrate) MigrateDown(steps int) error

MigrateDown applies `down` migrations from migration dir in order. `steps` are number of migrations to perform. If steps == -1 all `down` migrations will be applied.

func (*PQMigrate) MigrateFromFile added in v1.0.0

func (ctx *PQMigrate) MigrateFromFile(fileName string) error

MigrateFromFile loads the specified file and does a direct migration without modifying the migrations table. Useful for database schema and database seeds.

func (*PQMigrate) MigrateUp added in v1.0.0

func (ctx *PQMigrate) MigrateUp(steps int) error

MigrateUp applies `up` migrations from migration dir in order. `steps` are number of migrations to perform. If steps == -1 all `up` migrations will be applied.

func (*PQMigrate) Sync added in v1.0.0

func (ctx *PQMigrate) Sync(cb ConfirmCB) error

Sync tries to synchronize db and fs state by first checking if any migrations have changed on fs, then finding migrations that exist in db but not in fs. The last step is to apply all migrations that only only exist in fs.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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