/// <summary> /// Upgrade/downgrade to the specified version. /// </summary> /// <param name="version"> /// The required version of the repository. /// </param> /// <param name="cancel"> /// </param> /// <returns></returns> public async Task MirgrateToVersionAsync(int version, CancellationToken cancel = default(CancellationToken)) { if (version != 0 && !Migrations.Any(m => m.Version == version)) { throw new ArgumentOutOfRangeException("version", $"Repository version '{version}' is unknown."); } var currentVersion = CurrentVersion; var increment = CurrentVersion < version ? 1 : -1; while (currentVersion != version) { var nextVersion = currentVersion + increment; log.InfoFormat("Migrating to version {0}", nextVersion); if (increment > 0) { var migration = Migrations.FirstOrDefault(m => m.Version == nextVersion); if (migration.CanUpgrade) { await migration.UpgradeAsync(ipfs, cancel); } } else if (increment < 0) { var migration = Migrations.FirstOrDefault(m => m.Version == currentVersion); if (migration.CanDowngrade) { await migration.DowngradeAsync(ipfs, cancel); } } CurrentVersion = nextVersion; currentVersion = nextVersion; } }
public MigrationSpecification LoadMigrationIfPresent(int version) { return(Migrations.FirstOrDefault(m => m.Version == version)); }