database-designer
Provides schema design, vector indexing, and query optimization for PostgreSQL.
Install
mkdir -p .claude/skills/database-designer-moshesham && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10714" && unzip -o skill.zip -d .claude/skills/database-designer-moshesham && rm skill.zipInstalls to .claude/skills/database-designer-moshesham
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
PostgreSQL and pgvector schema design. Use when: designing database schemas, adding vector embeddings, optimizing queries, creating indexes, planning migrations, working with schema.sql or schema_v2.sql.Key capabilities
- →Design PostgreSQL schemas
- →Implement pgvector embeddings
- →Optimize query performance
- →Create HNSW indexes
- →Manage schema migrations
How it works
It provides SQL templates for table structures, vector extensions, and indexing strategies to support semantic search and query optimization.
Inputs & outputs
When to use database-designer
- →Designing database schemas
- →Adding pgvector support for AI search
- →Optimizing slow database queries
- →Planning database migrations
About this skill
Database Designer
When to Use
- Designing or modifying
database/schema.sqlordatabase/schema_v2.sql - Adding pgvector support for semantic search
- Creating indexes for search performance
- Planning schema migrations
- Optimizing slow queries
Schema Design Principles
Table Structure
-- Standard table with audit fields
CREATE TABLE grants (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
external_id VARCHAR(255) UNIQUE NOT NULL,
title TEXT NOT NULL,
description TEXT,
amount_min NUMERIC(15, 2),
amount_max NUMERIC(15, 2),
deadline TIMESTAMPTZ,
source VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
CONSTRAINT valid_amount CHECK (amount_min <= amount_max)
);
pgvector Setup
-- Enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Add embedding column (OpenAI ada-002 = 1536 dims)
ALTER TABLE grants ADD COLUMN embedding vector(1536);
-- Create HNSW index for fast similarity search
CREATE INDEX grants_embedding_idx ON grants
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
Semantic Search Query
-- Find similar grants using cosine similarity
SELECT id, title,
1 - (embedding <=> $1::vector) AS similarity
FROM grants
WHERE embedding IS NOT NULL
ORDER BY embedding <=> $1::vector
LIMIT 10;
Indexing Strategy
B-tree Indexes (Exact Matches)
-- For filtering by source
CREATE INDEX idx_grants_source ON grants(source);
-- For deadline queries
CREATE INDEX idx_grants_deadline ON grants(deadline)
WHERE deadline IS NOT NULL;
GIN Indexes (Full-text Search)
-- Full-text search on title and description
ALTER TABLE grants ADD COLUMN search_vector tsvector;
CREATE INDEX idx_grants_search ON grants USING gin(search_vector);
-- Trigger to update search vector
CREATE OR REPLACE FUNCTION update_search_vector()
RETURNS TRIGGER AS $$
BEGIN
NEW.search_vector :=
setweight(to_tsvector('english', COALESCE(NEW.title, '')), 'A') ||
setweight(to_tsvector('english', COALESCE(NEW.description, '')), 'B');
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
Composite Indexes
-- For common filter + sort patterns
CREATE INDEX idx_grants_source_deadline
ON grants(source, deadline DESC);
Migration Best Practices
- Use transactions: Wrap migrations in
BEGIN/COMMIT - Add columns nullable first: Then backfill, then add constraint
- Create indexes concurrently:
CREATE INDEX CONCURRENTLY - Version your schemas: Name files with timestamps
-- migrations/20240315_add_embeddings.sql
BEGIN;
ALTER TABLE grants ADD COLUMN IF NOT EXISTS embedding vector(1536);
CREATE INDEX CONCURRENTLY IF NOT EXISTS grants_embedding_idx
ON grants USING hnsw (embedding vector_cosine_ops);
COMMIT;
Query Optimization
EXPLAIN ANALYZE
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM grants
WHERE source = 'grants.gov'
AND deadline > NOW()
ORDER BY deadline;
Common Optimizations
- Add missing indexes for WHERE/JOIN columns
- Use
LIMITwithORDER BYto enable index scan - Partition large tables by date or source
- Use connection pooling (PgBouncer)
Anti-patterns
- UUID as string: Use native UUID type
- Missing NOT NULL: Always specify constraints
- No foreign keys: Enforce referential integrity
- SERIAL vs UUID: Use UUID for distributed systems
- Missing updated_at trigger: Always track modifications
When not to use it
- →Non-PostgreSQL databases
- →Simple applications without search requirements
Prerequisites
Limitations
- →Requires pgvector extension support
How it compares
It explicitly integrates vector embedding design with standard relational schema practices, whereas generic designers focus only on tables.
Compared to similar skills
database-designer side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| database-designer (this skill) | 0 | 4mo | No flags | Intermediate |
| drizzle-orm | 32 | 2mo | No flags | Intermediate |
| event-store-design | 5 | 2mo | No flags | Advanced |
| backend-development | 17 | 4mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by moshesham
View all by moshesham →You might also like
drizzle-orm
EpicenterHQ
Drizzle ORM patterns for type branding and custom types. Use when working with Drizzle column definitions, branded types, or custom type conversions.
event-store-design
wshobson
Design and implement event stores for event-sourced systems. Use when building event sourcing infrastructure, choosing event store technologies, or implementing event persistence patterns.
backend-development
skillcreatorai
Backend API design, database architecture, microservices patterns, and test-driven development. Use for designing APIs, database schemas, or backend system architecture.
postgresql
sickn33
Design a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features
epic-database
epicweb-dev
Guide on Prisma, SQLite, and LiteFS for Epic Stack
sql-translation
tidyverse
Guide for adding SQL function translations to dbplyr backends. Use when implementing new database-specific R-to-SQL translations for functions like string manipulation, date/time, aggregates, or window functions.