public void BuildDbModelChanges(DbUpgradeInfo upgradeInfo, IDbObjectComparer comparer, ILog log)
        {
            _upgradeInfo = upgradeInfo;
            _comparer    = comparer;
            _log         = log;
            _newModel    = upgradeInfo.NewDbModel;
            _oldModel    = upgradeInfo.OldDbModel;
            _options     = _upgradeInfo.Settings.UpgradeOptions;
            var driver = _newModel.Driver;

            _useRefIntegrity = driver.Supports(DbFeatures.ReferentialConstraints) && _newModel.Config.Options.IsSet(DbOptions.UseRefIntegrity);
            _compareTables   = _options.IsSet(DbUpgradeOptions.UpdateTables);
            _compareIndexes  = _options.IsSet(DbUpgradeOptions.UpdateIndexes);
            _compareViews    = driver.Supports(DbFeatures.Views) && _options.IsSet(DbUpgradeOptions.UpdateViews);
            _dropUnknown     = _options.IsSet(DbUpgradeOptions.DropUnknownObjects);
            _supportsSchemas = driver.Supports(DbFeatures.Schemas);

            // Nullify all obj.Peer fields to make sure we drop references to old model - mostly convenience in debugging
            // to allow multiple entry into this method in debugger
            _oldModel.ResetPeerRefs();
            MatchObjectsWithPeers();

            //new stuff
            BuildChangeList();

            // Do not do it here, refs to old objects might be need by Sql generators; we will reset refs after completing update
            // _newModel.ResetPeerRefs()
        }//class
Exemple #2
0
        public ActionResult GenerateScript(ScriptModel model)
        {
            if (ModelState.IsValid && model.DacPac.ContentLength != 0)
            {
                var upgradeService = new DbUpgradeService(DbConnection.From(model.ConnectionString, model.DatabaseName));
                var upgradeOptions = DbUpgradeOptions.From(model.IgnoreObjectTypes);

                upgradeOptions.IgnoreNotForReplication    = model.IgnoreNotForReplication;
                upgradeOptions.DropConstraintsNotInSource = model.DropConstraintsNotInSource;
                upgradeOptions.DropIndexesNotInSource     = model.DropIndexesNotInSource;
                upgradeOptions.VerifyDeployment           = model.VerifyDeployment;

                using (var memoryStream = new MemoryStream())
                {
                    model.DacPac.InputStream.CopyTo(memoryStream);

                    var dacpac        = memoryStream.ToArray();
                    var upgradeScript = upgradeService.GenerateUpgradeScript(dacpac, upgradeOptions, model.DatabaseName);

                    return(View("Publish", new PublishScript {
                        Script = upgradeScript
                    }));
                }
            }

            return(View());
        }
Exemple #3
0
        public void AddDbModelChanges(DbUpgradeInfo upgradeInfo, MemoryLog log)
        {
            _upgradeInfo = upgradeInfo;
              _newModel = upgradeInfo.NewDbModel;
              _oldModel = upgradeInfo.OldDbModel;
              _log = log;
              _options = _upgradeInfo.Settings.UpgradeOptions;
              var driver = _newModel.Driver;
              _useRefIntegrity = driver.Supports(DbFeatures.ReferentialConstraints) && _newModel.Config.Options.IsSet(DbOptions.UseRefIntegrity) ;
              _compareTables = _options.IsSet(DbUpgradeOptions.UpdateTables);
              _compareIndexes = _options.IsSet(DbUpgradeOptions.UpdateIndexes);
              _compareViews = driver.Supports(DbFeatures.Views) && _options.IsSet(DbUpgradeOptions.UpdateViews);
              var usesStoredProcs = driver.Supports(DbFeatures.StoredProcedures) && _newModel.Config.Options.IsSet(DbOptions.UseStoredProcs);
              _compareStoredProcs = usesStoredProcs && _options.IsSet(DbUpgradeOptions.UpdateStoredProcs);
              _dropUnknown = _options.IsSet(DbUpgradeOptions.DropUnknownObjects);
              _supportsSchemas = driver.Supports(DbFeatures.Schemas);
              _supportsOrderInIndexes = driver.Supports(DbFeatures.OrderedColumnsInIndexes);

              // Nullify all obj.Peer fields to make sure we drop references to old model - mostly convenience in debugging
              // to allow multiple entry into this method in debugger
              _oldModel.ResetPeerRefs();
              MatchObjectsWithPeers();

              //new stuff
              BuildChangeList();

              // Do not do it here, refs to old objects might be need by Sql generators; we will reset refs after completing update
              // _newModel.ResetPeerRefs()
        }
