microsoft / DACExtensions

DACExtensions contains samples that extend Data-Tier Applications using DacFx. These samples include deployment contributors and static code analysis rules that can be used with Visual Studio as well as examples of how to use the DacFx public mode
MIT License
125 stars 41 forks source link

Advice or direction on merging and multiplatforming dacpacs #23

Closed StingyJack closed 5 years ago

StingyJack commented 5 years ago

Is there any advice for how to most efficiently merge a set of dacpacs together into one resulting dacpac?

When publishing a set of 5 dacpacs consecutively to an existing database, the execution seems to take a long time (7-10 minutes). If I publish those 5 to a new database and then extract a composite dacpac from that db, the composite dacpac takes only about 2-3 minutes to publish compared to the 5 individuals. The creation of the composite still takes a long time. Is there a faster or more efficient way to merge or publish multiple dacpacs?

EDIT: original question was posted here with a better example

On a similar theme, is there a faster way for creating several dacpac's targeting different versions of SQL server from one project other than changing the DSP and recompiling?

GoEddie commented 5 years ago

I've seen this asked a few times, it is possible to merge dacpacs, you need to read them in one at a time and then write them into a new model, then to get the pre/post deploy files you need to go back to the original dacpac - probably with refactor log as well.

I've put up a sample here that works for me, you pass in the path to the target dacpac that will be created and then the paths of the dacpac's you want to merge in.

It handles pre/post deploy scripts, I didnt add the merge for the refactorlog but that should be similar to the pre/post scripts but with some xml splicing in the right places:

https://github.com/GoEddie/DacpacMerge

There is also a small issue in that if you use quoted identifiers or non-ansi nulls these would get lost but I don't know anyone who relies on these nowadays.

These also use the memory backed models so if your dacpac's are massive they might run out of memory so switching to file-based dacpac's might be needed.

To target different versions you need to change the DSP and recompile, I have edited the model.xml before and updated the checksum in the origin.xml to match the new checksum using the System.IO.Packaging API but you can always just deploy with /p:AllowIncompatiblePlatform=true if you aren't deploying anything that is actually incompatible

Thought of another issue, if your dacpacs have a reference outside of the ones you are merging you will lose those references, this can help you put them back: https://github.com/GoEddie/Dacpac-References

StingyJack commented 5 years ago

@GoEddie - thanks for the info, I'll check that out. IIRC I had tried a similar approach but had trouble figuring out the checksums correctly.