Ejemplo n.º 1
0
func runMigrationsUpTo(b backend.Backend, targetVersion int64) (bool, error) {
	migrationsRun := 0

	currentVersion := b.CurrentSchemaVersion()

	for i := int64(1); i <= latestMigrationVersion; i++ {
		m := availableMigrations[i]

		// skip migrations we've already run
		if currentVersion >= m.Version {
			continue
		}

		// run migrations up to and through our target version.
		if m.Version > targetVersion {
			break
		}

		if err := m.Run(b); err != nil {
			return false, err
		}

		migrationsRun++
	}

	if migrationsRun == 0 {
		fmt.Println("No migrations needed to be run.")
	} else {
		fmt.Println("All migrations ran successfully.")
	}

	return false, nil
}