Пример #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 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;
                }
            }
        }
 /// <inheritdoc />
 public virtual void MarkUpToVersion(MigrationVersion version)
 {
     _migrationLocator.GetAllMigrations()
     .Where(m => m.Version <= version)
     .ToList()
     .ForEach(m => MarkVersion(m.Version));
 }