Skip to content

feat(planetscale): check unchangeable props with adopt: true#1357

Merged
Mkassabov merged 3 commits intoalchemy-run:mainfrom
mmkal:mmkal/26/03/06/featplanetscalecheckregionmatchesadopttrueregionspecified
Mar 6, 2026
Merged

feat(planetscale): check unchangeable props with adopt: true#1357
Mkassabov merged 3 commits intoalchemy-run:mainfrom
mmkal:mmkal/26/03/06/featplanetscalecheckregionmatchesadopttrueregionspecified

Conversation

@mmkal
Copy link
Copy Markdown
Contributor

@mmkal mmkal commented Mar 6, 2026

Hi! At https://github.com/iterate/iterate we use adopt: true with planetscale for our DB created by hand. It'd be good to still be able to kinda specify the database region as an assertion, since the impacts of the wrong region are very big.

This eliminates the risk of setting region: "aws-eu-west-2" and happily and confidently going ahead with a database that's in the wrong continent without realising. (It doesn't fix it, but it at least fails the deployment and prompts us to fix it).

Also validates kind and arch on adopt. These are also immutable after creation and were previously silently trusted from props (so you could adopt a mysql db while claiming it's postgresql, and downstream code would act on the wrong kind).

Branch region is also covered: branches can be in different regions from the database, so the Branch resource now accepts region and validates it on adopt too. actualRegion is exposed in both Database and Branch outputs.

// Catches wrong-region adopt
const db = await Database("my-db", {
  name: "os-production",
  adopt: true,
  region: { slug: "aws-eu-west-2" }, // throws if actual region differs
  kind: "postgresql", // throws if actual kind differs
  arch: "x86", // throws if actual arch differs
  clusterSize: "PS_10",
});

console.log(db.actualRegion.slug); // "aws-eu-west-2"

@mmkal mmkal marked this pull request as draft March 6, 2026 12:17
@mmkal mmkal changed the title feat(planetscale): check region matches adopt: true + region specified feat(planetscale): check unchangeable props with adopt: true Mar 6, 2026
@Mkassabov Mkassabov self-requested a review March 6, 2026 15:34
Copy link
Copy Markdown
Collaborator

@Mkassabov Mkassabov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is marked as a draft but I left a few quick comments.

This is a very valuable change and makes me want to re-discuss with the team what adoption looks like in the next version of alchemy so we don't run into problems like this again. So thank you!

Feel free to @ me when you feel this is done and I can review & merge.

…e, add docs links

Address PR review feedback:
- Rename actualRegion to region on Branch and Database output types
  (outputs overwrite inputs with actual values per alchemy convention)
- Drop displayName from region output (redundant)
- Use concise region: { slug: data.region.slug } in return statements
- Add @see links to PlanetScale regions docs
- Fix example slugs to include GCP regions
@mmkal mmkal marked this pull request as ready for review March 6, 2026 17:37
@mmkal
Copy link
Copy Markdown
Contributor Author

mmkal commented Mar 6, 2026

@Mkassabov thanks for the feedback - I've addressed your comments and marked ready for review

@Mkassabov Mkassabov merged commit ca29de3 into alchemy-run:main Mar 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants