How do I set up a database with AI?
Have the AI propose a schema and migrations, review them yourself, apply them to a local copy first, and only then run them on the real database.
A database is where your app keeps data that must survive: users, orders, messages. Setting one up means designing tables (the schema), writing migrations (numbered SQL files that create or change tables, applied in order) and loading starting data.
AI agents can do all of this in minutes, which is useful and risky. A safe workflow:
- Brief the AI on what the app stores, how records relate and what rules the data must follow, and ask it to explain its design.
- Review the schema: every table needs a primary key, relationships need foreign keys, required fields should be NOT NULL, and common lookups need indexes.
- Check each migration for destructive changes, such as dropped columns or renamed tables, before it runs.
- Apply migrations locally, test, then apply them to production.
- Insert data with parameterized queries, never by pasting values into SQL text.
- Make sure backups or exports exist, and try a restore.
Also pick the right kind of storage: SQL for structured records, object storage for files, and a key-value store for simple, fast lookups.
Vumbli's Databases with AI: Set Up, Migrate, Store track teaches this end to end on Cloudflare D1, including fixing an AI-written migration that would lose data. Databases & SQL Deep Dive teaches the SQL itself.
Start with these missions
- Where your data can live (Databases with AI: Set Up, Migrate, Store)
- Prompt: get a schema designed, not guessed (Databases with AI: Set Up, Migrate, Store)
- Your first questions to a database (Databases & SQL Deep Dive)
- Summaries with GROUP BY and HAVING (Databases & SQL Deep Dive)
Tracks that teach it
More questions, answered by building