GuidesUpdated

Can two coding agents use the same development database?

Find which database each agent worktree uses, choose shared or isolated state on purpose, and review competing migrations before you integrate.

On this page

Two agents can edit separate worktrees and still share one development database. One agent's seed or migration changes what the other sees, so a green test can describe the wrong state. A worktree separates files; the database endpoint, volume and data need their own decision. The example here is a profile-settings branch and a billing-history branch.

Canopy local service controls beside agent worktrees
Canopy local service controls beside agent worktrees

Prove whether the agents share state

Before either agent migrates or runs a mutating test, record each one's working directory, branch, database host, and database name or project reference. Compare non-secret identifiers, not credentials. A different frontend port doesn't mean a different database. Check Docker Compose project names, published ports, volumes and any shared cloud project.

Git worktrees are separate working directories on one repository; they don't create a second database. Only your configuration and a live check show whether two connection strings reach separate data.

  • If both agents see the same disposable marker row, they share data. Remove it afterwards.
  • Never test isolation by writing a marker into production.

Pick the isolation the work needs

Static UI work can share a read-only backend. Tests that insert, delete, reset, seed or migrate need separate databases, or one branch at a time. Separate schemas in one server may still share roles and extensions.

A Compose project name separates copies of an environment, but not published host ports or external volumes; give each copy its own name, ports and database target. Supabase branches have separate database instances, API endpoints, Auth settings and storage, with their own migration rules.

Start from the smallest setup that protects the test result.
TaskPossible state setupEvidence required
Read-only UI workOne shared dev APINo writes or schema changes; both branches name the same endpoint
Independent mutating testsSeparate local databases or branch environmentsDistinct targets and seed data; neither test alters the other
Only one local databaseRun migrations and mutating tests in turnRecorded order, reset plan and clean baseline before each run
Related migrationsOne integration owner and ordered migration reviewBoth migrations apply to a fresh baseline in order

Keep migrations reviewable while agents work

Let each agent own its own migration and state which schema objects change, what data it assumes, how it was tested, and whether the app works with the old schema during rollout. Don't let both agents reset or push to the same remote project.

Supabase keeps migrations in version control and applies them in order on branches, which can expose conflicts. Two passing branches can still add clashing constraints, columns or policies. Review the SQL and combined order before any shared or production apply.

  • Name one integration owner for migrations that touch the same table or policy.
  • Test against representative existing rows when data must survive.

Test each branch, then the combined result

In Canopy, save each checkout's app, API, worker and database commands and confirm their working directories and URLs. Run each branch's check against its own database. Profile: save and reload a name, and confirm another account can't edit it. Billing: a user sees only their own entries.

After combining the code, build a clean integration database from the common baseline, apply both migration sets in order and repeat both journeys. Branch tests prove only that branch's assumptions.

  • Read the final diff and PR checks after integration, not just the agent summaries.
  • Leave production migration approval with the designated owner.

Clean up without deleting the wrong data

Identify the finished branch's database, Compose project and volumes before cleanup. Compose `down` with volume removal destroys that project's data, so confirm the project and that its data is disposable first. External volumes and shared hosted projects may outlive a branch by design. Keep a short setup note with branch-to-environment mapping and migration order, and no secrets.

Copyable resources

Two-agent database map

Record endpoint identifiers and results, never database passwords or service-role keys.

Task A / branch / worktree / commit: [ ]
Task B / branch / worktree / commit: [ ]
A app and database target (non-secret): [ ]
B app and database target (non-secret): [ ]
A Compose project, host port, volume or hosted branch: [ ]
B Compose project, host port, volume or hosted branch: [ ]
Shared state allowed? [what and why]
Mutating tests, seeds, resets and migration owner: [ ]
A feature check and database state: [ ]
B feature check and database state: [ ]
Combined migration order on clean integration state: [ ]
Combined feature and cross-user checks: [ ]
Cleanup target confirmed by: [ ]
Production apply owner and approval path: [ ]

Frequently asked questions

Do Git worktrees give coding agents separate databases?

No. They give separate checked-out files and branch state. Connection settings, database instances, volumes and data are whatever your project configures.

Is a different Docker Compose project name enough?

It separates Compose resources, but host ports, bind mounts, external volumes and connection strings can still point two projects at the same state. Check them.

Can I let two agents write migrations at once?

They can draft changes on separate branches with isolated test environments. Have an integration owner review overlapping schema changes and run both migration sets together before any shared or production apply.

What if I cannot afford a second database?

Run mutating tests and migrations one branch at a time on a disposable database. Record the order and restore a known baseline between runs.

More questions and answers →

Sources and further reading