Пример #1
0
 /// <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 in ascending order.
 /// </summary>
 /// <param name="migrationLocator">The migration locator</param>
 /// <param name="repository">The migration repository and the repository to apply the migrations to.</param>
 public static Task UpdateToLatestAsync(
     IMigrationLocatorAsync migrationLocator,
     IRepositoryAsync repository)
 {
     return(UpdateToLatestAsync(
                migrationLocator,
                repository,
                repository as IRepositoryToMigrate));
 }
Пример #2
0
        /// <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;
                }
            }
        }