Exemple #4
0
        public void GenerateScriptTest()
        {
            var dbConnection = DbConnection.From(modelConnection, "unemployment");
            var service      = new DbUpgradeService(dbConnection);
            var dacpac       = service.GenerateDacPac();

            var script = service.GenerateUpgradeScript(dacpac, DbUpgradeOptions.From(ObjectType.Users, ObjectType.Views, ObjectType.RoleMembership, ObjectType.Permissions, ObjectType.ExtendedProperties, ObjectType.StoredProcedures, ObjectType.Logins, ObjectType.DatabaseTriggers, ObjectType.ServerTriggers), "newdb");

            Assert.IsNotNull(script);
        }
Exemple #5
0
 public DbUpdateConfig(XmlDocument xmlConfig)
 {
     ProviderType       = xmlConfig.GetValue(ToolConfigNames.Provider);
     ConnectionString   = xmlConfig.GetValue(ToolConfigNames.ConnectionString);
     Driver             = ToolHelper.CreateDriver(ProviderType, ConnectionString);
     ModelUpdateOptions = ReflectionHelper.ParseEnum <DbUpgradeOptions>(xmlConfig.GetValue(ToolConfigNames.ModelUpdateOptions));
     DbOptions          = ReflectionHelper.ParseEnum <DbOptions>(xmlConfig.GetValue(ToolConfigNames.DbOptions));
     AssemblyPath       = xmlConfig.GetValue(ToolConfigNames.AssemblyPath);
     AppClassName       = xmlConfig.GetValue(ToolConfigNames.AppClassName);
     OutputPath         = xmlConfig.GetValue(ToolConfigNames.OutputPath);
 }
Exemple #6
0
        public readonly string SchemaManagementConnectionString; //optional, admin-privilege conn string

        public DbSettings(DbDriver driver, DbOptions options,
                          string connectionString,
                          string schemaManagementConnectionString = null,
                          DbUpgradeMode upgradeMode       = DbUpgradeMode.NonProductionOnly,
                          DbUpgradeOptions upgradeOptions = DbUpgradeOptions.Default,
                          IDbNamingPolicy namingPolicy    = null,
                          string dataSourceName           = "(Default)")
            : this(new DbModelConfig(driver, options, namingPolicy), connectionString, schemaManagementConnectionString,
                   upgradeMode, upgradeOptions, dataSourceName)
        {
        }
Exemple #7
0
 public DbUpdateConfig(XmlDocument xmlConfig)
 {
     ProviderType = xmlConfig.GetValue(ToolConfigNames.Provider);
       ConnectionString = xmlConfig.GetValue(ToolConfigNames.ConnectionString);
       Driver = ToolHelper.CreateDriver(ProviderType, ConnectionString);
       ModelUpdateOptions = ReflectionHelper.ParseEnum<DbUpgradeOptions>(xmlConfig.GetValue(ToolConfigNames.ModelUpdateOptions));
       DbOptions = ReflectionHelper.ParseEnum<DbOptions>(xmlConfig.GetValue(ToolConfigNames.DbOptions));
       AssemblyPath = xmlConfig.GetValue(ToolConfigNames.AssemblyPath);
       AppClassName = xmlConfig.GetValue(ToolConfigNames.AppClassName);
       OutputPath = xmlConfig.GetValue(ToolConfigNames.OutputPath);
 }
