Documentation ¶
Index ¶
- Constants
- Variables
- func AddMigration(up, down GoMigration)deprecated
- func AddMigrationContext(up, down GoMigrationContext)
- func AddMigrationNoTx(up, down GoMigrationNoTx)deprecated
- func AddMigrationNoTxContext(up, down GoMigrationNoTxContext)
- func AddNamedMigration(filename string, up, down GoMigration)deprecated
- func AddNamedMigrationContext(filename string, up, down GoMigrationContext)
- func AddNamedMigrationNoTx(filename string, up, down GoMigrationNoTx)deprecated
- 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(filename 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 ResetGlobalMigrations()
- func Run(command string, db *sql.DB, dir string, args ...string) errordeprecated
- 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) errordeprecated
- 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 SetGlobalMigrations(migrations ...*Migration) 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 Dialect
- type GoFunc
- type GoMigrationdeprecated
- type GoMigrationContext
- type GoMigrationNoTxdeprecated
- type GoMigrationNoTxContext
- type Logger
- type Migration
- type MigrationRecorddeprecated
- type MigrationResult
- type MigrationStatus
- type MigrationType
- 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
- type PartialError
- type Provider
- func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (*MigrationResult, error)
- func (p *Provider) Close() error
- func (p *Provider) Down(ctx context.Context) (*MigrationResult, error)
- func (p *Provider) DownTo(ctx context.Context, version int64) ([]*MigrationResult, error)
- func (p *Provider) GetDBVersion(ctx context.Context) (int64, error)
- func (p *Provider) GetVersions(ctx context.Context) (current, target int64, err error)
- func (p *Provider) HasPending(ctx context.Context) (bool, error)
- func (p *Provider) ListSources() []*Source
- func (p *Provider) Ping(ctx context.Context) error
- func (p *Provider) Status(ctx context.Context) ([]*MigrationStatus, error)
- func (p *Provider) Up(ctx context.Context) ([]*MigrationResult, error)
- func (p *Provider) UpByOne(ctx context.Context) (*MigrationResult, error)
- func (p *Provider) UpTo(ctx context.Context, version int64) ([]*MigrationResult, error)
- type ProviderOption
- func WithAllowOutofOrder(b bool) ProviderOption
- func WithDisableGlobalRegistry(b bool) ProviderOption
- func WithDisableVersioning(b bool) ProviderOption
- func WithExcludeNames(excludes []string) ProviderOption
- func WithExcludeVersions(versions []int64) ProviderOption
- func WithGoMigrations(migrations ...*Migration) ProviderOption
- func WithLogger(l Logger) ProviderOption
- func WithSessionLocker(locker lock.SessionLocker) ProviderOption
- func WithStore(store database.Store) ProviderOption
- func WithVerbose(b bool) ProviderOption
- type Source
- type State
- type TransactionMode
Constants ¶
const ( // DefaultTablename is the default name of the database table used to track history of applied // migrations. DefaultTablename = "goose_db_version" )
const VERSION = "v3.18.0"
Deprecated: VERSION will no longer be supported in the next major release.
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 )
var ( // ErrVersionNotFound is returned when a specific migration version is not located. This can // occur if a .sql file or a Go migration function for the specified version is missing. ErrVersionNotFound = errors.New("version not found") // ErrNoMigrations is returned by [NewProvider] when no migrations are found. ErrNoMigrations = errors.New("no migrations found") // ErrAlreadyApplied indicates that the migration cannot be applied because it has already been // executed. This error is returned by [Provider.Apply]. ErrAlreadyApplied = errors.New("migration already applied") // ErrNotApplied indicates that the rollback cannot be performed because the migration has not // yet been applied. This error is returned by [Provider.Apply]. ErrNotApplied = errors.New("migration not applied") )
Functions ¶
func AddMigration
deprecated
func AddMigration(up, down GoMigration)
AddMigration adds Go migrations.
Deprecated: Use AddMigrationContext.
func AddMigrationContext ¶ added in v3.13.0
func AddMigrationContext(up, down GoMigrationContext)
AddMigrationContext adds Go migrations.
func AddMigrationNoTx
deprecated
added in
v3.9.0
func AddMigrationNoTx(up, down GoMigrationNoTx)
AddMigrationNoTx adds Go migrations that will be run outside transaction.
Deprecated: Use AddMigrationNoTxContext.
func AddMigrationNoTxContext ¶ added in v3.13.0
func AddMigrationNoTxContext(up, down GoMigrationNoTxContext)
AddMigrationNoTxContext adds Go migrations that will be run outside transaction.
func AddNamedMigration
deprecated
func AddNamedMigration(filename string, up, down GoMigration)
AddNamedMigration adds named Go migrations.
Deprecated: Use AddNamedMigrationContext.
func AddNamedMigrationContext ¶ added in v3.13.0
func AddNamedMigrationContext(filename string, up, down GoMigrationContext)
AddNamedMigrationContext adds named Go migrations.
func AddNamedMigrationNoTx
deprecated
added in
v3.9.0
func AddNamedMigrationNoTx(filename string, up, down GoMigrationNoTx)
AddNamedMigrationNoTx adds named Go migrations that will be run outside transaction.
Deprecated: Use AddNamedMigrationNoTxContext.
func AddNamedMigrationNoTxContext ¶ added in v3.13.0
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 ¶ added in v3.13.0
DownContext rolls back a single migration from the current version.
func DownToContext ¶ added in v3.13.0
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 ¶ added in v3.13.0
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 ¶ added in v3.13.0
GetDBVersionContext is an alias for EnsureDBVersion, but returns -1 in error.
func NumericComponent ¶
NumericComponent parses the version from the migration file name.
XXX_descriptivename.ext where XXX specifies the version number and ext specifies the type of migration, either .sql or .go.
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 ¶ added in v3.13.0
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 ¶ added in v3.13.0
ResetContext rolls back all migrations
func ResetGlobalMigrations ¶ added in v3.16.0
func ResetGlobalMigrations()
ResetGlobalMigrations resets the global Go migrations registry.
Not safe for concurrent use.
func RunContext ¶ added in v3.13.0
RunContext runs a goose command.
func RunWithOptions
deprecated
added in
v3.3.0
func RunWithOptionsContext ¶ added in v3.13.0
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 ¶ added in v3.1.0
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 SetGlobalMigrations ¶ added in v3.16.0
SetGlobalMigrations registers Go migrations globally. It returns an error if a migration with the same version has already been registered. Go migrations must be constructed using the NewGoMigration function.
Not safe for concurrent use.
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 ¶ added in v3.13.0
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 ¶ added in v3.13.0
UpByOneContext migrates up by a single version.
func UpToContext ¶ added in v3.13.0
func Version ¶
func Version(db *sql.DB, dir string, opts ...OptionsFunc) error
Version prints the current version of the database.
func VersionContext ¶ added in v3.13.0
VersionContext prints the current version of the database.
Types ¶
type Dialect ¶ added in v3.15.1
Dialect is the type of database dialect. It is an alias for database.Dialect.
const ( DialectClickHouse Dialect = database.DialectClickHouse DialectMSSQL Dialect = database.DialectMSSQL DialectMySQL Dialect = database.DialectMySQL DialectPostgres Dialect = database.DialectPostgres DialectRedshift Dialect = database.DialectRedshift DialectSQLite3 Dialect = database.DialectSQLite3 DialectTiDB Dialect = database.DialectTiDB DialectVertica Dialect = database.DialectVertica DialectYdB Dialect = database.DialectYdB DialectStarrocks Dialect = database.DialectStarrocks )
type GoFunc ¶ added in v3.16.0
type GoFunc struct { // Exactly one of these must be set, or both must be nil. RunTx func(ctx context.Context, tx *sql.Tx) error // -- OR -- RunDB func(ctx context.Context, db *sql.DB) error // Mode is the transaction mode for the migration. When one of the run functions is set, the // mode will be inferred from the function and the field is ignored. Users do not need to set // this field when supplying a run function. // // If both run functions are nil, the mode defaults to TransactionEnabled. The use case for nil // functions is to record a version in the version table without invoking a Go migration // function. // // The only time this field is required is if BOTH run functions are nil AND you want to // override the default transaction mode. Mode TransactionMode }
GoFunc represents a Go migration function.
type GoMigration
deprecated
added in
v3.9.0
type GoMigrationContext ¶ added in v3.13.0
GoMigrationContext is a Go migration func that is run within a transaction and receives a context.
type GoMigrationNoTx
deprecated
added in
v3.9.0
type GoMigrationNoTxContext ¶ added in v3.13.0
GoMigrationNoTxContext is a Go migration func that is run outside a transaction and receives a context.
type Logger ¶
type Logger interface { Fatalf(format string, v ...interface{}) Printf(format string, v ...interface{}) }
Logger is standard logger interface
type Migration ¶
type Migration struct { Type MigrationType Version int64 // Source is the path to the .sql script or .go file. It may be empty for Go migrations that // have been registered globally and don't have a source file. Source string UpFnContext, DownFnContext GoMigrationContext UpFnNoTxContext, DownFnNoTxContext GoMigrationNoTxContext // These fields will be removed in a future major version. They are here for backwards // compatibility and are an implementation detail. Registered bool UseTx bool Next int64 // next version, or -1 if none Previous int64 // previous version, -1 if none UpFn GoMigration // Deprecated: use UpFnContext instead. DownFn GoMigration // Deprecated: use DownFnContext instead. UpFnNoTx GoMigrationNoTx // Deprecated: use UpFnNoTxContext instead. DownFnNoTx GoMigrationNoTx // Deprecated: use DownFnNoTxContext instead. // contains filtered or unexported fields }
Migration struct represents either a SQL or Go migration.
Avoid constructing migrations manually, use NewGoMigration function.
func NewGoMigration ¶ added in v3.16.0
NewGoMigration creates a new Go migration.
Both up and down functions may be nil, in which case the migration will be recorded in the versions table but no functions will be run. This is useful for recording (up) or deleting (down) a version without running any functions. See GoFunc for more details.
func (*Migration) DownContext ¶ added in v3.13.0
DownContext runs a down migration.
type MigrationRecord
deprecated
type MigrationResult ¶ added in v3.16.0
type MigrationResult struct { Source *Source Duration time.Duration Direction string // Empty indicates no action was taken during the migration, but it was still versioned. For // SQL, it means no statements; for Go, it's a nil function. Empty bool // Error is only set if the migration failed. Error error }
MigrationResult is the result of a single migration operation.
func (*MigrationResult) String ¶ added in v3.17.0
func (m *MigrationResult) String() string
String returns a string representation of the migration result.
Example down:
EMPTY down 00006_posts_view-copy.sql (607.83µs) OK down 00005_posts_view.sql (646.25µs)
Example up:
OK up 00005_posts_view.sql (727.5µs) EMPTY up 00006_posts_view-copy.sql (378.33µs)
type MigrationStatus ¶ added in v3.16.0
MigrationStatus represents the status of a single migration.
type MigrationType ¶ added in v3.16.0
type MigrationType string
MigrationType is the type of migration.
const ( TypeGo MigrationType = "go" TypeSQL MigrationType = "sql" )
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 ¶ added in v3.3.0
type OptionsFunc func(o *options)
func WithAllowMissing ¶ added in v3.3.0
func WithAllowMissing() OptionsFunc
func WithNoColor ¶ added in v3.8.0
func WithNoColor(b bool) OptionsFunc
func WithNoVersioning ¶ added in v3.5.0
func WithNoVersioning() OptionsFunc
type PartialError ¶ added in v3.16.0
type PartialError struct { // Applied are migrations that were applied successfully before the error occurred. May be // empty. Applied []*MigrationResult // Failed contains the result of the migration that failed. Cannot be nil. Failed *MigrationResult // Err is the error that occurred while running the migration and caused the failure. Err error }
PartialError is returned when a migration fails, but some migrations already got applied.
func (*PartialError) Error ¶ added in v3.16.0
func (e *PartialError) Error() string
func (*PartialError) Unwrap ¶ added in v3.22.0
func (e *PartialError) Unwrap() error
type Provider ¶ added in v3.16.0
type Provider struct {
// contains filtered or unexported fields
}
Provider is a goose migration provider.
func NewProvider ¶ added in v3.16.0
func NewProvider(dialect Dialect, db *sql.DB, fsys fs.FS, opts ...ProviderOption) (*Provider, error)
NewProvider returns a new goose provider.
The caller is responsible for matching the database dialect with the database/sql driver. For example, if the database dialect is "postgres", the database/sql driver could be github.com/lib/pq or github.com/jackc/pgx. Each dialect has a corresponding database.Dialect constant backed by a default database.Store implementation. For more advanced use cases, such as using a custom table name or supplying a custom store implementation, see WithStore.
fsys is the filesystem used to read migration files, but may be nil. Most users will want to use os.DirFS, os.DirFS("path/to/migrations"), to read migrations from the local filesystem. However, it is possible to use a different "filesystem", such as embed.FS or filter out migrations using fs.Sub.
See ProviderOption for more information on configuring the provider.
Unless otherwise specified, all methods on Provider are safe for concurrent use.
func (*Provider) ApplyVersion ¶ added in v3.16.0
func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (*MigrationResult, error)
ApplyVersion applies exactly one migration for the specified version. If there is no migration available for the specified version, this method returns ErrVersionNotFound. If the migration has already been applied, this method returns ErrAlreadyApplied.
The direction parameter determines the migration direction: true for up migration and false for down migration.
func (*Provider) Close ¶ added in v3.16.0
Close closes the database connection initially supplied to the provider.
func (*Provider) Down ¶ added in v3.16.0
func (p *Provider) Down(ctx context.Context) (*MigrationResult, error)
Down rolls back the most recently applied migration. If there are no migrations to rollback, this method returns ErrNoNextVersion.
Note, migrations are rolled back in the order they were applied. And not in the reverse order of the migration version. This only applies in scenarios where migrations are allowed to be applied out of order.
func (*Provider) DownTo ¶ added in v3.16.0
DownTo rolls back all migrations down to, but not including, the specified version.
For example, if the current database version is 11,10,9... and the requested version is 9, only migrations 11, 10 will be rolled back.
Note, migrations are rolled back in the order they were applied. And not in the reverse order of the migration version. This only applies in scenarios where migrations are allowed to be applied out of order.
func (*Provider) GetDBVersion ¶ added in v3.16.0
GetDBVersion returns the highest version recorded in the database, regardless of the order in which migrations were applied. For example, if migrations were applied out of order (1,4,2,3), this method returns 4. If no migrations have been applied, it returns 0.
func (*Provider) GetVersions ¶ added in v3.21.0
GetVersions returns the max database version and the target version to migrate to.
Note, this method will not use a SessionLocker if one is configured. This allows callers to check for versions without blocking or being blocked by other operations.
func (*Provider) HasPending ¶ added in v3.20.0
HasPending returns true if there are pending migrations to apply, otherwise, it returns false. If out-of-order migrations are disabled, yet some are detected, this method returns an error.
Note, this method will not use a SessionLocker if one is configured. This allows callers to check for pending migrations without blocking or being blocked by other operations.
func (*Provider) ListSources ¶ added in v3.16.0
ListSources returns a list of all migration sources known to the provider, sorted in ascending order by version. The path field may be empty for manually registered migrations, such as Go migrations registered using the WithGoMigrations option.
func (*Provider) Ping ¶ added in v3.16.0
Ping attempts to ping the database to verify a connection is available.
func (*Provider) Status ¶ added in v3.16.0
func (p *Provider) Status(ctx context.Context) ([]*MigrationStatus, error)
Status returns the status of all migrations, merging the list of migrations from the database and filesystem. The returned items are ordered by version, in ascending order.
func (*Provider) Up ¶ added in v3.16.0
func (p *Provider) Up(ctx context.Context) ([]*MigrationResult, error)
Up applies all pending migrations. If there are no new migrations to apply, this method returns empty list and nil error.
func (*Provider) UpByOne ¶ added in v3.16.0
func (p *Provider) UpByOne(ctx context.Context) (*MigrationResult, error)
UpByOne applies the next pending migration. If there is no next migration to apply, this method returns ErrNoNextVersion.
func (*Provider) UpTo ¶ added in v3.16.0
UpTo applies all pending migrations up to, and including, the specified version. If there are no migrations to apply, this method returns empty list and nil error.
For example, if there are three new migrations (9,10,11) and the current database version is 8 with a requested version of 10, only versions 9,10 will be applied.
type ProviderOption ¶ added in v3.16.0
type ProviderOption interface {
// contains filtered or unexported methods
}
ProviderOption is a configuration option for a goose goose.
func WithAllowOutofOrder ¶ added in v3.16.0
func WithAllowOutofOrder(b bool) ProviderOption
WithAllowOutofOrder allows the provider to apply missing (out-of-order) migrations. By default, goose will raise an error if it encounters a missing migration.
For example: migrations 1,3 are applied and then version 2,6 are introduced. If this option is true, then goose will apply 2 (missing) and 6 (new) instead of raising an error. The final order of applied migrations will be: 1,3,2,6. Out-of-order migrations are always applied first, followed by new migrations.
func WithDisableGlobalRegistry ¶ added in v3.17.0
func WithDisableGlobalRegistry(b bool) ProviderOption
WithDisableGlobalRegistry prevents the provider from registering Go migrations from the global registry. By default, goose will register all Go migrations including those registered globally.
func WithDisableVersioning ¶ added in v3.16.0
func WithDisableVersioning(b bool) ProviderOption
WithDisableVersioning disables versioning. Disabling versioning allows applying migrations without tracking the versions in the database schema table. Useful for tests, seeding a database or running ad-hoc queries. By default, goose will track all versions in the database schema table.
func WithExcludeNames ¶ added in v3.16.0
func WithExcludeNames(excludes []string) ProviderOption
WithExcludeNames excludes the given file name from the list of migrations. If called multiple times, the list of excludes is merged.
func WithExcludeVersions ¶ added in v3.16.0
func WithExcludeVersions(versions []int64) ProviderOption
WithExcludeVersions excludes the given versions from the list of migrations. If called multiple times, the list of excludes is merged.
func WithGoMigrations ¶ added in v3.16.0
func WithGoMigrations(migrations ...*Migration) ProviderOption
WithGoMigrations registers Go migrations with the provider. If a Go migration with the same version has already been registered, an error will be returned.
Go migrations must be constructed using the NewGoMigration function.
func WithLogger ¶ added in v3.23.0
func WithLogger(l Logger) ProviderOption
WithLogger will set a custom Logger, which will override the default logger.
func WithSessionLocker ¶ added in v3.16.0
func WithSessionLocker(locker lock.SessionLocker) ProviderOption
WithSessionLocker enables locking using the provided SessionLocker.
If WithSessionLocker is not called, locking is disabled.
func WithStore ¶ added in v3.16.0
func WithStore(store database.Store) ProviderOption
WithStore configures the provider with a custom database.Store implementation.
By default, the provider uses the database.NewStore function to create a store backed by the given dialect. However, this option allows users to provide their own implementation or call database.NewStore with custom options, such as setting the table name.
Example:
// Create a store with a custom table name. store, err := database.NewStore(database.DialectPostgres, "my_custom_table_name") if err != nil { return err } // Create a provider with the custom store. provider, err := goose.NewProvider("", db, nil, goose.WithStore(store)) if err != nil { return err }
func WithVerbose ¶ added in v3.16.0
func WithVerbose(b bool) ProviderOption
WithVerbose enables verbose logging.
type Source ¶ added in v3.16.0
type Source struct { Type MigrationType Path string Version int64 }
Source represents a single migration source.
The Path field may be empty if the migration was registered manually. This is typically the case for Go migrations registered using the [WithGoMigration] option.
type TransactionMode ¶ added in v3.16.0
type TransactionMode int
TransactionMode represents the possible transaction modes for a migration.
const ( TransactionEnabled TransactionMode = iota + 1 TransactionDisabled )
func (TransactionMode) String ¶ added in v3.16.0
func (m TransactionMode) String() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package database defines a generic Store interface for goose to use when interacting with the database.
|
Package database defines a generic Store interface for goose to use when interacting with the database. |
examples
|
|
internal
|
|
gooseutil
Package gooseutil provides utility functions we want to keep internal to the package.
|
Package gooseutil provides utility functions we want to keep internal to the package. |
Package lock defines the Locker interface and implements the locking logic.
|
Package lock defines the Locker interface and implements the locking logic. |