Documentation
¶
Overview ¶
Package migration provides migration registration and execution.
Index ¶
- func RunDown(p RunParams) error
- func RunLatest(p RunParams) error
- func RunList(p RunParams) error
- func RunRollback(p RunParams) error
- func RunUp(p RunParams) error
- type Registration
- type RunOptions
- type RunParams
- type Tracker
- func (t *Tracker) EnsureTable() error
- func (t *Tracker) GetApplied() ([]string, error)
- func (t *Tracker) GetBatchMigrations(batch int) ([]string, error)
- func (t *Tracker) GetLastBatch() (int, error)
- func (t *Tracker) RecordMigration(name string, batch int) error
- func (t *Tracker) RecordMigrationTx(tx *sql.Tx, name string, batch int) error
- func (t *Tracker) RemoveMigration(name string) error
- func (t *Tracker) RemoveMigrationTx(tx *sql.Tx, name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunDown ¶
RunDown rolls back the last single migration that was applied. Each migration is wrapped in a transaction.
func RunLatest ¶
RunLatest executes pending Up migrations in order using the provided schema. Each migration is wrapped in a transaction.
func RunRollback ¶
RunRollback rolls back the last batch of migrations (or all if Options.All is true). Each migration is wrapped in a transaction.
Types ¶
type Registration ¶
Registration represents a single migration with its metadata and operations.
type RunOptions ¶
type RunOptions struct {
All bool // For rollback --all (rollback all batches)
DryRun bool // Show SQL without executing
Args []string // Positional arguments
}
RunOptions holds optional flags for migration commands.
type RunParams ¶
type RunParams struct {
Config *config.Config
Registrations []Registration
Schema *schema.Schema
Options RunOptions
}
RunParams holds all parameters needed to run migrations.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker handles migration tracking in the database.
func NewTracker ¶
NewTracker creates a new migration tracker.
func (*Tracker) EnsureTable ¶
EnsureTable creates the migrations tracking table if it doesn't exist.
func (*Tracker) GetApplied ¶
GetApplied returns the list of applied migration names in order.
func (*Tracker) GetBatchMigrations ¶
GetBatchMigrations returns migration names for a specific batch in reverse order.
func (*Tracker) GetLastBatch ¶
GetLastBatch returns the highest batch number, or 0 if no migrations exist.
func (*Tracker) RecordMigration ¶
RecordMigration inserts a record for a successfully run migration.
func (*Tracker) RecordMigrationTx ¶
RecordMigrationTx inserts a record using the provided transaction.
func (*Tracker) RemoveMigration ¶
RemoveMigration deletes a migration record.