Best practices for automating deleting a local/development database
pmenard
Posts: 5 New member
During full deployments to, logically transient, non-prod environments we want databases to be recreated from scratch every time. For that matter, not every dev will be concerned with deploying migrations locally.
I've investigated a few options, is there anything considered best practice by those that have been using the product(s) for a while?
For devs specifically...
I've investigated a few options, is there anything considered best practice by those that have been using the product(s) for a while?
For devs specifically...
- Have I missed some SCA/VS user-configuration such that VS deployments "overwrite"? Sometimes devs won't care, sometimes we just want to blow away the DB and start from scratch before writing new migrations without changing tooling.
- Is there some argument I've missed on the SCA scripts that already does this?
- Roll our own process to drop the DB(s) before entering the SCA process?
- Roll our own conditional SQL in the prj's normal script process triggered on a SQLCMD variable? ...concerning to deploy a DROP DB to prod
Tagged:
Best Answer
-
Andrea_Angella Posts: 66 Silver 4I am not aware of any argument you can provide to get the behavior you expect.
The last option you suggest can be achieved using a pre-script but I would be very concerned to drop production unintentionally.
So I suggest the second option of adding an extra step to drop the database before calling SCA. Add this extra step only when you deploy to transient environments.
Andrea Angella
Lead Software Engineer | Red Gate
Website: www.productivecsharp.com
Twitter: @angella_andrea
Answers
For the devs,
A toggle in SCA's UI would be great. There are limited options for automating such for the devs (a new configuration copied from debug, with an added drop task?).
As for automation,
It has to run somewhere, and with a push to have consistent deployment tooling across environments, the drop code is somewhere inclusive to production deployments.
It would be great if SCA had an argument which could be driven from configuration so roll-your-own wasn't necessary.
But I agree, if my current choices are to put it in conditional SQL or our overall mgt scripts, the latter wins.
Thank you!
>integration/qa/staging/etc environment? Or a dev environment?
Automation => all common environments, dev -> prod. Only lower environments ever get an automated 'drop' database, however.
UI => local/personal dev environments
While I think the idea of starting your db from scratch is great, there is the data issue. Loading a set of test data is something you need to consider, or I'd expect you would. In any case, if you start each dev session with a new db, I think you're ahead of most shops.
I'll drop a note to the team about how someone might integrate this with SCA-Client.
>write a script in the pre area
I think I'm still leaning towards keeping the drop controls outside of SQL scripts for now.
>Loading a set of test data is something you need to consider
Absolutely
We're in the midst of migrating an existing home-grown deployment system to SCA...
Primary development occurs within a personal environment, and gets built from scratch with basic metadata. Test-specific data is loaded only as necessary.
For non-prod shared environments, we have mixtures of fully redeployed and long-lived/migrated databases. We drive test-data loads from the tests scheduled against the particular database.
...as such, test-data will likely continue to be non-SCA, though now that you have me thinking about it... 💡 I do wonder if additional, data-only, SCA projects could be paired with our integration tests to package data & tests side by side. 🤔 ...that won't be until later this year though
It is probably best not to wire this into SCA as a feature because it is so simple to do. I like the way that SCA actually allows you to do things the way you prefer.
The trick is to delete the database and re-create it before you do the release. Because all your releases are identical (same source and the target is an empty database) you can use just one Release object. This saves a lot of time!
Here is the whole script, including the database deletion and recreation. Please let me know if it isn't quite what you're looking for and I'll fix it.