Skip to content

Commit 509d47b

Browse files
feat: remove autocommit checker, add --diff-branch flag, bump to v0.3.0
Remove custom autocommit block checker and delegate to squawk's native `assume_in_transaction` config in `.squawk.toml`. Add `--diff-branch` flag so consumers can skip linting migrations that already exist on a given branch. Consolidate version-check workflow into ci.yml. Clean up gitignore to only entries relevant to this project.
1 parent 3d188ad commit 509d47b

10 files changed

Lines changed: 276 additions & 505 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,20 @@ jobs:
3232
- name: Run pre-commit hooks
3333
run: poetry run pre-commit run --all-files
3434

35+
- name: Check version consistency
36+
run: |
37+
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/' || true)
38+
INIT_VERSION=$(grep '^__version__ = ' squawk_alembic/__init__.py | sed 's/__version__ = "\(.*\)"/\1/' || true)
39+
if [ -z "$PYPROJECT_VERSION" ] || [ -z "$INIT_VERSION" ]; then
40+
echo "::error::Could not parse version from pyproject.toml or __init__.py"
41+
exit 1
42+
fi
43+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
44+
echo "::error::Version mismatch: pyproject.toml ($PYPROJECT_VERSION) != __init__.py ($INIT_VERSION)"
45+
echo "Run 'make bump VERSION=x.y.z' to update both files."
46+
exit 1
47+
fi
48+
echo "Versions match: $PYPROJECT_VERSION"
49+
3550
- name: Run tests
3651
run: poetry run pytest tests/ -v

.github/workflows/version-check.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.gitignore

Lines changed: 10 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,26 @@
1-
# Byte-compiled / optimized / DLL files
1+
# Byte-compiled / optimized
22
__pycache__/
33
*.py[cod]
44
*$py.class
55

6-
# C extensions
7-
*.so
8-
96
# Distribution / packaging
10-
.Python
117
build/
12-
develop-eggs/
138
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
share/python-wheels/
249
*.egg-info/
25-
.installed.cfg
2610
*.egg
27-
MANIFEST
28-
29-
# PyInstaller
30-
# Usually these files are written by a python script from a template
31-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32-
*.manifest
33-
*.spec
3411

35-
# Installer logs
36-
pip-log.txt
37-
pip-delete-this-directory.txt
12+
# Virtual environments
13+
.venv/
3814

39-
# Unit test / coverage reports
40-
htmlcov/
41-
.tox/
42-
.nox/
43-
.coverage
44-
.coverage.*
45-
.cache
46-
nosetests.xml
47-
coverage.xml
48-
*.cover
49-
*.py,cover
50-
.hypothesis/
15+
# Test / coverage
5116
.pytest_cache/
52-
cover/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
.pybuilder/
76-
target/
77-
78-
# Jupyter Notebook
79-
.ipynb_checkpoints
80-
81-
# IPython
82-
profile_default/
83-
ipython_config.py
84-
85-
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89-
90-
# pipenv
91-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94-
# install all needed dependencies.
95-
#Pipfile.lock
96-
97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
103-
104-
# pdm
105-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106-
#pdm.lock
107-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108-
# in version control.
109-
# https://pdm.fming.dev/#use-with-ide
110-
.pdm.toml
111-
112-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113-
__pypackages__/
114-
115-
# Celery stuff
116-
celerybeat-schedule
117-
celerybeat.pid
118-
119-
# SageMath parsed files
120-
*.sage.py
121-
122-
# Environments
123-
.env
124-
.venv
125-
env/
126-
venv/
127-
ENV/
128-
env.bak/
129-
venv.bak/
130-
131-
# Spyder project settings
132-
.spyderproject
133-
.spyproject
134-
135-
# Rope project settings
136-
.ropeproject
137-
138-
# mkdocs documentation
139-
/site
140-
141-
# mypy
142-
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
148-
149-
# pytype static type analyzer
150-
.pytype/
151-
152-
# Cython debug symbols
153-
cython_debug/
17+
.coverage
18+
htmlcov/
15419

155-
# PyCharm
156-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158-
# and can be added to the global gitignore or merged into this file. For a more nuclear
159-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
20+
# Editors / OS
16021
.idea/
161-
22+
.vscode/
16223
.DS_Store
163-
.vscode
164-
.python-version
165-
166-
compare_output/
167-
export/backup/
168-
node_modules/
16924

