package module
v0.0.0-...-1d76b18 Latest Latest

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 16 Imported by: 7



Goose is a database migration tool. Manage your database's evolution by creating incremental SQL files or Go functions.

This fork

This is a fork of with some customizations for working with Fleet.

This should be used through the make migration command in Fleet.




This section is empty.


View Source
var (
	ErrNoCurrentVersion = errors.New("no current version found")
	ErrNoNextVersion    = errors.New("no next version found")


func AddMigration

func AddMigration(up func(*sql.Tx) error, down func(*sql.Tx) error)

AddMigration exists for legacy support of the package global use of Goose. Calling the AddMigration method on a Goose struct is the preferred method.

func Create

func Create(db *sql.DB, dir, name, migrationType string) error

Create writes a new blank migration file.

func CreateMigration

func CreateMigration(name, migrationType, dir string, t time.Time) ([]string, error)

func NumericComponent

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 Run

func Run(command string, db *sql.DB, dir string, args ...string) error

func SetDialect

func SetDialect(d string) error


type Client

type Client struct {
	// TableName is the name of the table used to store migration status
	// for this client.
	TableName string
	// Dialect is the SqlDialect to use.
	Dialect SqlDialect
	// Migrations is the list of migrations.
	Migrations Migrations

Client stores the migration state and preferences. Prefer interacting with the Goose API through a Client struct created with New rather than using the global Client and functions.

func New

func New(tableName string, dialect SqlDialect) *Client

func (*Client) AddMigration

func (c *Client) AddMigration(up func(*sql.Tx) error, down func(*sql.Tx) error)

AddMigration adds a new go migration to the goose struct.

func (*Client) Down

func (c *Client) Down(db *sql.DB, dir string) error

func (*Client) FinalizeMigration

func (c *Client) FinalizeMigration(tx *sql.Tx, direction bool, v int64) error

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

func (*Client) GetDBVersion

func (c *Client) GetDBVersion(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 (*Client) Redo

func (c *Client) Redo(db *sql.DB, dir string) error

func (*Client) SetDialect

func (c *Client) SetDialect(d string) error

func (*Client) Status

func (c *Client) Status(db *sql.DB, dir string) error

func (*Client) Up

func (c *Client) Up(db *sql.DB, dir string) error

func (*Client) UpByOne

func (c *Client) UpByOne(db *sql.DB, dir string) error

func (*Client) Version

func (c *Client) Version(db *sql.DB, dir string) error

type Migration

type Migration struct {
	Version  int64
	Next     int64               // next version, or -1 if none
	Previous int64               // previous version, -1 if none
	Source   string              // path to .sql script
	UpFn     func(*sql.Tx) error // Up go migration function
	DownFn   func(*sql.Tx) error // Down go migration function

func (*Migration) String

func (m *Migration) String() string

type MigrationRecord

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

type Migrations

type Migrations []*Migration

func (Migrations) Current

func (ms Migrations) Current(current int64) (*Migration, error)

func (Migrations) Last

func (ms Migrations) Last() (*Migration, error)

func (Migrations) Len

func (ms Migrations) Len() int

helpers so we can use pkg sort

func (Migrations) Less

func (ms Migrations) Less(i, j int) bool

func (Migrations) Next

func (ms Migrations) Next(current int64) (*Migration, error)

func (Migrations) String

func (ms Migrations) String() string

func (Migrations) Swap

func (ms Migrations) Swap(i, j int)

type MySqlDialect

type MySqlDialect struct{}

type PostgresDialect

type PostgresDialect struct{}

type SqlDialect

type SqlDialect interface {
	// contains filtered or unexported methods

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

func GetDialect

func GetDialect() SqlDialect

type Sqlite3Dialect

type Sqlite3Dialect struct{}


Path Synopsis

Jump to

Keyboard shortcuts

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