/sqlty:sqlty-cifrom sqlty
Sets up or repairs sqlty in pre-commit hooks and GitHub Actions CI. Covers sqlty-rewrite, sqlty-check, sqlty-breaking, and sqlty-strip commands, plus troubleshooting hook installation failures.
Ships in sqlty. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Run sqlty where it blocks bad queries: before a commit and on every pull request. Each command exits 1 on what it guards:
| Command | Fails when |
|---|---|
sqlty rewrite --check . | a --sql string is not wrapped yet |
sqlty check . | a rule with severity error fires |
sqlty breaking --against REF | the schema change breaks the queries of either revision |
sqlty strip --check . | a file has SQL[T] wrappers, when you commit plain strings |
Run sqlty version: this skill may be newer or older than the installed sqlty.
When it and sqlty --help disagree, trust the command.
# .github/workflows/sqlty.yml
name: sqlty
on: [pull_request]
jobs:
sqlty:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # sqlty breaking reads the base branch
- uses: astral-sh/setup-uv@v7
- run: uv sync
- run: uv run sqlty rewrite --check .
- run: uv run sqlty check --output-format github .
- run: uv run sqlty breaking --output-format github --against origin/${{ github.base_ref }}
fetch-depth: 0 is required: with the default shallow clone, sqlty breaking
can't find the base branch and exits 2.--output-format github prints each diagnostic as an annotation on its line
of the pull request's diff.uv sync to install it.# .pre-commit-config.yaml
default_language_version:
python: python3.14 # sqlty requires Python >= 3.14
repos:
- repo: https://github.com/jirikuncar/sqlty
rev: v0.10.0
hooks:
- id: sqlty-rewrite
- id: sqlty-check
| Failure | Fix |
|---|---|
| the hook environment can't install sqlty | keep default_language_version at Python 3.14 or newer |
the install compiles Rust, or cargo is missing | install a Rust toolchain, or use the local hooks below |
sqlty-rewrite fails the commit | it rewrote files: review and stage them |
| a schema change passes but breaks queries | update rev: older hooks run only on Python files, newer ones check the whole project when its schema or config changes |
Local hooks reuse the sqlty of your environment and need no build:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: sqlty-rewrite
name: sqlty rewrite
entry: uv run sqlty rewrite .
language: system
pass_filenames: false
types_or: [python, sql, toml]
- id: sqlty-check
name: sqlty check
entry: uv run sqlty check .
language: system
pass_filenames: false
types_or: [python, sql, toml]
narrow-type (a SQL[tuple[...]] that doesn't admit the rows its query now
returns, such as str for a column made nullable) is an error. stale-type (a
SQL[tuple[...]] only wider than the rows, such as str | None for a column made
NOT NULL) and stale-rewrite (an unwrapped --sql string) are warnings by
default, so sqlty check exits 0 on them. Promote what you want CI to enforce:
[tool.sqlty]
schema = "schema.sql"
[tool.sqlty.rules]
stale-type = "error"
untyped-query = "error"
sqlty check --error-on-warning fails on every warning instead. Keep schema
current: regenerate it from the database in the same pull request as the
migration (pg_dump --schema-only, sqlite3 app.db .schema,
mysqldump --no-data), or point schema at the migrations directory.
Each file uses the nearest pyproject.toml above it that has a [tool.sqlty]
table, so one sqlty check . covers several projects. A nested table replaces
the root one; they are not merged.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub jirikuncar/sqlty --plugin sqlty7 skills in this plugin
/sqltyWrite, type and check raw SQL in Python with sqlty. Use when adding or editing a query in a project that uses sqlty (strings starting with --sql, SQL[T] or SQLTemplate[T] wrappers, a [tool.sqlty] section), when generating Python row types for a query, when typing raw SQL in Go as sqlty.SQL[R, P], or when checking that queries still fit a schema migration before deploying. Routes to sqlty-rewrite, sqlty-check, sqlty-breaking, sqlty-ci and sqlty-adopt for each task./sqlty-adoptIntroduce sqlty into an existing Python project with raw SQL queries, one module at a time. Use when a project doesn't use sqlty yet and you are asked to add it, type its SQL queries, configure [tool.sqlty] (dialect, schema from a database dump or migrations), choose which queries to convert first, mark the ones sqlty can't type yet, or add the first CI gate./sqlty-breakingCheck that a schema change or migration doesn't break the queries running during a rolling deploy, with sqlty breaking, and plan an expand and contract migration. Use when adding, dropping, renaming or changing a table or column, writing a migration, making a column nullable or NOT NULL, reading a sqlty breaking finding (backward or forward), or splitting a schema change into safe pull requests./sqlty-checkRun sqlty check and act on its diagnostics, name the row type of a query, and check query parameters, including the typed parameters of SQL[R, P]. Use when sqlty check reports a diagnostic such as [unknown-column] or [narrow-type], when replacing SQL[tuple[...]] with a TypedDict, dataclass, NamedTuple or pydantic model, when a column may be NULL, when a call passes the wrong parameters, when a join inflates a SUM, AVG or COUNT ([fanout-aggregate], [chasm-join]) or compares a foreign key with a column it does not reference or keys of different tables ([foreign-key-mismatch], [entity-mismatch]), when suppressing a diagnostic with a sqlty ignore comment, or when changing a rule's severity in [tool.sqlty.rules]./sqlty-rewriteWrap --sql query strings as SQL[T] with sqlty rewrite, update or remove the wrappers, and keep them in sync after editing a query. Use when writing a new SQL query in Python, editing the SQL inside an SQL[T] wrapper, committing or removing wrappers (sqlty rewrite, sqlty strip, --check, --diff), choosing an import-style, wrapping untyped queries as SQL[UNTYPED], or using the sqlty magic codec (a "coding sqlty" source encoding) instead of committed wrappers./sqlty-serverRun sqlty in an editor with sqlty server, the language server, and the VS Code extension. Use when setting up sqlty in VS Code, Cursor, VSCodium, Neovim, Vim, Helix, Emacs or another LSP client, highlighting SQL in query strings, fixing a query on save with source.fixAll.sqlty, formatting query strings with source.format.sqlty, showing sqlty breaking findings while editing, or when the editor reports nothing or different diagnostics than sqlty check.Other plugins' skills for the same job