Order of scripts being run for deployments
Monday
Posts: 77 Silver 3
Getting started with SCA and running into an issue:
I needed to alter a function which was used in a check constraint on a table. In order to do this the constraint must be dropped, function altered then the constraint can be added back. SCA is not smart enough to run the changes in the correct order. I figured I would make each change individually one by one and import , generate scripts, refresh , etc 3 separate times. This passed the shadow database verification but on deployment, SCA still does not run in the correct order.
I see there are pre and post deployment folders. Is the correct approach to add scripts to drop and re-add constraints there? If so I don't want these scripts running for all deployments so I would delete them after my deployment?
Thanks
I needed to alter a function which was used in a check constraint on a table. In order to do this the constraint must be dropped, function altered then the constraint can be added back. SCA is not smart enough to run the changes in the correct order. I figured I would make each change individually one by one and import , generate scripts, refresh , etc 3 separate times. This passed the shadow database verification but on deployment, SCA still does not run in the correct order.
I see there are pre and post deployment folders. Is the correct approach to add scripts to drop and re-add constraints there? If so I don't want these scripts running for all deployments so I would delete them after my deployment?
Thanks
Tagged:
Best Answers
-
MikielAgutu Posts: 29 Silver 1Hello Monday
Sorry you're having issues using SQL Change Automation.There are a couple of things you could try here. First, instead of importing changes one by one, can you try to manually write a migration script that performs the required operations in the correct order?If that doesn't work, you may need to alter settings that control the order in which SQL Change Automation deploys scripts.From the documentation page:'By default deployment order is determined by file path, taking into account both folder path and file name. The file name must always start with a numeric prefix. To adjust the order of deployment, simply change the file's numeric prefix. If two migrations have the same number, then the rest of the filename will be used as the tie-breaker.'You can also configure the order of deployment with Migration Grouping, here.If you're still not having any luck, then Pre & Post-Deployment Scripts might help, as you said.In order to ensure the Pre/Post scripts are only executed in certain environments you'll have to manually write some SQL to check which DB context you're in. I don't recommend adding Pre/Post scripts, deploying the project, and then deleting them. Such an approach would lead to inconsistency if you source control your project.Hope that helpsMikielMikiel Agutu | Software Engineer | Redgate Software -
MikielAgutu Posts: 29 Silver 1Hello MondayIt looks like a script ordering issue to me.Programmable Objects contain logic to drop and re-create themselves upon deployment. In this case, it looks like both objects have already been deployed to the shadow database.When you refresh, the project is deployed to the shadow database once more. When Return_RM_ID is deployed, it attempts to drop and re-create. However because a dependency exists between these two objects, the server blocks the change, which is fair enough.To fix this you'll have to manually amend the Programmable Object file in order to ensure the objects are deployed in the correct order every time. You can see more about how to do this on this documentation post.Thanks.Mikiel Agutu | Software Engineer | Redgate Software
-
MikielAgutu Posts: 29 Silver 1It's perfectly fine to edit the Programmable Object scripts manually. As long as your manual changes are valid there shouldn't be any issues with clashes between automatic and manual changes.Mikiel Agutu | Software Engineer | Redgate Software
Answers
How do I fix this?