我有一个数据库项目,它对我的本地MSSQL 2008数据库很好。它在脚本/后部署下有一个脚本,进入设置表,以及其他表。我有每个表1个文件,例如。一个Setting.sql文件,用于将数据插入到设置表中。
设置将根据我部署的数据库而有所不同。
我如何脚本? Basicaly我想能够说两个文件,
Prod.Setting.sql和Dev.Setting.sql和VS 2010将使用适当的脚本,取决于什么
解决方案完全可行,但有两个选项和几个步骤。您可以有一组完整的重复的脚本,每个配置一个。或者,您可以有一组脚本,其内容考虑您正在使用的配置。我会用第一个,我会保持简单。
创建两个解决方案配置,或者如果你喜欢使用Debug和Release。我将使用这些例子。
对于每个配置,创建一个新的.sqlcmdvars文件。
Database_Release.sqlcmdvars Database_Debug.sqlcmdvars解决方案配置到每个和在数据库项目属性中更改变量文件下拉到指向您创建的相应文件。
在每个文件中,您可以定义变量在部署期间使用。在每个中创建一个新变量
$(DeploymentConfiguration)并将其中每一个的值设置为Debug或Release
然后在任何Pre或Post部署脚本,您可以这样做:
IF'$(DeploymentConfiguration)'='Debug' BEGIN PRINT'执行调试部署':r .\Debug\SomeNeededScript.sql END 如果'$(DeploymentConfiguration)'='发布' BEGIN PRINT'执行发布部署':r .\Release\Anotherscript.sql END
I've got a Database project which works fine for my local MSSQL 2008 database.
It has a script under scripts/post-deployment that inserts standing data configuration into a settings table, and other tables. I've got 1 file for each table, e.g. a Setting.sql file to insert data into the Settings table.
The settings will be different depending on the database I deploy to.
How can I script this? Basicaly I would like to be able to have say 2 files,
Prod.Setting.sql and Dev.Setting.sql and VS 2010 would use the appropriate script depending on what database (environment) I am deploying to.
解决方案Completely doable but there two options and a few steps involved. You can have a complete duplicate set of scripts, one for each configuration. Or, you can have one set of scripts, the contents of which take into account the configuration you are using. I'll go with the first, and I'll keep it simple.
Create two solution configurations, or use Debug and Release if you like. I'll use these for the example.
For each configuration, create a new .sqlcmdvars file.
Database_Release.sqlcmdvars Database_Debug.sqlcmdvarsSwitch your solution configuration to each and in the database project properties change the variables file drop down to point at the corresponding file you created.
In each of those files you can define variables to be used during deployment. Create a new variable in each one
$(DeploymentConfiguration)And set its value in each one to either Debug or Release
Then in any of your Pre or Post deployment scripts you can do something like so:
IF '$(DeploymentConfiguration)' = 'Debug' BEGIN PRINT 'Executing Debug deployment' :r .\Debug\SomeNeededScript.sql END IF '$(DeploymentConfiguration)' = 'Release' BEGIN PRINT 'Executing Release deployment' :r .\Release\Anotherscript.sql END
更多推荐
Visual Studio 2010数据库项目部署到不同的环境
发布评论