Ssdt post deployment script runs once

I am new to SQL Server database tools and may be mistaken in assuming what post-deployment scripts do. So correct me if I am wrong.

As far as I know, after deployment after deployment, the post-deployment script will be launched, and not just one deployment.

If I want the post-deployment script to run the script only once, is there a way to do this without also requiring a version table or history in the database that logs when these scripts are already running?

those. can I add any subsequent corrections to the script as a new file in the project with the version number and add it to the post-deployment script, but the previous scripts will be ignored in some way (potentially without deleting it first)? regardless of whether the script works during deployment?

Is there a configuration for this kind of thing or is it an unintended behavior?

+7
sql sql-server-2008 deployment visual-studio-2012 ssdt
source share
1 answer

The Pre and Post-deploy scripts are designed to run on every release of the project. Your best practice is to make them repeatable. Add checks so that if the data already exists, you don't run again or something like that. You can create some kind of basic logging table to save this - if the row is not found in the table, run the script and put the row in the table.

You cannot tell the project to only run the latest version of the script if there are several scripts, because they are all embedded in one large file, PreDeploy.sql or PostDeploy.sql. You will need something in each / script section that tells it where to look, know or not to run. This may be an existing data check, a table check, a version check, or something else, but she must know somewhere what to use in order to know whether to run it.

It is impossible to disable this, except to comment on the scripts or process them in any way through the SQLCMD variables or other checks. However, you still need coding in how each script should be executed or not. If you give an example or two of what you are trying to accomplish in your Pre / Post Deploy scripts, we can probably give some recommendations.

For our purposes, we make scripts reusable and delete them as they run. They are still in the original management or you can use a snapshot to store this version of the project until they are deleted.

+9
source share

All Articles