Skip to main content

Software Factories: Ship Database Changes With No Human in the Loop

A software factory is a pipeline in which agents take work from a ticket to a merged pull request and a deployment, with people only at policy points.

Code can be regenerated and redeployed, but a migration changes production data, so database changes need their own gate. Atlas is the database layer a factory plugs into: it decides whether a change is safe to ship without a person.

Ship database changes with no human in the loop

In a software factory, agents work tickets in parallel. Atlas runs at every station a database change passes: it plans the migration, reviews it, tests it at production size, sends it back to the agent when a check fails, and deploys only what passed.

✻ claude#481✻ claude#482✻ claude#483PlanReviewTestDeployProduction> add due_onplanning…✓ plannedreviewing…✓ no issuestesting…✓ bounds helddeploying…✓ applied✓ live> index orders✻ Thinking…planning…✓ plannedplanning…✓ plannedreviewing…✓ no issuesreviewing…✓ no issuestesting…✗ lock 19.3stesting…✓ bounds helddeploying…✓ applied✓ live> bump pgvectorplanning…✓ plannedreviewing…✓ no issuestesting…✓ bounds helddeploying…✓ applied✓ live

Atlas at Every Station​

In its sandbox, the agent runs Atlas to plan, review, and test each change on an ephemeral dev database, before it opens a pull request. CI runs the same checks on the pull request, and only the pipeline deploys.

A failed check goes back to the agent with what broke, and the agent fixes the change and runs the checks again.

The stations are the same for versioned and declarative migrations, and each workflow runs them with its own commands:

StationVersioned migrationsDeclarative migrations
Planatlas migrate diffatlas schema plan
Reviewatlas migrate lintatlas schema plan lint
Testatlas migrate test
atlas schema test
atlas schema plan test
atlas schema test
Deployatlas migrate push on merge
atlas migrate apply on deploy
atlas schema push on merge
atlas schema apply on deploy

Plan​

The agent edits the desired schema, in SQL, HCL, or the project's ORM models, and does not write migration SQL by hand.

Atlas plans the migration according to the team's diff policy, such as creating indexes concurrently or skipping destructive changes.

A versioned plan is the next migration file. When two agents add migration files at the same time, atlas.sum makes the second pull request conflict, and its agent rebases the file on top of the first with atlas migrate rebase.

A declarative plan is stored in the Schema Registry, or in the team's own blob storage or OCI registry. Once approved, its statements are the exact statements that run on deploy.

Review​

The same analyzers review migration files and plans. They flag destructive and backward-incompatible changes, changes that depend on the data, and table locks and rewrites, and custom policies enforce the team's own rules.

The agent lints in its sandbox, and CI posts the report on the pull request.

In a migration file, an agent can skip a check with an atlas:nolint directive, so set force on the checks that must always run, and keep atlas.hcl under code owners.

Test​

Tests assess how migrations and any other database code behave and perform, including functions, triggers, views, queries, and Data Scripts.

Migration and plan tests check that the change applies and leaves the expected rows, and schema tests check that the code behaves as the tests assert.

The profiler measures what each statement costs, such as rows read, table rewrites, and lock time, and a workload runs the application's traffic during a migration, so a test catches a migration that blocks it.

In a factory, the tests hold that cost to bounds on production data.

Deploy​

Agents never deploy a change themselves.

After the merge, CI pushes the migration directory or the desired schema to the Schema Registry, and the deploy applies that version from the registry with the tool the team already uses, such as a CI job, the Kubernetes Operator, or the Terraform Provider.

Before the deploy, CI runs the tests again on a masked production snapshot. Agents check what is deployed where with atlas cloud.

In the declarative workflow, CI approves the plan on merge, and atlas schema apply runs it without a person.

When no approved plan matches the database, Atlas plans the change at deploy, and the review policy decides whether a person approves it.

Correct Is Not the Same as Safe​

Lint flags statements known to lock, such as an index created without CONCURRENTLY, and tests check that the code handles the data correctly. Neither tells how long a statement holds a lock, because that depends on how many rows the table has and what they look like.

The expensive cases are ordinary ones:

  • Changing a column type can rewrite the whole table.
  • Building an index sorts every row.
  • Adding NOT NULL or a CHECK constraint scans the table under a lock.
  • A backfill touches every row its WHERE clause matches.
  • A query, function, or trigger that filters on a column with no index reads every row each time it runs.

On an empty dev database, these take milliseconds, because the agent sees the schema and not the rows behind it. The same change can be safe on a small table and cause an outage on a large one, so the gate has to measure what the change costs on your data.

Write the Bounds​

A profile expectation is a bound on what a step of a test does to the database, and the test fails when the step crosses it.

The team writes the bounds once, in a .test.hcl file. The online set below allows no table rewrites and at most five seconds of blocked reads or writes, and the test applies it to version 3:

