migrate

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 7 Imported by: 0

README

Migrate

A small Go package for running SQL migrations from an fs.FS source and tracking applied migrations using the standard database/sql package.

package main

import (
	"context"
	"database/sql"
	"os"

	_ "github.com/mattn/go-sqlite3"
	"github.com/vsysd/migrate"
)

var migrations = os.DirFS("migrations")

func main() {
	db, err := sql.Open("sqlite3", "app.db")
	if err != nil {
		panic(err)
	}

	migrator := migrate.New(db, "schema_migrations")

	if err := migrator.Up(context.Background(), migrations); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

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

Migrator applies SQL migrations from a filesystem source and tracks executed migrations in a database table using database/sql.

func New

func New(db *sql.DB, schemaTable string) *Migrator

New returns a Migrator that applies SQL migrations using db and records applied migrations in schemaTable.

func (*Migrator) Up

func (m *Migrator) Up(ctx context.Context, fsys fs.FS) error

Up applies all pending .sql migrations.

Migrations are applied in lexicographical filename order. Each migration is executed once and recorded in the configured schema table.

Jump to

Keyboard shortcuts

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