Skip to content

Commit

Permalink
Run migration on remote D1
Browse files Browse the repository at this point in the history
I have not setup D1 tables so far. Now use migration SQL files generated
by drizzle kit (with local SQLite db).

Currently `wrangler pages dev` doesn't support `--remote`, afraid we can
only run app with remote D1 "after" deployment.

cloudflare/workers-sdk#3505
  • Loading branch information
bootleq committed Nov 3, 2024
1 parent 1a287e6 commit d95e061
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ application fetches pre-build JSON instead of hit CMS again.

## Database

Currently, local pages dev doesn't support `--remote` D1, so we use local
sqlite db during development.

When everything is ready, run the drizzle migrations on remote D1.

- List tables, can also used to establish local db first time

pnpm db:tables

- Migrations with drizzle-kit
- Migrations with drizzle-kit (locally)

pnpm db:migrate:gen
pnpm db:migrate:drop
pnpm db:migrate

- Remove local db + drizzle meta, then reset with migrations
- Remove local db + drizzle meta, then reset with migrations (DANGER)

pnpm db:delete
pnpm db:delete && pnpm db:tables && pnpm db:migrate:gen && pnpm db:migrate
Expand All @@ -50,6 +55,11 @@ application fetches pre-build JSON instead of hit CMS again.
PRAGMA defer_foreign_keys = (on|off)
SELECT name, sql FROM sqlite_master

- Run migrations on remote D1

pnpm wrangler d1 list
pnpm wrangler d1 migrations apply feeders --remote


## Authentication

Expand Down
35 changes: 0 additions & 35 deletions db/migrations/0001_create_users_spots_and_followups.sql

This file was deleted.

2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AUTH_TRUST_HOST=4
binding = "DB"
database_name = "feeders"
database_id = "8dc8ae83-03b2-4c66-8259-4456facef8ce"
migrations_dir = "db/migrations"
migrations_dir = "drizzle"

[[r2_buckets]]
binding = "R2"
Expand Down

0 comments on commit d95e061

Please sign in to comment.