mirror of https://github.com/status-im/migrate.git
update comments
This commit is contained in:
parent
4ec7db3188
commit
53890882cf
22
file/file.go
22
file/file.go
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
var filenameRegex = "^([0-9]+)_(.*)\\.(up|down)\\.%s$"
|
var filenameRegex = "^([0-9]+)_(.*)\\.(up|down)\\.%s$"
|
||||||
|
|
||||||
// FilenameRegex build regular expression stmt with given
|
// FilenameRegex builds regular expression stmt with given
|
||||||
// filename extension from driver.
|
// filename extension from driver.
|
||||||
func FilenameRegex(filenameExtension string) *regexp.Regexp {
|
func FilenameRegex(filenameExtension string) *regexp.Regexp {
|
||||||
return regexp.MustCompile(fmt.Sprintf(filenameRegex, filenameExtension))
|
return regexp.MustCompile(fmt.Sprintf(filenameRegex, filenameExtension))
|
||||||
|
@ -26,11 +26,22 @@ func FilenameRegex(filenameExtension string) *regexp.Regexp {
|
||||||
// File represents one file on disk.
|
// File represents one file on disk.
|
||||||
// Example: 001_initial_plan_to_do_sth.up.sql
|
// Example: 001_initial_plan_to_do_sth.up.sql
|
||||||
type File struct {
|
type File struct {
|
||||||
|
// absolute path to file
|
||||||
Path string
|
Path string
|
||||||
|
|
||||||
|
// the name of the file
|
||||||
FileName string
|
FileName string
|
||||||
|
|
||||||
|
// version parsed from filename
|
||||||
Version uint64
|
Version uint64
|
||||||
|
|
||||||
|
// the actual migration name parsed from filename
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
|
// content of the file
|
||||||
Content []byte
|
Content []byte
|
||||||
|
|
||||||
|
// UP or DOWN migration
|
||||||
Direction direction.Direction
|
Direction direction.Direction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +50,13 @@ type Files []File
|
||||||
|
|
||||||
// MigrationFile represents both the UP and the DOWN migration file.
|
// MigrationFile represents both the UP and the DOWN migration file.
|
||||||
type MigrationFile struct {
|
type MigrationFile struct {
|
||||||
|
// version of the migration file, parsed from the filenames
|
||||||
Version uint64
|
Version uint64
|
||||||
|
|
||||||
|
// reference to the *up* migration file
|
||||||
UpFile *File
|
UpFile *File
|
||||||
|
|
||||||
|
// reference to the *down* migration file
|
||||||
DownFile *File
|
DownFile *File
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,8 +280,8 @@ func (mf MigrationFiles) Swap(i, j int) {
|
||||||
|
|
||||||
// LineColumnFromOffset reads data and returns line and column integer
|
// LineColumnFromOffset reads data and returns line and column integer
|
||||||
// for a given offset.
|
// for a given offset.
|
||||||
// TODO is there a better way?
|
|
||||||
func LineColumnFromOffset(data []byte, offset int) (line, column int) {
|
func LineColumnFromOffset(data []byte, offset int) (line, column int) {
|
||||||
|
// TODO is there a better way?
|
||||||
fs := token.NewFileSet()
|
fs := token.NewFileSet()
|
||||||
tf := fs.AddFile("", fs.Base(), len(data))
|
tf := fs.AddFile("", fs.Base(), len(data))
|
||||||
tf.SetLinesForContent(data)
|
tf.SetLinesForContent(data)
|
||||||
|
@ -275,9 +291,9 @@ func LineColumnFromOffset(data []byte, offset int) (line, column int) {
|
||||||
|
|
||||||
// LinesBeforeAndAfter reads n lines before and after a given line.
|
// LinesBeforeAndAfter reads n lines before and after a given line.
|
||||||
// Set lineNumbers to true, to prepend line numbers.
|
// Set lineNumbers to true, to prepend line numbers.
|
||||||
|
func LinesBeforeAndAfter(data []byte, line, before, after int, lineNumbers bool) []byte {
|
||||||
// TODO(mattes): Trim empty lines at the beginning and at the end
|
// TODO(mattes): Trim empty lines at the beginning and at the end
|
||||||
// TODO(mattes): Trim offset whitespace at the beginning of each line, so that indentation is preserved
|
// TODO(mattes): Trim offset whitespace at the beginning of each line, so that indentation is preserved
|
||||||
func LinesBeforeAndAfter(data []byte, line, before, after int, lineNumbers bool) []byte {
|
|
||||||
startLine := line - before
|
startLine := line - before
|
||||||
endLine := line + after
|
endLine := line + after
|
||||||
lines := bytes.SplitN(data, []byte("\n"), endLine+1)
|
lines := bytes.SplitN(data, []byte("\n"), endLine+1)
|
||||||
|
|
Loading…
Reference in New Issue