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
| Resource | Name on stage dev | Notes |
|---|---|---|
| PlanetScale Postgres database | scwrap-dev | PS-5, eu-central. Retained on removal. |
| PlanetScale roles | bid_cbf_owner, scwrap | Retained on removal. |
| Hyperdrive connection | scwrap-dev-planetscale | Logs 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.
CI=1 pnpm infra:database:plan --stage dev --no-input
CI=1 pnpm infra:database:deploy --stage dev --no-input --yes| Command | Does |
|---|---|
infra:database:plan | Prints the plan and changes nothing. |
infra:database:deploy | Applies 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
- alchemy.database.ts: the Stack
- database.ts: the
plananddeploycommands - database-plan.ts: the plan guard and its test