feat(postgres): add generic Postgres.Database resource with migration support - #1100
Open
wanjohiryan wants to merge 1 commit into
Open
feat(postgres): add generic Postgres.Database resource with migration support#1100wanjohiryan wants to merge 1 commit into
wanjohiryan wants to merge 1 commit into
Conversation
… support
Adds a Postgres.Database resource that connects to any Postgres instance
(self-hosted, cloud-hosted, or local) with built-in migration support
using the same migrationsDir / importFiles pattern as Neon and PlanetScale.
- Connection via URL string or individual host/port/user/password/database fields
- XOR types enforce compile-time mutual exclusion (connectionString vs fields, dev.docker vs dev passthrough)
- Dev mode: auto-starts a local Postgres Docker container or passthrough connection
- Migrations: creates tracking table, applies .sql files in transactions, skips already-applied
- Migrations table default: __alchemy_migrations
- PostgresOrigin output consumable by Cloudflare.Hyperdrive
- Docker volume: .alchemy/storage/postgres/{id}/data bind mount
Contributor
|
So does this deploy a database or just connect to one? |
Author
|
It uses an already existing one... only in dev does it run a container (if docker option is true). It is supposed to give an e2e managed service for anyone who is trying to use alchemy as IAC, and they do not use Neon or Planetscale. It also does migration for you on deploy... which is what i was mostly going for. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
Postgres.Databaseresource that connects to any Postgres instance and handlesmigrations automatically — the same
migrationsDir/importFilesflow as Neon andPlanetScale, but for self- or cloud-hosted Postgres.
Usage
Dev mode — auto Docker container
In dev you never set up a local Postgres manually.
alchemy devstarts one for you:Data persists in
.alchemy/storage/postgres/app-db/datavia a Docker bind mount.A
pg_isreadyhealthcheck ensures the container is accepting connections beforemigrations run.
Dev mode — passthrough
Use a different connection in dev (e.g. a staging DB):
Wired into Hyperdrive
The
originattribute feeds directly intoCloudflare.Hyperdrive:XOR compilation errors
Two compiler-guarded constraints:
Migration internals
__alchemy_migrationstracking table on first run.sqlfile inside a transaction (BEGIN → query → INSERT → COMMIT)importFilesare content-hashed and re-applied on change (no tracking table row)What this PR does not include
read/listimplementation (these providers are pass-through, there's nocloud API to query)
Files
Disclosure
a) This feature was developed with the assistance of AI (Anthropic, Kimi & DeepSeek).
All code was manually reviewed for correctness against the existing alchemy
provider patterns.
b) The feature has not been tested thoroughly because this repository depends on
git submodules (distilled, cloudflare-tools) that recursively pull in gigabytes
of dependencies — framework-specific adapters for Astro, Svelte, Waku, Nuxt,
React Start, Next.js, etc. These submodules are unnecessary for a single new
resource and would consume excessive bandwidth and storage. A full
bun installfollowed by
bun tsc -bcould not be run. All 17 import paths were verifiedmanually against their target exports; one bug (incorrect namespace import for
ProviderLayer) was caught and fixed during review.