// Ensure detects the current datastore version, and runs all the known migrations
// to upgrade to the latest known version.
Ensure detects the current datastore version, and runs all the known migrations
to upgrade to the latest known version.
// Ensure detects the current datastore version and runs all the known migrations // to upgrade to the latest known version .
func (m *Migrator) Ensure() error {
	currentVersion, emptyDS, err := m.getCurrentVersion()
	if err != nil {
		return fmt.Errorf("getting current version: %s", err)
	}
	targetVersion := m.getTargetVersion()
	if emptyDS {
		if err := m.bootstrapEmptyDatastore(targetVersion); err != nil {
			return fmt.Errorf("bootstrapping empty database: %s", err)
		}
		return nil
	}
	log.Infof("Current datastore version is %d, target version %d", currentVersion, targetVersion)
	if currentVersion == targetVersion {
		return nil
	}
	if currentVersion > targetVersion {
		return fmt.Errorf("migrations are forward only, current version %d, target version %d", currentVersion, targetVersion)
	}
	for i := currentVersion + 1; i <= targetVersion; i++ {
		log.Infof("Running %d migration...", i)
		if err := m.run(i); err != nil {
			return fmt.Errorf("running migration %d: %s", i, err)
		}
		log.Infof("Migration %d ran successfully", i)
	}
	return nil
}
func ( m * Migrator ) Ensure ( ) error { currentVersion , emptyDS , err := m . getCurrentVersion ( ) if err != nil { return fmt . Errorf ( " " , err ) } targetVersion := m . getTargetVersion ( ) if emptyDS { if err := m . bootstrapEmptyDatastore ( targetVersion ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil } log . Infof ( " " , currentVersion , targetVersion ) if currentVersion == targetVersion { return nil } if currentVersion > targetVersion { return fmt . Errorf ( " " , currentVersion , targetVersion ) } for i := currentVersion + 1 ; i <= targetVersion ; i ++ { log . Infof ( " " , i ) if err := m . run ( i ) ; err != nil { return fmt . Errorf ( " " , i , err ) } log . Infof ( " " , i ) } return nil }
Ensure detects the current datastore version, and runs all the known migrations
to upgrade to the latest known version.
Ensure detects the current datastore version and runs all the known migrations to upgrade to the latest known version .
// If the database is empty, we can assume Powergate started fresh // and requires no migration. Set current version to latest version // in migrations script.