migrate.test.hcl
expect "profile" "online" {
metric "db.table.rewrites" {
eq = 0
}
metric "db.lock.time" {
le = "5s"
}
}

test "migrate" "index" {
migrate {
to = "1"
}
dataset {
use = dataset.synthetic.orders
}
migrate {
to = "2"
}
migrate {
to = "3"
expect "profile" {
use = [expect.profile.online]
}
}
}

A bound can cover rows read or written, table rewrites and the disk their copies take, lock time, CPU, memory, I/O, or log volume. The metrics reference lists every metric and the labels that narrow it, such as a single table.

Bounds apply to the migrate steps of migration tests and to the exec, catch, and script commands of schema and migration tests, so the queries, functions, triggers, and Data Scripts an agent writes get the same bounds as its migrations.

A bound Atlas cannot verify fails the test too, so a pass means every bound held.

Put the test files under code owners. An agent can change database code on its own, and loosening a bound takes a person.

Expectations are supported on PostgreSQL, MySQL 8.0.28 and later with performance_schema on, and SQL Server.

Preview Feature

Datasets, profiling, and profile expectations are in preview and open to a subset of Teams and Enterprise customers. To get access, reach out through your Atlas support channel or message us on Intercom.

Run the Bounds Twice​

The bounds run twice before a change reaches production, each time on different data. A failed bound in either run goes back to the agent, and only a change that holds every bound on real data deploys.

In the agent's sandbox​

The sandbox run loads synthetic data. Atlas generates rows from the schema, and a table's total sets how many rows it holds in production, so Atlas loads a sample and reports lock times and table copies at the production size.

A statement whose cost grows with the table fails on the agent's machine, in seconds, with no access to production.

Before deploy​

CI runs the same bounds on a production snapshot. An rds_snapshot dataset loads an Amazon RDS snapshot export, a sampler loads part of a table with every row it references, and masks hash or redact sensitive columns before any row reaches the test database:

migrate.test.hcl
dataset "rds_snapshot" "prod" {
src = "s3://backups/exports/prod-2026-10-13/appdb?region=us-east-1"
exclude = ["analytics.events*"]
}

The snapshot run catches what scaling cannot predict: real rows that break the change, such as a NULL under a new NOT NULL or a duplicate under a new unique index, skewed values, and limits that apply only past a size.

Name the tests by their data, such as index_synthetic and index_snapshot, and select them with --run, which matches test names by regular expression. The agent runs the synthetic tests on every change, and CI runs the snapshot tests before deploy:

# In the agent's sandbox
atlas migrate test --dev-url "docker://postgres/18/dev" --run synthetic .

# In CI, before deploy
atlas migrate test --dev-url "docker://postgres/18/dev" --run snapshot .

Only CI needs the credentials that read the export. Keep them in a CI environment that only the default branch can use: a test file can run programs, and a pull request can change it.

What the Agent Gets Back​

A failed bound names the test, the bound, the lock, and the statement that broke it. This is the first failure of the profiling page's example:

-- FAIL: index (1.73s)
migrate.test.hcl:43:
Error: db.lock.time: public.orders (ShareLock, blocks writes): ~19.3s at 50,000,000 rows, expected less than or equal to 5s (3_status_index.sql:1)

The test ran over a sample in under two seconds, and the lock time is reported for the 50,000,000 rows of production. The agent changes the statement and runs the test again, with no one reviewing the loop.

With --profile, it also gets the full profile of every statement.

What the Numbers Measure​

A test run measures the work your code does on your data, not the conditions it runs in. Rows, rewrites, copy sizes, and log volume depend on the data and the statements, and carry over to production as long as the dev database runs your production version and settings.

A loaded snapshot has no live traffic, and a lock that takes half a second on an idle copy can take longer behind real queries, so leave headroom in time bounds.

CPU, memory, and I/O measure the machine that runs the test, the agent's sandbox or the CI runner. Use them to compare one change with another, not as production numbers.

A sampled table can miss the one row that breaks a new constraint, so load the full table for constraint changes.

Where People Step In​

People step in at policy points instead of reviewing every change:

  • To loosen a bound or a lint policy.
  • To approve the changes a review policy pauses.
  • For anything the bounds and policies do not cover.

Get Started with a Coding Agent​

With a coding agent, install the Atlas agent skills. One command installs them:

Install the skills from a terminal. It installs the Atlas plugin, with all its skills, for every project on this machine.

claude plugin marketplace add ariga/atlas
claude plugin install atlas@ariga

Then start the onboarding skill in Claude Code. See Claude Code with Atlas for the other ways to use the skills.

/atlas:atlas-onboard

The atlas skill has the agent lint and test each change it makes, with versioned or declarative migrations. To set up Atlas in a new project, start the atlas-onboard skill.

Next Steps​