-
Notifications
You must be signed in to change notification settings - Fork 70
Make prefer-robust-stmts aware of alembic version update transactions #1311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kodiakhq
merged 4 commits into
sbdchd:master
from
DylanGriffith:DylanGriffith/better-alembic-transaction-detection
Aug 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eea2049
Make prefer-robust-stmts aware of alembic version update transactions
DylanGriffith 6f2e1c9
Dont delete comments
DylanGriffith 6ade42a
Only check is_alembic_version_update once
DylanGriffith ed5fc8e
Merge branch 'master' into DylanGriffith/better-alembic-transaction-d…
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...er__rules__prefer_robust_stmts__test__alembic_add_column_in_separate_transaction_err.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| source: crates/squawk_linter/src/rules/prefer_robust_stmts.rs | ||
| expression: lint_errors(sql) | ||
| --- | ||
| warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through. | ||
| ╭▸ | ||
| 3 │ ALTER TABLE t ADD COLUMN test_column TEXT; | ||
| │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| ╭╴ | ||
| 3 │ ALTER TABLE t ADD COLUMN if not exists test_column TEXT; | ||
| ╰╴ +++++++++++++ |
13 changes: 13 additions & 0 deletions
13
...__rules__prefer_robust_stmts__test__alembic_create_index_in_separate_transaction_err.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| source: crates/squawk_linter/src/rules/prefer_robust_stmts.rs | ||
| expression: lint_errors(sql) | ||
| --- | ||
| warning[prefer-robust-stmts]: Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through. | ||
| ╭▸ | ||
| 3 │ CREATE INDEX foo_idx ON bar (baz); | ||
| │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
| │ | ||
| ├ help: Use an explicit name for a concurrently created index | ||
| ╭╴ | ||
| 3 │ CREATE INDEX if not exists foo_idx ON bar (baz); | ||
| ╰╴ +++++++++++++ |
11 changes: 11 additions & 0 deletions
11
...er__rules__prefer_robust_stmts__test__alembic_drop_table_in_separate_transaction_err.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| source: crates/squawk_linter/src/rules/prefer_robust_stmts.rs | ||
| expression: lint_errors(sql) | ||
| --- | ||
| warning[prefer-robust-stmts]: Missing `IF EXISTS`, the migration can't be rerun if it fails part way through. | ||
| ╭▸ | ||
| 3 │ DROP TABLE old_table; | ||
| │ ━━━━━━━━━━━━━━━━━━━━━ | ||
| ╭╴ | ||
| 3 │ DROP TABLE if exists old_table; | ||
| ╰╴ +++++++++ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if we can avoid this search by keeping track of the alembic_version_updates when we look through on line 26?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I code-golfed it down a little to only check it once now. I'm not totally sure it's more readable but the logic is the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it wasn't so easy to change it exactly the way you suggested because I would have had to keep a list of indexes in that line and then loop over them and see if any were inside this range and it seemed a little more awkward than this approach.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh gotcha, thanks for the PR :D