Documentation
¶
Index ¶
- Variables
- func NewDB(ctx context.Context, cfg *config.Database) (*sql.DB, error)
- type Migrator
- func (m *Migrator) Create(name string) (string, error)
- func (m *Migrator) Down(ctx context.Context, steps int) ([]*goose.MigrationResult, error)
- func (m *Migrator) DownAll(ctx context.Context) ([]*goose.MigrationResult, error)
- func (m *Migrator) Fresh(ctx context.Context) ([]*goose.MigrationResult, []*goose.MigrationResult, error)
- func (m *Migrator) Redo(ctx context.Context) ([]*goose.MigrationResult, []*goose.MigrationResult, error)
- func (m *Migrator) Status(ctx context.Context) ([]*goose.MigrationStatus, error)
- func (m *Migrator) Up(ctx context.Context, steps int) ([]*goose.MigrationResult, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrMigrationFailed = errors.New("migration failed")
Functions ¶
Types ¶
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator runs goose migrations against the application database.
Runtime operations (Up, Down, Status, Redo) use the embedded migration files compiled into the binary. Create writes new files to disk and is intended for development only.
Methods that apply migrations return []*goose.MigrationResult and error. On partial failure goose returns a *goose.PartialError containing both the successfully applied migrations and the failed one. Migrator preserves this contract — callers can use errors.As to extract partial results when needed.
func (*Migrator) Create ¶ added in v0.10.0
Create writes a new empty SQL migration file to disk. Development-only operation.
func (*Migrator) Down ¶ added in v0.10.0
Down rolls back applied migrations. Steps must be > 0, or use DownAll.
func (*Migrator) Fresh ¶ added in v0.10.0
func (m *Migrator) Fresh(ctx context.Context) ([]*goose.MigrationResult, []*goose.MigrationResult, error)
Fresh drops all tables and re-applies all migrations from scratch. Development-only operation — equivalent to Laravel's migrate:fresh.
Returns both down and up results so the caller can observe the full operation. On DownAll failure only downResults are populated. On Up failure both slices contain whatever was completed before the error.
func (*Migrator) Redo ¶ added in v0.10.0
func (m *Migrator) Redo(ctx context.Context) ([]*goose.MigrationResult, []*goose.MigrationResult, error)
Redo rolls back the last migration and re-applies only that one migration.