Пример #1
0
        internal override void ApplyMigration(DbMigration migration, DbMigration lastMigration)
        {
            IMigrationMetadata migrationMetadata = (IMigrationMetadata)migration;
            VersionedModel     sourceModel1      = this.GetLastModel(lastMigration, migrationMetadata.Id);
            VersionedModel     sourceModel2      = migration.GetSourceModel();
            VersionedModel     targetModel       = migration.GetTargetModel();

            if (sourceModel2 != null && this.IsModelOutOfDate(sourceModel2.Model, lastMigration))
            {
                base.AutoMigrate(migrationMetadata.Id.ToAutomaticMigrationId(), sourceModel1, sourceModel2, false);
                sourceModel1 = sourceModel2;
            }
            string    defaultSchema = DbMigrator.GetDefaultSchema(migration);
            XDocument historyModel  = this.GetHistoryModel(defaultSchema);
            IEnumerable <MigrationOperation> systemOperations = Enumerable.Empty <MigrationOperation>();

            if (object.ReferenceEquals((object)sourceModel1.Model, (object)this._emptyModel.Value) && !base.HistoryExists())
            {
                systemOperations = (IEnumerable <MigrationOperation>) this._modelDiffer.Diff(this._emptyModel.Value, historyModel, (Lazy <ModificationCommandTreeGenerator>)null, (MigrationSqlGenerator)null, (string)null, (string)null);
            }
            else
            {
                string lastDefaultSchema = this.GetLastDefaultSchema(migrationMetadata.Id);
                if (!string.Equals(lastDefaultSchema, defaultSchema, StringComparison.Ordinal))
                {
                    systemOperations = (IEnumerable <MigrationOperation>) this._modelDiffer.Diff(this.GetHistoryModel(lastDefaultSchema), historyModel, (Lazy <ModificationCommandTreeGenerator>)null, (MigrationSqlGenerator)null, (string)null, (string)null);
                }
            }
            migration.Up();
            this.ExecuteOperations(migrationMetadata.Id, targetModel, migration.Operations, systemOperations, false, false);
        }
Пример #2
0
        private VersionedModel GetLastModel(
            DbMigration lastMigration,
            string currentMigrationId = null)
        {
            if (lastMigration != null)
            {
                return(lastMigration.GetTargetModel());
            }
            string    migrationId;
            string    productVersion;
            XDocument lastModel = this._historyRepository.GetLastModel(out migrationId, out productVersion, (string)null);

            if (lastModel != null && (currentMigrationId == null || string.CompareOrdinal(migrationId, currentMigrationId) < 0))
            {
                return(new VersionedModel(lastModel, productVersion));
            }
            return(new VersionedModel(this._emptyModel.Value, (string)null));
        }