How to create, manage, migrate, seed, inspect, and back up the D1 database.
wrangler d1 create sonan-location-launchpad
Copy the database_id and add it to wrangler.toml.
# Local
wrangler d1 execute sonan-location-launchpad --file=db/migrations/001_schema.sql
# Remote (production)
wrangler d1 execute sonan-location-launchpad --remote --file=db/migrations/001_schema.sql
wrangler d1 execute sonan-location-launchpad --remote --file=db/seed/seed.sql
# List all locations
wrangler d1 execute sonan-location-launchpad --remote --command="SELECT * FROM locations"
# Count tasks per location
wrangler d1 execute sonan-location-launchpad --remote --command="SELECT location_id, COUNT(*) as tasks FROM tasks GROUP BY location_id"
# View overdue tasks
wrangler d1 execute sonan-location-launchpad --remote --command="SELECT title, due_date FROM tasks WHERE due_date < date('now') AND status != 'Done'"
wrangler d1 execute sonan-location-launchpad --remote --command="YOUR SQL HERE"
wrangler d1 export sonan-location-launchpad --remote --output backup.sql
This creates a backup.sql file with all schema and data. Store this in a secure location (e.g., Google Drive, encrypted S3).
| Resource | Free Limit |
|---|---|
| Storage | 5 GB |
| Reads/day | 25 million rows |
| Writes/day | 50,000 rows |
| Databases | 10 |