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

Function SkipMax

migrate.go:727–769  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

725//
726// Returns the number of skipped migrations.
727func 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.
772func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration {

Callers 1

TestSkipMigrationMethod · 0.85

Calls 3

InsertMethod · 0.95
PlanMigrationFunction · 0.85
newTxErrorFunction · 0.85

Tested by 1

TestSkipMigrationMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…