squawk-cli 1.6.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: squawk-cli
3
- Version: 1.6.0
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: Steve Dignam <steve@dignam.xyz>
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 [![npm](https://img.shields.io/npm/v/squawk-cli)](https://www.npmjs.com/package/squawk-cli)
22
21
 
23
- > linter for Postgres migrations
22
+ > Linter for Postgres migrations & SQL
24
23
 
25
- [quick start](https://squawkhq.com/docs/) | [rules documentation](https://squawkhq.com/docs/rules) | [github action](https://github.com/sbdchd/squawk-action) | [diy github integration](https://squawkhq.com/docs/github_app)
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
- ## Usage
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
- note: Changing the size of a varchar field requires an ACCESS EXCLUSIVE lock.
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
- example.sql:9:2: warning: require-concurrent-index-creation
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
- 9 |
66
- 10 | CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
52
+ ### Or via the Playground
67
53
 
68
- note: Creating an index blocks writes.
69
- note: Create the index CONCURRENTLY.
54
+ Use the WASM powered playground to check your SQL locally in the browser!
70
55
 
71
- example.sql:11:2: warning: disallowed-unique-constraint
56
+ <https://play.squawkhq.com>
72
57
 
73
- 11 |
74
- 12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
58
+ ## Usage
75
59
 
76
- note: Adding a UNIQUE constraint requires an ACCESS EXCLUSIVE lock which blocks reads.
77
- help: Create an index CONCURRENTLY and create the constraint using the index.
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
- --dump-ast <ast-format>
112
- Output AST in JSON [possible values: Raw, Parsed, Debug]
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
- ## prior art
247
+ ## Prior Art
208
248
 
209
249
  - <https://github.com/erik/squabble>
210
250
 
211
- ### related tools
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
- ## related blog posts / SE Posts / PG Docs
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
- ## dev
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
- ### adding a new rule
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,37 +301,30 @@ 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
- ### releasing a new version
304
+ ### Releasing a New Version
305
+
306
+ 1. Update the `CHANGELOG.md`
307
+
308
+ Include a description of any fixes / additions. Make sure to include the PR numbers and credit the authors.
264
309
 
265
- 1. update the CHANGELOG.md and bump version in the cli `Cargo.toml`, ensure the
266
- lock file is updated, and update `package.json` and commit the changes
310
+ 2. Run `s/update-version`
267
311
 
268
312
  ```bash
269
- # update version in Cargo.toml files and package.json to 4.5.3
313
+ # update version in cli/Cargo.toml, package.json, flake.nix to 4.5.3
270
314
  s/update-version 4.5.3
271
315
  ```
272
316
 
273
- 2. create a new release on github - CI will attach the binaries automatically
274
- 3. wait for build artifacts to be attached to release.
275
- 4. login to `npm` and publish new version.
317
+ 3. Create a new release on GitHub
276
318
 
277
- ```bash
278
- npm login
279
- npm publish
280
- ```
319
+ Use the text and version from the `CHANGELOG.md`
281
320
 
282
- ### algolia
321
+ ### Algolia
283
322
 
284
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).
285
324
 
286
- ## how it works
287
-
288
- squawk wraps calls to [libpg_query-sys](https://github.com/tdbgamer/libpg_query-sys) in a safe
289
- interface and parses the JSON into easier to work with structures.
290
- libpg_query-sys in turn uses [bindgen](https://rust-lang.github.io/rust-bindgen/) to bind to
291
- [libpg_query](https://github.com/lfittl/libpg_query), which itself wraps Postgres' SQL
292
- parser in a bit of C code that outputs the parsed AST into a JSON string.
325
+ ## How it Works
293
326
 
294
- Squawk then runs the rule functions over the parsed AST, gathers and pretty
295
- prints the rule violations.
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!
296
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.0.dist-info/METADATA,sha256=HRi5ixTmllerjvbNYHaflWa0dmWrZs1PtaMtS-AQL6Q,8969
2
- squawk_cli-1.6.0.dist-info/WHEEL,sha256=iynIFuruP98iAQ_vbgENee_L7CnfkfNjTMl4i53tE2Q,103
3
- squawk_cli-1.6.0.data/scripts/squawk,sha256=fmdIWVGapk_rM4nxc6IPbo5t1mKcBhJKm8QH12qsk2Y,7779260
4
- squawk_cli-1.6.0.dist-info/RECORD,,