Skip a set of migrations Will skip at most `max` migrations. Pass 0 for no limit. Returns the number of skipped migrations.
(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int)
| 725 | // |
| 726 | // Returns the number of skipped migrations. |
| 727 | func SkipMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) { |
| 728 | migrations, dbMap, err := PlanMigration(db, dialect, m, dir, max) |
| 729 | if err != nil { |
| 730 | return 0, err |
| 731 | } |
| 732 | |
| 733 | // Skip migrations |
| 734 | applied := 0 |
| 735 | for _, migration := range migrations { |
| 736 | var executor SqlExecutor |
| 737 | |
| 738 | if migration.DisableTransaction { |
| 739 | executor = dbMap |
| 740 | } else { |
| 741 | executor, err = dbMap.Begin() |
| 742 | if err != nil { |
| 743 | return applied, newTxError(migration, err) |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | err = executor.Insert(&MigrationRecord{ |
| 748 | Id: migration.Id, |
| 749 | AppliedAt: time.Now(), |
| 750 | }) |
| 751 | if err != nil { |
| 752 | if trans, ok := executor.(*gorp.Transaction); ok { |
| 753 | _ = trans.Rollback() |
| 754 | } |
| 755 | |
| 756 | return applied, newTxError(migration, err) |
| 757 | } |
| 758 | |
| 759 | if trans, ok := executor.(*gorp.Transaction); ok { |
| 760 | if err := trans.Commit(); err != nil { |
| 761 | return applied, newTxError(migration, err) |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | applied++ |
| 766 | } |
| 767 | |
| 768 | return applied, nil |
| 769 | } |
| 770 | |
| 771 | // Filter a slice of migrations into ones that should be applied. |
| 772 | func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration { |
searching dependent graphs…