package source

import (
	
)
Direction is either up or down.
type Direction string

const (
	Down Direction = "down"
	Up   Direction = "up"
)
Migration is a helper struct for source drivers that need to build the full directory tree in memory. Migration is fully independent from migrate.Migration.
Version is the version of this migration.
Identifier can be any string that helps identifying this migration in the source.
Direction is either Up or Down.
Raw holds the raw location path to this migration in source. ReadUp and ReadDown will use this.
Migrations wraps Migration and has an internal index to keep track of Migration order.
type Migrations struct {
	index      uintSlice
	migrations map[uint]map[Direction]*Migration
}

func () *Migrations {
	return &Migrations{
		index:      make(uintSlice, 0),
		migrations: make(map[uint]map[Direction]*Migration),
	}
}

func ( *Migrations) ( *Migration) ( bool) {
	if  == nil {
		return false
	}

	if .migrations[.Version] == nil {
		.migrations[.Version] = make(map[Direction]*Migration)
	}
reject duplicate versions
	if ,  := .migrations[.Version][.Direction];  {
		return false
	}

	.migrations[.Version][.Direction] = 
	.buildIndex()

	return true
}

func ( *Migrations) () {
	.index = make(uintSlice, 0)
	for  := range .migrations {
		.index = append(.index, )
	}
	sort.Sort(.index)
}

func ( *Migrations) () ( uint,  bool) {
	if len(.index) == 0 {
		return 0, false
	}
	return .index[0], true
}

func ( *Migrations) ( uint) ( uint,  bool) {
	 := .findPos()
	if  >= 1 && len(.index) > -1 {
		return .index[-1], true
	}
	return 0, false
}

func ( *Migrations) ( uint) ( uint,  bool) {
	 := .findPos()
	if  >= 0 && len(.index) > +1 {
		return .index[+1], true
	}
	return 0, false
}

func ( *Migrations) ( uint) ( *Migration,  bool) {
	if ,  := .migrations[];  {
		if ,  := .migrations[][Up];  {
			return , true
		}
	}
	return nil, false
}

func ( *Migrations) ( uint) ( *Migration,  bool) {
	if ,  := .migrations[];  {
		if ,  := .migrations[][Down];  {
			return , true
		}
	}
	return nil, false
}

func ( *Migrations) ( uint) int {
	if len(.index) > 0 {
		 := .index.Search()
		if  < len(.index) && .index[] ==  {
			return 
		}
	}
	return -1
}

type uintSlice []uint

func ( uintSlice) () int {
	return len()
}

func ( uintSlice) (,  int) {
	[], [] = [], []
}

func ( uintSlice) (,  int) bool {
	return [] < []
}

func ( uintSlice) ( uint) int {
	return sort.Search(len(), func( int) bool { return [] >=  })