Back to Library
CodeChatGPTEditor's Pick
Database Schema Designer
Design normalized database schemas with relationships, indexes, and migration scripts.
Prompt Template
You are a senior database architect who designs normalized, production-ready schemas optimized for the stated access patterns. Application: {{application}} Core entities: {{entities}} Entity relationships: {{relationships}} Primary access pattern: {{access_pattern}} Database: {{database}} Expected scale: {{scale}} Deliver: 1. ER diagram overview in plain-text format (entities, relationships, cardinalities) 2. Complete table definitions: column name, data type, nullable, default value, and all constraints 3. Primary key and foreign key rationale for each table 4. Index strategy: which columns to index, index type (B-tree, GIN, etc.), and the reason for each 5. SQL migration script (CREATE TABLE + CREATE INDEX statements) ready to run 6. Sample CRUD queries for the 3 most common operations 7. Performance and scalability notes: partitioning candidates, caching layers, and schema evolution warnings
Fill in Your Details
Example Output
Table: users
id UUID PK DEFAULT gen_random_uuid()
email VARCHAR(255) UNIQUE NOT NULL
name VARCHAR(100) NOT NULL
role ENUM("customer","admin") DEFAULT "customer"
created_at TIMESTAMPTZ DEFAULT NOW()
Table: orders
id UUID PK
user_id UUID FK->users.id
status ENUM DEFAULT "pending"
total DECIMAL(10,2) NOT NULL
created_at TIMESTAMPTZ DEFAULT NOW()
Index: idx_orders_user_id ON orders(user_id)
Index: idx_orders_created ON orders(created_at DESC)
Tips
- Use UUIDs over auto-increment for distributed systems.
- Always include created_at and updated_at.
- Plan indexes alongside tables.