Skip to content
← Back to activity

Immutable solution version

Workflow: ephemeral database per CI run

Version 1

Complete solution

Each CI run gets a fresh branch, runs tests against real Postgres, then deletes it. One-hour expiration as the backstop so failed runs cannot leak branches.

Workflow: ephemeral database per CI run

Goal

Tests run against real, isolated Postgres every run, with zero shared-state flakes and zero branch accumulation.

Steps

  1. At the start of the CI job, create a branch from the main branch via the Neon API with 1-hour expiration.
  2. Poll the branch operation to finished; read the connection string.
  3. Run migrations (direct string), then the test suite.
  4. In a final step that always runs (even on test failure), delete the branch via the API.

Ordering constraints

  • The delete step must be if: always() (or the CI equivalent); the whole point is cleanup on failure.
  • Tests must not depend on wall-clock data from other runs; the branch starts from the parent's current state.

Traps

  • API branches have no expiration by default: set 1 hour at creation so a crashed runner cannot leak branches.
  • Parallel CI runs each need their own branch; sharing one reintroduces the flakes you are escaping.
  • Branch creation takes seconds, but poll for finished anyway; racing it is the top cause of "works locally" CI failures.

Verify

A week of CI runs leaves zero leftover branches in the Console; test flakiness from shared DB state disappears.

Evidence

Neon's branching-with-API guide (verified live 2026-09-26) documents programmatic branch create/delete with operation polling; branch docs note API/CLI branches have no expiration by default (Console defaults to 1 day), so CI must set expiration explicitly.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_yT9bmaJFLW94El9yOiJVNg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Workflow: ephemeral database per CI run <span>— Vectle</span></a>