file

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2016 License: MIT Imports: 11 Imported by: 79

Documentation

Overview

Package file contains functions for low-level migration files handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilenameRegex

func FilenameRegex(filenameExtension string) *regexp.Regexp

FilenameRegex builds regular expression stmt with given filename extension from driver.

func LineColumnFromOffset

func LineColumnFromOffset(data []byte, offset int) (line, column int)

LineColumnFromOffset reads data and returns line and column integer for a given offset.

func LinesBeforeAndAfter

func LinesBeforeAndAfter(data []byte, line, before, after int, lineNumbers bool) []byte

LinesBeforeAndAfter reads n lines before and after a given line. Set lineNumbers to true, to prepend line numbers.

Types

type File

type File struct {
	// absolute path to file
	Path string

	// the name of the file
	FileName string

	// version parsed from filename
	Version Version

	// the actual migration name parsed from filename
	Name string

	// content of the file
	Content []byte

	// UP or DOWN migration
	Direction direction.Direction
}

File represents one file on disk. Example: 20060102150405_initial_plan_to_do_sth.up.sql

func (*File) ReadContent

func (f *File) ReadContent() error

ReadContent reads the file into the content if it's empty.

type Files

type Files []File

Files is a slice of Files.

type MigrationFile

type MigrationFile struct {
	// version of the migration file, parsed from the filenames
	Version Version

	// reference to the *up* migration file
	UpFile *File

	// reference to the *down* migration file
	DownFile *File
}

MigrationFile represents both the UP and the DOWN migration file.

type MigrationFiles

type MigrationFiles []MigrationFile

MigrationFiles is a slice of MigrationFiles.

func ReadMigrationFiles

func ReadMigrationFiles(path string, filenameRegex *regexp.Regexp) (files MigrationFiles, err error)

ReadMigrationFiles reads all migration files from a given path.

func (*MigrationFiles) Applied added in v1.3.0

func (mf *MigrationFiles) Applied(versions Versions) (Files, error)

Applied returns the list of applied migration files.

func (MigrationFiles) Len

func (mf MigrationFiles) Len() int

Len is the number of elements in the collection. Required by Sort Interface{}.

func (MigrationFiles) Less

func (mf MigrationFiles) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j. Required by Sort Interface{}.

func (*MigrationFiles) Pending added in v1.3.0

func (mf *MigrationFiles) Pending(versions Versions) (Files, error)

Pending returns the list of pending migration files.

func (*MigrationFiles) Relative added in v1.3.0

func (mf *MigrationFiles) Relative(relativeN int, versions Versions) (Files, error)

Relative travels relatively through migration files.

+1 will fetch the next up migration file
+2 will fetch the next two up migration files
+n will fetch ...
-1 will fetch the the previous down migration file
-2 will fetch the next two previous down migration files
-n will fetch ...

func (MigrationFiles) Swap

func (mf MigrationFiles) Swap(i, j int)

Swap swaps the elements with indexes i and j. Required by Sort Interface{}.

type Version added in v1.3.0

type Version uint64 // Version is the migration version.

type Versions added in v1.3.0

type Versions []Version // Versions is the list of migrations.

func (Versions) Contains added in v1.3.0

func (versions Versions) Contains(version Version) bool

Contains checks if a _version_ is contained in the list of migrations.

func (Versions) Len added in v1.3.0

func (versions Versions) Len() int

Len is the number of elements in the collection. Required by Sort Interface{}

func (Versions) Less added in v1.3.0

func (versions Versions) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j. Required by Sort Interface{}.

func (Versions) Swap added in v1.3.0

func (versions Versions) Swap(i, j int)

Swap swaps the elements with indexes i and j. Required by Sort Interface{}.

Jump to

Keyboard shortcuts

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