Documentation
¶
Index ¶
- Variables
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) Create(name string) (upPath, downPath string, err error)
- func (e *Engine) Down(n int) error
- func (e *Engine) DownAll() error
- func (e *Engine) Force(version int) error
- func (e *Engine) List() ([]MigrationFile, error)
- func (e *Engine) Up() error
- func (e *Engine) UpN(n int) error
- func (e *Engine) Version() (version uint, dirty bool, err error)
- type MigrationFile
Constants ¶
This section is empty.
Variables ¶
var ErrNoChange = migrate.ErrNoChange
ErrNoChange is returned when there's nothing to migrate.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the main migration runner. It wraps golang-migrate/migrate with a simpler API.
func New ¶
New creates a new migration engine from a config. It validates the config, builds the DSN, and initializes golang-migrate.
func (*Engine) Close ¶
Close releases all resources held by the engine. Always call this when done (use defer engine.Close()).
func (*Engine) Create ¶
Create creates a new migration file pair (up and down) with the given name. Returns an error if a migration with the same name already exists. Returns the paths of the created files.
func (*Engine) Down ¶
Down reverts the last N applied migrations. Use Down(1) to revert only the most recent one (safe default).
func (*Engine) DownAll ¶
DownAll reverts ALL applied migrations. This is destructive — use with caution!
func (*Engine) Force ¶
Force sets the migration version without running any migrations. Useful for fixing a "dirty" state when a migration failed mid-way. Passing -1 resets the version to nothing.
func (*Engine) List ¶
func (e *Engine) List() ([]MigrationFile, error)
List returns all migration files found in the migrations directory. Does NOT query the database — just reads files from disk.
func (*Engine) Up ¶
Up applies all pending migrations. Returns ErrNoChange if there's nothing to apply.
func (*Engine) UpN ¶
UpN applies the next N pending migrations. Use UpN(1) to apply only the next one.