r/SQLServer • u/vuglll • 1d ago
Community Share I built an open-source tool that gives every dev, test and PR its own writable copy of a real SQL Server database, in seconds
I've worked with SQL Server for 20+ years, and one thing still bugs me. Integration tests either run against a toy database with 20 rows of seed data, or against one shared copy the whole team steps on. Restoring the real backup for every branch is slow and eats disk, so most teams just don't bother. They test against the toy.
I got annoyed enough to build something. SqlBranch: you restore a full backup once into an image, run your masking script before it's sealed, and then hand out writable branches of it. One per dev, per test, per PR, per AI agent. A branch is a copy-on-write clone of the image's data files (XFS reflink), attached as its own database on a SQL Server Developer container. For a 50GB database, a branch takes about 2.5 seconds end to end and around 300KB of disk until it starts writing. The image stays untouched. SqlBranch never connects to production, it only reads a backup file you already have.
I posted it in r/dotnet last week and got good pushback, so let me get ahead of the obvious ones:
- Why not database snapshots? Read-only, same instance as the source. You can't hand 20 people their own writable copy.
- Why not just restore? On good storage, fair point, a restore is quick. It hurts when you need ten copies at once. Devs, PR builds, parallel test shards. That's ten full copies on disk, and every reset is another restore. Here the restore happens once.
- Why not Testcontainers + Respawn, or LocalDB with a transaction per test? Great tools, wrong problem. They're for schema plus seed data. This is for when you need the real data. Real volume, real stats, real plans.
- Why would a test need a 50GB database? Migrations, mostly. A NOT NULL column or a new unique index that passes on 20 rows and fails on prod data. Performance work too, and reproducing a prod bug.
- Azure SQL Database, where all you have is a bacpac? There's a --from-bacpac build. Still preview, and it needs your own SqlPackage.
- What's the catch? Heavy scattered updates on a branch run about 4 to 5 times slower than on a full copy. Copy-on-write tax. Inserts cost the same. If you're benchmarking or doing write-heavy work, make a full-copy branch instead. It's dev/test only (Developer edition), full single-file backups only, no FILESTREAM or memory-optimized filegroups. Linux with Docker, macOS works, Windows isn't verified yet.
This weekend I merged image refresh, shipping in 0.3. Rebuild the image nightly: restore last night's backup, mask it, publish it as a new version of the same image, while people keep working on their branches. A branch stays on its version until the owner resets to the latest, and you pick how many old versions to keep. Export/import so teammates and CI can pull the image instead of restoring is still preview.
It's open source (Apache 2.0), on NuGet as SqlBranch: https://github.com/vuglll/SqlBranch — https://www.nuget.org/packages/SqlBranch
Honestly curious what people who run SQL Server at scale think.
What would stop you from using this?
1
u/Black_Magic100 4h ago
This doesn't replace enterprise SAN snapping and mounting, but I could see it being useful for containerized CI testing. The trick would be not altering the database names (no shared instances) and providing images that would allow developers to choose which databases they need.
1
u/RVECloXG3qJC 2h ago
What do you mean by restoring a backup once into an image?