示例#1
0
        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
示例#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());
        }
示例#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()
        }
示例#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);
        }
示例#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);
 }
示例#6
0
文件: DbSettings.cs 项目: radtek/vita
        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)
        {
        }
示例#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);
 }
示例#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)
 {
 }
示例#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);
        }
示例#10
0
文件: DbSettings.cs 项目: radtek/vita
 // 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;
 }
示例#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;
 }
示例#12
0
 public static bool IsSet(this DbUpgradeOptions options, DbUpgradeOptions option)
 {
     return (options & option) != 0;
 }
示例#13
0
 public static bool IsSet(this DbUpgradeOptions options, DbUpgradeOptions option)
 {
     return((options & option) != 0);
 }