squawk-cli 1.2.0__py3-none-win32.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,296 @@
1
+ Metadata-Version: 2.3
2
+ Name: squawk-cli
3
+ Version: 1.2.0
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
+ Note: due to `squawk`'s dependency on
37
+ [`libpg_query`](https://github.com/lfittl/libpg_query/issues/44), `squawk`
38
+ supports Linux, macOS and Windows
39
+
40
+ ```shell
41
+ npm install -g squawk-cli
42
+
43
+ # or install binaries directly via the releases page
44
+ https://github.com/sbdchd/squawk/releases
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ```shell
50
+ ❯ squawk example.sql
51
+ example.sql:2:1: warning: prefer-text-field
52
+
53
+ 2 | --
54
+ 3 | -- Create model Bar
55
+ 4 | --
56
+ 5 | CREATE TABLE "core_bar" (
57
+ 6 | "id" serial NOT NULL PRIMARY KEY,
58
+ 7 | "alpha" varchar(100) NOT NULL
59
+ 8 | );
60
+
61
+ note: Changing the size of a varchar field requires an ACCESS EXCLUSIVE lock.
62
+ help: Use a text field with a check constraint.
63
+
64
+ example.sql:9:2: warning: require-concurrent-index-creation
65
+
66
+ 9 |
67
+ 10 | CREATE INDEX "field_name_idx" ON "table_name" ("field_name");
68
+
69
+ note: Creating an index blocks writes.
70
+ note: Create the index CONCURRENTLY.
71
+
72
+ example.sql:11:2: warning: disallowed-unique-constraint
73
+
74
+ 11 |
75
+ 12 | ALTER TABLE table_name ADD CONSTRAINT field_name_constraint UNIQUE (field_name);
76
+
77
+ note: Adding a UNIQUE constraint requires an ACCESS EXCLUSIVE lock which blocks reads.
78
+ help: Create an index CONCURRENTLY and create the constraint using the index.
79
+ ```
80
+
81
+ ### `squawk --help`
82
+
83
+ ```
84
+ squawk
85
+ Find problems in your SQL
86
+
87
+ USAGE:
88
+ squawk [FLAGS] [OPTIONS] [path]... [SUBCOMMAND]
89
+
90
+ FLAGS:
91
+ --assume-in-transaction
92
+ Assume that a transaction will wrap each SQL file when run by a migration tool
93
+
94
+ Use --no-assume-in-transaction to override this setting in any config file that exists
95
+ -h, --help
96
+ Prints help information
97
+
98
+ --list-rules
99
+ List all available rules
100
+
101
+ -V, --version
102
+ Prints version information
103
+
104
+ --verbose
105
+ Enable debug logging output
106
+
107
+
108
+ OPTIONS:
109
+ -c, --config <config-path>
110
+ Path to the squawk config file (.squawk.toml)
111
+
112
+ --dump-ast <ast-format>
113
+ Output AST in JSON [possible values: Raw, Parsed, Debug]
114
+
115
+ --exclude-path <excluded-path>...
116
+ Paths to exclude
117
+
118
+ For example: --exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql
119
+
120
+ --exclude-path='*user_ids.sql'
121
+
122
+ -e, --exclude <rule>...
123
+ Exclude specific warnings
124
+
125
+ For example: --exclude=require-concurrent-index-creation,ban-drop-database
126
+ --explain <rule>
127
+ Provide documentation on the given rule
128
+
129
+ --pg-version <pg-version>
130
+ Specify postgres version
131
+
132
+ For example: --pg-version=13.0
133
+ --reporter <reporter>
134
+ Style of error reporting [possible values: Tty, Gcc, Json]
135
+
136
+ --stdin-filepath <filepath>
137
+ Path to use in reporting for stdin
138
+
139
+
140
+ ARGS:
141
+ <path>...
142
+ Paths to search
143
+
144
+
145
+ SUBCOMMANDS:
146
+ help Prints this message or the help of the given subcommand(s)
147
+ upload-to-github Comment on a PR with Squawk's results
148
+ ```
149
+
150
+ ## Rules
151
+
152
+ Individual rules can be disabled via the `--exclude` flag
153
+
154
+ ```shell
155
+ squawk --exclude=adding-field-with-default,disallowed-unique-constraint example.sql
156
+ ```
157
+
158
+ ### Configuration file
159
+
160
+ Rules can also be disabled with a configuration file.
161
+
162
+ 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.
163
+
164
+ ```shell
165
+ squawk --config=~/.squawk.toml example.sql
166
+ ```
167
+
168
+ The `--exclude` flag will always be prioritized over the configuration file.
169
+
170
+ **Example `.squawk.toml`**
171
+
172
+ ```toml
173
+ excluded_rules = [
174
+ "require-concurrent-index-creation",
175
+ "require-concurrent-index-deletion",
176
+ ]
177
+ ```
178
+
179
+ See the [Squawk website](https://squawkhq.com/docs/rules) for documentation on each rule with examples and reasoning.
180
+
181
+ ## Bot Setup
182
+
183
+ Squawk works as a CLI tool but can also create comments on GitHub Pull
184
+ Requests using the `upload-to-github` subcommand.
185
+
186
+ Here's an example comment created by `squawk` using the `example.sql` in the repo:
187
+
188
+ <https://github.com/sbdchd/squawk/pull/14#issuecomment-647009446>
189
+
190
+ See the ["GitHub Integration" docs](https://squawkhq.com/docs/github_app) for more information.
191
+
192
+ ## `pre-commit` hook
193
+
194
+ Integrate Squawk into Git workflow with [pre-commit](https://pre-commit.com/). Add the following
195
+ to your project's `.pre-commit-config.yaml`:
196
+
197
+ ```
198
+ repos:
199
+ - repo: https://github.com/sbdchd/squawk
200
+ rev: v0.10.0
201
+ hooks:
202
+ - id: squawk
203
+ files: path/to/postres/migrations/written/in/sql
204
+ ```
205
+
206
+ Note the `files` parameter as it specifies the location of the files to be linted.
207
+
208
+ ## prior art
209
+
210
+ - <https://github.com/erik/squabble>
211
+
212
+ ### related tools
213
+
214
+ - <https://github.com/yandex/zero-downtime-migrations>
215
+ - <https://github.com/tbicr/django-pg-zero-downtime-migrations>
216
+ - <https://github.com/3YOURMIND/django-migration-linter>
217
+ - <https://github.com/ankane/strong_migrations>
218
+ - <https://github.com/AdmTal/PostgreSQL-Query-Lock-Explainer>
219
+ - <https://github.com/stripe/pg-schema-diff>
220
+ - <https://github.com/kristiandupont/schemalint>
221
+
222
+ ## related blog posts / SE Posts / PG Docs
223
+
224
+ - <https://www.braintreepayments.com/blog/safe-operations-for-high-volume-postgresql/>
225
+ - <https://gocardless.com/blog/zero-downtime-postgres-migrations-the-hard-parts/>
226
+ - <https://www.citusdata.com/blog/2018/02/22/seven-tips-for-dealing-with-postgres-locks/>
227
+ - <https://realpython.com/create-django-index-without-downtime/#non-atomic-migrations>
228
+ - <https://dba.stackexchange.com/questions/158499/postgres-how-is-set-not-null-more-efficient-than-check-constraint>
229
+ - <https://www.postgresql.org/docs/10/sql-altertable.html#SQL-ALTERTABLE-NOTES>
230
+ - <https://www.postgresql.org/docs/current/explicit-locking.html>
231
+ - <https://benchling.engineering/move-fast-and-migrate-things-how-we-automated-migrations-in-postgres-d60aba0fc3d4>
232
+ - <https://medium.com/paypal-tech/postgresql-at-scale-database-schema-changes-without-downtime-20d3749ed680>
233
+
234
+ ## dev
235
+
236
+ ```shell
237
+ cargo install
238
+ cargo run
239
+ ./s/test
240
+ ./s/lint
241
+ ./s/fmt
242
+ ```
243
+
244
+ ... or with nix:
245
+
246
+ ```
247
+ $ nix develop
248
+ [nix-shell]$ cargo run
249
+ [nix-shell]$ cargo insta review
250
+ [nix-shell]$ ./s/test
251
+ [nix-shell]$ ./s/lint
252
+ [nix-shell]$ ./s/fmt
253
+ ```
254
+
255
+ ### adding a new rule
256
+
257
+ When adding a new rule, the `s/new-rule` script will create stubs for your rule in Rust and in Documentation site.
258
+
259
+ ```bash
260
+ s/new-rule 'prefer big serial'
261
+ ```
262
+
263
+ ### releasing a new version
264
+
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
267
+
268
+ ```bash
269
+ # update version in Cargo.toml files and package.json to 4.5.3
270
+ s/update-version 4.5.3
271
+ ```
272
+
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.
276
+
277
+ ```bash
278
+ npm login
279
+ npm publish
280
+ ```
281
+
282
+ ### algolia
283
+
284
+ 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
+
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.
293
+
294
+ Squawk then runs the rule functions over the parsed AST, gathers and pretty
295
+ prints the rule violations.
296
+
@@ -0,0 +1,4 @@
1
+ squawk_cli-1.2.0.dist-info/METADATA,sha256=XYKSvo1u2jEfnxVfBgCcyzJN6N6wwN5V0sAf01-5wDQ,9280
2
+ squawk_cli-1.2.0.dist-info/WHEEL,sha256=6NoyABykjEKtE5wivMs156-gz0KS0aIyw_jJvPZ8GB4,89
3
+ squawk_cli-1.2.0.data/scripts/squawk.exe,sha256=vaRjj_d_mVbqIkefmQ97BMT3dpa0XasCdgba07jAiwQ,5863936
4
+ squawk_cli-1.2.0.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-win32