Help us shape the future of Go! Take the 2026 Go Developer Survey

migration

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package migrations is deprecated. Use github.com/shauryagautam/Astra/pkg/database/migration instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(dir, name string) (string, error)

Generate creates a new migration file in the specified directory.

Types

type Embedder

type Embedder struct {
	FS embed.FS
}

Embedder allows embedding migration SQL files directly into the Go binary.

func (*Embedder) ReadDir

func (e *Embedder) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir returns the migration files.

func (*Embedder) ReadFile

func (e *Embedder) ReadFile(name string) ([]byte, error)

ReadFile reads a specific migration file.

type MigrationRecord

type MigrationRecord struct {
	ID       int
	Name     string
	Batch    int
	RunAt    time.Time
	Checksum string
}

MigrationRecord represents a migration that has been applied to the database.

type Runner

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

Runner handles running and rolling back migration.

func NewRunner

func NewRunner(db *sql.DB, dir string, fileSystem fs.FS) *Runner

NewRunner creates a new migration runner.

func (*Runner) Fresh

func (r *Runner) Fresh(ctx context.Context) error

Fresh drops all user tables and re-runs all migration. CAUTION: destructive operation — for development use only.

func (*Runner) Rollback

func (r *Runner) Rollback(ctx context.Context) error

Rollback rolls back the last batch of migration.

func (*Runner) RollbackN

func (r *Runner) RollbackN(ctx context.Context, n int) error

RollbackN rolls back the last N individual migration.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes all pending migrations in order.

func (*Runner) Setup

func (r *Runner) Setup(ctx context.Context) error

Setup ensures the migrations table exists with all required columns.

func (*Runner) Status

func (r *Runner) Status(ctx context.Context) (applied []MigrationRecord, pending []string, err error)

Status returns all applied migration records and a list of pending file names.

Jump to

Keyboard shortcuts

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