goose: Index | Files

package goose

import ""


Package Files

dbconf.go dialect.go migrate.go migration_go.go migration_sql.go util.go


var (
    ErrTableDoesNotExist = errors.New("table does not exist")
    ErrNoPreviousVersion = errors.New("no previous version found")

func CreateMigration Uses

func CreateMigration(name, migrationType, dir string, t time.Time) (path string, err error)

func EnsureDBVersion Uses

func EnsureDBVersion(conf *DBConf, db *sql.DB) (int64, error)

retrieve the current version for this DB. Create and initialize the DB version table if it doesn't exist.

func FinalizeMigration Uses

func FinalizeMigration(conf *DBConf, txn *sql.Tx, direction bool, v int64) error

Update the version table for the given migration, and finalize the transaction.

func GetDBVersion Uses

func GetDBVersion(conf *DBConf) (version int64, err error)

wrapper for EnsureDBVersion for callers that don't already have their own DB instance

func GetMostRecentDBVersion Uses

func GetMostRecentDBVersion(dirpath string) (version int64, err error)

helper to identify the most recent possible version within a folder of migration scripts

func GetPreviousDBVersion Uses

func GetPreviousDBVersion(dirpath string, version int64) (previous int64, err error)

func NumericComponent Uses

func NumericComponent(name string) (int64, error)

look for migration scripts with names in the form:


where XXX specifies the version number and ext specifies the type of migration

func OpenDBFromDBConf Uses

func OpenDBFromDBConf(conf *DBConf) (*sql.DB, error)

OpenDBFromDBConf wraps database/sql.DB.Open() and configures the newly opened DB based on the given DBConf.

Callers must Close() the returned DB.

func RunMigrations Uses

func RunMigrations(conf *DBConf, migrationsDir string, target int64) (err error)

func RunMigrationsOnDb Uses

func RunMigrationsOnDb(conf *DBConf, migrationsDir string, target int64, db *sql.DB) (err error)

Runs migration on a specific database instance.

type DBConf Uses

type DBConf struct {
    MigrationsDir string
    Env           string
    Driver        DBDriver
    PgSchema      string

func NewDBConf Uses

func NewDBConf(p, env string, pgschema string) (*DBConf, error)

extract configuration details from the given file

type DBDriver Uses

type DBDriver struct {
    Name    string
    OpenStr string
    Import  string
    Dialect SqlDialect

DBDriver encapsulates the info needed to work with a specific database driver

func (*DBDriver) IsValid Uses

func (drv *DBDriver) IsValid() bool

ensure we have enough info about this driver

type Migration Uses

type Migration struct {
    Version  int64
    Next     int64  // next version, or -1 if none
    Previous int64  // previous version, -1 if none
    Source   string // path to .go or .sql script

func CollectMigrations Uses

func CollectMigrations(dirpath string, current, target int64) (m []*Migration, err error)

collect all the valid looking migration scripts in the migrations folder, and key them by version

type MigrationRecord Uses

type MigrationRecord struct {
    VersionId int64
    TStamp    time.Time
    IsApplied bool // was this a result of up() or down()

type MySqlDialect Uses

type MySqlDialect struct{}

type PostgresDialect Uses

type PostgresDialect struct{}

type SqlDialect Uses

type SqlDialect interface {
    // contains filtered or unexported methods

SqlDialect abstracts the details of specific SQL dialects for goose's few SQL specific statements

type Sqlite3Dialect Uses

type Sqlite3Dialect struct{}

Package goose imports 22 packages (graph) and is imported by 65 packages. Updated 2019-09-23. Refresh now. Tools for package owners.