Exemple #8
0
 public DbSettings(DbDriver driver, DbOptions options, 
     string connectionString,
     string schemaManagementConnectionString = null,
     DbUpgradeMode upgradeMode = DbUpgradeMode.NonProductionOnly,
     DbUpgradeOptions upgradeOptions = DbUpgradeOptions.Default,
     IDbInfoService dbInfoProvider = null,
     string dataSourceName = null,
     DbNamingPolicy namingPolicy = null)
     : this(new DbModelConfig(driver, options, namingPolicy), connectionString, schemaManagementConnectionString, 
       upgradeMode, upgradeOptions, dbInfoProvider, dataSourceName)
 {
 }
Exemple #9
0
        public DbUpdateConfig(XmlDocument xmlConfig)
        {
            ProviderType = xmlConfig.GetValue(ToolConfigNames.Provider);
            var serverType = (DbServerType)Enum.Parse(typeof(DbServerType), ProviderType);

            ConnectionString   = xmlConfig.GetValue(ToolConfigNames.ConnectionString);
            Driver             = DataUtility.CreateDriver(serverType);
            ModelUpdateOptions = StringHelper.ParseEnum <DbUpgradeOptions>(xmlConfig.GetValue(ToolConfigNames.ModelUpdateOptions));
            DbOptions          = StringHelper.ParseEnum <DbOptions>(xmlConfig.GetValue(ToolConfigNames.DbOptions));
            AssemblyPath       = xmlConfig.GetValue(ToolConfigNames.AssemblyPath);
            AppClassName       = xmlConfig.GetValue(ToolConfigNames.AppClassName);
            OutputPath         = xmlConfig.GetValue(ToolConfigNames.OutputPath);
        }
Exemple #10
0
 // Use this constructor for shared db model (multi-tenant app aganst multiple identical databases)
 public DbSettings(DbModelConfig modelConfig,
                   string connectionString,
                   string schemaManagementConnectionString = null,
                   DbUpgradeMode upgradeMode       = DbUpgradeMode.NonProductionOnly,
                   DbUpgradeOptions upgradeOptions = DbUpgradeOptions.Default,
                   string dataSourceName           = "(Default)")
 {
     ModelConfig      = modelConfig;
     ConnectionString = connectionString;
     SchemaManagementConnectionString = schemaManagementConnectionString ?? connectionString;
     UpgradeMode    = upgradeMode;
     UpgradeOptions = upgradeOptions;
     DataSourceName = dataSourceName;
 }
Exemple #11
0
 // Use this constructor for shared db model (multi-tenant app aganst multiple identical databases)
 public DbSettings(DbModelConfig modelConfig, 
     string connectionString,
     string schemaManagementConnectionString = null,
     DbUpgradeMode upgradeMode = DbUpgradeMode.NonProductionOnly,
     DbUpgradeOptions upgradeOptions = DbUpgradeOptions.Default,
     IDbInfoService dbInfoProvider = null,
     string dataSourceName = null)
 {
     ModelConfig = modelConfig;
       ConnectionString = connectionString;
       SchemaManagementConnectionString = schemaManagementConnectionString ?? connectionString;
       UpgradeMode = upgradeMode;
       UpgradeOptions = upgradeOptions;
       DbInfoProvider = dbInfoProvider;
       DataSourceName = dataSourceName ?? DataSource.DefaultName;
 }
Exemple #12
0
 public static bool IsSet(this DbUpgradeOptions options, DbUpgradeOptions option)
 {
     return (options & option) != 0;
 }
Exemple #13
0
 public static bool IsSet(this DbUpgradeOptions options, DbUpgradeOptions option)
 {
     return((options & option) != 0);
 }