Public: anyone can read this; the crew can change it.

Data: managed Postgres on DigitalOcean as an infra kind (#16696) #17128

opened this

Merged 38h 57m ago, live in production

A managed Postgres on DigitalOcean is now a kind the infra plan can price, hold to the account's ceiling and build. Its URL becomes the app's production secret. The new database tests pass, along with the existing infra, schema, MCP, door, dead-code and hollow suites and tsc.

Notes

opened this

A managed Postgres on DigitalOcean is now a kind the infra plan can price, hold to the account's ceiling and build. Its URL becomes the app's production secret. The new database tests pass, along with the existing infra, schema, MCP, door, dead-code and hollow suites and tsc. I did not run the whole suite; the forge's check does that.

What changed

  • Migration (a new table): managed_database holds name, account, region, size, app, secret name, cluster id and state. 20261201170000-managed-database is pinned, and src/generated/migrations.ts is regenerated on this base, which was what broke #17090.
  • Price read (src/cloud/database.ts): DigitalOcean's API lists sizes but no prices, so the four one-node sizes are held there at list price (1 vCPU/1 GB $15, 1/2 $30, 2/4 $60, 4/8 $120 a month). The ceiling rounds them up, and the account's month (accountCents) and the infra meters now count databases.
  • Plan step (src/cloud/plan.ts): Want gains DatabaseWant. A database plans three steps: create the cluster, wait until it is online, then give the app its URL. Refusals are worded: no account, read-only, not a DigitalOcean account, bad region, unknown size, reserved secret name, unknown app, name taken, and the ceiling's own sentence. Machine planning is untouched, and the existing plan tests are unchanged.
  • Binding (src/actions/database.ts): the cluster is made once, even on a retry, because it is looked up by tag first. The URL is read from DigitalOcean at bind time and set as a secret app_env variable (DATABASE_URL, or a named secret). Production only, so a preview never holds the production database. It never appears on the row or in an event.
  • Doors:
    • Terminal: d on the Infrastructure screen (app, region, size, then the plan with Build); databases also show in its list.
    • MCP: the infra tool's plan takes want {database: true, app, where: account@region, size?, secret?}.
    • API: POST /api/v1/admin/infra/plan takes database: true.
    • infra list and says name databases.
    • docs/features/infra.md has a new section.
  • Reuse: I reused refusalOf, spendOf, gatedFetch, oneAtATime, setAppEnvVar, nameFor and keptPlaces for regions. No new dependency.

What I chose not to do

  • No delete or retire for a database. Deleting data is a typed-name confirm, so for now delete it at DigitalOcean; the forge row stays. Because of this, databases have no end date.
  • No /infra web page change. It composes machines only; the page's meters include database cost.
  • No test for the new API branch. MCP and the terminal share its planDatabase and are tested.
  • The gate's "No door:" waiver. The new feature modules wire into the existing Infrastructure screen and infra.md, so a second screen or page would only repeat them. The gate's both-doors rule asks for a new screen and how-to, so I used its No door: line, with the reason in the commit.
  • Prices are a table, not read live. If DigitalOcean changes list prices, DATABASE_SIZES needs an edit.

How to try it: on the preview, call the infra tool with plan and want {database: true, app: "<owner>/<app>", where: "digitalocean/<account>@nyc1"}, then apply its id. Or press d on the terminal's Infrastructure screen. Build needs a DigitalOcean account with writes allowed.

Closes #17074

5 earlier comments
commented

A managed Postgres on DigitalOcean is now a kind the infra plan can price, hold to the account's ceiling and build. Its URL becomes the app's production secret. The new database tests pass, along with the existing infra, schema, MCP, door, dead-code and hollow suites and tsc. I did not run the whole suite; the forge's check does that.

What changed

  • Migration (a new table): managed_database holds name, account, region, size, app, secret name, cluster id and state. 20261201170000-managed-database is pinned, and src/generated/migrations.ts is regenerated on this base, which was what broke #17090.
  • Price read (src/cloud/database.ts): DigitalOcean's API lists sizes but no prices, so the four one-node sizes are held there at list price (1 vCPU/1 GB $15, 1/2 $30, 2/4 $60, 4/8 $120 a month). The ceiling rounds them up, and the account's month (accountCents) and the infra meters now count databases.
  • Plan step (src/cloud/plan.ts): Want gains DatabaseWant. A database plans three steps: create the cluster, wait until it is online, then give the app its URL. Refusals are worded: no account, read-only, not a DigitalOcean account, bad region, unknown size, reserved secret name, unknown app, name taken, and the ceiling's own sentence. Machine planning is untouched, and the existing plan tests are unchanged.
  • Binding (src/actions/database.ts): the cluster is made once, even on a retry, because it is looked up by tag first. The URL is read from DigitalOcean at bind time and set as a secret app_env variable (DATABASE_URL, or a named secret). Production only, so a preview never holds the production database. It never appears on the row or in an event.
  • Doors:
    • Terminal: d on the Infrastructure screen (app, region, size, then the plan with Build); databases also show in its list.
    • MCP: the infra tool's plan takes want {database: true, app, where: account@region, size?, secret?}.
    • API: POST /api/v1/admin/infra/plan takes database: true.
    • infra list and says name databases.
    • docs/features/infra.md has a new section.
  • Reuse: I reused refusalOf, spendOf, gatedFetch, oneAtATime, setAppEnvVar, nameFor and keptPlaces for regions. No new dependency.

What I chose not to do

  • No delete or retire for a database. Deleting data is a typed-name confirm, so for now delete it at DigitalOcean; the forge row stays. Because of this, databases have no end date.
  • No /infra web page change. It composes machines only; the page's meters include database cost.
  • No test for the new API branch. MCP and the terminal share its planDatabase and are tested.
  • The gate's "No door:" waiver. The new feature modules wire into the existing Infrastructure screen and infra.md, so a second screen or page would only repeat them. The gate's both-doors rule asks for a new screen and how-to, so I used its No door: line, with the reason in the commit.
  • Prices are a table, not read live. If DigitalOcean changes list prices, DATABASE_SIZES needs an edit.

How to try it: on the preview, call the infra tool with plan and want {database: true, app: "<owner>/<app>", where: "digitalocean/<account>@nyc1"}, then apply its id. Or press d on the terminal's Infrastructure screen. Build needs a DigitalOcean account with writes allowed.

commented

I merged main into the branch, resolved the three conflicts, and pushed. The tests I ran pass and tsc --noEmit is clean. I did not run the full suite, and the forge's check will run it on this push.

  • src/actions/infra.ts: the infra view now carries both this branch's databases and main's snapshots and snapshotsHidden. The monthly total counts databases, ended machines and kept snapshots.
  • src/tui/screens/infra.ts: I kept the database compose screen and the new snapshot rows and keys.
  • src/generated/migrations.ts: regenerated with bun scripts/own-source.ts, so it lists both the infra-snapshot and managed-database migrations.
  • Key clash: both sides bound d in the Infrastructure screen, main to delete a snapshot and this branch to compose a database. main's snapshot tests rely on d, so the database now uses b. I changed the screen's key list and hint, the database terminal test, and the line in docs/features/infra.md.
  • Gate: bun scripts/gate.ts --fix printed three similarity warnings: planDatabase/planCompose, databaseNamed/getChange, and setDatabase/setSnapshot. I left them as they are.

The terminal test for the database compose screen failed on the first push because of the d clash, and it passes after the b change. I ran only the infra, managed-database, snapshot, own-source and TUI drill tests. I did not run scripts/design-lint.ts, as I touched no web files.

commented

I fixed one of the three failures and pushed. The other two are probably a flaky boot test that I couldn't reproduce.

  • Event audience coverage: this branch's new database.created and database.bound events (src/actions/database.ts) had no audience. I added kind.startsWith("database.") to the owner-only list in src/core/event_audience.ts, next to infra.*, since they name the owner's cloud account. test/event-audience-coverage.test.ts now passes and tsc --noEmit is clean.
  • Boot tests: the two failures are in test/boot-production.test.ts, and the log shows them failing in 0.59 ms and 0.21 ms, which looks like a hook or startup failure under shard load, not an assertion. All 6 tests in that file pass when I run it alone. The branch doesn't touch main.ts or its boot. If they fail again on this push, I need the check log's error line for them to go further.
commented

This round adds the API test and the name check; the rest of the pull is as @sentinel reviewed it. The type check and test/managed-database.test.ts (15 tests) pass. The full check has not run on this push.

What changed

  • API test: one new test calls the real POST /api/v1/admin/infra/plan handler from adminRoutes with database: true. A non-admin gets 404 (not_found). A body with no where gets 422. A valid body returns 200 with three steps and no refusals.
  • Name check: wantDatabase in src/cloud/plan.ts now refuses a database named like an existing machine with NAME_TAKEN. The test uses a properly typed Have record rather than as never.

Already tested, nothing added: both cases you asked about were already covered by existing tests in test/managed-database.test.ts. "A refused create leaves no cluster, and a retry makes exactly one" asserts a single POST /v2/databases on retry. "The URL is the app's secret…" asserts DATABASE_URL is undefined for the preview scope and is not in any event or row.

Not done: the web composer and the delete are still missing, as you accepted. The gate's near-duplicate notes on planDatabase, databaseNamed and setDatabase were left alone. --fix changed nothing, so its comment-wrap note stays. It says the nightly rewrap on main handles those comments.

Try it: bun test test/managed-database.test.ts. In the terminal, open the infra screen and press b to compose a database.

🤖 Generated with Claude Code

commented

The gate's as never rule failed on the plan API test I added. That test now registers the routes on a real Router<Handler> and reads the handler with handlerOf, so the as never cast is gone.

The rule check passes locally now, but I only ran it after committing, since the gate skips uncommitted files. The type check and test/managed-database.test.ts (15 tests) pass. The full check has not run on this push.

The test still has one as unknown as on the handler's context (a minimal context object, like the one the tool test already uses). The gate did not flag it.

The gate's notes about a long comment line and three near-duplicate functions are unchanged from the last push. They were not what failed the check.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The merge had conflicts in two files, and I kept both sides in each.

  • src/http/mcp/tools/infra.ts: the import line now brings in both planDatabase and the bucket actions. The tool's doc string describes the Postgres database want and also the price/bind bucket actions. I used main's shorter description, "Machines and spend."
  • docs/features/infra.md: the "A database (#17074)" section and main's "Buckets (#17073)" section both stay.

The type check is clean, and the 9 infra, database and bucket test files pass (90 tests, 0 failures). I did not run the full suite or the scoped scripts/fast.ts run. It asked for 3617 test files, so I timed it out and ran only the files that cover this change.

scripts/gate.ts --fix printed three similar-code notes and left nothing to commit. They pair planDatabase with planCompose, databaseNamed with getChange, and setDatabase with setSnapshot. I did not fold any of them together. The --fix output was cut to its last three lines, so I don't know whether those notes block the check.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs