DevOps for a Small Team: Real Test Data, Locked-Down Production
Testing with real data catches bugs fake data never shows: the odd record, the broken character, the search that returns thousands of results.
But real data on a developer’s machine brings two risks:
- Other people’s data leaks. A copy on a laptop is a copy you no longer control.
- A laptop breaks production. One wrong command, one wrong password in the wrong file.
This is the setup I built so a small team can test with real data and neither of those can happen. It runs today with one person. It is built for the first developers who join.
You don’t need to know how any of it works. I set up the copy, the deploy steps and the backups, and hand you one page that says who can touch production and how.
Rule 1: real data lives in production only
Dev and every laptop get a copy of one account: mine. Never anyone else’s. One command refreshes it:
- It reads my account from production.
- It replaces the old copy on dev or the laptop.
- It never writes to production.
What makes it safe is the database, not the script. The copy uses a read-only login that the database itself limits to my account. Even a bug in the copy tool cannot see another customer. If that login leaks, the worst case is someone reading my own data.
More on protecting customer data: Understanding security in your SaaS.
Rule 2: no laptop changes production
Database changes (a new table, a new column) used to run from a laptop. That meant the production password lived on a laptop.
Now the deploy platform runs them during its build:
- A snapshot comes first. The step is built. It becomes required before the first users arrive: then no snapshot means no change, and the live site stays as it was. Taking the production password off the laptop is on the same launch list.
- Anything that deletes data stops the deploy. To allow one, I name that exact file in the platform’s settings, redeploy, then remove the setting. A setting left behind cannot wave through the next one.
- Changes only add. The old code keeps working, so the database can change before the new code goes live.
Dev works the same way, so the process gets tested before production sees it. It follows the Twelve-Factor App rules: one-off jobs like database changes run as part of the release, and every site runs the same steps.
Rule 3: going live is a click
A push builds the new version, and the dev site gets it first. Once other people’s data is on production, the new version waits until I press Promote.
Until then, with only my own account on production, fixes go live at once. The switch is one setting, flipped right before the first users arrive.
Rule 4: test code cannot reach production
The app has a browser extension. There are now two builds from the same code:
- Production build: can only talk to the live site.
- Test build: can only talk to dev and local machines, and only checks when I press a button.
The browser enforces it. The test build is not told to stay away from production. It is not allowed to reach it.
Rule 5: a copy every night, locked once users arrive
Every night, a copy of production is made and kept for 30 days.
When I checked the rollback plan before launch, that nightly copy had failed three nights in a row, and nobody had noticed. A backup only counts once you have checked it ran.
Today production holds only my account, so the copy is plain. Right before the first users arrive, it gets locked: the service that stores the copies can lock them but never open them, and the key that opens them stays with me.
What waits until the team grows
These cost money, so they wait for real users or a second developer:
- Enforced code review: nothing reaches the main branch without approval. How I review AI-written code explains the checks each change already gets.
- Split database logins: the app’s login cannot delete tables.
- Backups nobody can delete: storage that accepts new files but refuses deletes.
- Paid database backups: 7 days of undo instead of 6 hours.
Each one is written down with the trigger that turns it on.
What it costs
Almost nothing today. The database, hosting and backups run on free plans. The first paid step is the database plan, at beta.
The short version
Real data stays in production. Developers get a copy of one test account, limited by the database itself. Only the deploy platform changes production, with a snapshot first and deletes refused. Going live is a click.
Tell me how your app ships today and I’ll show you where real data could leak or a laptop could break production.
Could a developer on your team break production from their laptop today?
Stack: Next.js on Vercel, Postgres on Neon, a Chrome extension (Manifest V3), GitHub. Three environments: local (Docker Postgres), dev (its own Neon project), production.
One account, enforced by Postgres row-level security
The copy reads production through a role made only for it. A migration creates it with no password, so it cannot log in until the owner turns it on in the database console once.
CREATE ROLE copy_reader NOLOGIN;
-- The owner's accounts. Security definer, so the role never reads the
-- membership table freely.
CREATE FUNCTION copy_reader_account_ids() RETURNS SETOF uuid
LANGUAGE sql STABLE SECURITY DEFINER SET search_path = public, pg_temp
AS $$ SELECT account_id FROM account_members WHERE user_id = '<owner id>' $$;
-- Per copied table:
ALTER TABLE job_views ENABLE ROW LEVEL SECURITY;
CREATE POLICY copy_reader_own ON job_views FOR SELECT TO copy_reader
USING (account_id IN (SELECT copy_reader_account_ids()));
GRANT SELECT ON job_views TO copy_reader;
Why this does not touch the app: table owners skip row-level security, and the app connects as the owner. I checked that on production and dev before shipping.
Tested in a rolled-back transaction on a local copy with four accounts: the role saw one, and UPDATE failed with permission denied. A table added later is invisible to the role until a migration grants it: no grant, no access.
The copy tool
- Reads the foreign keys from the target database and orders tables parents first. A loop in the keys fails loudly.
- Swaps the owner’s user id for the target site’s (dev uses a different login provider instance, so the id differs).
- Deletes the old copy and inserts the new one in one transaction on the target.
- Skips per-site secrets: session bindings, extension passes, billing.
- Refuses production as a target. Production is only ever a source.
End-to-end test on two throwaway databases: about 40,000 rows, old copy replaced, other accounts untouched.
Migrations run in the build
vercel.json:
{ "buildCommand": "node scripts/migrate-on-build.mjs && npm run build" }
The script decides by environment:
export function buildTarget(env) {
if (env.VERCEL !== "1") return "skip";
if (env.VERCEL_ENV === "production") return "prod";
if (env.VERCEL_ENV === "preview" && env.VERCEL_GIT_COMMIT_REF === "dev") return "dev";
return "skip";
}
On production it:
- Lists pending files against the
schema_migrationsledger. - Scans them for
DROP TABLE,DROP COLUMN,TRUNCATE,DELETE FROM(comments stripped). Any hit fails the build unlessALLOW_DELETEnames that exact file. - Takes a Neon snapshot through the API with a key scoped to the production project. A
REQUIRE_SNAPSHOTswitch, still off, makes it mandatory: once on (before beta), no key means no migration, the build fails, and live stays. Until then production holds only my account, and a pre-push check backs it up before any new database change. - Applies each file in its own transaction.
Before beta, production switches to Vercel’s staged deployments (“auto-assign custom domains” off). The schema can then change before Promote. That is safe because migrations only add: remove a column only after the code that reads it is gone.
Other preview branches skip migrations, and dev’s database URL is scoped to the dev branch, so a random branch preview never holds a database key.
Nothing off production messages a real person
Local and dev hold a copy of a real account, so outbound messages check the environment:
export function isProdDeployment(env = process.env) {
return env.VERCEL_ENV?.trim() === "production";
}
Off production, Telegram reads only a separate test bot token, and email only goes to localhost SMTP (a local mail catcher). A real token pasted into the wrong environment still sends nothing.
Two extension builds
One script writes both from the same source. Only the manifest and one flag differ:
| Production | Test | |
|---|---|---|
host_permissions | the live origin only | localhost, 127.0.0.1, dev origin |
| Name | normal | ”TEST” |
| Timer | on | off, manual check only |
The extension already drops any saved app address outside host_permissions, so Chrome itself blocks the test build from production. The build script also fails if the wrong host appears in the wrong build, and a test covers both.
The production build ships from a release branch. A pre-push hook refuses to move it unless the release script sets a confirm variable, and the script asks you to type “release”.
Found while building it: the old store build pointed at the www host, which redirects. Extension calls would have failed.
Nightly backup, locked before beta
A GitHub Action runs pg_dump (Postgres 17 image, to match the server). While production holds only my account the dump is stored plain. Once a public key is committed, the same workflow locks it:
key="$(openssl rand -hex 32)"
KEY="$key" openssl enc -aes-256-cbc -pbkdf2 -salt -in prod.dump -out prod.dump.enc -pass env:KEY
printf '%s' "$key" | openssl pkeyutl -encrypt -pubin -inkey ops/prod-backup-public.pem \
-pkeyopt rsa_padding_mode:oaep -out prod.key.enc
A fresh random key per night locks the dump; the public key locks that key. GitHub only holds the public half, so it can lock but never unlock. Copies are workflow artifacts with 30-day retention, not commits, so the repo does not grow. A restore script refuses the production host as a target.
Still open
- Split database roles so the app’s runtime role cannot run DDL.
- Required reviews on the main branch (paid plan on private repos).
- Write-only object storage for backups (append, no delete).
- Neon’s protected branches (paid) so no API key can delete or reset production.
More Posts
All posts
November 25, 2026
Why Your App Went Offline on Vercel's Free Plan (and How to Stay Under the Limits)
Vercel's free plan pauses every site on the account when one monthly limit runs out. What the limits mean in plain words, what uses them up, and the fixes, from a real case.
November 24, 2026
Why Your Project Starts With a Small Paid Step: Requirements and an Estimate Before the Build
A price given before the work is measured is a guess, and someone pays for it later. What a small paid first step gets you: written decisions, a cost range and a time range, and the choice to stop there.