migrate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package migrate provides versioned database migrations for SQL backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppliedMigration

type AppliedMigration struct {
	Version     int       `json:"version"`
	Description string    `json:"description"`
	AppliedAt   time.Time `json:"applied_at"`
}

type Migration

type Migration struct {
	Version     int
	Description string
	Up          string // SQL to apply
	Down        string // SQL to roll back
}

Migration represents a single versioned migration.

type MigrationStatus

type MigrationStatus struct {
	CurrentVersion int                `json:"current_version"`
	Applied        []AppliedMigration `json:"applied"`
	Pending        []Migration        `json:"pending"`
}

Status returns the current migration version and list of applied migrations.

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator manages versioned migrations for a SQL database.

func New

func New(db *sql.DB) *Migrator

New creates a new Migrator for the given database connection.

func (*Migrator) Add

func (m *Migrator) Add(version int, description, up, down string) *Migrator

Add registers a migration. Migrations are applied in version order.

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context) error

Migrate applies all pending migrations.

func (*Migrator) Rollback

func (m *Migrator) Rollback(ctx context.Context) error

Rollback reverts the last applied migration.

func (*Migrator) Status

func (m *Migrator) Status(ctx context.Context) (*MigrationStatus, error)

Jump to

Keyboard shortcuts

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