Pkg.go.dev is a new destination for Go discovery & docs. Check it out at pkg.go.dev/github.com/felixge/pgmigrate and share your feedback.

package pgmigrate

import "github.com/felixge/pgmigrate"

Package pgmigrate implements a minimalistic migration library for postgres. See README for more information.

pgmigrate.go

❖ var DefaultConfig = Config{ Schema: "migrations", Table: "migrations", }

DefaultConfig should be used by most users.

❖ type Config struct { // Schema is the name of the postgres schema the migrations table is stored in. Schema string // Table is the name of the migrations table. Table string }

Config allows to customize pgmigrate. However, most users should use the DefaultConfig.

❖ func (c *Config) Migrate(db *sql.DB, ms Migrations) (Migrations, error)

Migrate validates ms, and on success applies any ms that has not already been executed. The return value is either an error, or a list of all migrations that were applied.

❖ type Migration struct { ID int Description string SQL string }

Migration holds a migration

Valid returns an error if the migration is invalid.

❖ type Migrations []Migration

Migrations holds a list of migrations sorted by id. The first migration needs to have ID 1, and each following ID has to be incremented by 1.

LoadMigrations loads all migration files named {{id}}_{{description}}.sql inside dirFS and returns them or an error. The returned Migrations are guaranteed to be sorted, but no validated.

Len is part of the sort.Interface.

❖ func (m Migrations) Less(i, j int) bool

Less is part of the sort.Interface.

❖ func (m Migrations) Swap(i, j int)

Swap is part of the sort.Interface.

Valid returns an error if m holds an invalid migration list.

Package pgmigrate imports 8 packages (graph). Updated 2017-12-01. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).