-
Notifications
You must be signed in to change notification settings - Fork 125
Open
Description
Description
When running alchemy dev, the local D1 database (Miniflare) loses all data on each restart because it runs in-memory. However, Alchemy skips re-applying migrations on subsequent starts ([skipped] DB Skipped Resource (no changes)), resulting in no such table errors.
Steps to Reproduce
- Create a project with
D1DatabaseandmigrationsDir - Run
alchemy dev --stage dev— first run applies migrations correctly - Stop the dev server (Ctrl+C)
- Run
alchemy dev --stage devagain - D1 resource is skipped:
[skipped] DB Skipped Resource (no changes) - Any query to D1 fails with
D1_ERROR: no such table: <table_name>: SQLITE_ERROR
Expected Behavior
Local D1 migrations should be re-applied on every alchemy dev restart, since Miniflare D1 is in-memory and doesn't persist data between restarts.
Additional Context
- Alchemy version: 0.82.2
- The
d1-local-migrations.jslogic works correctly when it runs — the issue is that theD1Databaseresource is skipped entirely due tono changesdetection. d1Persist: trueis set inminiflare-controller.js, but no sqlite files are created under.alchemy/miniflare/v3/d1/— only KV has sqlite files.applyLocalD1Migrationscreates a separate Miniflare instance to run migrations, thendispose()s it. Even if migrations ran, the data wouldn't be available to the Worker's Miniflare instance since there's no shared sqlite file on disk.- Using
CloudflareStateStorefor state (not local filesystem), which may contribute to the skip logic not detecting that local data was lost.
Workaround
Using dev: { remote: true } on D1Database to connect to the deployed D1 instance during local development.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels