Redgate SQL Change Automation: Build - Predeploy executes after temporary database is dropped
ptrubs
Posts: 16 Bronze 3
I must be missing something pretty basic here.
I've got a SQL Source Control project that I'm building using Redgate SQL Change Automation: Build.
it builds the database (using a temporary name), and then drops it before pre or post deploy script are run?
in my case the pre-deploy just adds a couple of rows to a table. but the table no longer exists. Obviously, this breaks the build as there are no objects or even a database?
what am I missing?
I've got a SQL Source Control project that I'm building using Redgate SQL Change Automation: Build.
it builds the database (using a temporary name), and then drops it before pre or post deploy script are run?
in my case the pre-deploy just adds a couple of rows to a table. but the table no longer exists. Obviously, this breaks the build as there are no objects or even a database?
what am I missing?
Tagged:
Best Answer
-
ptrubs Posts: 16 Bronze 3I've just come across this issue again, and the salient part of this problem (that may not be clear from the above) is that this issue occurs in the BUILD task (rather than the release task) - So the pre-deploy script has to be valid for an empty database (ie a database with no objects in it)
Answers
Could it be a bug in Redgate SQL Change Automation: Build that occurs only when there is a pre-deploy script?
Thanks for your query about SQL Source Control. By default the temporary database should be created first, then the pre-deployment scripts would be deployed followed by the schema objects and lastly the post-deployment script. Are you able to provide a copy of what you included in the pre-deployment script? Also, do you have a copy of the log files for this build?
Kind regards,
Pete Ruiz
if the temp db is created first - it will be empty
The pre-deploy script will run - if it references any object in the database, it will fail
the schema will be updated to the latest version
post-deploy...
Which I think now answers my question, and raises other issues - please confirm
if the pre-deploy references any object, you have to check for existence of that object before using it in the pre-deploy, whether it be a table, proc, view etc, just so the build step will work...
is that in the documentation anywhere you can point to?
insert into dbo.x values ('y')
The above statement fails during the build phase - because the db has no objects in it when the pre-deploy is execute.
Why use the pre-deployment script for this?
There is nothing explicit in your documentation (that I've found) that states what should not be included in the pre-deploy
I personally don't think I would the pre-deploy for this - but I can imagine use-cases that might require it, I'm just trying to find the explanation why this pattern failed for one of my developers (who has updated to use the post-deploy) - and if it is required - the work around (ie - test for existence)