Skip to content

The database Stack

ScwrapDatabase declares a retained PlanetScale Postgres database and its Hyperdrive connection. No Scraper, Release or instance reads it.

ScwrapDatabase is a second Alchemy Stack in apps/infra/alchemy.database.ts. It is separate from an instance: an instance has no database, and nothing in this repository connects to this one. The Stack exists so that the database keeps a declaration and cannot be dropped by accident.

What it declares ​

ResourceName on stage devNotes
PlanetScale Postgres databasescwrap-devPS-5, eu-central. Retained on removal.
PlanetScale rolesbid_cbf_owner, scwrapRetained on removal.
Hyperdrive connectionscwrap-dev-planetscaleLogs in as the scwrap role, query cache off.

The database holds the bid_cbf schema, which is owned and migrated outside this repository, and the scwrap schema.

Commands ​

Run them from an Amp orb. CI never touches this Stack.

sh
CI=1 pnpm infra:database:plan --stage dev --no-input
CI=1 pnpm infra:database:deploy --stage dev --no-input --yes
CommandDoes
infra:database:planPrints the plan and changes nothing.
infra:database:deployApplies exactly the plan it just checked. Needs --yes.

WARNING

Deploying this Stack needs the owner's approval.

The plan guard ​

The PlanetScale database and its roles declare RemovalPolicy.retain(). That keeps the physical database when its declaration is removed, but Alchemy would still forget it, or replace it with an empty one.

So both commands check the complete plan first. assertSafeDatabasePlan refuses any replace, delete or orphaned action on a Planetscale.PostgresDatabase, including a removed or renamed declaration. When the check fails, nothing is applied.

  • There is no force flag and no destroy command. Do not go around the guard with the raw Alchemy CLI.
  • A change to replicas, region or cluster architecture can plan a replacement. Treat that as a stop and ask the owner for a separate plan that preserves the data.

Credentials ​

with-credentials.ts --database logs in to personal OpenBao as personal-manager and reads scwrap/development/deployment, scwrap/development/database and personal/planetscale. It requires every field of scwrap/development/deployment, although this Stack uses only the Cloudflare account and token from it.

Source ​