squawk-cli 1.6.1__py3-none-macosx_10_12_x86_64.whl → 2.0.0__py3-none-macosx_10_12_x86_64.whl
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.
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: squawk-cli
|
3
|
-
Version:
|
3
|
+
Version: 2.0.0
|
4
4
|
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
5
5
|
Classifier: Operating System :: MacOS
|
6
6
|
Classifier: Operating System :: Microsoft :: Windows
|
@@ -11,8 +11,7 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
11
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
12
12
|
Summary: Linter for PostgreSQL migrations
|
13
13
|
Keywords: postgres,postgresql,linter
|
14
|
-
Author:
|
15
|
-
Author-email: Steve Dignam <steve@dignam.xyz>
|
14
|
+
Author: Squawk Team & Contributors
|
16
15
|
License: GPL-3.0
|
17
16
|
Requires-Python: >=3.8
|
18
17
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
@@ -20,17 +19,15 @@ Project-URL: Source Code, https://github.com/sbdchd/squawk
|
|
20
19
|
|
21
20
|
# squawk [](https://www.npmjs.com/package/squawk-cli)
|
22
21
|
|
23
|
-
>
|
22
|
+
> Linter for Postgres migrations & SQL
|
24
23
|
|
25
|
-
[
|
24
|
+
[Quick Start](https://squawkhq.com/docs/) | [Playground](https://play.squawkhq.com) | [Rules Documentation](https://squawkhq.com/docs/rules) | [GitHub Action](https://github.com/sbdchd/squawk-action) | [DIY GitHub Integration](https://squawkhq.com/docs/github_app)
|
26
25
|
|
27
26
|
## Why?
|
28
27
|
|
29
28
|
Prevent unexpected downtime caused by database migrations and encourage best
|
30
29
|
practices around Postgres schemas and SQL.
|
31
30
|
|
32
|
-
Also it seemed like a nice project to spend more time with Rust.
|
33
|
-
|
34
31
|
## Install
|
35
32
|
|
36
33
|
```shell
|
@@ -43,38 +40,70 @@ pip install squawk-cli
|
|
43
40
|
https://github.com/sbdchd/squawk/releases
|
44
41
|
```
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
```shell
|
49
|
-
❯ squawk example.sql
|
50
|
-
example.sql:2:1: warning: prefer-text-field
|
51
|
-
|
52
|
-
2 | --
|
53
|
-
3 | -- Create model Bar
|
54
|
-
4 | --
|
55
|
-
5 | CREATE TABLE "core_bar" (
|
56
|
-
6 | "id" serial NOT NULL PRIMARY KEY,
|
57
|
-
7 | "alpha" varchar(100) NOT NULL
|
58
|
-
8 | );
|
43
|
+
### Or via Docker
|
59
44
|
|
60
|
-
|
61
|
-
help: Use a text field with a check constraint.
|
45
|
+
You can also run Squawk using Docker. The official image is available on GitHub Container Registry.
|
62
46
|
|
63
|
-
|
47
|
+
```shell
|
48
|
+
# Assuming you want to check sql files in the current directory
|
49
|
+
docker run --rm -v $(pwd):/data ghcr.io/sbdchd/squawk:latest *.sql
|
50
|
+
```
|
64
51
|
|
65
|
-
|
66
|
-
10 | CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
|
52
|
+
### Or via the Playground
|
67
53
|
|
68
|
-
|
69
|
-
note: Create the index CONCURRENTLY.
|
54
|
+
Use the WASM powered playground to check your SQL locally in the browser!
|
70
55
|
|
71
|
-
|
56
|
+
<https://play.squawkhq.com>
|
72
57
|
|
73
|
-
|
74
|
-
12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
|
58
|
+
## Usage
|
75
59
|
|
76
|
-
|
77
|
-
|
60
|
+
```shell
|
61
|
+
❯ squawk example.sql
|
62
|
+
warning[prefer-bigint-over-int]: Using 32-bit integer fields can result in hitting the max `int` limit.
|
63
|
+
--> example.sql:6:10
|
64
|
+
|
|
65
|
+
6 | "id" serial NOT NULL PRIMARY KEY,
|
66
|
+
| ^^^^^^
|
67
|
+
|
|
68
|
+
= help: Use 64-bit integer values instead to prevent hitting this limit.
|
69
|
+
warning[prefer-identity]: Serial types make schema, dependency, and permission management difficult.
|
70
|
+
--> example.sql:6:10
|
71
|
+
|
|
72
|
+
6 | "id" serial NOT NULL PRIMARY KEY,
|
73
|
+
| ^^^^^^
|
74
|
+
|
|
75
|
+
= help: Use Identity columns instead.
|
76
|
+
warning[prefer-text-field]: Changing the size of a `varchar` field requires an `ACCESS EXCLUSIVE` lock, that will prevent all reads and writes to the table.
|
77
|
+
--> example.sql:7:13
|
78
|
+
|
|
79
|
+
7 | "alpha" varchar(100) NOT NULL
|
80
|
+
| ^^^^^^^^^^^^
|
81
|
+
|
|
82
|
+
= help: Use a `TEXT` field with a `CHECK` constraint.
|
83
|
+
warning[require-concurrent-index-creation]: During normal index creation, table updates are blocked, but reads are still allowed.
|
84
|
+
--> example.sql:10:1
|
85
|
+
|
|
86
|
+
10 | CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
|
87
|
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
88
|
+
|
|
89
|
+
= help: Use `CONCURRENTLY` to avoid blocking writes.
|
90
|
+
warning[constraint-missing-not-valid]: By default new constraints require a table scan and block writes to the table while that scan occurs.
|
91
|
+
--> example.sql:12:24
|
92
|
+
|
|
93
|
+
12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
|
94
|
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
95
|
+
|
|
96
|
+
= help: Use `NOT VALID` with a later `VALIDATE CONSTRAINT` call.
|
97
|
+
warning[disallowed-unique-constraint]: Adding a `UNIQUE` constraint requires an `ACCESS EXCLUSIVE` lock which blocks reads and writes to the table while the index is built.
|
98
|
+
--> example.sql:12:28
|
99
|
+
|
|
100
|
+
12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
|
101
|
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
102
|
+
|
|
103
|
+
= help: Create an index `CONCURRENTLY` and create the constraint using the index.
|
104
|
+
|
105
|
+
Find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules
|
106
|
+
Found 7 issues in 1 file (checked 1 source file)
|
78
107
|
```
|
79
108
|
|
80
109
|
### `squawk --help`
|
@@ -94,9 +123,6 @@ FLAGS:
|
|
94
123
|
-h, --help
|
95
124
|
Prints help information
|
96
125
|
|
97
|
-
--list-rules
|
98
|
-
List all available rules
|
99
|
-
|
100
126
|
-V, --version
|
101
127
|
Prints version information
|
102
128
|
|
@@ -108,8 +134,8 @@ OPTIONS:
|
|
108
134
|
-c, --config <config-path>
|
109
135
|
Path to the squawk config file (.squawk.toml)
|
110
136
|
|
111
|
-
--
|
112
|
-
Output
|
137
|
+
--debug <format>
|
138
|
+
Output debug info [possible values: Lex, Parse]
|
113
139
|
|
114
140
|
--exclude-path <excluded-path>...
|
115
141
|
Paths to exclude
|
@@ -122,8 +148,6 @@ OPTIONS:
|
|
122
148
|
Exclude specific warnings
|
123
149
|
|
124
150
|
For example: --exclude=require-concurrent-index-creation,ban-drop-database
|
125
|
-
--explain <rule>
|
126
|
-
Provide documentation on the given rule
|
127
151
|
|
128
152
|
--pg-version <pg-version>
|
129
153
|
Specify postgres version
|
@@ -154,6 +178,22 @@ Individual rules can be disabled via the `--exclude` flag
|
|
154
178
|
squawk --exclude=adding-field-with-default,disallowed-unique-constraint example.sql
|
155
179
|
```
|
156
180
|
|
181
|
+
### Disabling rules via comments
|
182
|
+
|
183
|
+
Rule violations can be ignored via the `squawk-ignore` comment:
|
184
|
+
|
185
|
+
```sql
|
186
|
+
-- squawk-ignore ban-drop-column
|
187
|
+
alter table t drop column c cascade;
|
188
|
+
```
|
189
|
+
|
190
|
+
You can also ignore multiple rules by making a comma seperated list:
|
191
|
+
|
192
|
+
```sql
|
193
|
+
-- squawk-ignore ban-drop-column, renaming-column,ban-drop-database
|
194
|
+
alter table t drop column c cascade;
|
195
|
+
```
|
196
|
+
|
157
197
|
### Configuration file
|
158
198
|
|
159
199
|
Rules can also be disabled with a configuration file.
|
@@ -204,11 +244,11 @@ repos:
|
|
204
244
|
|
205
245
|
Note the `files` parameter as it specifies the location of the files to be linted.
|
206
246
|
|
207
|
-
##
|
247
|
+
## Prior Art
|
208
248
|
|
209
249
|
- <https://github.com/erik/squabble>
|
210
250
|
|
211
|
-
###
|
251
|
+
### Related Tools
|
212
252
|
|
213
253
|
- <https://github.com/yandex/zero-downtime-migrations>
|
214
254
|
- <https://github.com/tbicr/django-pg-zero-downtime-migrations>
|
@@ -218,8 +258,9 @@ Note the `files` parameter as it specifies the location of the files to be linte
|
|
218
258
|
- <https://github.com/stripe/pg-schema-diff>
|
219
259
|
- <https://github.com/kristiandupont/schemalint>
|
220
260
|
- <https://github.com/supabase-community/postgres-language-server>
|
261
|
+
- <https://github.com/premium-minds/sonar-postgres-plugin>
|
221
262
|
|
222
|
-
##
|
263
|
+
## Related Blog Posts / SE Posts / PG Docs
|
223
264
|
|
224
265
|
- <https://www.braintreepayments.com/blog/safe-operations-for-high-volume-postgresql/>
|
225
266
|
- <https://gocardless.com/blog/zero-downtime-postgres-migrations-the-hard-parts/>
|
@@ -231,7 +272,7 @@ Note the `files` parameter as it specifies the location of the files to be linte
|
|
231
272
|
- <https://benchling.engineering/move-fast-and-migrate-things-how-we-automated-migrations-in-postgres-d60aba0fc3d4>
|
232
273
|
- <https://medium.com/paypal-tech/postgresql-at-scale-database-schema-changes-without-downtime-20d3749ed680>
|
233
274
|
|
234
|
-
##
|
275
|
+
## Dev
|
235
276
|
|
236
277
|
```shell
|
237
278
|
cargo install
|
@@ -252,7 +293,7 @@ $ nix develop
|
|
252
293
|
[nix-shell]$ ./s/fmt
|
253
294
|
```
|
254
295
|
|
255
|
-
###
|
296
|
+
### Adding a New Rule
|
256
297
|
|
257
298
|
When adding a new rule, the `s/new-rule` script will create stubs for your rule in Rust and in Documentation site.
|
258
299
|
|
@@ -260,7 +301,7 @@ When adding a new rule, the `s/new-rule` script will create stubs for your rule
|
|
260
301
|
s/new-rule 'prefer big serial'
|
261
302
|
```
|
262
303
|
|
263
|
-
###
|
304
|
+
### Releasing a New Version
|
264
305
|
|
265
306
|
1. Update the `CHANGELOG.md`
|
266
307
|
|
@@ -277,18 +318,13 @@ s/new-rule 'prefer big serial'
|
|
277
318
|
|
278
319
|
Use the text and version from the `CHANGELOG.md`
|
279
320
|
|
280
|
-
###
|
321
|
+
### Algolia
|
281
322
|
|
282
323
|
The squawkhq.com Algolia index can be found on [the crawler website](https://crawler.algolia.com/admin/crawlers/9bf0dffb-bc5a-4d46-9b8d-2f1197285213/overview). Algolia reindexes the site every day at 5:30 (UTC).
|
283
324
|
|
284
|
-
##
|
285
|
-
|
286
|
-
squawk wraps calls to [libpg_query-sys](https://github.com/tdbgamer/libpg_query-sys) in a safe
|
287
|
-
interface and parses the JSON into easier to work with structures.
|
288
|
-
libpg_query-sys in turn uses [bindgen](https://rust-lang.github.io/rust-bindgen/) to bind to
|
289
|
-
[libpg_query](https://github.com/lfittl/libpg_query), which itself wraps Postgres' SQL
|
290
|
-
parser in a bit of C code that outputs the parsed AST into a JSON string.
|
325
|
+
## How it Works
|
291
326
|
|
292
|
-
Squawk
|
293
|
-
|
327
|
+
Squawk uses its parser (based on rust-analyzer's parser) to create a CST. The
|
328
|
+
linters then use an AST layered on top of the CST to navigate and record
|
329
|
+
warnings, which are then pretty printed!
|
294
330
|
|
@@ -0,0 +1,4 @@
|
|
1
|
+
squawk_cli-2.0.0.dist-info/METADATA,sha256=SdjUfQKCoaw3Id-MQM-9qYO4YbrcvFuqRtWalfl0_i0,10411
|
2
|
+
squawk_cli-2.0.0.dist-info/WHEEL,sha256=iynIFuruP98iAQ_vbgENee_L7CnfkfNjTMl4i53tE2Q,103
|
3
|
+
squawk_cli-2.0.0.data/scripts/squawk,sha256=9K4hkLSpRwrqGmUy1ZEZZVpF5oE7xUSOF0ctIxADnd0,6916428
|
4
|
+
squawk_cli-2.0.0.dist-info/RECORD,,
|
@@ -1,4 +0,0 @@
|
|
1
|
-
squawk_cli-1.6.1.dist-info/METADATA,sha256=nyHE6hIEDeD4cfj-1CEKm1oIbuWhFr5-0FGPlUakjSM,8853
|
2
|
-
squawk_cli-1.6.1.dist-info/WHEEL,sha256=iynIFuruP98iAQ_vbgENee_L7CnfkfNjTMl4i53tE2Q,103
|
3
|
-
squawk_cli-1.6.1.data/scripts/squawk,sha256=84XAsr8C8c456aZrwjKzkmcWNPXCdSkH_cSEyB9QvWs,7779524
|
4
|
-
squawk_cli-1.6.1.dist-info/RECORD,,
|
File without changes
|