squabble
v1.4.0
捕獲不安全的SQL遷移。
$ squabble sql/migration.sql
sql/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 1004
ConstraintNotAllowed
When adding a column to an existing table, certain constraints can have
unintentional side effects, like locking the table or introducing
performance issues.
...爭吵也可以與您的編輯器集成在一起,以在SQL文件中捕獲錯誤。
$ echo ' SELECT * FROM WHERE x = y; ' | squabble --reporter=plain
stdin:1:15 CRITICAL: syntax error at or near "WHERE"當前,大多數規則都集中在Postgres及其怪癖上。但是,爭吵可以解析任何ANSI SQL,並感謝其他數據庫的新規則!
$ pip3 install squabble
$ squabble --help筆記
只有在python 3.5+上支持爭吵
如果您想從來源安裝:
$ git clone https://github.com/erik/squabble.git && cd squabble
$ python3 -m venv ve && source ve/bin/activate
$ python setup.py install
$ squabble --help 要查看規則列表,請嘗試
$ squabble --list-rules然後,要顯示有關規則的更多詳細信息(例如理由和配置選項)
$ squabble --show-rule AddColumnDisallowConstraints配置文件到位後,可以在命令行上明確傳遞或自動查找。
$ squabble -c path/to/config ...如果在命令行上沒有明確給出,則挑剔會在以下位置(按順序)尋找名為.squabblerc的文件:
./.squabblerc(git_repo_root)/.squabblerc~/.squabblerc還可以通過使用表格中的SQL線註釋來應用配置-- squabble-enable:RuleName或-- squabble-disable:RuleName 。
例如,為了禁用RuleA並僅適用於一個RuleB ,可以做到這一點:
-- squabble-disable:RuleA
-- squabble-enable:RuleB config=value array=1,2,3
SELECT email FROM users WHERE ...;為防止爭吵在文件上運行,請使用-- squabble-disable 。請注意,這也將禁用語法檢查。請注意,此標誌將優先於命令行或文件其餘部分上的任何其他配置。
{
"reporter" : " color " ,
"plugins" : [
" /some/directory/with/custom/rules "
],
"rules" : {
"AddColumnsDisallowConstraints" : {
"disallowed" : [ " DEFAULT " , " FOREIGN " , " NOT NULL " ]
}
}
}當然, squabble不是這個空間中的第一個工具。如果它不符合您的需求,請考慮以下工具之一:
SELECT而不是遷移的陳述。沒有以下項目是不可能的:
文檔中使用的徽標圖像由名詞項目的Gianni -Dolce Merda創建。