Back to Exercises
D1 Migration
Write a D1 migration that follows CREATE SOMETHING patterns.
Objectives
- Design a minimal schema
- Write reversible migrations
- Apply proper indexing strategy
Beads Tasks
Create these tasks in Beads before starting. You learn Beads by using Beads.
bd create "Praxis: D1 migration for [feature]" --type=task--labels=learn,infrastructurebd create "Design minimal schema (question every column)" --type=task--labels=learnbd create "Write up migration" --type=task--labels=learnbd create "Write down migration (reversible)" --type=task--labels=learnbd create "Add indexes with justification" --type=task--labels=learnClaude Code Prompt
Copy this prompt into Claude Code to build YOUR own version:
## Setup: Track this exercise with Beads ```bash bd create "Praxis: D1 migration for [feature]" --type=task --labels=learn,infrastructure bd create "Design minimal schema (question every column)" --type=task --labels=learn bd create "Write up migration" --type=task --labels=learn bd create "Write down migration (reversible)" --type=task --labels=learn bd create "Add indexes with justification" --type=task --labels=learn ``` --- Help me design a D1 database schema for [FEATURE] following MY minimal data philosophy. I'm building MY approach to database design. For [FEATURE]: 1. **Question every column**: - What data is truly required? - What can be derived instead of stored? - What's the minimal viable schema? 2. **Design the schema**: - Create table definitions - Apply proper types (TEXT, INTEGER, REAL, BLOB) - Add NOT NULL only where essential - Use sensible defaults 3. **Write migrations**: - UP migration (creates the schema) - DOWN migration (reverts cleanly) 4. **Index strategy**: - Which queries will be common? - Create indexes with clear justification - Avoid over-indexing 5. **Document MY data principles**: - When do I store vs. derive? - What's my naming convention? - How do I handle relationships? Feature to model: [YOUR_FEATURE] Expected queries: [YOUR_COMMON_QUERIES]
Your Solution
Write code that addresses the objectives above. Apply the principles from the Infrastructure path.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15