Open dzsquared opened 2 months ago
Thanks Drew! :-)
The expected workflow would be:
Run pre-compare script Compare and generate deployment script Run pre-deployment script Run deployment script Run post-deployment script
It would also be nice to flag that 'pre-compare' script as 'One Time'
or 'Every Time
'.
'One Time
' would be used for most advanced schema changes and data transformation, where the script should only execute once per target database and then be archived, not execute at every deployment.
Would that require something like a "schema version" mark in the target database to know if that script has executed or not? Or would we just have to write our scripts to be stateless by reading the schema metadata and react conditionally?
'Every Time
might do things like:
Chiming in here with my two cents, I love DACPACs for the mental model of "this is what my database should look like, make it happen" but this is an area where the experience could be better. As mentioned, sometimes there are things that I simply don't want the DACPAC to do, either because it can't (the non nullable column is an example) but also sometimes because the approach it takes to a change is not ideal and I want more control over it.
The other part of the experience that is not ideal, is that there is sometimes data that I want source controlled. For example static/seed data.
For this reason, I've landed up using something like DbUp twice: once as a pre-deployment step before the DACPAC, and once as a post-deployment step after the DACPAC. I use the pre-deployment for any changes like adding non nullable columns or anything else I don't want the DACPAC to change, and then the post-deployment for things like data.
I pick DbUp because it makes the experience much smoother, I don't need to focus as much on writing my scripts in an idempotent way because it uses a journaling table to know what has and hasn't been run yet.
It would be lovely if the DACPAC could handle this kind of scenario.
https://developercommunity.visualstudio.com/t/Add-Pre-compare-Script-Option-for-DACPAC/10594162
Bringing this item over from VS Developer Community since the core implementation would be in Microsoft.Build.Sql and DacFx.