Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

database-schema-designer

БесплатноБез исполняемых скриптовНе проверен

Designs database schemas with proper normalization, indexing, constraints, and tenant isolation patterns. Use when someone needs to create a new database…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Database Schema Designer

Overview

This skill designs database schemas from requirements, including table structures, relationships, indexes, constraints, row-level security policies, and migration scripts. It produces production-ready SQL with proper normalization and performance considerations.

Instructions

Step 1: Understand the Domain

Identify the core entities, their relationships, and access patterns:

  • What are the main entities? (users, orders, products, etc.)
  • What are the relationships? (one-to-many, many-to-many)
  • What queries will be most frequent? (reads vs writes, filtering patterns)
  • Is multi-tenancy needed? What isolation level?

Step 2: Design the Schema

Apply these principles:

  • 3NF by default — normalize to third normal form unless denormalization is justified by read performance
  • UUIDs for public IDs — use UUID v7 (time-ordered) for primary keys exposed to clients; serial for internal-only. On PostgreSQL 18+ use DEFAULT uuidv7(). On 13–17 gen_random_uuid() is built in but returns random v4 UUIDs, so generate v7 in the application or accept v4 (time-ordered keys index better)
  • Timestamps everywhere — created_at and updated_at on all tables
  • Soft deletes when appropriate — deleted_at TIMESTAMPTZ for recoverable records
  • JSONB for flexible fields — use for tenant-specific settings, metadata, but not for frequently queried fields

Step 3: Add Indexes

-- Always index foreign keys
CREATE INDEX idx_tasks_project_id ON tasks(project_id);

-- Composite indexes for common query patterns
CREATE INDEX idx_tasks_project_status ON tasks(project_id, status) WHERE deleted_at IS NULL;

-- Partial indexes for filtered queries
CREATE INDEX idx_tasks_active ON tasks(assigned_to, due_date) WHERE status != 'done';

Step 4: Implement Tenant Isolation (if multi-tenant)

For shared-database multi-tenancy:

-- Add tenant_id to all tenant-scoped tables
ALTER TABLE projects ADD COLUMN tenant_id UUID NOT NULL REFERENCES tenants(id);

-- Enable RLS
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;

-- Create isolation policy. The second argument (true) makes current_setting
-- return NULL instead of an error when the setting was never set. NULLIF also
-- maps the empty string left after a transaction-local setting ends to NULL.
-- Either way the comparison matches no rows (fail closed) instead of raising
-- "invalid input syntax for type uuid".
CREATE POLICY tenant_isolation ON projects
    FOR ALL
    USING (tenant_id = NULLIF(current_setting('app.current_tenant_id', true), '')::UUID)
    WITH CHECK (tenant_id = NULLIF(current_setting('app.current_tenant_id', true), '')::UUID);

-- Ensure tenant_id is in composite indexes
CREATE INDEX idx_projects_tenant ON projects(tenant_id, created_at DESC);

Set the tenant inside each transaction, never with a plain SET on a pooled connection (the value would leak to the next request that reuses the connection):

BEGIN;
SELECT set_config('app.current_tenant_id', '3f6c2a1e-8b4d-4e7a-9c1f-5d2e8a7b6c40', true);
SELECT id, name FROM projects ORDER BY created_at DESC LIMIT 20;
COMMIT;

Enabling RLS on a table with no policy denies every row to non-bypass roles, so create the policy in the same migration as ENABLE ROW LEVEL SECURITY.

Step 5: Generate Migration Files

Output as numbered migration files compatible with common tools:

migrations/
  001_create_tenants.sql
  002_create_users.sql
  003_create_projects.sql
  004_enable_rls_policies.sql

Each migration should be idempotent where possible (CREATE TABLE IF NOT EXISTS, CREATE INDEX IF NOT EXISTS).

Examples

Example 1: Project Management Schema

User prompt:

Design a schema for a project management app with projects, tasks, members, and comments.

Agent output:

CREATE TABLE projects (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    tenant_id UUID NOT NULL REFERENCES tenants(id),
    name VARCHAR(255) NOT NULL,
    description TEXT,
    status VARCHAR(20) NOT NULL DEFAULT 'active'
        CHECK (status IN ('active', 'archived', 'deleted')),
    created_by UUID NOT NULL REFERENCES users(id),
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE tasks (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
    tenant_id UUID NOT NULL REFERENCES tenants(id),
    title VARCHAR(500) NOT NULL,
    description TEXT,
    status VARCHAR(20) NOT NULL DEFAULT 'todo'
        CHECK (status IN ('todo', 'in_progress', 'review', 'done')),
    priority SMALLINT NOT NULL DEFAULT 2 CHECK (priority BETWEEN 0 AND 4),
    assigned_to UUID REFERENCES users(id),
    due_date DATE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

-- Indexes for common access patterns
CREATE INDEX idx_tasks_project_status ON tasks(pro
Полный SKILL.md на GitHub

Установить database-schema-designer в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл database-schema-designer?

Designs database schemas with proper normalization, indexing, constraints, and tenant isolation patterns. Use when someone needs to create a new database schema, add multi-tenant support, design row-level security policies, or optimize table structures. Trigger words: database schema, table design, RLS, row-level security, foreign keys, indexes, migrations, ERD, data model, normalization.

Как установить скилл database-schema-designer?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл database-schema-designer запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить database-schema-designer с