Categorygithub.com/terinjokes/sqlitestdb/migrators/golangmigrator
modulepackage
0.1.2
Repository: https://github.com/terinjokes/sqlitestdb.git
Documentation: pkg.go.dev

# README

golangmigrator provides a sqlitestdb.Migrator that can be used to migrate the template database using golang-migrate.

Because Hash() requires calculating a unique hash based on the contents of the migrations, this implementation only supports reading migration files from disk or from an embedded filesystem.

package db_test

import (
	"testing"

	_ "github.com/mattn/go-sqlite3"
	"github.com/terinjokes/sqlitestdb"
	"github.com/terinjokes/sqlitestdb/migrators/golangmigrator"
)

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

func TestMigrateFromDisk(t *testing.T) {
	gm := golangmigrator.New("migrations")
	db := sqlitestdb.New(t, sqlitestdb.Config{Driver: "sqlite3"}, gm)

	var version string
	err := db.QueryRowContext("sqlite_version()").Scan(&version)
	if err != nil {
		t.Fatalf("could not read from SQLite: %+v\n", err)
	}
}

func TestMigrateFromEmbeddedFS(t *testing.T) {
	gm := golangmigrator.New("migrations", golangmigrator.WithFS(migrationsFS))
	db := sqlitestdb.New(t, sqlitestdb.Config{Driver: "sqlite3"}, gm)

	var version string
	err := db.QueryRowContext("sqlite_version()").Scan(&version)
	if err != nil {
		t.Fatalf("could not read from SQLite: %+v\n", err)
	}
}

# Functions

New returns a [GolangMigrator], which implements sqlitestdb.Migrator using golang-migrate to perform up migrations.
WithFS specifies a [fs.FS] from which to read the migration files.

# Structs

GolangMigrator is a [sqlitestdb.Migrator] that uses golang-migrate to perform migrations.

# Type aliases

Option provides a way to configure the GolangMigrator struct and its behavior.