Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An extensible linter for SQL queries and migrations.

License

NotificationsYou must be signed in to change notification settings

erik/squabble

Repository files navigation

build statusDocumentation StatusPyPI version

Catch unsafe SQL migrations.

$squabble sql/migration.sqlsql/migration.sql:4:46 ERROR: column "uh_oh" has a disallowed constraint [1004]ALTER TABLE big_table ADD COLUMN uh_oh integer DEFAULT 0;                                               ^#Use --explain to get more information on a lint violation$squabble --explain 1004ConstraintNotAllowed     When adding a column to an existing table, certain constraints can have     unintentional side effects, like locking the table or introducing     performance issues.     ...

Squabble can also beintegrated with your editor to catch errors inSQL files.

$echo'SELECT * FROM WHERE x = y;'| squabble --reporter=plainstdin:1:15 CRITICAL: syntax error at or near "WHERE"

Currently, most of the rules have been focused on Postgres and itsquirks. However, squabble can parse any ANSI SQL and new rules that arespecific to other databases are appreciated!

Installation

$pip3 install squabble$squabble --help

Note

Squabble is only supported on Python 3.5+

If you’d like to install from source:

$git clone https://github.com/erik/squabble.git&&cd squabble$python3 -m venv ve&&source ve/bin/activate$python setup.py install$squabble --help

Configuration

To see a list of rules, try

$squabble --list-rules

Then, to show more verbose information about a rule (such as rationaleand configuration options)

$squabble --show-rule AddColumnDisallowConstraints

Once a configuration file is in place, it can be passed explicitly onthe command line, or automatically looked up.

$squabble -c path/to/config ...

If not explicitly given on the command line, squabble will look for afile named.squabblerc in the following places (in order):

  • ./.squabblerc
  • (git_repo_root)/.squabblerc
  • ~/.squabblerc

Per-File Configuration

Configuration can also be applied at the file level by using SQL line commentsin the form-- squabble-enable:RuleName or-- squabble-disable:RuleName.

For example, to disableRuleA and enableRuleB just for one file,this could be done:

-- squabble-disable:RuleA-- squabble-enable:RuleB config=value array=1,2,3SELECT emailFROM usersWHERE ...;

To prevent squabble from running on a file, use-- squabble-disable. Notethat this will also disable syntax checking. Note that this flag will takeprecedence over any other configuration set either on the command line or inthe rest of the file.

Example Configuration

{"reporter":"color","plugins": ["/some/directory/with/custom/rules"  ],"rules": {"AddColumnsDisallowConstraints": {"disallowed": ["DEFAULT","FOREIGN","NOT NULL"]    }  }}

Prior Art

squabble is of course not the first tool in this space. If itdoesn't fit your needs, consider one of these tools:

  • sqlcheck - regularexpression based (rather than parsing), focuses more onSELECTstatements than migrations.
  • sqlint - checks that thesyntax of a file is valid. Uses the same parsing library assquabble.
  • sqlfluff -focused more on style and formatting, seems to still be a work inprogress.

Acknowledgments

This project would not be possible without:

  • libpg_query - Postgresquery parser
  • pglast - Python bindings tolibpg_query
  • Postgres - …obviously

Thelogo image usedin the documentation is created by Gianni - Dolce Merda from the NounProject.

About

An extensible linter for SQL queries and migrations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp