internal override void RevertMigration( string migrationId, DbMigration migration, XDocument targetModel) { IEnumerable <MigrationOperation> systemOperations = Enumerable.Empty <MigrationOperation>(); string defaultSchema = DbMigrator.GetDefaultSchema(migration); XDocument historyModel1 = this.GetHistoryModel(defaultSchema); if (object.ReferenceEquals((object)targetModel, (object)this._emptyModel.Value) && !this._historyRepository.IsShared()) { systemOperations = (IEnumerable <MigrationOperation>) this._modelDiffer.Diff(historyModel1, this._emptyModel.Value, (Lazy <ModificationCommandTreeGenerator>)null, (MigrationSqlGenerator)null, (string)null, (string)null); } else { string lastDefaultSchema = this.GetLastDefaultSchema(migrationId); if (!string.Equals(lastDefaultSchema, defaultSchema, StringComparison.Ordinal)) { XDocument historyModel2 = this.GetHistoryModel(lastDefaultSchema); systemOperations = (IEnumerable <MigrationOperation>) this._modelDiffer.Diff(historyModel1, historyModel2, (Lazy <ModificationCommandTreeGenerator>)null, (MigrationSqlGenerator)null, (string)null, (string)null); } } migration.Down(); this.ExecuteOperations(migrationId, new VersionedModel(targetModel, (string)null), migration.Operations, systemOperations, true, false); }
internal override void RevertMigration( string migrationId, DbMigration migration, XDocument targetModel) { var systemOperations = Enumerable.Empty <MigrationOperation>(); var migrationSchema = GetDefaultSchema(migration); var historyModel = GetHistoryModel(migrationSchema); if (ReferenceEquals(targetModel, _emptyModel.Value) && !_historyRepository.IsShared()) { systemOperations = _modelDiffer.Diff(historyModel, targetModel); } else { var lastMigrationSchema = GetLastDefaultSchema(migrationId); if (!string.Equals(lastMigrationSchema, migrationSchema, StringComparison.Ordinal)) { var lastHistoryModel = GetHistoryModel(lastMigrationSchema); systemOperations = _modelDiffer.Diff(historyModel, lastHistoryModel); } } migration.Down(); ExecuteOperations(migrationId, targetModel, migration.Operations, systemOperations, downgrading: true); }
internal override void RevertMigration(string migrationId, DbMigration migration, XDocument sourceModel, XDocument targetModel) { bool?includeSystemOps = null; if (ReferenceEquals(targetModel, _emptyModel.Value) && !_historyRepository.IsShared()) { includeSystemOps = true; if (!sourceModel.HasSystemOperations()) { // upgrade scenario, inject the history model AttachHistoryModel(sourceModel); } } var systemOperations = _modelDiffer.Diff(sourceModel, targetModel, includeSystemOps) .Where(o => o.IsSystem); migration.Down(); ExecuteOperations(migrationId, targetModel, migration.Operations.Concat(systemOperations), downgrading: true); }