feat(db): environment_builds table (SUPER-3017)

Draft
SA
16d ago
+17291-0

Schema only, in its own PR as packages/trpc/AGENTS.md rule 10 asks. Code that uses it follows in the next PR. Plan: #9104 (plans/20261030-0017-environment-builds.md, decision D4).

What it adds

  • environment_builds: one row per build of an environment's golden. Status (running, succeeded, failed), trigger (manual, daily, repositories, promote), kind (incremental, fresh), the repositories it built, the commit, the golden it made, and the error.
  • A partial unique index on environment_id where status = 'running': at most one running build per environment. A second request is refused by the database.
  • Three new enum types.

Migration safety checklist (.agents/skills/db-migrations/SKILL.md)

  • Sizes: the migration touches only a new table and environments. On a copy-on-write branch of production made today, environments is 96 kB with 41 rows. I did not query production itself.
  • No column type change.
  • Lock order: the new table first, then the FK to environments (child, then parent). No foreign keys to auth.organizations or auth.users, so no lock on the hot auth tables.
  • No long ACCESS EXCLUSIVE on a hot table: only CREATE TYPE, CREATE TABLE, one FK and two indexes on an empty table.
  • Every statement is far inside 60 s: the whole migration applied in 1.6 s with lock_timeout=5s statement_timeout=60s.
  • Not rehearsed under load: no hot table is locked and nothing large is scanned, so the skill says the size and lock checks are enough.
  • No reads move to a new table or column.
  • No tRPC input or output change in this PR.
  • Preview branch: not reused yet; delete it if the migration changes after it runs.

Verified

  • Generated with drizzle-kit generate on top of current main (0176); nothing in packages/db/drizzle/ is hand-edited.
  • Applied to a fresh Neon branch only (super-3017-environment-builds-migration-2), never a shared or production database.
  • On a dev branch, in a transaction that was rolled back: a second running build for the same environment was refused with unique_violation, and a new build was accepted once the first had finished.
  • bun run typecheck in packages/db, Biome on the changed files.

Linear: SUPER-3017


Summary by cubic

Adds the environment_builds table to record one build of an environment's golden. Schema only; code that uses it follows in the next PR.

  • Partial unique index keeps at most one running build per environment; a second is refused by the database.
  • Adds three enum types for build status, trigger, and kind. The promote trigger records golden saves from a workspace.
  • Columns include the built repositories, commit, produced golden, and error. Succeeded rows keep their golden so it can be restored.
  • No foreign keys to auth tables, so the migration locks only the new table and environments.