Search code examples
sql-serverdatabase-migrationsql-server-data-toolsdatabase-project

Share variable in SSDT pre and post deployment scripts


We're using SSDT to upgrade out databases, and I want to disable a feature (the value of which is stored in the db) which may or may not be enabled, and then re-set it to it's original value.

i.e.

Pre-Deployment
- Make a note of whether Property X is Enabled/Disabled
- Set Property X to Disabled

Deploy
- (Various Actions)

Post-Deployment
- Set Property X to the original value it was during Pre-Deployment

Presumably this is a relatively frequent pattern (in wix scripts it's called the remember property pattern), I'm just not sure how to do it as part of an SSDT Migration.


Solution

  • I would have a table, in the pre-deploy script if no row insert the state then in the post-deploy read from the state and action and delete the row.

    I would do it like that rather than just storing it so you guarantee that if it dies it will self-correct next time it runs.