Documentation ¶
Overview ¶
Package internal defines common functionality available within the library.
Index ¶
Constants ¶
const (
// TimeFormat provides a consistent timestamp layout for migrations.
TimeFormat = "20060102150405"
)
Variables ¶
var ( ForwardDirections = []string{ "forward", "migrate", "up", } ReverseDirections = []string{ "reverse", "rollback", "down", } )
Allowed names for directions in migration filenames.
var ( ErrNotFound = errors.New("not found") ErrDataInvalid = errors.New("data invalid") )
General error values to help shape behavior.
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
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 )
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
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
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
ParseMigration constructs a Migration from a Filename.
type MigrationParams ¶ added in v0.8.0
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
Version is for comparing migrations to each other.
func ParseVersion ¶ added in v0.8.0
ParseVersion extracts Version info from a file's basename.