tern

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tern runs jackc/tern migrations for testdb through tern's Go library, so no tern binary or tern.conf is needed.

pool := postgres.Setup(t, testdb.WithMigrator(tern.Dir("./migrations")))

A Migrator's Migrate method is also a template setup function:

tpl, err := postgres.EnsureTemplate(ctx, "schema", tern.Dir("./migrations").Migrate)

Index

Constants

View Source
const DefaultVersionTable = "schema_version"

DefaultVersionTable is where tern records the applied version, matching the tern CLI's default.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

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

Migrator applies tern migrations to a PostgreSQL database. Create one with Dir or FS.

func Dir

func Dir(dir string, opts ...Option) *Migrator

Dir returns a Migrator for the migration files in a directory on disk.

func FS

func FS(fsys fs.FS, path string, opts ...Option) *Migrator

FS returns a Migrator for the migration files under path in fsys, which lets migrations ship inside the test binary with embed.FS:

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

tern.FS(migrations, "migrations")

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context, dsn string) (err error)

Migrate applies every pending migration to the database at dsn.

type Option

type Option func(*Migrator)

Option configures a Migrator.

func WithDisableTx

func WithDisableTx() Option

WithDisableTx runs migrations outside a transaction, for statements that cannot run inside one (CREATE INDEX CONCURRENTLY, for example).

func WithVersionTable

func WithVersionTable(name string) Option

WithVersionTable sets the table tern records the schema version in. Default: DefaultVersionTable.

Jump to

Keyboard shortcuts

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