Documentation ¶
Index ¶
- type Config
- type ConfirmCB
- type Logger
- type PQMigrate
- func (ctx *PQMigrate) CreateDB(cb ConfirmCB) error
- func (ctx *PQMigrate) CreateMigration(name string) error
- func (ctx *PQMigrate) DropDB(cb ConfirmCB) error
- func (ctx *PQMigrate) DumpDBFull(fname *string) error
- func (ctx *PQMigrate) DumpDBFullWithPath(fname *string) (string, error)
- func (ctx *PQMigrate) DumpDBSchema() ([]byte, error)
- func (ctx *PQMigrate) DumpDBSchemaToFile(fname *string) error
- func (ctx *PQMigrate) DumpDBSchemaToFileWithName(schemaName, migrationsName string) error
- func (ctx *PQMigrate) Finish() error
- func (ctx *PQMigrate) LoadDBSchema(schemaName string, cb ConfirmCB) error
- func (ctx *PQMigrate) LoadFullDump(dumpName string) error
- func (ctx *PQMigrate) MigrateDown(steps int) error
- func (ctx *PQMigrate) MigrateDownFile(fileName string) error
- func (ctx *PQMigrate) MigrateFromFile(fileName string) error
- func (ctx *PQMigrate) MigrateUp(steps int) error
- func (ctx *PQMigrate) MigrateUpFile(fileName string) error
- func (ctx *PQMigrate) Replace(fileName string, cb ConfirmCB) error
- func (ctx *PQMigrate) Squash(cb ConfirmCB) error
- func (ctx *PQMigrate) Sync(cb ConfirmCB) error
- func (ctx *PQMigrate) UnSquash(cb ConfirmCB) 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 FS *embed.FS // Support for embedded migrations in application 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 PQMigrate ¶ added in v1.0.0
type PQMigrate struct {
// contains filtered or unexported fields
}
PQMigrate utility for managing common postgresql operations
func (*PQMigrate) CreateDB ¶ added in v1.0.0
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
CreateMigration creates a new migration file with specified name
func (*PQMigrate) DropDB ¶ added in v1.0.0
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
DumpDBFull dumps database schema and content to a file named `dump_<timestamp-unix>.sql`
func (*PQMigrate) DumpDBFullWithPath ¶ added in v1.4.0
func (*PQMigrate) DumpDBSchema ¶ added in v1.0.0
DumpDBSchema dumps the database schema without owner information.
func (*PQMigrate) DumpDBSchemaToFile ¶ added in v1.0.0
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
DumpDBSchemaToFileWithName calls `DumpDBSchema` and writes output to specified file.
func (*PQMigrate) Finish ¶ added in v1.0.0
Finish commits lingering database transaction (if all in one transaction specified) and closes database handle.
func (*PQMigrate) LoadDBSchema ¶ added in v1.0.0
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
LoadFullDump loads database schema and data from specified file into the given database.
func (*PQMigrate) MigrateDown ¶ added in v1.0.0
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) MigrateDownFile ¶ added in v1.2.0
MigrateDownFile applies specified `down` migration and deletes both `up` and `down` from migrations table.
func (*PQMigrate) MigrateFromFile ¶ added in v1.0.0
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
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) MigrateUpFile ¶ added in v1.2.0
MigrateUpFile applies specified `up` migration and inserts both `up` and `down` into the migrations table.
func (*PQMigrate) Replace ¶ added in v1.1.0
Replace tries to replace a specified migration in the database without running the migration itself. Useful for if a broken `down` migration has found its way into the db and needs to be replaced.
func (*PQMigrate) Squash ¶ added in v1.3.0
Squash takes all migrations present on fs and squashes them into one file. Usable to reduce clutter.