squawk-cli 1.5.4__py3-none-manylinux_2_28_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
@@ -0,0 +1,295 @@
1
+ Metadata-Version: 2.3
2
+ Name: squawk-cli
3
+ Version: 1.5.4
4
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
5
+ Classifier: Operating System :: MacOS
6
+ Classifier: Operating System :: Microsoft :: Windows
7
+ Classifier: Operating System :: POSIX :: Linux
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Rust
10
+ Classifier: Programming Language :: Python :: Implementation :: CPython
11
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
12
+ Summary: Linter for PostgreSQL migrations
13
+ Keywords: postgres,postgresql,linter
14
+ Author: Steve Dignam <steve@dignam.xyz>
15
+ Author-email: Steve Dignam <steve@dignam.xyz>
16
+ License: GPL-3.0
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
19
+ Project-URL: Source Code, https://github.com/sbdchd/squawk
20
+
21
+ # squawk [![npm](https://img.shields.io/npm/v/squawk-cli)](https://www.npmjs.com/package/squawk-cli)
22
+
23
+ > linter for Postgres migrations
24
+
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)
26
+
27
+ ## Why?
28
+
29
+ Prevent unexpected downtime caused by database migrations and encourage best
30
+ practices around Postgres schemas and SQL.
31
+
32
+ Also it seemed like a nice project to spend more time with Rust.
33
+
34
+ ## Install
35
+
36
+ ```shell
37
+ npm install -g squawk-cli
38
+
39
+ # or via PYPI
40
+ pip install squawk-cli
41
+
42
+ # or install binaries directly via the releases page
43
+ https://github.com/sbdchd/squawk/releases
44
+ ```
45
+
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 | );
59
+
60
+ note: Changing the size of a varchar field requires an ACCESS EXCLUSIVE lock.
61
+ help: Use a text field with a check constraint.
62
+
63
+ example.sql:9:2: warning: require-concurrent-index-creation
64
+
65
+ 9 |
66
+ 10 | CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
67
+
68
+ note: Creating an index blocks writes.
69
+ note: Create the index CONCURRENTLY.
70
+
71
+ example.sql:11:2: warning: disallowed-unique-constraint
72
+
73
+ 11 |
74
+ 12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
75
+
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.
78
+ ```
79
+
80
+ ### `squawk --help`
81
+
82
+ ```
83
+ squawk
84
+ Find problems in your SQL
85
+
86
+ USAGE:
87
+ squawk [FLAGS] [OPTIONS] [path]... [SUBCOMMAND]
88
+
89
+ FLAGS:
90
+ --assume-in-transaction
91
+ Assume that a transaction will wrap each SQL file when run by a migration tool
92
+
93
+ Use --no-assume-in-transaction to override this setting in any config file that exists
94
+ -h, --help
95
+ Prints help information
96
+
97
+ --list-rules
98
+ List all available rules
99
+
100
+ -V, --version
101
+ Prints version information
102
+
103
+ --verbose
104
+ Enable debug logging output
105
+
106
+
107
+ OPTIONS:
108
+ -c, --config <config-path>
109
+ Path to the squawk config file (.squawk.toml)
110
+
111
+ --dump-ast <ast-format>
112
+ Output AST in JSON [possible values: Raw, Parsed, Debug]
113
+
114
+ --exclude-path <excluded-path>...
115
+ Paths to exclude
116
+
117
+ For example: --exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql
118
+
119
+ --exclude-path='*user_ids.sql'
120
+
121
+ -e, --exclude <rule>...
122
+ Exclude specific warnings
123
+
124
+ For example: --exclude=require-concurrent-index-creation,ban-drop-database
125
+ --explain <rule>
126
+ Provide documentation on the given rule
127
+
128
+ --pg-version <pg-version>
129
+ Specify postgres version
130
+
131
+ For example: --pg-version=13.0
132
+ --reporter <reporter>
133
+ Style of error reporting [possible values: Tty, Gcc, Json]
134
+
135
+ --stdin-filepath <filepath>
136
+ Path to use in reporting for stdin
137
+
138
+
139
+ ARGS:
140
+ <path>...
141
+ Paths to search
142
+
143
+
144
+ SUBCOMMANDS:
145
+ help Prints this message or the help of the given subcommand(s)
146
+ upload-to-github Comment on a PR with Squawk's results
147
+ ```
148
+
149
+ ## Rules
150
+
151
+ Individual rules can be disabled via the `--exclude` flag
152
+
153
+ ```shell
154
+ squawk --exclude=adding-field-with-default,disallowed-unique-constraint example.sql
155
+ ```
156
+
157
+ ### Configuration file
158
+
159
+ Rules can also be disabled with a configuration file.
160
+
161
+ By default, Squawk will traverse up from the current directory to find a `.squawk.toml` configuration file. You may specify a custom path with the `-c` or `--config` flag.
162
+
163
+ ```shell
164
+ squawk --config=~/.squawk.toml example.sql
165
+ ```
166
+
167
+ The `--exclude` flag will always be prioritized over the configuration file.
168
+
169
+ **Example `.squawk.toml`**
170
+
171
+ ```toml
172
+ excluded_rules = [
173
+ "require-concurrent-index-creation",
174
+ "require-concurrent-index-deletion",
175
+ ]
176
+ ```
177
+
178
+ See the [Squawk website](https://squawkhq.com/docs/rules) for documentation on each rule with examples and reasoning.
179
+
180
+ ## Bot Setup
181
+
182
+ Squawk works as a CLI tool but can also create comments on GitHub Pull
183
+ Requests using the `upload-to-github` subcommand.
184
+
185
+ Here's an example comment created by `squawk` using the `example.sql` in the repo:
186
+
187
+ <https://github.com/sbdchd/squawk/pull/14#issuecomment-647009446>
188
+
189
+ See the ["GitHub Integration" docs](https://squawkhq.com/docs/github_app) for more information.
190
+
191
+ ## `pre-commit` hook
192
+
193
+ Integrate Squawk into Git workflow with [pre-commit](https://pre-commit.com/). Add the following
194
+ to your project's `.pre-commit-config.yaml`:
195
+
196
+ ```
197
+ repos:
198
+ - repo: https://github.com/sbdchd/squawk
199
+ rev: v0.10.0
200
+ hooks:
201
+ - id: squawk
202
+ files: path/to/postres/migrations/written/in/sql
203
+ ```
204
+
205
+ Note the `files` parameter as it specifies the location of the files to be linted.
206
+
207
+ ## prior art
208
+
209
+ - <https://github.com/erik/squabble>
210
+
211
+ ### related tools
212
+
213
+ - <https://github.com/yandex/zero-downtime-migrations>
214
+ - <https://github.com/tbicr/django-pg-zero-downtime-migrations>
215
+ - <https://github.com/3YOURMIND/django-migration-linter>
216
+ - <https://github.com/ankane/strong_migrations>
217
+ - <https://github.com/AdmTal/PostgreSQL-Query-Lock-Explainer>
218
+ - <https://github.com/stripe/pg-schema-diff>
219
+ - <https://github.com/kristiandupont/schemalint>
220
+
221
+ ## related blog posts / SE Posts / PG Docs
222
+
223
+ - <https://www.braintreepayments.com/blog/safe-operations-for-high-volume-postgresql/>
224
+ - <https://gocardless.com/blog/zero-downtime-postgres-migrations-the-hard-parts/>
225
+ - <https://www.citusdata.com/blog/2018/02/22/seven-tips-for-dealing-with-postgres-locks/>
226
+ - <https://realpython.com/create-django-index-without-downtime/#non-atomic-migrations>
227
+ - <https://dba.stackexchange.com/questions/158499/postgres-how-is-set-not-null-more-efficient-than-check-constraint>
228
+ - <https://www.postgresql.org/docs/10/sql-altertable.html#SQL-ALTERTABLE-NOTES>
229
+ - <https://www.postgresql.org/docs/current/explicit-locking.html>
230
+ - <https://benchling.engineering/move-fast-and-migrate-things-how-we-automated-migrations-in-postgres-d60aba0fc3d4>
231
+ - <https://medium.com/paypal-tech/postgresql-at-scale-database-schema-changes-without-downtime-20d3749ed680>
232
+
233
+ ## dev
234
+
235
+ ```shell
236
+ cargo install
237
+ cargo run
238
+ ./s/test
239
+ ./s/lint
240
+ ./s/fmt
241
+ ```
242
+
243
+ ... or with nix:
244
+
245
+ ```
246
+ $ nix develop
247
+ [nix-shell]$ cargo run
248
+ [nix-shell]$ cargo insta review
249
+ [nix-shell]$ ./s/test
250
+ [nix-shell]$ ./s/lint
251
+ [nix-shell]$ ./s/fmt
252
+ ```
253
+
254
+ ### adding a new rule
255
+
256
+ When adding a new rule, the `s/new-rule` script will create stubs for your rule in Rust and in Documentation site.
257
+
258
+ ```bash
259
+ s/new-rule 'prefer big serial'
260
+ ```
261
+
262
+ ### releasing a new version
263
+
264
+ 1. update the CHANGELOG.md and bump version in the cli `Cargo.toml`, ensure the
265
+ lock file is updated, and update `package.json` and commit the changes
266
+
267
+ ```bash
268
+ # update version in Cargo.toml files and package.json to 4.5.3
269
+ s/update-version 4.5.3
270
+ ```
271
+
272
+ 2. create a new release on github - CI will attach the binaries automatically
273
+ 3. wait for build artifacts to be attached to release.
274
+ 4. login to `npm` and publish new version.
275
+
276
+ ```bash
277
+ npm login
278
+ npm publish
279
+ ```
280
+
281
+ ### algolia
282
+
283
+ 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).
284
+
285
+ ## how it works
286
+
287
+ squawk wraps calls to [libpg_query-sys](https://github.com/tdbgamer/libpg_query-sys) in a safe
288
+ interface and parses the JSON into easier to work with structures.
289
+ libpg_query-sys in turn uses [bindgen](https://rust-lang.github.io/rust-bindgen/) to bind to
290
+ [libpg_query](https://github.com/lfittl/libpg_query), which itself wraps Postgres' SQL
291
+ parser in a bit of C code that outputs the parsed AST into a JSON string.
292
+
293
+ Squawk then runs the rule functions over the parsed AST, gathers and pretty
294
+ prints the rule violations.
295
+
@@ -0,0 +1,4 @@
1
+ squawk_cli-1.5.4.dist-info/METADATA,sha256=uCTrmcOqcjfgux20y6x7P_bzlxvhUVJl6zOrlZtqzmY,8895
2
+ squawk_cli-1.5.4.dist-info/WHEEL,sha256=HEiZG98WwLJCHM9RszH8IKENRYcsqlTjHFhLljYzc0Q,105
3
+ squawk_cli-1.5.4.data/scripts/squawk,sha256=hDALmfNsWuLQVsxAJPh3NYZZ0ABuhR6YzaHst7fn1l8,11384968
4
+ squawk_cli-1.5.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.1)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-manylinux_2_28_x86_64