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 deletes the SQLite database file and re-applies all migrations from scratch. Development-only operation — equivalent to Laravel's migrate:fresh.
This avoids FK constraint issues during rollback by removing the file entirely. The database connection is closed, the file is deleted, a new connection is opened via NewDB, and the goose provider is recreated before running Up.
After Fresh returns, the old *sql.DB (held by other components via Wire) is closed. This is safe because Fresh is a CLI-only operation — the process exits after it.
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.