Ejemplo n.º 1
0
        /// <summary>
        /// Performs Db model update actions, depending on instance type (dev, staging, production).
        /// </summary>
        public DbUpgradeInfo BuildUpgradeInfo()
        {
            //Even if we do not do db model upgrades, we still may have migration actions (post upgrate), which we will run after completing connection to db
            var driver = _database.DbModel.Driver;

            _upgradeInfo = new DbUpgradeInfo(_database.Settings, _database.DbModel);
            var oldDbVersion = LoadDbVersionInfo();

            if (!CheckCanUpgrade(oldDbVersion))
            {
                return(_upgradeInfo);
            }
            var loader = driver.CreateDbModelLoader(_database.Settings, _log);

            if (driver.Supports(DbFeatures.Schemas))
            {
                var schemas = _database.DbModel.Schemas.Select(s => s.Schema).ToList();
                loader.SetSchemasSubset(schemas);
            }
            _upgradeInfo.OldDbModel             = loader.LoadModel();
            _upgradeInfo.OldDbModel.VersionInfo = oldDbVersion;
            //assign prior versions
            //Compare two models and get changes
            var modelComparer = new DbModelComparer();

            modelComparer.BuildDbModelChanges(_upgradeInfo, loader as IDbObjectComparer, _log);
            //build scripts
            var updater = driver.CreateDbModelUpdater(_database.Settings);

            updater.BuildScripts(_upgradeInfo);
            //Add migrations
            var migrSet = new DbMigrationSet(_app, _database, _upgradeInfo.OldDbModel);

            foreach (var module in this._database.DbModel.EntityApp.Modules)
            {
                migrSet.CurrentModule = module;
                module.RegisterMigrations(migrSet);
            }
            migrSet.CurrentModule = null;
            _upgradeInfo.AddMigrations(migrSet);
            //Update final status
            _upgradeInfo.VersionsChanged = oldDbVersion != null && _database.DbModel.VersionInfo.VersionChanged(oldDbVersion);
            if (_upgradeInfo.AllScripts.Count > 0 || _upgradeInfo.VersionsChanged)
            {
                _upgradeInfo.Status = UpgradeStatus.ChangesDetected;
            }
            else
            {
                _upgradeInfo.Status = UpgradeStatus.NoChanges;
            }
            //Sort, Clear up
            _upgradeInfo.AllScripts.Sort(DbUpgradeScript.CompareExecutionOrder);
            _database.DbModel.ResetPeerRefs(); //drop refs to old model
            return(_upgradeInfo);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Performs Db model update actions, depending on instance type (dev, staging, production). 
 /// </summary>
 public DbUpgradeInfo BuildUpgradeInfo()
 {
     //Even if we do not do db model upgrades, we still may have migration actions (post upgrate), which we will run after completing connection to db
       var driver = _database.DbModel.Driver;
       var loader = driver.CreateDbModelLoader(_database.Settings, _log);
       _upgradeInfo = new DbUpgradeInfo(_database.Settings, _database.DbModel);
       var oldDbVersion = LoadDbVersionInfo(loader);
       if (!CheckCanUpgrade(oldDbVersion))
     return _upgradeInfo;
       _upgradeInfo.OldDbModel = loader.LoadModel();
       _upgradeInfo.OldDbModel.VersionInfo = oldDbVersion;
       //assign prior versions
       //Compare two models and get changes
       var modelComparer = new DbModelComparer();
       modelComparer.AddDbModelChanges(_upgradeInfo, _log);
       //build scripts
       var updater = driver.CreateDbModelUpdater(_database.Settings);
       updater.BuildScripts(_upgradeInfo);
       //Add migrations
       var migrSet = new DbMigrationSet(_app, _database, _upgradeInfo.OldDbModel);
       foreach (var module in this._database.DbModel.EntityApp.Modules) {
     migrSet.CurrentModule = module;
     module.RegisterMigrations(migrSet);
       }
       migrSet.CurrentModule = null;
       _upgradeInfo.AddMigrations(migrSet);
       //Update final status
       _upgradeInfo.VersionsChanged = _database.DbModel.VersionInfo.VersionChanged(oldDbVersion);
       if (_upgradeInfo.AllScripts.Count > 0 || _upgradeInfo.VersionsChanged)
     _upgradeInfo.Status = UpgradeStatus.ChangesDetected;
       else
     _upgradeInfo.Status = UpgradeStatus.NoChanges;
       //Sort, Clear up
       _upgradeInfo.AllScripts.Sort(DbUpgradeScript.CompareExecutionOrder);
       _database.DbModel.ResetPeerRefs(); //drop refs to old model
       return _upgradeInfo;
 }