Skip to main content

Custom SQL lint rules for Postgres migrations — sqlfluff + pygrep, pre-commit-friendly.

Project description

sarj-sql-lint

Custom SQL lint rules for Postgres migrations. AST-based via sqlfluff for the SARJ101 rule + zero-dependency pygrep regex hooks for migration-hygiene checks. Designed for pre-commit.

uv tool install sarj-sql-lint

Rules

Code id Flags
SARJ101 enforce-timestamptz TIMESTAMP without WITH TIME ZONE — use TIMESTAMPTZ
SARJ102 idempotent-ddl CREATE TABLE/INDEX, ADD COLUMN, DROP TABLE/INDEX without IF [NOT] EXISTS
SARJ103 no-pg-enum CREATE TYPE ... AS ENUM — use TEXT + CHECK constraint
SARJ104 prefer-text-over-varchar VARCHAR(n) / CHARACTER VARYING(n) — use TEXT (+ CHECK length if needed)
SARJ105 insert-requires-on-conflict INSERT INTO statement (multi-line aware) with no ON CONFLICT clause
SARJ106 prefer-jsonb JSON column type or ::json cast — use JSONB
SARJ107 no-limit-offset OFFSET keyword — use cursor pagination (WHERE id > :cursor ... LIMIT n)

Pre-commit

- repo: https://github.com/sarj-ai/standards
  rev: sql-v0.1.0
  hooks:
    - id: sarj-enforce-timestamptz
      files: '\.sql$'
    - id: sarj-idempotent-ddl
      files: '\.sql$'
    - id: sarj-ban-postgres-enums
      files: '\.sql$'
    - id: sarj-ban-create-trigger
      files: '\.sql$'
    - id: sarj-prefer-text-over-varchar
      files: '\.sql$'
    - id: sarj-insert-requires-on-conflict
      files: '\.sql$'
    - id: sarj-prefer-jsonb
      files: '\.sql$'
    - id: sarj-no-limit-offset
      files: '\.sql$'

CLI

sarj-sql-lint check --rule enforce-timestamptz svcs/db/db/migrations/*.sql
sarj-sql-lint list-rules

Diagnostic format is path:line:col: CODE message — Ruff-compatible.

Each rule's source under src/sarj_sql_lint/rules/ carries its own description and diagnostic message.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sarj_sql_lint-0.2.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sarj_sql_lint-0.2.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file sarj_sql_lint-0.2.0.tar.gz.

File metadata

  • Download URL: sarj_sql_lint-0.2.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sarj_sql_lint-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a7ed9d0b143e9a84840ac0a31d025c1f3501ecff76c96ab81cff14452646f5b3
MD5 d8b169ab441d76e4892a5c013c7d5531
BLAKE2b-256 597433902399cc19aaaa313bbe70fea1a29fe3a51f624c4dc1ea55c493610b06

See more details on using hashes here.

File details

Details for the file sarj_sql_lint-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sarj_sql_lint-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sarj_sql_lint-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7aa33504b1e72464cb869dffd265a2398a0a6ecb1d9a4cebc9a9ef224b3f3be
MD5 27cd036004ee583b27a8d9da844fe659
BLAKE2b-256 e3cf98df2f85a86aefa47f6174b63ce00e6a86d34dea5141534926c1d8bf965d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page