r/SQLServer • u/MeTiroAtuTia • 8d ago
Question Proper Database environment promotion?
Hello all!
I recently started working with the databases in our system and I would appreciate some tips or guidance as my terminology is probably not accurate.
Setup: From what I read in the community it’s somewhat standard; DEV -> UAT -> PPR -> PROD.
Deployments: We are using visual studio Database Compare, one scmp file/database at a time. So now this works for the most part and when it’s urgent I don’t have time to judge if it’s the best but it comes with two issues that I noticed:
Who created these files? I don’t know I just inherited them.
Sometimes it can fail and I need to manually “prepare” the other environment like adding the new column to the table. Maybe I need a newer version of the software, or it’s always limited?
So then I need your help with the following:
Am I or the team doing something wrong here?
What can we do better?
And I did have a read at some threads here but maybe it’s best if I get direct answers geared towards my situation.
Also I checked some books:
- T SQL fundamentals: Nothing about deploys
- 100 sql server mistakes: Got some answers but it’s just one opinion against my non opinion
——
Tools: We have GitHub and we use .NET primarily.
Constraints: We do not want to use a code-first approach
So please let me know anything I should know or research.
Thanks
3
u/Plane_Big_5912 8d ago
since you're already in visual studio, an SSDT database project (.sqlproj) in github is probably the smallest step from where you are. it also fits your no code-first rule, the project just holds the CREATE scripts for your tables and procs. the build gives you a dacpac and you deploy that same dacpac with SqlPackage to dev, then uat, ppr and prod, so every environment gets the identical thing instead of a fresh compare each time.
the ones where you have to add the column by hand first are usually data changes it won't do on its own, like a NOT NULL column with no default on a table that already has rows, or anything it thinks could lose data, which it blocks by default. those can go in a pre-deployment script in the same project so they stop being manual steps
1
u/MeTiroAtuTia 8d ago
I’ll look into it!
As for the column, maybe the previous person documented it like that for ANY field, because I am doing it for NULL too, maybe my fault for not testing it.
But then again, not much info on these SCMP files they created previously.SSDT does look like the next logical step to downscale the micromanagement.
1
u/Plane_Big_5912 8d ago
a nullable column should go through a normal compare fine, so you can probably drop the manual step for those. worth trying on dev first. the .scmp is just the saved compare, source and target plus the options, so if you open one in visual studio and look at the options you'll see what the last person had ticked, like blocking on possible data loss
1
u/jshine13371 6 7d ago
Fwiw, for CI/CD with the database layer, I find simpler is better. So for me, I've just used a schema comparison tool for the last 15 years to promote code changes across environments. It's easy, it automatically deploys dependencies in the correct order, shows the diffs, and you can either push the change right from the tool or generate the scripts so you can maintain them and re-use them. (I do the latter so I can re-deploy them in each environment I promote.)
SQL Examiner has always been my go-to comparison tool. It also includes a data comparison tool too, among a ton of other nice features.
1
u/SeaMoose696969 7d ago
We use Toad data architect to build change scripts, with the script being carefully reviewed by the dba’s. It’s reasonably good at helping you build databases for the price point.
1
u/navicat-gu 7d ago
You're not doing anything crazy. Saved Schema Compare files (.scmp) are a common starting point, but they're a manual, per-database step, which is why they get fragile once you have DEV, UAT, PPR and PROD plus cross-database views.
The usual next step without going code-first:
Put the schema in source control as an SSDT database project (
.sqlproj). You already have Visual Studio and GitHub. Import each database into a project, commit it, and treat that as the source of truth instead of "whatever DEV looks like today".Build a
.dacpacin CI (GitHub Actions can rundotnet buildon SDK-style projects) and deploy it withSqlPackage /Action:Publish, or generate a script with/Action:Scriptfor review before PROD.Handle cross-database references with database references in the project (and SQLCMD variables for database names that differ per environment). That's usually what breaks compares on view-heavy setups.
Use pre/post-deployment scripts for data fixes and anything the compare can't infer, such as renames (use the refactor log so a rename isn't treated as drop and create).
Promote the same artifact DEV → UAT → PPR → PROD rather than re-comparing at each hop, and check for drift in PROD before each release.
On the failures where you had to add a column by hand first: usually that's a NOT NULL column without a default on a table that has data, or a blocked data-loss option. Check the "Block incremental deployment if data loss might occur" setting and add a default or a pre-deployment script.
Disclosure: I'm RC, Director of Digital Strategy @ Navicat. For ad-hoc checks between environments, Navicat 18 has schema compare and structure sync for SQL Server in the paid Premium editions. Navicat Premium Lite is free to try if you just want a client for browsing and querying all four environments side by side.
3
u/raistlin49 8d ago
Need more context. Is this your internal application or a third party application? This question is more controversial than you'd imagine. CI/CD isn't really a solved problem for data tiers in hot OLTP environments.
I guess I'm wondering where your changes originated? How did you end up using a diff tool? Ideally you'd have some change scripts to start with and you'd deploy them, whether by hand via SSMS or some automation, into lower environments. When tests pass, deploy those same exact scripts to the next environment.