migration

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package migration provides migration registration and execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunDown

func RunDown(p RunParams) error

RunDown rolls back the last single migration that was applied. Each migration is wrapped in a transaction.

func RunLatest

func RunLatest(p RunParams) error

RunLatest executes pending Up migrations in order using the provided schema. Each migration is wrapped in a transaction.

func RunList

func RunList(p RunParams) error

RunList displays all migrations with their status (applied/pending).

func RunRollback

func RunRollback(p RunParams) error

RunRollback rolls back the last batch of migrations (or all if Options.All is true). Each migration is wrapped in a transaction.

func RunUp

func RunUp(p RunParams) error

RunUp runs the next pending migration or a specific one if Args[0] provided. Each migration is wrapped in a transaction.

Types

type Registration

type Registration struct {
	Name string
	Up   func(*schema.Schema)
	Down func(*schema.Schema)
}

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

func NewTracker(db *sql.DB, d dialect.Dialect, tableName string) *Tracker

NewTracker creates a new migration tracker.

func (*Tracker) EnsureTable

func (t *Tracker) EnsureTable() error

EnsureTable creates the migrations tracking table if it doesn't exist.

func (*Tracker) GetApplied

func (t *Tracker) GetApplied() ([]string, error)

GetApplied returns the list of applied migration names in order.

func (*Tracker) GetBatchMigrations

func (t *Tracker) GetBatchMigrations(batch int) ([]string, error)

GetBatchMigrations returns migration names for a specific batch in reverse order.

func (*Tracker) GetLastBatch

func (t *Tracker) GetLastBatch() (int, error)

GetLastBatch returns the highest batch number, or 0 if no migrations exist.

func (*Tracker) RecordMigration

func (t *Tracker) RecordMigration(name string, batch int) error

RecordMigration inserts a record for a successfully run migration.

func (*Tracker) RecordMigrationTx

func (t *Tracker) RecordMigrationTx(tx *sql.Tx, name string, batch int) error

RecordMigrationTx inserts a record using the provided transaction.

func (*Tracker) RemoveMigration

func (t *Tracker) RemoveMigration(name string) error

RemoveMigration deletes a migration record.

func (*Tracker) RemoveMigrationTx

func (t *Tracker) RemoveMigrationTx(tx *sql.Tx, name string) error

RemoveMigrationTx deletes a migration record using the provided transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL