| name | database-schema |
| description | PostgreSQL schema access via grep lookups - provides table structures, columns, constraints, indexes, and relationships on-demand without embedding full schema |
Database Schema Expert
Purpose: Provide instant access to PostgreSQL database schema information via grep-based lookups.
When to use: Whenever you need table structure, columns, constraints, indexes, or relationships before implementing queries or entities.
Schema Access Pattern
Before writing ANY database-related code:
- Identify table name from task/context
- Run lookup (see commands below)
- Analyze structure (columns, types, constraints)
- Implement based on actual schema
Never assume schema structure - always verify with grep.
Important: The database-schema.sql is here: .claude/skills/database-schema/database-schema.sql
Lookup Commands
Basic Table Structure
grep -A 20 "CREATE TABLE.*<table_name>" database-schema.sql
Find All Columns for Table
grep -A 50 "CREATE TABLE.*<table_name>" database-schema.sql | grep -E "^\s+[a-z_]+ (VARCHAR|INTEGER|BIGINT|TIMESTAMP|BOOLEAN|TEXT|NUMERIC|UUID)"
Find Primary Key
grep -A 30 "CREATE TABLE.*<table_name>" database-schema.sql | grep "PRIMARY KEY"
Find Foreign Keys (Outgoing)
grep -A 50 "CREATE TABLE.*<table_name>" database-schema.sql | grep "FOREIGN KEY"
Find References TO This Table (Incoming)
grep "REFERENCES <table_name>" database-schema.sql
Find Indexes
grep "CREATE INDEX.*ON <table_name>" database-schema.sql
Find Constraints
grep -A 50 "CREATE TABLE.*<table_name>" database-schema.sql | grep "CONSTRAINT"
Find ALL Tables
grep "CREATE TABLE" database-schema.sql
Typical Workflow
Example: Implementing UserRepository
grep "CREATE TABLE.*users" database-schema.sql
grep -A 30 "CREATE TABLE users" database-schema.sql
grep "FOREIGN KEY" database-schema.sql | grep users
grep "REFERENCES users" database-schema.sql
grep "CREATE INDEX.*ON users" database-schema.sql
Schema File Structure
The database-schema.sql in this folder contains:
- Table definitions (
CREATE TABLE)
- Primary keys
- Foreign key relationships
- Indexes (
CREATE INDEX)
- Constraints (
CHECK, UNIQUE)
- Comments (
COMMENT ON)
Format: Standard PostgreSQL DDL statements
Multi-Table Queries
Finding related tables:
grep "REFERENCES customers" database-schema.sql
grep -A 50 "CREATE TABLE orders" database-schema.sql | grep "FOREIGN KEY"
Join candidates:
grep -E "(CREATE TABLE orders|REFERENCES orders)" database-schema.sql
Common Patterns
Check Column Type Before Mapping
grep -A 20 "CREATE TABLE products" database-schema.sql | grep "price"
Verify NOT NULL Constraints
grep -A 30 "CREATE TABLE users" database-schema.sql | grep "NOT NULL"
Find Enum-like Constraints
grep -A 40 "CREATE TABLE orders" database-schema.sql | grep "CHECK"
Integration with Code
Spring Boot Entity Mapping:
grep table → get columns + types
- Map PostgreSQL types → Java types:
VARCHAR → String
INTEGER/BIGINT → Integer/Long
TIMESTAMP → LocalDateTime
BOOLEAN → Boolean
UUID → UUID
NUMERIC(p,s) → BigDecimal
- Map constraints → JPA annotations:
PRIMARY KEY → @Id
FOREIGN KEY → @ManyToOne / @OneToMany
NOT NULL → nullable = false
UNIQUE → @Column(unique = true)
Keeping Schema Updated
When schema changes:
-
Export from database:
pg_dump -h localhost -U user -d dbname --schema-only > database-schema.sql
-
Or update manually in database-schema.sql
-
Skill automatically uses latest version
Performance Tips
- Use specific table names in grep (faster than wildcards)
- Pipe multiple greps for complex filters
- Use
-A (lines After) for full table definitions
- Use
-B (lines Before) for context
Constraints
- Read-only: This skill provides schema information only
- No writes: Does not modify database or schema file
- Local scope: Schema file must be in same directory as SKILL.md
Example Session
User: "Implement CustomerRepository with pagination"
You:
1. grep -A 40 "CREATE TABLE customers" database-schema.sql
â†' Identify: id (BIGINT), name (VARCHAR), email (VARCHAR), created_at (TIMESTAMP)
2. grep "CREATE INDEX.*ON customers" database-schema.sql
â†' Found: idx_customers_email, idx_customers_created_at
3. Implement:
- Entity with @Id on id
- Pageable query on created_at (indexed)
- Email-based findBy (indexed)
Token Efficiency
This skill is token-light:
- No schema embedded in skill text
- On-demand grep loads only relevant tables
- Schema lookups: 50-200 tokens per query
Compared to embedding full schema: Significant reduction by loading only what's needed per query