SSDT Composite Database Reference with PostDeploy
Asked Answered
B

1

7

I have two SSDT projects. Database1 references Database2.

Database projects

When deploying Database1, Table2 (from Database2) is deployed as expected. That is because when I am deploying, the check box "Include composite objects" is checked.

The problem is that only the schema/objects from Database2 are deployed with Database1. The "Script.PostDeployment.sql" file is not generated in the script as a part of the Database1 deployment. It is, however, included in the script when I deploy Database2 directly to the target database.

How do I include the pre/post deploy scripts from referenced dacpac files or SSDT projects?

Bronchiole answered 21/8, 2012 at 7:25 Comment(0)
I
5

I believe you are going to have to have the post deployment script of database 1 call the post deployment script of database 2. Like

 Use SQLCMD syntax to include a file in the post-deployment script.         
 Example:      :r .\myfile.sql  

I can't see any other way as in most cases the post deployment script of another DB should probably not be ran when deploying. You may also want to consider refactoring the part of the script that needs to be ran on the deployment of both databases into its own file, and referencing it in both post deployments scripts.

Ifni answered 21/8, 2012 at 14:54 Comment(2)
I could probably do that currently since I have the referenced SSDT project in the same sln, but I will eventually be referencing only a dacpac which will have the pre/post deploy wrapped up inside of it. Why does SSDT not execute pre/post scripts for referenced dacpac files? That seems like a requirement.Bronchiole
Because your reference only deploys table 2 of db 2. What if the deployment script for db 2 altered the data in table 27 of db 2? You probably wouldn't want that to be run when you deploy db 1 (or it could not even exist in the current context, and break the deploy).Ifni

© 2022 - 2024 — McMap. All rights reserved.