예제 #1
0
        private static void ApplyMigration(
            IRepositoryToMigrate repositoryToMigrate,
            IRepository repository,
            RepositoryMigration startedMigration)
        {
            try
            {
                MigrationHelpers.StartMigration(
                    repository.AddMigration,
                    startedMigration);

                startedMigration.Migration.Update(repository, repositoryToMigrate);

                MigrationHelpers.CompleteMigration(
                    repository.UpsertMigration,
                    startedMigration);
            }
            catch (Exception exception)
            {
                OnUpgradeException(
                    repositoryToMigrate,
                    repository,
                    startedMigration,
                    exception);
            }
        }
예제 #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 void UpdateToLatest(
            IMigrationLocator migrationLocator,
            IRepository repository,
            IRepositoryToMigrate repositoryToMigrate)
        {
            MigrationSession migrationSession;

            if (MigrationSessionHelpers.TryStartMigrationSession(
                    repository.AddMigrationSession,
                    MigrationSessionHelpers.MigrationSessionIsAvailableToExecute(repository.GetMigrationSessions()),
                    MigrationHelpers.GetMigrationsToBeAppliedAscending(
                        MigrationHelpers.GetMaxVersionOrDefault(repository.GetMigrations()),
                        migrationLocator.GetAllMigrations()),
                    out migrationSession))
            {
                try
                {
                    UpdateTo(
                        repositoryToMigrate,
                        repository,
                        migrationSession);
                    MigrationSessionHelpers.CompleteMigrationSession(
                        repository.UpsertMigrationSession,
                        migrationSession);
                }
                catch (MigrationException migrationException)
                {
                    MigrationSessionHelpers.FailMigrationSession(
                        repository.UpsertMigrationSession,
                        migrationSession,
                        migrationException);
                    throw migrationException;
                }
            }
        }
예제 #3
0
        private static async Task ApplyMigrationAsync(
            IRepositoryToMigrate repositoryToMigrate,
            IRepositoryAsync repository,
            RepositoryMigrationAsync startedMigration)
        {
            try
            {
                await MigrationHelpersAsync.StartMigrationAsync(
                    repository.AddMigrationAsync,
                    startedMigration).ConfigureAwait(false);

                await startedMigration.Migration.UpdateAsync(
                    repository,
                    repositoryToMigrate).ConfigureAwait(false);

                await MigrationHelpersAsync.CompleteMigrationAsync(
                    repository.UpsertMigrationAsync,
                    startedMigration).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                await OnUpgradeExceptionAsync(
                    repositoryToMigrate,
                    repository,
                    startedMigration,
                    exception).ConfigureAwait(false);
            }
        }
예제 #4
0
        private static async Task OnUpgradeExceptionAsync(
            IRepositoryToMigrate repositoryToMigrate,
            IRepositoryAsync repository,
            RepositoryMigrationAsync repositoryMigration,
            Exception exception)
        {
            try
            {
                await repositoryMigration.Migration.RollbackAsync(
                    repository,
                    repositoryToMigrate).ConfigureAwait(false);

                await MigrationHelpersAsync.FailMigrationAsync(
                    repository.DeleteMigrationAsync,
                    repositoryMigration).ConfigureAwait(false);

                throw new MigrationException(
                          exception,
                          repositoryMigration.Version);
            }
            catch (Exception rollbackEx)
            {
                await OnRollbackExceptionAsync(
                    repositoryMigration.Migration,
                    rollbackEx).ConfigureAwait(false);
            }
        }
예제 #5
0
 private static void UpdateTo(
     IRepositoryToMigrate repositoryToMigrate,
     IRepository repository,
     MigrationSession migrationSession)
 {
     ApplyMigrations(
         repositoryToMigrate,
         repository,
         migrationSession);
 }
예제 #6
0
 private static Task UpdateToAsync(
     IRepositoryToMigrate repositoryToMigrate,
     IRepositoryAsync repository,
     MigrationSessionAsync migrationSession)
 {
     return(ApplyMigrationsAsync(
                repositoryToMigrate,
                repository,
                migrationSession));
 }
예제 #7
0
 private static void ApplyMigrations(
     IRepositoryToMigrate repositoryToMigrate,
     IRepository repository,
     MigrationSession migrationSession)
 {
     foreach (Migration migration in migrationSession.MigrationsToBeApplied)
     {
         ApplyMigration(
             repositoryToMigrate,
             repository,
             new RepositoryMigration(migration));
     }
 }
예제 #8
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);
     }
 }
예제 #9
0
 private static void OnUpgradeException(
     IRepositoryToMigrate repositoryToMigrate,
     IRepository repository,
     RepositoryMigration repositoryMigration,
     Exception exception)
 {
     try
     {
         repositoryMigration.Migration.Rollback(repository, repositoryToMigrate);
         MigrationHelpers.FailMigration(
             repository.DeleteMigration,
             repositoryMigration);
         throw new MigrationException(
                   exception,
                   repositoryMigration.Version);
     }
     catch (Exception rollbackEx)
     {
         OnRollbackException(
             repositoryMigration.Migration,
             rollbackEx);
     }
 }
예제 #10
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;
                }
            }
        }
예제 #11
0
 public abstract void Rollback(IRepository repository, IRepositoryToMigrate repositoryToMigrate);
예제 #12
0
 public abstract void Update(IRepository repository, IRepositoryToMigrate repositoryToMigrate);
예제 #13
0
 public abstract Task RollbackAsync(IRepositoryAsync repository, IRepositoryToMigrate repositoryToMigrate);
예제 #14
0
 public abstract Task UpdateAsync(IRepositoryAsync repository, IRepositoryToMigrate repositoryToMigrate);