How to run different pre and post SSDT pubish scripts depending on the deploy profile

前端 未结 3 653
终归单人心
终归单人心 2021-01-13 20:10

I am using SSDT in Visual Studio 2013.

I have created some pre and post publish scripts for the development server. The pre-deployment scripts empty data from tables

3条回答
  •  攒了一身酷
    2021-01-13 20:48

    You have a few options:

    1 - Wrap your data changes in calls to @servername or something unique to the environment so you would have something like:

    if @@servername = 'dev_server'
    begin
         delete blah
         insert blah
    
    end
    

    2 - You can also achieve something similar using sqlcmd variables, pass in a variable called "/v:DestoryData=true" or something and then you can reference that in your script.

    3 - Don't use pre/post deploy scripts but have your own mechanism for running them i.e. use a batch file to deploy your dacpacs and add a call to sqlcmd before and after - the downside to this is that when deploying, changes to a table result in any foreign keys being disabled before the pre-deploy and re-enabled after the post-deploy.

    4 - Edit the dacpacs, the pre/post deploy scripts are just text files inside the dacpac which is essentially a zip file that follows the microsoft packaging format and there is a .net packaging api to let you modify it.

    I think that is about it, please ask if anything is unclear :)

    ed

提交回复
热议问题