Database Schema Designer
Added Apr 1, 2026
About This Prompt
A well-designed database schema is the foundation of any application, and mistakes made at this level are extremely expensive to fix later. This prompt generates production-ready schemas that incorporate best practices like soft deletes, audit timestamps, proper indexing, and thoughtful normalization decisions. The migration script output means you can apply the schema directly to your development database. The example queries help validate that the schema supports your actual access patterns efficiently. Invaluable for greenfield projects, significant feature additions that require new tables, or refactoring legacy schemas.
Variables to Customize
[DATABASE_TYPE]
Which database system
Example: PostgreSQL
[APPLICATION_TYPE]
What the application does
Example: multi-tenant project management SaaS
[CORE_FUNCTIONALITY]
Key features the schema must support
Example: organizations with team members, projects with tasks and subtasks, file attachments, comments with mentions, and time tracking
[MIGRATION_FORMAT]
Migration tool format
Example: Prisma schema with migration SQL
Tips for Best Results
- Describe your expected query patterns so indexes can be optimized for your use case
- Mention your expected data volume for appropriate partitioning suggestions
- Ask about Row Level Security if you are building a multi-tenant system
Example Output
```sql
-- Organizations (tenant table)
CREATE TABLE organizations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
slug VARCHAR(100) UNIQUE NOT NULL,
plan_tier VARCHAR(20) DEFAULT 'free' CHECK (plan_tier IN ('free', 'pro', 'enterprise')),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
deleted_at TIMESTAMPTZ NULL -- soft delete
);
CREATE INDEX idx_organizations_slug ON organizations(slug) WHERE deleted_at IS NULL;
-- Members (junction: users <-> organizations)
CREATE TABLE organization_members (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
organization_id UUID REFERENCES organizations(id),
user_id UUID REFERENCES users(id),
role VARCHAR(20) DEFAULT 'member' CHECK (role IN ('owner', 'admin', 'member', 'viewer')),
UNIQUE(organization_id, user_id)
);
```