skills/consiliency/schema-alignment/SKILL.md
Detect and report drift between database schema and code data models. Works with SQLAlchemy, Django ORM, Prisma, TypeORM, and other ORMs. Generic across any project.
npx skillsauth add aiskillstore/marketplace schema-alignmentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Detect drift between database schemas and code data models. This skill identifies missing columns, type mismatches, orphaned migrations, and naming inconsistencies.
This skill is framework-generic. It works with any ORM or database:
| Variable | Default | Description | |----------|---------|-------------| | SCHEMA_SOURCE | auto | Schema source: auto, migrations, live_db, models | | SEVERITY_THRESHOLD | medium | Report issues at this level or higher | | AUTO_FIX | false | Attempt to generate fix suggestions | | INCLUDE_TYPES | true | Include type mismatch detection |
MANDATORY - Follow the Workflow steps below in order.
If you're about to:
STOP -> Check schema alignment -> Generate migration if needed -> Then proceed
Identify the database and ORM:
Check for these indicators:
| File/Dependency | Technology |
|-----------------|------------|
| alembic.ini, alembic/ | Alembic (SQLAlchemy) |
| prisma/schema.prisma | Prisma |
| manage.py + migrations/ | Django |
| ormconfig.json | TypeORM |
| drizzle.config.ts | Drizzle |
| supabase/migrations/ | Supabase (PostgreSQL) |
Parse migration files to reconstruct current schema:
# Alembic example
from alembic.script import ScriptDirectory
from alembic.config import Config
config = Config("alembic.ini")
scripts = ScriptDirectory.from_config(config)
# Walk revisions to build schema
Query information_schema (if accessible):
SELECT table_name, column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = 'public';
Parse ORM model files directly.
Parse model definitions from code:
# Look for patterns like:
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
email = Column(String(255), nullable=False)
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
Also extract related types:
Run comparisons:
| Check | Source A | Source B | Issue Type | |-------|----------|----------|------------| | Missing column | DB schema | ORM model | MISSING_IN_MODEL | | Missing column | ORM model | DB schema | MISSING_IN_DB | | Type mismatch | DB type | Code type | TYPE_MISMATCH | | Nullable mismatch | DB nullable | Model nullable | NULLABLE_MISMATCH | | Name mismatch | snake_case | camelCase | NAMING_DRIFT | | Missing migration | Model change | Migration files | MISSING_MIGRATION | | FK constraint | DB constraint | ORM relationship | FK_MISMATCH |
Output format:
# Schema Alignment Report
**Generated**: 2025-12-24T10:00:00Z
**Database**: PostgreSQL (via Supabase)
**ORM**: SQLAlchemy 2.0
## Summary
| Severity | Count |
|----------|-------|
| HIGH | 2 |
| MEDIUM | 3 |
| LOW | 5 |
## Issues
### 1. MISSING_IN_MODEL (HIGH)
**Table**: `curation_jobs`
**Column**: `retry_count` (INTEGER NOT NULL DEFAULT 0)
**Model**: `src/models/curation_job.py:CurationJob`
The column exists in the database but is not defined in the ORM model.
**Fix**:
```python
retry_count: Mapped[int] = mapped_column(Integer, default=0)
Table: books
Column: isbn (VARCHAR(13))
Model: src/models/book.py:Book.isbn -> str
Database constrains to 13 characters but model allows unbounded string.
Fix:
isbn: Mapped[str] = mapped_column(String(13))
Model Change: User.preferences added (JSONB)
Migration: Not found
A new column was added to the model but no migration exists.
Fix:
alembic revision --autogenerate -m "add user preferences"
## Cookbook
### SQLAlchemy Detection
- IF: Parsing SQLAlchemy models
- THEN: Read and execute `./cookbook/sqlalchemy-detection.md`
### Prisma Detection
- IF: Parsing Prisma schema
- THEN: Read and execute `./cookbook/prisma-detection.md`
### Alembic Migrations
- IF: Generating migration fix
- THEN: Read and execute `./cookbook/alembic-migration.md`
## Issue Severity Matrix
| Issue Type | Default Severity | Upgrade If |
|------------|-----------------|------------|
| MISSING_IN_MODEL | HIGH | Column is NOT NULL |
| MISSING_IN_DB | MEDIUM | Model references it |
| TYPE_MISMATCH | MEDIUM | Could cause data loss |
| NULLABLE_MISMATCH | LOW | NOT NULL in code, nullable in DB |
| NAMING_DRIFT | LOW | - |
| MISSING_MIGRATION | LOW | - |
| FK_MISMATCH | MEDIUM | Causes ORM errors |
## Integration
### With /ai-dev-kit:check-schema
Direct invocation:
```bash
# Full check
/ai-dev-kit:check-schema
# Check specific tables
/ai-dev-kit:check-schema --tables=users,orders
# Generate fixes
/ai-dev-kit:check-schema --auto-fix
# Output to file
/ai-dev-kit:check-schema --output=alignment-report.md
Runs as pre-flight check for database-related lanes:
Lane: SL-DB (Database Schema)
Pre-flight checks:
1. ✓ Git worktree clean
2. ✗ Schema alignment check failed
- 2 HIGH severity issues found
- See alignment-report.md
Action: Resolve schema issues before proceeding.
Runs during phase planning:
Planning Phase P1...
Schema Alignment: ⚠️ 3 issues detected
- 1 missing migration
- 2 type mismatches
Recommendation: Add schema alignment task to SL-DB lane.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"generated_at": {"type": "string", "format": "date-time"},
"database": {"type": "string"},
"orm": {"type": "string"},
"summary": {
"type": "object",
"properties": {
"high": {"type": "integer"},
"medium": {"type": "integer"},
"low": {"type": "integer"}
}
},
"issues": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {"type": "string"},
"severity": {"enum": ["HIGH", "MEDIUM", "LOW"]},
"table": {"type": "string"},
"column": {"type": "string"},
"model_location": {"type": "string"},
"description": {"type": "string"},
"fix": {"type": "string"}
}
}
}
}
}
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.