Inheritance: IMigrationStepMetadata
Esempio n. 1
0
 public IEnumerable<MigrationStep> Aggregate()
 {
     Dictionary<string, Aggregation> aggregations = FindLargestApplicableAggregations();
     foreach (ApplicableMigration applicableMigration in _applicableMigrations)
     {
         MigrationStepMetadata migrationStepMetadata;
         Aggregation aggregation;
         if (aggregations.TryGetValue(applicableMigration.Migration.Metadata.ModuleName, out aggregation))
         {
             // Note: we issue an aggregated migration step when the last migration is hit to adhere more or less
             // to the ordering of the migrations.
             if (applicableMigration.Migration.Metadata.Timestamp == aggregation.LastAggregatedMigration.Timestamp)
             {
                 // aggregate migration step
                 migrationStepMetadata = new MigrationStepMetadata(MigrationDirection.Up, false, aggregation.AggregatedMigrations);
                 Log.Info("Using {0} to aggregate {1} migration(s) from module '{2}'", aggregation.Migration.Implementation.GetName(), migrationStepMetadata.Migrations.Count(), migrationStepMetadata.ModuleName);
                 yield return new MigrationStep(aggregation.Migration.Implementation, migrationStepMetadata);
             }
             if (applicableMigration.Migration.Metadata.Timestamp <= aggregation.Migration.Metadata.Timestamp)
             {
                 continue; // the migration will be included in the aggregate
             }
         }
         // single migration step
         migrationStepMetadata = new MigrationStepMetadata(applicableMigration.Direction, applicableMigration.Migration.UseModuleNameAsDefaultSchema, new[] { MetadataFor(applicableMigration) });
         yield return new MigrationStep(applicableMigration.Migration.Implementation, migrationStepMetadata);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Alters the database schema by applying the specified migration. Versioning is unaffected by this operation and any timestamp information on the <paramref name="migration"/> is disregarded.
        /// </summary>
        public void Alter(IMigration migration)
        {
            if (migration is IReversibleMigration)
            {
                Log.Info(LogCategory.General, "Migrations used to modify the database schema directly cannot be reversed.");
            }

            var migrationMetadata = new MigrationMetadata(0, "Bypass", "This migration is being executed without affecting the versioning.");
            var stepMetadata = new MigrationStepMetadata(MigrationDirection.Up, false, new[] { migrationMetadata });
            var batch = new MigrationBatch(new[]
            {
                new MigrationStep(migration, stepMetadata)
            }, Enumerable.Empty<IMigrationMetadata>(), new NoVersioning(), Configuration);
            batch.Execute();
        }