private async Task <ICollection <IMigration> > GetPendingMigrationsAsync() { var allMigrations = GetAllMigrations(); var completedMigrations = await _migrationRepository.GetAllAsync(paging : 1000).AnyContext(); var currentVersion = completedMigrations.Documents.Count > 0 ? completedMigrations.Documents.Max(m => m.Version) : 0; return(allMigrations.Where(m => m.Version > currentVersion).ToList()); }
private async Task <ICollection <IMigration> > GetPendingMigrationsAsync() { var allMigrations = GetAllMigrations(); var completedMigrations = await _migrationRepository.GetAllAsync(paging : 1000).AnyContext(); // if migrations have never run before, mark the up to date with the most recent migration if (completedMigrations.Documents.Count == 0) { var max = allMigrations.Max(m => m.Version); await MarkMigrationCompleteAsync(max); return(new List <IMigration>()); } var currentVersion = completedMigrations.Documents.Max(m => m.Version); return(allMigrations.Where(m => m.Version > currentVersion).ToList()); }
public async Task <ICollection <IMigration> > GetPendingMigrationsAsync() { var migrations = Migrations.OrderBy(m => m.Version).ToList(); var completedMigrations = await _migrationRepository.GetAllAsync(o => o.PageLimit(1000)).AnyContext(); int max = 0; // if migrations have never run before, mark highest version as completed if (completedMigrations.Documents.Count == 0) { if (migrations.Count > 0) { max = migrations.Where(m => m.Version.HasValue).Max(m => m.Version.Value); } await MarkMigrationCompleteAsync(max); return(new List <IMigration>()); } int currentVersion = completedMigrations.Documents.Max(m => m.Version); return(migrations.Where(m => (m.Version.HasValue == false && ShouldRunUnversionedMigrations) || (m.Version.HasValue && m.Version > currentVersion)).ToList()); }