コード例 #1
0
 internal static Task CompleteMigrationSessionAsync(
     Func <MigrationSessionAsync, Task> upsertMigrationSession,
     MigrationSessionAsync migrationSession)
 {
     migrationSession.CompleteMigrationSession();
     return(upsertMigrationSession(migrationSession));
 }
コード例 #2
0
 internal static Task FailMigrationSessionAsync(
     Func <MigrationSessionAsync, Task> upsertMigrationSession,
     MigrationSessionAsync migrationSession,
     MigrationException migrationException)
 {
     migrationSession.FailMigrationSession(migrationException);
     return(upsertMigrationSession(migrationSession));
 }
コード例 #3
0
 private static Task UpdateToAsync(
     IRepositoryToMigrate repositoryToMigrate,
     IRepositoryAsync repository,
     MigrationSessionAsync migrationSession)
 {
     return(ApplyMigrationsAsync(
                repositoryToMigrate,
                repository,
                migrationSession));
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
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;
                }
            }
        }