internal static Task CompleteMigrationSessionAsync( Func <MigrationSessionAsync, Task> upsertMigrationSession, MigrationSessionAsync migrationSession) { migrationSession.CompleteMigrationSession(); return(upsertMigrationSession(migrationSession)); }
internal static Task FailMigrationSessionAsync( Func <MigrationSessionAsync, Task> upsertMigrationSession, MigrationSessionAsync migrationSession, MigrationException migrationException) { migrationSession.FailMigrationSession(migrationException); return(upsertMigrationSession(migrationSession)); }
private static Task UpdateToAsync( IRepositoryToMigrate repositoryToMigrate, IRepositoryAsync repository, MigrationSessionAsync migrationSession) { return(ApplyMigrationsAsync( repositoryToMigrate, repository, migrationSession)); }
private static async Task ApplyMigrationsAsync( IRepositoryToMigrate repositoryToMigrate, IRepositoryAsync repository, MigrationSessionAsync migrationSession) { foreach (MigrationAsync migration in migrationSession.MigrationsToBeApplied) { await ApplyMigrationAsync( repositoryToMigrate, repository, new RepositoryMigrationAsync(migration)).ConfigureAwait(false); } }
internal static async Task <MigrationSessionAsync> TryStartMigrationSession( Func <MigrationSessionAsync, Task> addMigrationSession, bool migrationSessionStarted, IEnumerable <MigrationAsync> migrationsToBeApplied) { MigrationSessionAsync migrationSession; if (migrationSessionStarted) { migrationSession = new MigrationSessionAsync( migrationsToBeApplied, GetFirstVersionOrDefault(migrationsToBeApplied), GetLastVersionOrDefault(migrationsToBeApplied)); await addMigrationSession(migrationSession).ConfigureAwait(false); } else { migrationSession = null; } return(migrationSession); }
/// <summary> /// Use the migration locator to derive what migrations should be executed. /// Compare the migrations to be executed against the migrations applied to the repository. /// Synchronously apply the migrations that were not applied to the repository to migrate in ascending order. /// </summary> /// <param name="migrationLocator">The migration locator</param> /// <param name="repository">The migration repository</param> /// <param name="repositoryToMigrate">The repository to apply the migrations to.</param> public static async Task UpdateToLatestAsync( IMigrationLocatorAsync migrationLocator, IRepositoryAsync repository, IRepositoryToMigrate repositoryToMigrate) { MigrationSessionAsync migrationSession = await MigrationSessionHelpersAsync.TryStartMigrationSession( repository.AddMigrationSessionAsync, MigrationSessionHelpersAsync.MigrationSessionIsAvailableToExecuteAsync(await repository.GetMigrationSessionsAsync().ConfigureAwait(false)), MigrationHelpersAsync.GetMigrationsToBeAppliedAscending( MigrationHelpersAsync.GetMaxVersionOrDefault(await repository.GetMigrationsAsync().ConfigureAwait(false)), await migrationLocator.GetAllMigrationsAsync().ConfigureAwait(false))).ConfigureAwait(false); if (migrationSession != null) { try { await UpdateToAsync( repositoryToMigrate, repository, migrationSession).ConfigureAwait(false); await MigrationSessionHelpersAsync.CompleteMigrationSessionAsync( repository.UpsertMigrationSessionAsync, migrationSession).ConfigureAwait(false); } catch (MigrationException migrationException) { await MigrationSessionHelpersAsync.FailMigrationSessionAsync( repository.UpsertMigrationSessionAsync, migrationSession, migrationException).ConfigureAwait(false); throw migrationException; } } }