Restrict Objects getting dropped accidently
sasankj
Posts: 23 New member
Is there a way we can force the Deployment step to throw a warning or throw error if it finds any drop statements? This is to make sure there are no accidental "drops" / "deletes" going into production through pipeline .
Answers
There's information about using SQL Compare options in SQL Change Automation at https://documentation.red-gate.com/sca3/automating-database-changes/automated-deployments/using-sql-compare-options-with-sql-change-automation-powershell-module. You can also put option parameters in the SQL Change Automation Build/Release extensions (TFS/VSTS/Octopus Deploy).
Stephanie M. Herr :-)
Product Manager Database DevOps
I am attaching a screen shot of my Deployment step and attaching release log.
I'm looking for something that would help here, but I think this is problematic from our view in that we do perform some drops for procedures in some scripting. Anything that's pre-SQL2016 can't handle CREATE OR ALTER, and the standard pattern we have is: if exists() drop, create.
I think that the solution I'd lean towards here is to fail builds that contain drops, not wait until the release stage. My initial thought is to capture a list of tables and store this in my db. This would essentially be a way of auditing the state of the db. If you maintained this in your existing prod (and qa/staging/UAT, etc), then you'd know what objects exist. After a build, I'd run a left join from this table to sys.objects, and if things were missing, I'd then fail the build or return an error to the user. This would help me detect drops.
You could easily expand this type of check into views, procs, functions, users, etc.