Skip to main content

Squawk

A linter, code formatter, and language server for Postgres migrations & SQL

Prevent Downtime

Lint your schema changes and prevent blocking reads / writes.

GitHub Integration

Use the Squawk GitHub App to lint your pull requests.

VSCode Support

Squawk's language server and VSCode extension provides code formatting & linting in your editor.

Rules

Prevent schema mistakes

rule namedescription
ban-char-fieldPrevent mistaken use of character type in schema.
prefer-bigint-over-intPrevent hitting the 32 bit max int limit.
prefer-bigint-over-smallintPrevent hitting the 16 bit max int limit.
prefer-identitySerial types have confusing behaviors. Use identity columns instead.
prefer-timestamptzEnsure consistent timezone handling for timestamps, regardless of your database session timezone.
ban-concurrent-index-creation-in-transactionPrevent forbidden use of transactions during concurrent index creation.
ban-create-domain-with-constraintDomains with constraints have poor support for online migrations
ban-alter-domain-with-add-constraintDomains with constraints have poor support for online migrations
ban-uncommitted-transactionEnsure all transactions are committed
require-enum-value-orderingRequire BEFORE or AFTER when adding enum values
require-table-schemaRequire explicit schema in table DDL to avoid ambiguity.
identifier-too-longPrevent implicit truncation for identifiers that are too long.
require-concurrent-partition-detachPrevent blocking reads/writes to table while partition is detached.

Make backwards compatible schema changes

rule namedescription
adding-required-fieldPrevent adding a new required field to an existing table.
ban-drop-databasePrevent breaking existing clients that depend on the database.
ban-drop-not-nullPrevent breaking existing clients that don't expect NULL values.
ban-drop-tablePrevent breaking existing clients that depend on the table.
changing-column-typePrevent breaking existing clients that depend on column type. Prevent blocking reads/writes to table while table is rewritten.
renaming-columnPrevent breaking existing clients that depend on column.
renaming-tablePrevent breaking existing clients that depend on table.
ban-truncate-cascadeTruncate cascade will recursively truncate all related tables!
ban-drop-viewPrevent breaking clients that depend on views or materialized views.
ban-drop-functionPrevent breaking clients that call functions or procedures.
ban-drop-typePrevent breaking clients that use dropped types.
ban-drop-defaultPrevent inserts from failing or writing NULL after dropping a column default.
ban-drop-triggerPrevent silent changes when a trigger is dropped (opt-in).
ban-drop-schemaPrevent breaking clients that use a dropped schema.
ban-drop-sequencePrevent breaking clients that use a dropped sequence.
ban-drop-domainPrevent breaking clients that use a dropped domain.
ban-drop-constraintPrevent removing a constraint guarantee.
ban-drop-generated-expressionPrevent dropping a generated expression.
renaming-objectPrevent renaming objects used by clients.
ban-set-schemaPrevent moving objects used by clients to another schema.
ban-alter-identityPrevent changing identity columns used by clients.
ban-drop-extensionPrevent dropping extensions used by clients.
ban-alter-generated-expressionPrevent breaking inserts with generated columns (opt-in).
ban-drop-indexPrevent dropping indexes used by clients (opt-in).
ban-set-defaultPrevent silent changes to column defaults (opt-in).
ban-disable-triggerPrevent changes to triggers, rules, and row level security (opt-in).
ban-replica-identityDetect changes to replica identity and publications (opt-in).
ban-drop-policyPrevent dropping policies and rules (opt-in).
ban-revokePrevent revoking client privileges (opt-in).
ban-replace-view-functionPrevent replacing views and routines (opt-in).
ban-create-policyReview new policy access rules (opt-in).
ban-alter-policy-conditionReview policy condition changes (opt-in).
ban-alter-policy-rolesReview policy role changes (opt-in).
ban-alter-function-optionsReview function option changes (opt-in).
ban-alter-view-optionsReview view option changes (opt-in).
ban-alter-role-optionsReview role option and configuration changes (opt-in).
ban-alter-database-optionsReview database option and configuration changes (opt-in).
ban-alter-row-level-securityReview row level security changes (opt-in).
ban-new-write-restrictionDetect new write restrictions on existing tables (opt-in).
ban-add-enum-valueDetect new enum values (opt-in).
ban-add-composite-attributeDetect new composite attributes (opt-in).
ban-add-columnDetect columns added to existing tables (opt-in).
ban-detach-inheritanceDetect partition detach and NO INHERIT (opt-in).
ban-alter-sequence-valuesDetect changes to sequence values (opt-in).
ban-alter-system-optionsReview server configuration changes (opt-in).
ban-alter-extensionReview extension updates and member removals (opt-in).

Apply schema changes safely

rule namedescription
adding-field-with-defaultPrevent blocking reads/writes to table while table is rewritten on PG < 11.
adding-foreign-key-constraintPrevent blocking writes to tables while verifying foreign key constraint.
adding-not-nullable-fieldPrevent blocking reads/writes to table while table is scanned on PG < 11.
adding-serial-primary-key-fieldPrevent blocking reads/writes to table while index is built.
changing-column-typePrevent breaking existing clients that depend on column type. Prevent blocking reads/writes to table while table is rewritten.
constraint-missing-not-validPrevent blocking writes to the table while the scan occurs.
disallowed-unique-constraintPrevent blocking reads/writes to table while index is built.
prefer-robust-stmtsEnsure migrations are atomic or retriable.
prefer-text-fieldPrevent blocking reads and writes to table while table metadata is updated.
require-concurrent-index-creationPrevent blocking writes to table while index is created.
require-concurrent-index-deletionPrevent blocking reads/writes to table while index is dropped.
transaction-nestingEnsure migrations use transactions correctly.
ban-create-domain-with-constraintDomains with constraints have poor support for online migrations
ban-alter-domain-with-add-constraintDomains with constraints have poor support for online migrations
require-lock-timeoutRequire a lock timeout
require-statement-timeoutRequire a statement timeout
require-concurrent-partition-detachPrevent blocking reads/writes to table while partition is detached.
require-concurrent-reindexPrevent blocking reads/writes to table while index is reindexed.
prefer-repackPrevent blocking reads/writes to table when rebuilding.