migrate

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 5 Imported by: 3

README

go-evolutionary-migrate

Lightweight SQLite migration runner that applies SQL files in lexicographic order and tracks progress using PRAGMA user_version.

Overview

A tiny, predictable migration runner for SQLite projects that prefer plain SQL files over full-featured migration tools.

It keeps ordering simple (lexicographic filenames) and tracks progress using SQLite's built-in PRAGMA user_version.

Inspiration

Evolutionary Database Design by Pramod Sadalage and Martin Fowler.

Usage

Imagine that you have SQL files for your migrations here:

your-module/
  migrations/
    001_init.sql
    002_add_users.sql

The simplest way to store your migrations are within the Go binary itself. Run assumes that your *.sql files are at the root of the filesystem.

//go:embed migrations/*.sql
var embeddedMigrations embed.FS

migrationsFS, err := fs.Sub(embeddedMigrations, "migrations")
if err != nil {
  return err
}
if err := migrate.Run(ctx, db, migrationsFS); err != nil {
  return err
}
Path-based semantics
migrationsFS := os.DirFS("/path/to/migrations")
if err := migrate.Run(ctx, db, migrationsFS); err != nil {
  return err
}

Behavior

  • Each file is executed as a single SQL statement.
  • Files are applied in lexicographic order by filename.
  • PRAGMA user_version is set to the 1-based index of the last applied migration.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, db *sql.DB, fsys fs.FS) error

Run applies SQLite migrations from fsys. Migrations are executed in lexicographic order by filename, with each file treated as a single statement. The database user_version pragma tracks the last applied migration index.

Types

This section is empty.

Jump to

Keyboard shortcuts

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