sql-database-assistant
БесплатноЗапускает вложенные скриптыНе проверенReview SQL queries for index and scan problems, document schemas from DDL, and generate migrations with rollback and destructive-change flags. Use when tuning…
от borghei★ 1 250 звёзд на GitHubОб этом скилле
SQL Database Assistant
Category: Engineering Domain: Database Development & Optimization
Overview
The SQL Database Assistant skill provides tools for analyzing SQL query performance, exploring database schemas from DDL files, and generating migration SQL from schema differences. It helps teams write efficient queries, maintain clean schemas, and manage database evolution safely.
When to Use
- A query is slow and you want the likely text-level causes before reading its plan.
- You need schema documentation (tables, columns, keys) from DDL.
- You have a current and a target schema and need the migration SQL and its rollback.
Clarify First
Before analyzing or generating, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.
- Task: query optimization / schema documentation / migration generation (selects the script).
- SQL input: the query, the DDL file, or the from/to schema pair to operate on (the script's actual input).
- Target database / dialect: Postgres / MySQL / etc. The scripts have no dialect option and always emit PostgreSQL-style migration SQL, so for another database, adapt the generated statements by hand and note which ones changed.
Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.
Quick Start
# Review a file of queries (bundled sample: 8 findings; --strict exits 1 on any finding)
python scripts/query_optimizer.py --file examples/queries.sql --strict
# Review one inline query
python scripts/query_optimizer.py --query "SELECT * FROM users WHERE name LIKE '%john%'"
# Document a schema
python scripts/schema_explorer.py --file examples/schema.sql --format markdown
# Diff two schemas: additive change exits 0, drops exit 1 until reviewed
python scripts/migration_generator.py --from examples/schema.sql --to examples/schema_additive.sql
python scripts/migration_generator.py --from examples/schema.sql --to examples/schema_v2.sql
Tools Overview
| Tool | What it checks or produces | Key flags |
|---|---|---|
query_optimizer.py |
SELECT *, leading-wildcard LIKE, missing WHERE, correlated subqueries, join and OR patterns, DISTINCT, unbounded ORDER BY, = NULL; comments are ignored |
--file or --query, --format text/json, --strict |
schema_explorer.py |
Table catalog, columns with types/nullability/defaults, indexes, foreign keys | --file, --format text/json/markdown |
migration_generator.py |
UP and commented DOWN SQL for added/dropped tables and columns and type changes, with a destructive-change banner | --from, --to, --format, --allow-destructive |
Exit codes: 0 ok; 1 query_optimizer.py --strict found something, or
migration_generator.py produced destructive steps (drops or type changes) without
--allow-destructive; 2 bad input (file not found). Index changes are not diffed.
The optimizer reads query text only. For a real diagnosis ask for the plan
(EXPLAIN (ANALYZE, BUFFERS) in PostgreSQL, EXPLAIN ANALYZE in MySQL 8) and trust it over
the script when they disagree: look for sequential scans on large tables, row-estimate
errors and sorts or hashes spilling to disk.
Workflows
Query Optimization Workflow
- Identify slow queries - Collect queries from slow query log
- Analyze - Run query_optimizer.py on each query
- Review findings - Prioritize by estimated impact
- Optimize - Apply suggested improvements
- Verify - Re-analyze to confirm optimization
Schema Documentation Workflow
- Export DDL - Dump schema from database
- Explore - Run schema_explorer.py to generate docs
- Review - Check relationships and data types
- Publish - Include in project documentation
Migration Workflow
- Capture current - Export current schema DDL
- Define target - Write desired schema DDL
- Generate migration - Run migration_generator.py; exit 1 means it drops or retypes something
- Review SQL - For every
[DESTRUCTIVE]step, decide how the data is preserved (backup, copy column, expand-and-contract) before passing--allow-destructive - Test - Apply UP, then the DOWN script, then UP again on a copy of production data
- Deploy - Done when UP and DOWN both ran cleanly on the copy, data in kept columns is unchanged, and the backup of dropped data is verified
CI Integration
# Lint SQL queries (--file takes one file, so loop over the directory)
for f in queries/*.sql; do
python scripts/query_optimizer.py --file "$f" --format json --strict || exit 1
done
# Generate schema docs
python scripts/schema_explorer.py --file schema.sql --format markdown > SCHEMA.md
Scope & Limitations
In Scope:
- Static review
Установить sql-database-assistant в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл sql-database-assistant?
Review SQL queries for index and scan problems, document schemas from DDL, and generate migrations with rollback and destructive-change flags. Use when tuning a query, documenting a schema, or diffing two schemas.
Как установить скилл sql-database-assistant?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sql-database-assistant запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic