Documentation
¶
Index ¶
- type Config
- type ConfirmCB
- type Logger
- type PGMigrate
- func (ctx *PGMigrate) CreateDB(cb ConfirmCB) error
- func (ctx *PGMigrate) CreateMigration(name string) error
- func (ctx *PGMigrate) DropDB(cb ConfirmCB) error
- func (ctx *PGMigrate) DumpDBFull(fname *string) error
- func (ctx *PGMigrate) DumpDBSchema() ([]byte, error)
- func (ctx *PGMigrate) DumpDBSchemaToFile(fname *string) error
- func (ctx *PGMigrate) DumpDBSchemaToFileWithName(schemaName, migrationsName string) error
- func (ctx *PGMigrate) Finish() error
- func (ctx *PGMigrate) LoadDBSchema(schemaName string, cb ConfirmCB) error
- func (ctx *PGMigrate) LoadFullDump(dumpName string) error
- func (ctx *PGMigrate) MigrateDown(steps int) error
- func (ctx *PGMigrate) MigrateFromFile(fileName string) error
- func (ctx *PGMigrate) MigrateUp(steps int) error
- func (ctx *PGMigrate) Sync() error
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 ¶
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 PGMigrate ¶
type PGMigrate struct {
// contains filtered or unexported fields
}
PGMigrate utility for managing common postgresql operations
func (*PGMigrate) CreateDB ¶
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 (*PGMigrate) CreateMigration ¶
CreateMigration creates a new migration file with specified name
func (*PGMigrate) DropDB ¶
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 (*PGMigrate) DumpDBFull ¶
DumpDBFull dumps database schema and content to a file named `dump_<timestamp-unix>.sql`
func (*PGMigrate) DumpDBSchema ¶
DumpDBSchema dumps the database schema without owner information.
func (*PGMigrate) DumpDBSchemaToFile ¶
DumpDBSchemaToFile dumps database schema and performed database migrations to files named `schema_<timestamp-unix>.sql` and `migrations_<timestamp-unix>.sql`.
func (*PGMigrate) DumpDBSchemaToFileWithName ¶
DumpDBSchemaToFileWithName calls `DumpDBSchema` and writes output to specified file.
func (*PGMigrate) Finish ¶
Finish commits lingering database transaction (if all in one transaction specified) and closes database handle.
func (*PGMigrate) LoadDBSchema ¶
LoadDBSchema loads specified schema and inserts migrations from matching migrations file if found next to the schema sql.
func (*PGMigrate) LoadFullDump ¶
func (*PGMigrate) MigrateDown ¶
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 (*PGMigrate) MigrateFromFile ¶
MigrateFromFile loads the specified file and does a direct migration without modifying the migrations table. Useful for database schema and database seeds.
func (*PGMigrate) MigrateUp ¶
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.