MCPcopy
hub / github.com/rubenv/sql-migrate / ToApply

Function ToApply

migrate.go:772–798  ·  view source on GitHub ↗

Filter a slice of migrations into ones that should be applied.

(migrations []*Migration, current string, direction MigrationDirection)

Source from the content-addressed store, hash-verified

770
771// Filter a slice of migrations into ones that should be applied.
772func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration {
773 index := -1
774 if current != "" {
775 for index < len(migrations)-1 {
776 index++
777 if migrations[index].Id == current {
778 break
779 }
780 }
781 }
782
783 switch direction {
784 case Up:
785 return migrations[index+1:]
786 case Down:
787 if index == -1 {
788 return []*Migration{}
789 }
790 toApply := make([]*Migration, index+1)
791 for i := 0; i < index+1; i++ {
792 toApply[index-i] = migrations[i]
793 }
794 return toApply
795 }
796
797 panic("Not possible")
798}
799
800func ToCatchup(migrations, existingMigrations []*Migration, lastRun *Migration) []*PlannedMigration {
801 missing := make([]*PlannedMigration, 0)

Callers 10

planMigrationCommonMethod · 0.85
TestGetAllMethod · 0.85
TestGetAbcMethod · 0.85
TestGetCdeMethod · 0.85
TestGetDoneMethod · 0.85
TestDownDoneMethod · 0.85
TestDownCdeMethod · 0.85
TestDownAbcMethod · 0.85
TestDownAllMethod · 0.85

Calls

no outgoing calls

Tested by 9

TestGetAllMethod · 0.68
TestGetAbcMethod · 0.68
TestGetCdeMethod · 0.68
TestGetDoneMethod · 0.68
TestDownDoneMethod · 0.68
TestDownCdeMethod · 0.68
TestDownAbcMethod · 0.68
TestDownAllMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…