Documentation ¶
Index ¶
- Constants
- Variables
- func AddMigration(up, down GoMigration)
- func AddMigrationContext(up, down GoMigrationContext)
- func AddMigrationNoTx(up, down GoMigrationNoTx)
- func AddMigrationNoTxContext(up, down GoMigrationNoTxContext)
- func AddNamedMigration(filename string, up, down GoMigration)
- func AddNamedMigrationContext(filename string, up, down GoMigrationContext)
- func AddNamedMigrationNoTx(filename string, up, down GoMigrationNoTx)
- func AddNamedMigrationNoTxContext(filename string, up, down GoMigrationNoTxContext)
- func Create(db *sql.DB, dir, name, migrationType string) error
- func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, migrationType string) error
- func Down(db *sql.DB, dir string, opts ...OptionsFunc) error
- func DownContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func DownTo(db *sql.DB, dir string, version int64, opts ...OptionsFunc) error
- func DownToContext(ctx context.Context, db *sql.DB, dir string, version int64, ...) error
- func EnsureDBVersion(db *sql.DB) (int64, error)
- func EnsureDBVersionContext(ctx context.Context, db *sql.DB) (int64, error)
- func Fix(dir string) error
- func GetDBVersion(db *sql.DB) (int64, error)
- func GetDBVersionContext(ctx context.Context, db *sql.DB) (int64, error)
- func NumericComponent(name string) (int64, error)
- func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error)
- func Redo(db *sql.DB, dir string, opts ...OptionsFunc) error
- func RedoContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func Reset(db *sql.DB, dir string, opts ...OptionsFunc) error
- func ResetContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func Run(command string, db *sql.DB, dir string, args ...string) error
- func RunContext(ctx context.Context, command string, db *sql.DB, dir string, args ...string) error
- func RunWithOptions(command string, db *sql.DB, dir string, args []string, options ...OptionsFunc) error
- func RunWithOptionsContext(ctx context.Context, command string, db *sql.DB, dir string, args []string, ...) error
- func SetBaseFS(fsys fs.FS)
- func SetDialect(s string) error
- func SetLogger(l Logger)
- func SetSequential(s bool)
- func SetTableName(n string)
- func SetVerbose(v bool)
- func Status(db *sql.DB, dir string, opts ...OptionsFunc) error
- func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func TableName() string
- func Up(db *sql.DB, dir string, opts ...OptionsFunc) error
- func UpByOne(db *sql.DB, dir string, opts ...OptionsFunc) error
- func UpByOneContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func UpContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- func UpTo(db *sql.DB, dir string, version int64, opts ...OptionsFunc) error
- func UpToContext(ctx context.Context, db *sql.DB, dir string, version int64, ...) error
- func Version(db *sql.DB, dir string, opts ...OptionsFunc) error
- func VersionContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsFunc) error
- type GoMigration
- type GoMigrationContext
- type GoMigrationNoTx
- type GoMigrationNoTxContext
- type Logger
- type Migration
- type MigrationRecord
- type Migrations
- func (ms Migrations) Current(current int64) (*Migration, error)
- func (ms Migrations) Last() (*Migration, error)
- func (ms Migrations) Len() int
- func (ms Migrations) Less(i, j int) bool
- func (ms Migrations) Next(current int64) (*Migration, error)
- func (ms Migrations) Previous(current int64) (*Migration, error)
- func (ms Migrations) String() string
- func (ms Migrations) Swap(i, j int)
- type OptionsFunc
Constants ¶
const VERSION = "v3.2.0"
Deprecated: VERSION will no longer be supported in v4.
Variables ¶
var ( // ErrNoMigrationFiles when no migration files have been found. ErrNoMigrationFiles = errors.New("no migration files found") // ErrNoCurrentVersion when a current migration version is not found. ErrNoCurrentVersion = errors.New("no current version found") // ErrNoNextVersion when the next migration version is not found. ErrNoNextVersion = errors.New("no next version found") // MaxVersion is the maximum allowed version. MaxVersion int64 = math.MaxInt64 )
Functions ¶
func AddMigrationContext ¶
func AddMigrationContext(up, down GoMigrationContext)
AddMigrationContext adds Go migrations.
func AddMigrationNoTx ¶
func AddMigrationNoTx(up, down GoMigrationNoTx)
AddMigrationNoTx adds Go migrations that will be run outside transaction.
func AddMigrationNoTxContext ¶
func AddMigrationNoTxContext(up, down GoMigrationNoTxContext)
AddMigrationNoTxContext adds Go migrations that will be run outside transaction.
func AddNamedMigration ¶
func AddNamedMigration(filename string, up, down GoMigration)
AddNamedMigration adds named Go migrations.
func AddNamedMigrationContext ¶
func AddNamedMigrationContext(filename string, up, down GoMigrationContext)
AddNamedMigrationContext adds named Go migrations.
func AddNamedMigrationNoTx ¶
func AddNamedMigrationNoTx(filename string, up, down GoMigrationNoTx)
AddNamedMigrationNoTx adds named Go migrations that will be run outside transaction.
func AddNamedMigrationNoTxContext ¶
func AddNamedMigrationNoTxContext(filename string, up, down GoMigrationNoTxContext)
AddNamedMigrationNoTxContext adds named Go migrations that will be run outside transaction.
func CreateWithTemplate ¶
func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, migrationType string) error
Create writes a new blank migration file.
func Down ¶
func Down(db *sql.DB, dir string, opts ...OptionsFunc) error
Down rolls back a single migration from the current version.
func DownContext ¶
DownContext rolls back a single migration from the current version.
func DownToContext ¶
func DownToContext(ctx context.Context, db *sql.DB, dir string, version int64, opts ...OptionsFunc) error
DownToContext rolls back migrations to a specific version.
func EnsureDBVersion ¶
EnsureDBVersion retrieves the current version for this DB. Create and initialize the DB version table if it doesn't exist.
func EnsureDBVersionContext ¶
EnsureDBVersionContext retrieves the current version for this DB. Create and initialize the DB version table if it doesn't exist.
func GetDBVersion ¶
GetDBVersion is an alias for EnsureDBVersion, but returns -1 in error.
func GetDBVersionContext ¶
GetDBVersionContext is an alias for EnsureDBVersion, but returns -1 in error.
func NumericComponent ¶
NumericComponent looks for migration scripts with names in the form: XXX_descriptivename.ext where XXX specifies the version number and ext specifies the type of migration
func OpenDBWithDriver ¶
OpenDBWithDriver creates a connection to a database, and modifies goose internals to be compatible with the supplied driver by calling SetDialect.
func Redo ¶
func Redo(db *sql.DB, dir string, opts ...OptionsFunc) error
Redo rolls back the most recently applied migration, then runs it again.
func RedoContext ¶
RedoContext rolls back the most recently applied migration, then runs it again.
func Reset ¶
func Reset(db *sql.DB, dir string, opts ...OptionsFunc) error
Reset rolls back all migrations
func ResetContext ¶
ResetContext rolls back all migrations
func RunContext ¶
RunContext runs a goose command.
func RunWithOptions ¶
func RunWithOptions(command string, db *sql.DB, dir string, args []string, options ...OptionsFunc) error
RunWithOptions runs a goose command with options.
func RunWithOptionsContext ¶
func RunWithOptionsContext(ctx context.Context, command string, db *sql.DB, dir string, args []string, options ...OptionsFunc) error
RunWithOptionsContext runs a goose command with options.
func SetBaseFS ¶
SetBaseFS sets a base FS to discover migrations. It can be used with 'embed' package. Calling with 'nil' argument leads to default behaviour: discovering migrations from os filesystem. Note that modifying operations like Create will use os filesystem anyway.
func SetDialect ¶
SetDialect sets the dialect to use for the goose package.
func SetSequential ¶
func SetSequential(s bool)
SetSequential set whether to use sequential versioning instead of timestamp based versioning
func Status ¶
func Status(db *sql.DB, dir string, opts ...OptionsFunc) error
Status prints the status of all migrations.
func StatusContext ¶
StatusContext prints the status of all migrations.
func Up ¶
func Up(db *sql.DB, dir string, opts ...OptionsFunc) error
Up applies all available migrations.
func UpByOne ¶
func UpByOne(db *sql.DB, dir string, opts ...OptionsFunc) error
UpByOne migrates up by a single version.
func UpByOneContext ¶
UpByOneContext migrates up by a single version.
func UpToContext ¶
func Version ¶
func Version(db *sql.DB, dir string, opts ...OptionsFunc) error
Version prints the current version of the database.
func VersionContext ¶
VersionContext prints the current version of the database.
Types ¶
type GoMigration ¶
GoMigration is a Go migration func that is run within a transaction.
type GoMigrationContext ¶
GoMigrationContext is a Go migration func that is run within a transaction and receives a context.
type GoMigrationNoTx ¶
GoMigrationNoTx is a Go migration func that is run outside a transaction.
type GoMigrationNoTxContext ¶
GoMigrationNoTxContext is a Go migration func that is run outside a transaction and receives a context.
type Logger ¶
type Logger interface { Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Print(v ...interface{}) Println(v ...interface{}) Printf(format string, v ...interface{}) }
Logger is standard logger interface
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 or go file Registered bool UseTx bool // These are deprecated and will be removed in the future. // For backwards compatibility we still save the non-context versions in the struct in case someone is using them. // Goose does not use these internally anymore and instead uses the context versions. UpFn, DownFn GoMigration UpFnNoTx, DownFnNoTx GoMigrationNoTx // New functions with context UpFnContext, DownFnContext GoMigrationContext UpFnNoTxContext, DownFnNoTxContext GoMigrationNoTxContext // contains filtered or unexported fields }
Migration struct.
func (*Migration) DownContext ¶
DownContext runs a down migration.
type MigrationRecord ¶
type MigrationRecord struct { VersionID int64 TStamp time.Time IsApplied bool // was this a result of up() or down() }
MigrationRecord struct.
type Migrations ¶
type Migrations []*Migration
Migrations slice.
func CollectMigrations ¶
func CollectMigrations(dirpath string, current, target int64) (Migrations, error)
CollectMigrations returns all the valid looking migration scripts in the migrations folder and go func registry, and key them by version.
func (Migrations) Current ¶
func (ms Migrations) Current(current int64) (*Migration, error)
Current gets the current migration.
func (Migrations) Last ¶
func (ms Migrations) Last() (*Migration, error)
Last gets the last migration.
func (Migrations) Less ¶
func (ms Migrations) Less(i, j int) bool
func (Migrations) Next ¶
func (ms Migrations) Next(current int64) (*Migration, error)
Next gets the next migration.
func (Migrations) Previous ¶
func (ms Migrations) Previous(current int64) (*Migration, error)
Previous : Get the previous migration.
func (Migrations) String ¶
func (ms Migrations) String() string
func (Migrations) Swap ¶
func (ms Migrations) Swap(i, j int)
type OptionsFunc ¶
type OptionsFunc func(o *options)
func WithAllowMissing ¶
func WithAllowMissing() OptionsFunc
func WithNoColor ¶
func WithNoColor(b bool) OptionsFunc
func WithNoVersioning ¶
func WithNoVersioning() OptionsFunc