internal

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

Package internal defines common functionality available within the library.

Index

Constants

View Source
const (
	// TimeFormat provides a consistent timestamp layout for migrations.
	TimeFormat = "20060102150405"
)

Variables

View Source
var (
	ForwardDirections = []string{
		"forward",
		"migrate",
		"up",
	}
	ReverseDirections = []string{
		"reverse",
		"rollback",
		"down",
	}
)

Allowed names for directions in migration filenames.

View Source
var (
	ErrNotFound    = errors.New("not found")
	ErrDataInvalid = errors.New("data invalid")
)

General error values to help shape behavior.

View Source
var (
	MinVersion = time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC).Format(TimeFormat)
	MaxVersion = time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC).Format(TimeFormat)
)

Some reasonable lower, upper limits for migration versions.

Functions

func MakeFilename added in v0.8.0

func MakeFilename(version string, indirection Indirection, label string) string

MakeFilename creates a filename based on the independent parts. Format: "${direction}-${version}-${label}.sql"

func MakeMigrationFilename added in v0.8.0

func MakeMigrationFilename(m Migration) string

MakeMigrationFilename converts a Migration m to a filename.

Types

type Config added in v0.8.0

type Config struct {
	PathToFiles  string `json:"path_to_files"`
	ForwardLabel string `json:"forward_label"`
	ReverseLabel string `json:"reverse_label"`
}

Config is for various runtime settings.

type Direction added in v0.8.0

type Direction uint8

Direction describes which way the change goes.

const (
	// DirUnknown is a fallback value for an undetermined direction.
	DirUnknown Direction = iota
	// DirForward is like migrate up, typically the change you want to apply to
	// the DB.
	DirForward
	// DirReverse is like migrate down; used for rollbacks. Not all changes can
	// be rolled back.
	DirReverse
)

func (Direction) String added in v0.8.0

func (d Direction) String() string

type Filename added in v0.8.0

type Filename string

Filename is just a string with a specific format to migration files. One part has a generated timestamp, one part has a direction, another has a label.

type Indirection added in v0.8.0

type Indirection struct {
	Value Direction
	Label string
}

Indirection is some glue to help determine the direction of a migration, usually from a filename with an alias for a direction.

type InfoPrinter added in v0.8.0

type InfoPrinter interface {
	PrintInfo(state string, migration Migration) error
}

InfoPrinter outputs the state of one migration.

func NewJSON added in v0.8.0

func NewJSON(w io.Writer) InfoPrinter

NewJSON constructs an InfoPrinter to write out JSON.

func NewTSV added in v0.8.0

func NewTSV(w io.Writer) InfoPrinter

NewTSV constructs an InfoPrinter to write out tab separated values.

type Migration added in v0.8.0

type Migration interface {
	Indirection() Indirection
	Label() string
	Version() Version
}

A Migration is a database change with a direction name and timestamp. Typically, a Migration with a DirForward Direction is paired with another migration of DirReverse that has the same label.

func ParseMigration added in v0.8.0

func ParseMigration(name Filename) (mig Migration, err error)

ParseMigration constructs a Migration from a Filename.

type MigrationParams added in v0.8.0

type MigrationParams struct {
	Forward    Migration
	Reverse    Migration
	Reversible bool
	Dirpath    string
}

MigrationParams collects inputs needed to generate migration files. Setting Reversible to true will generate a migration file for each direction. Otherwise, it only generates a file in the forward direction. The Directory field refers to the path to the directory with the migration files.

func NewMigrationParams added in v0.8.0

func NewMigrationParams(name string, reversible bool, dirpath, fwdLabel, revLabel string) (out *MigrationParams, err error)

NewMigrationParams constructs a MigrationParams that's ready to use.

func (*MigrationParams) GenerateFiles added in v0.8.0

func (m *MigrationParams) GenerateFiles() (err error)

GenerateFiles creates the migration files. If the migration is reversible it generates files in forward and reverse directions; otherwise it generates just one migration file in the forward direction. It closes each file handle when it's done.

type Version added in v0.8.0

type Version interface {
	Before(u Version) bool
	String() string
	Value() int64
}

Version is for comparing migrations to each other.

func ParseVersion added in v0.8.0

func ParseVersion(basename string) (version Version, err error)

ParseVersion extracts Version info from a file's basename.

Directories

Path Synopsis
Package cmd contains all the CLI stuff.
Package cmd contains all the CLI stuff.
Package stub implements godfish interfaces for testing purposes.
Package stub implements godfish interfaces for testing purposes.

Jump to

Keyboard shortcuts

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