170-
171-
.serverless/
172-
173-
# Local files with credentials/secrets
174-
local_files/
175-
176-
# Claude skills/agents/config
177-
.claude/
178-
CLAUDE.md
179-
.mcp.json
25+
# Python version
26+
.python-version

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,58 @@ A [pre-commit](https://pre-commit.com/) hook that lints SQL in [Alembic](https:/
44

55
Squawk operates on raw SQL files, but Alembic migrations are Python. This hook bridges the gap by generating DDL via `alembic upgrade --sql` (offline mode) and passing the complete SQL output to squawk for analysis. This captures all SQL statements a migration produces, including ORM operations like `op.create_index()`, `op.create_table()`, and `op.alter_column()`.
66

7-
The hook also checks that concurrent index operations (`CONCURRENTLY` in `op.execute()` or `postgresql_concurrently=True` in `op.create_index()` / `op.drop_index()`) are wrapped in `autocommit_block()`.
8-
97
## Usage
108

119
Add the following to your `.pre-commit-config.yaml`:
1210

1311
```yaml
1412
repos:
15-
- repo: https://github.com/kintsugi-tax/kintsugi-squawk
16-
rev: v0.2.0
13+
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
14+
rev: v0.3.0
1715
hooks:
1816
- id: squawk-alembic
1917
```
2018
2119
No additional configuration is required. The hook auto-detects your migrations directory by reading `script_location` from `alembic.ini`. The consumer's `alembic` must be available on PATH (the hook calls it via subprocess).
2220

21+
### Pinning the squawk version
22+
23+
The hook depends on `squawk-cli >= 2.0`. To pin a specific squawk version (matching your local dev dependency, for example), use `additional_dependencies`:
24+
25+
```yaml
26+
repos:
27+
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
28+
rev: v0.3.0
29+
hooks:
30+
- id: squawk-alembic
31+
additional_dependencies: ["squawk-cli==2.41.0"]
32+
```
33+
34+
This overrides the default version and ensures pre-commit uses the exact squawk release you specify.
35+
36+
### Only lint new migrations
37+
38+
To skip migrations that already exist on a branch (useful for repos with existing violations you can't fix immediately), pass `--diff-branch`:
39+
40+
```yaml
41+
repos:
42+
- repo: https://github.com/kintsugi-tax/squawk-pre-commit
43+
rev: v0.3.0
44+
hooks:
45+
- id: squawk-alembic
46+
args: [--diff-branch, main]
47+
```
48+
49+
With this flag, the hook checks whether each migration file exists on the specified branch. Files that already exist are skipped. New files (not yet on the branch) are linted. This makes `pre-commit run --all-files` safe to run in repos where older migrations would fail linting.
50+
2351
## How It Works
2452

2553
When pre-commit runs, the hook:
2654

2755
1. Parses `alembic.ini` to find the migrations `versions/` directory
2856
2. Filters staged files to only those under that directory
29-
3. Checks for concurrent operations outside `autocommit_block()`
30-
4. Runs `alembic upgrade --sql` to generate the complete DDL for each migration
31-
5. Pipes the generated SQL to squawk for linting
57+
3. Runs `alembic upgrade --sql` to generate the complete DDL for each migration
58+
4. Pipes the generated SQL to squawk for linting
3259

3360
Merge migrations (where `down_revision` is a tuple) are skipped since they produce no DDL.
3461

@@ -55,5 +82,5 @@ To test the hook against a consumer repo locally:
5582

5683
```bash
5784
cd /path/to/consumer-repo
58-
pre-commit try-repo /path/to/kintsugi-squawk squawk-alembic --all-files
85+
pre-commit try-repo /path/to/squawk-pre-commit squawk-alembic --all-files
5986
```

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "squawk-alembic"
7-
version = "0.2.0"
7+
version = "0.3.0"
88
description = "Pre-commit hook to lint Alembic migration SQL with squawk"
99
packages = [{include = "squawk_alembic"}]
1010

1111
[tool.poetry.dependencies]
1212
python = ">=3.10"
13-
squawk-cli = "*"
13+
squawk-cli = ">=2.0"
1414

1515
[tool.poetry.group.dev.dependencies]
1616
alembic = "*"

squawk_alembic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.0"
1+
__version__ = "0.3.0"

0 commit comments

Comments
 (0)