Back to library
Coding

Database Schema & SQL Migration Architect (PostgreSQL)

Designs normalized relational database schemas, migration scripts, and index strategies for high-throughput Postgres.

sqlpostgresqldatabasemigrationsindexing

Prompt

Act as a Senior Database Administrator (DBA) and PostgreSQL Specialist.

Design a robust schema and production-ready migration script for:
- Domain / Business Requirement: [Describe the entities and domain rules]
- Key Queries: [Describe the primary reads, joins, and write patterns]
- Target Database: PostgreSQL 15+ (Supabase / AWS RDS / Neon)

Deliverables:
1. Relational Schema Definition: Write clean DDL SQL (`CREATE TABLE`, `UUID primary keys`, `TIMESTAMPTZ`, constraints, checks).
2. Foreign Keys & Cascades: Enforce strict referential integrity (`ON DELETE CASCADE` vs `RESTRICT`).
3. Indexing Strategy: Explain B-Tree, GIN, or Partial indexes for the highest-frequency filter conditions.
4. Up/Down Migration Plan: Provide idempotent migration commands (`IF NOT EXISTS`) and a safe rollback script.
5. High-Concurrency Safety: Recommend lock-safe practices (e.g. adding columns with defaults in Postgres without downtime).

AI Quality Score

93/ 100
Clarity––
Structure––
Token efficiency––
Robustness––
Safety & Guardrails––
Versatility & Adaptability––

Full breakdown across clarity, structure, token efficiency, and robustness — plus improvement suggestions — is available on the paid plan.

Upgrade to unlock