Drizzle ORM Schema, Relations, and Migration
Design a Drizzle schema and the migration that introduces it, for Postgres, with relations that match how the app actually queries. DOMAIN App: [APP] Tables to add now: [LIST ENTITIES AND THE FIELDS YOU KNOW] Required queries (these drive indexes): [QUERY_1], [QUERY_2], [QUERY_3] Tenancy column: [user_id | org_id | none] Soft delete: [YES | NO] Existing database: [EMPTY | HAS THESE TABLES] DELIVER TYPESCRIPT 1) schema.ts using drizzle-orm/pg-core. For each table: id strategy (uuid or bigint — pick one and justify), timestamps with time zone, not-null where the product requires it, and unique indexes that match real constraints (not every foreign key by reflex). 2) Relations via relations() so a single query can load [PARENT] with [CHILDREN] without an N+1. Show that query with db.query. 3) Partial index or composite index for the hottest filter in my query list, with a one-line reason. 4) The generated-style SQL migration (up and down). Down must be safe: no drop of a column that holds data unless I marked the table as new. 5) A seed snippet with 3 rows that satisfy the foreign keys. 6) A short note on what NOT to put in Drizzle (RLS policies, extensions) and where those SQL files live instead. Use explicit column names in snake_case in the database and camelCase in TypeScript field names via the column builder. Do not use float for money.
🌟 Example Output / Preview
Prompt Metadata
Primary Use Cases:
- •Legacy code modernization & technical refactoring
- •Full-stack layout generation & component structuring
- •CI/CD workflow automation & unit/E2E testing suites
Associated Tags:
💡 Pro Tips & Advice
1. Use bracketed items: Be sure to fill out all [PLACEHOLDER] elements with specific details before sending the prompt to the AI model.
2. Adjust temperature: For creative tasks, set AI temperature higher (e.g., 0.8), or lower (e.g., 0.2) for strict coding/technical tasks.
🔗 Related AI Prompts
Full SaaS Landing Page Build Spec (SEO + Conversion)
You are a Staff Product Designer + Frontend Engineer + SEO strategist. Build a complete, production-ready marketing landing page f...
SaaS Analytics Dashboard Full Build Spec
You are a Principal Product Designer + Frontend Lead. Design and specify a complete [LIGHT | DARK] analytics dashboard for [PRODUC...
SaaS Admin Panel Dashboard Build Spec
Design a full internal Admin Dashboard for [PRODUCT_NAME] used by [ADMIN_ROLE: support | ops | super-admin]. --- 🎯 CONTEXT Adm...