file

package
v1.93.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 12 Imported by: 0

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 AssetStore added in v1.91.0

type AssetStore struct {
	// Asset should return content of file in path if exists
	Asset func(path string) ([]byte, error)
	// AssetDir should return list of files in the path
	AssetDir func(path string) ([]string, error)
}

AssetStore is a bindatata asset store

func (AssetStore) ReadDir added in v1.91.0

func (s AssetStore) ReadDir(dirname string) ([]string, error)

List file in a given dir

func (AssetStore) ReadFile added in v1.91.0

func (s AssetStore) ReadFile(f *File) ([]byte, error)

Read contents of a file

type FSStore added in v1.91.0

type FSStore struct {
	FS fs.FS
}

FSStore is a regular file system store

func (FSStore) ReadDir added in v1.91.0

func (s FSStore) ReadDir(dirname string) ([]string, error)

List file in a given dir

func (FSStore) ReadFile added in v1.91.0

func (s FSStore) ReadFile(f *File) ([]byte, error)

Read contents of a file

type File

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

	// the name of the file
	FileName string

	// version parsed from filename
	Version uint64

	// the actual migration name parsed from filename
	Name string

	// content of the file
	Content []byte

	// UP or DOWN migration
	Direction direction.Direction

	// the store used to read the file contents;
	// defaults to LocalFSStore (a regular file system)
	Store FileStore
}

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

func (*File) ReadContent

func (f *File) ReadContent() error

ReadContent reads the file's content if the content is empty

type FileStore added in v1.91.0

type FileStore interface {
	// Read contents of a given file
	ReadFile(*File) ([]byte, error)
	// List filenames of a given directory (including subdirectories)
	ReadDir(string) ([]string, error)
}

FileStore interface is an abstraction layer with minimal functionality to get a list of migration files and read their contents.

type Files

type Files []File

Files is a slice of Files

type LocalFSStore added in v1.93.0

type LocalFSStore struct{}

LocalFSStore is a local file system store

func (LocalFSStore) ReadDir added in v1.93.0

func (s LocalFSStore) ReadDir(dirname string) ([]string, error)

List file in a given dir

func (LocalFSStore) ReadFile added in v1.93.0

func (s LocalFSStore) ReadFile(f *File) ([]byte, error)

Read contents of a file

type MigrationFile

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

	// 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 ReadMigrationFilesFromStore added in v1.91.0

func ReadMigrationFilesFromStore(store FileStore, path string, filenameRegex *regexp.Regexp) (files MigrationFiles, err error)

ReadMigrationFilesFromStore reads all migration files from a given file store

func (*MigrationFiles) From

func (mf *MigrationFiles) From(version uint64, relativeN int) (Files, error)

From 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) 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) Swap

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

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

func (*MigrationFiles) ToFirstFrom

func (mf *MigrationFiles) ToFirstFrom(version uint64) (Files, error)

ToFirstFrom fetches all (down) migration files including the migration file of the current version to the very first migration file.

func (*MigrationFiles) ToLastFrom

func (mf *MigrationFiles) ToLastFrom(version uint64) (Files, error)

ToLastFrom fetches all (up) migration files to the most recent migration file. The migration file of the current version is not included.

Jump to

Keyboard shortcuts

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