Filter a slice of migrations into ones that should be applied.
(migrations []*Migration, current string, direction MigrationDirection)
| 770 | |
| 771 | // Filter a slice of migrations into ones that should be applied. |
| 772 | func 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 | |
| 800 | func ToCatchup(migrations, existingMigrations []*Migration, lastRun *Migration) []*PlannedMigration { |
| 801 | missing := make([]*PlannedMigration, 0) |
no outgoing calls
searching dependent graphs…