package migrate

import (
	
	
	
	
)
DefaultBufferSize sets the in memory buffer size (in Bytes) for every pre-read migration (see DefaultPrefetchMigrations).
var DefaultBufferSize = uint(100000)
Migration holds information about a migration. It is initially created from data coming from the source and then used when run against the database.
Identifier can be any string to help identifying the migration in the source.
Version is the version of this migration.
TargetVersion is the migration version after this migration has been applied to the database. Can be -1, implying that this is a NilVersion.
Body holds an io.ReadCloser to the source.
BufferedBody holds an buffered io.Reader to the underlying Body.
BufferSize defaults to DefaultBufferSize
bufferWriter holds an io.WriteCloser and pipes to BufferBody. It's an *Closer for flow control.
Scheduled is the time when the migration was scheduled/ queued.
StartedBuffering is the time when buffering of the migration source started.
FinishedBuffering is the time when buffering of the migration source finished.
FinishedReading is the time when the migration source is fully read.
BytesRead holds the number of Bytes read from the migration source.
NewMigration returns a new Migration and sets the body, identifier, version and targetVersion. Body can be nil, which turns this migration into a "NilMigration". If no identifier is provided, it will default to "<empty>". targetVersion can be -1, implying it is a NilVersion. What is a NilMigration? Usually each migration version coming from source is expected to have an Up and Down migration. This is not a hard requirement though, leading to a situation where only the Up or Down migration is present. So let's say the user wants to migrate up to a version that doesn't have the actual Up migration, in that case we still want to apply the version, but with an empty body. We are calling that a NilMigration, a migration with an empty body. What is a NilVersion? NilVersion is a const(-1). When running down migrations and we are at the last down migration, there is no next down migration, the targetVersion should be nil. Nil in this case is represented by -1 (because type int).
func ( io.ReadCloser,  string,
	 uint,  int) (*Migration, error) {
	 := time.Now()
	 := &Migration{
		Identifier:    ,
		Version:       ,
		TargetVersion: ,
		Scheduled:     ,
	}

	if  == nil {
		if len() == 0 {
			.Identifier = "<empty>"
		}

		.StartedBuffering = 
		.FinishedBuffering = 
		.FinishedReading = 
		return , nil
	}

	,  := io.Pipe()
	.Body =  // want to simulate low latency? newSlowReader(body)
	.BufferSize = DefaultBufferSize
	.BufferedBody = 
	.bufferWriter = 
	return , nil
}
String implements string.Stringer and is used in tests.
func ( *Migration) () string {
	return fmt.Sprintf("%v [%v=>%v]", .Identifier, .Version, .TargetVersion)
}
LogString returns a string describing this migration to humans.
func ( *Migration) () string {
	 := "u"
	if .TargetVersion < int(.Version) {
		 = "d"
	}
	return fmt.Sprintf("%v/%v %v", .Version, , .Identifier)
}
Buffer buffers Body up to BufferSize. Calling this function blocks. Call with goroutine.
func ( *Migration) () error {
	if .Body == nil {
		return nil
	}

	.StartedBuffering = time.Now()

	 := bufio.NewReaderSize(.Body, int(.BufferSize))
start reading from body, peek won't move the read pointer though poor man's solution?
	if ,  := .Peek(int(.BufferSize));  != nil &&  != io.EOF {
		return 
	}

	.FinishedBuffering = time.Now()
write to bufferWriter, this will block until something starts reading from m.Buffer
	,  := .WriteTo(.bufferWriter)
	if  != nil {
		return 
	}

	.FinishedReading = time.Now()
	.BytesRead = 
close bufferWriter so Buffer knows that there is no more data coming
	if  := .bufferWriter.Close();  != nil {
		return 
	}
it's safe to close the Body too
	if  := .Body.Close();  != nil {
		return 
	}

	return nil