alembic-squawk 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/PKG-INFO +43 -2
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/README.md +42 -1
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/alembic_squawk/cli.py +4 -3
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/pyproject.toml +1 -1
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/alembic_squawk/__init__.py +0 -0
- {alembic_squawk-0.1.0 → alembic_squawk-0.2.0}/alembic_squawk/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: alembic-squawk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Split Alembic migrations into per-revision SQL files for linting with Squawk.
|
|
5
5
|
Keywords: alembic,squawk,sql-linter,migration
|
|
6
6
|
Author: Michael Bianco
|
|
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
|
|
|
23
23
|
|
|
24
24
|
- Strips the outer `BEGIN`/`COMMIT` Alembic wraps the full dump in, so each file contains only its own migration SQL. Pass `--assume-in-transaction` to Squawk when linting.
|
|
25
25
|
- Maps each revision back to its source `.py` file to preserve the original filename in output.
|
|
26
|
-
- Reads `#
|
|
26
|
+
- Reads squawk directives (e.g. `# squawk-ignore-file <rule>`, `# squawk-disable <rule>`) embedded as Python comments in migration files and prepends them as SQL directives in the generated output, so you can attach Squawk ignores without embedding raw SQL comments in Python source.
|
|
27
27
|
- Supports filtering by revision range or creation date to narrow linting to recently added migrations.
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
@@ -52,8 +52,49 @@ The output directory is wiped and recreated on every run.
|
|
|
52
52
|
|
|
53
53
|
Each file is named after its migration source file, e.g. `2026_03_16_d4b9da2f705c_add_users.sql`.
|
|
54
54
|
|
|
55
|
+
## Ignoring Squawk Errors
|
|
56
|
+
|
|
57
|
+
Squawk supports per-file ignore directives in SQL comments (e.g. `-- squawk-ignore-file ban-drop-column`). To attach these to a migration without embedding raw SQL comments in Python source, write the directive as a Python comment. The `--` prefix is optional.
|
|
58
|
+
|
|
59
|
+
**Note:** The comment must be at the very beginning of the line. Indented comments (e.g., inside a function) or inline comments (e.g., `op.execute("...") # squawk-disable`) are not supported and will be ignored.
|
|
60
|
+
|
|
61
|
+
For example, to hide a drop column error in your migration:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
"""add users table
|
|
65
|
+
|
|
66
|
+
Revision ID: 1a2b3c4d5e6f
|
|
67
|
+
Revises:
|
|
68
|
+
Create Date: 2026-03-16 10:22:01.123456
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
# squawk-ignore-file ban-drop-column
|
|
72
|
+
# -- squawk-disable require-concurrent-index-creation
|
|
73
|
+
|
|
74
|
+
from typing import Sequence, Union
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
from alembic import op
|
|
78
|
+
import sqlalchemy as sa
|
|
79
|
+
|
|
80
|
+
# ... migration code ...
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
When `alembic-squawk` generates the SQL for this revision, it will prepend those directives as standard SQL comments at the top of the file so Squawk honors them.
|
|
84
|
+
|
|
55
85
|
## Example
|
|
56
86
|
|
|
87
|
+
Here is an end-to-end example of how you might integrate `alembic-squawk` into a CI script or standard shell workflow to lint your database migrations:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# generate per-revision SQL files
|
|
91
|
+
uv run alembic-squawk --out-dir /tmp/alembic-squawk-lint
|
|
92
|
+
|
|
93
|
+
# the generated SQL is not wrapped in a transaction, but the entire migration will be.
|
|
94
|
+
# note: we use --assume-in-transaction so squawk knows to lint appropriately.
|
|
95
|
+
squawk --assume-in-transaction --pg-version=15 /tmp/alembic-squawk-lint/*.sql
|
|
96
|
+
```
|
|
97
|
+
|
|
57
98
|
[iloveitaly/python-starter-template](https://github.com/iloveitaly/python-starter-template) is a full Python app with a working integration of `alembic-squawk`.
|
|
58
99
|
|
|
59
100
|
## [MIT License](LICENSE.md)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
- Strips the outer `BEGIN`/`COMMIT` Alembic wraps the full dump in, so each file contains only its own migration SQL. Pass `--assume-in-transaction` to Squawk when linting.
|
|
13
13
|
- Maps each revision back to its source `.py` file to preserve the original filename in output.
|
|
14
|
-
- Reads `#
|
|
14
|
+
- Reads squawk directives (e.g. `# squawk-ignore-file <rule>`, `# squawk-disable <rule>`) embedded as Python comments in migration files and prepends them as SQL directives in the generated output, so you can attach Squawk ignores without embedding raw SQL comments in Python source.
|
|
15
15
|
- Supports filtering by revision range or creation date to narrow linting to recently added migrations.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
@@ -40,8 +40,49 @@ The output directory is wiped and recreated on every run.
|
|
|
40
40
|
|
|
41
41
|
Each file is named after its migration source file, e.g. `2026_03_16_d4b9da2f705c_add_users.sql`.
|
|
42
42
|
|
|
43
|
+
## Ignoring Squawk Errors
|
|
44
|
+
|
|
45
|
+
Squawk supports per-file ignore directives in SQL comments (e.g. `-- squawk-ignore-file ban-drop-column`). To attach these to a migration without embedding raw SQL comments in Python source, write the directive as a Python comment. The `--` prefix is optional.
|
|
46
|
+
|
|
47
|
+
**Note:** The comment must be at the very beginning of the line. Indented comments (e.g., inside a function) or inline comments (e.g., `op.execute("...") # squawk-disable`) are not supported and will be ignored.
|
|
48
|
+
|
|
49
|
+
For example, to hide a drop column error in your migration:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
"""add users table
|
|
53
|
+
|
|
54
|
+
Revision ID: 1a2b3c4d5e6f
|
|
55
|
+
Revises:
|
|
56
|
+
Create Date: 2026-03-16 10:22:01.123456
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
# squawk-ignore-file ban-drop-column
|
|
60
|
+
# -- squawk-disable require-concurrent-index-creation
|
|
61
|
+
|
|
62
|
+
from typing import Sequence, Union
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
from alembic import op
|
|
66
|
+
import sqlalchemy as sa
|
|
67
|
+
|
|
68
|
+
# ... migration code ...
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When `alembic-squawk` generates the SQL for this revision, it will prepend those directives as standard SQL comments at the top of the file so Squawk honors them.
|
|
72
|
+
|
|
43
73
|
## Example
|
|
44
74
|
|
|
75
|
+
Here is an end-to-end example of how you might integrate `alembic-squawk` into a CI script or standard shell workflow to lint your database migrations:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# generate per-revision SQL files
|
|
79
|
+
uv run alembic-squawk --out-dir /tmp/alembic-squawk-lint
|
|
80
|
+
|
|
81
|
+
# the generated SQL is not wrapped in a transaction, but the entire migration will be.
|
|
82
|
+
# note: we use --assume-in-transaction so squawk knows to lint appropriately.
|
|
83
|
+
squawk --assume-in-transaction --pg-version=15 /tmp/alembic-squawk-lint/*.sql
|
|
84
|
+
```
|
|
85
|
+
|
|
45
86
|
[iloveitaly/python-starter-template](https://github.com/iloveitaly/python-starter-template) is a full Python app with a working integration of `alembic-squawk`.
|
|
46
87
|
|
|
47
88
|
## [MIT License](LICENSE.md)
|
|
@@ -108,12 +108,13 @@ REVISION_ID_RE = re.compile(
|
|
|
108
108
|
# Captures the date portion only (YYYY-MM-DD).
|
|
109
109
|
CREATE_DATE_RE = re.compile(r"^Create Date: (\d{4}-\d{2}-\d{2})", re.MULTILINE)
|
|
110
110
|
|
|
111
|
-
# Matches squawk
|
|
111
|
+
# Matches squawk directives embedded as Python comments in migration
|
|
112
112
|
# source files, e.g.:
|
|
113
113
|
# # -- squawk-ignore-file ban-drop-column
|
|
114
|
+
# # squawk-disable require-concurrent-index-creation
|
|
114
115
|
# These are extracted and re-emitted as plain SQL comments in the generated
|
|
115
116
|
# output so Squawk honours them when linting the split files.
|
|
116
|
-
SQUAWK_IGNORE_RE = re.compile(r"^#\s*(
|
|
117
|
+
SQUAWK_IGNORE_RE = re.compile(r"^#\s*(?:--\s*)?(squawk-.*)", re.MULTILINE)
|
|
117
118
|
|
|
118
119
|
|
|
119
120
|
@dataclass
|
|
@@ -273,7 +274,7 @@ def write_chunks(
|
|
|
273
274
|
date_comment = (
|
|
274
275
|
f"-- Created at: {chunk.created_date}\n" if chunk.created_date else ""
|
|
275
276
|
)
|
|
276
|
-
ignore_comments = "".join(f"{d}\n" for d in chunk.squawk_ignores)
|
|
277
|
+
ignore_comments = "".join(f"-- {d}\n" for d in chunk.squawk_ignores)
|
|
277
278
|
chunk_content = date_comment + ignore_comments + "\n".join(chunk.lines) + "\n"
|
|
278
279
|
file_path.write_text(chunk_content, encoding="utf-8")
|
|
279
280
|
written_files.append(file_path)
|
|
File without changes
|
|
File without changes
|