Skip to content

Commit 6762a67

Browse files
psteinroeclaude
andauthored
feat(dblint): add pglinter (#632)
adds support for [`pglinter`](https://github.com/pmpetit/pglinter) and integrate it with `dblint`. It reuses the existing infrastructure, and 99% of the code changes are generated. adapted the `Dockerfile` to also install `pglinter`. Will take around 10 minutes now to build, but its all cached after that. the initial metadata is generated from the downloaded repo. a follow-up pr will automate this too. pglinter works in a weird way where the user defines thresholds for certain rules. e.g. ``` --- source: crates/pgls_pglinter/tests/diagnostics.rs expression: content snapshot_kind: text --- Category: pglinter/base/howManyObjectsWithUppercase Severity: Warning Message: Count number of objects with uppercase in name or in columns. Advices: Count number of objects with uppercase in name or in columns. [Info] Rule: B005 How to fix: [Info] 1. Do not use uppercase for any database objects ``` I would much rather see the actual objects that have an uppercase in name... Opened an issue to check in with the maintainer: pmpetit/pglinter#83 --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 25d67d6 commit 6762a67

File tree

77 files changed

+5695
-850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+5695
-850
lines changed

.github/actions/setup-postgres/action.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ runs:
4141
echo "Extension directory: $(pg_config --sharedir)/extension"
4242
echo "Library directory: $(pg_config --pkglibdir)"
4343
44-
# Clone and build plpgsql_check (pinned to v2.7.11 for PG15 compatibility)
44+
# Clone and build plpgsql_check (clone to /tmp to avoid workspace conflicts, pinned to v2.7.11)
45+
cd /tmp
4546
git clone --branch v2.7.11 --depth 1 https://github.com/okbob/plpgsql_check.git
4647
cd plpgsql_check
4748
@@ -59,30 +60,77 @@ runs:
5960
echo "Extension library files:"
6061
ls -la "$(pg_config --pkglibdir)/" | grep plpgsql || echo "No plpgsql_check library found"
6162
62-
# Install the pglpgsql_check extension on macOS (Part 2)
63-
- name: Create extension in database
63+
# Install the pglinter extension on macOS (pgrx-based Rust extension)
64+
- name: Install and compile pglinter
65+
if: runner.os == 'macOS'
66+
shell: bash
67+
run: |
68+
# First, ensure we're using the same PostgreSQL that the action installed
69+
export PATH="$(pg_config --bindir):$PATH"
70+
71+
# Install cargo-pgrx (version must match pglinter's pgrx dependency)
72+
cargo install cargo-pgrx --version 0.16.1 --locked
73+
74+
# Determine postgres version for pgrx init
75+
PG_VERSION=$(pg_config --version | grep -oE '[0-9]+' | head -1)
76+
echo "PostgreSQL version: $PG_VERSION"
77+
78+
# Initialize pgrx for the installed PostgreSQL version
79+
cargo pgrx init --pg${PG_VERSION} $(which pg_config)
80+
81+
# Clone and build pglinter (requires v1.1.0+ for get_violations API + rule_messages table)
82+
cd /tmp
83+
git clone --depth 1 https://github.com/pmpetit/pglinter.git
84+
cd pglinter
85+
86+
# Install using pgrx
87+
cargo pgrx install --pg-config $(which pg_config) --release
88+
89+
# Verify installation
90+
echo "Extension control files:"
91+
ls -la "$(pg_config --sharedir)/extension/" | grep pglinter || echo "No pglinter found"
92+
93+
echo "Extension library files:"
94+
ls -la "$(pg_config --pkglibdir)/" | grep pglinter || echo "No pglinter library found"
95+
96+
# Create extensions in database on macOS
97+
- name: Create extensions in database
6498
if: runner.os == 'macOS'
6599
shell: bash
66100
env:
67101
PGSERVICE: ${{ steps.postgres.outputs.service-name }}
68102
run: |
69103
psql -c "CREATE EXTENSION plpgsql_check;"
104+
psql -c "CREATE EXTENSION pglinter;"
70105
71106
# Verify installation
72-
psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'plpgsql_check';"
107+
psql -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('plpgsql_check', 'pglinter');"
108+
109+
# For Linux, use custom Docker image with plpgsql_check and pglinter
110+
- name: Set up Docker Buildx
111+
if: runner.os == 'Linux'
112+
uses: docker/setup-buildx-action@v3
73113

74-
# For Linux, use custom Docker image with plpgsql_check
75-
- name: Build and start PostgreSQL with plpgsql_check
114+
- name: Build PostgreSQL image with cache
115+
if: runner.os == 'Linux'
116+
uses: docker/build-push-action@v5
117+
with:
118+
context: .
119+
load: true
120+
tags: postgres-language-server-dev:latest
121+
cache-from: type=gha
122+
cache-to: type=gha,mode=max
123+
124+
- name: Start PostgreSQL container
76125
if: runner.os == 'Linux'
77126
shell: bash
78127
run: |
79-
docker build -t postgres-plpgsql-check:latest .
80128
docker run -d --name postgres \
81129
-e POSTGRES_USER=postgres \
82130
-e POSTGRES_PASSWORD=postgres \
83131
-e POSTGRES_DB=postgres \
84132
-p 5432:5432 \
85-
postgres-plpgsql-check:latest
133+
postgres-language-server-dev:latest
86134
# Wait for postgres to be ready
87135
for _ in {1..30}; do
88136
if docker exec postgres pg_isready -U postgres; then
@@ -91,3 +139,13 @@ runs:
91139
sleep 1
92140
done
93141
142+
# Create extensions in postgres database only (NOT template1)
143+
# This avoids polluting test databases - tests that need extensions can create them explicitly
144+
echo "Creating extensions in postgres database..."
145+
docker exec postgres psql -U postgres -c "CREATE SCHEMA IF NOT EXISTS extensions;"
146+
docker exec postgres psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS plpgsql_check SCHEMA extensions;"
147+
docker exec postgres psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS pglinter SCHEMA extensions;"
148+
149+
# Show extension status
150+
docker exec postgres psql -U postgres -c "SELECT extname, extversion FROM pg_extension WHERE extname IN ('plpgsql_check', 'pglinter');"
151+

.github/workflows/pull_request.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,26 @@ jobs:
9696
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9797

9898
# we need to use the same database as we do locally for sqlx prepare to output the same hashes
99-
- name: Build and start PostgreSQL with plpgsql_check
99+
- name: Set up Docker Buildx
100+
uses: docker/setup-buildx-action@v3
101+
102+
- name: Build PostgreSQL image with cache
103+
uses: docker/build-push-action@v5
104+
with:
105+
context: .
106+
load: true
107+
tags: postgres-language-server-dev:latest
108+
cache-from: type=gha
109+
cache-to: type=gha,mode=max
110+
111+
- name: Start PostgreSQL
100112
run: |
101-
docker build -t postgres-plpgsql-check:latest .
102113
docker run -d --name postgres \
103114
-e POSTGRES_USER=postgres \
104115
-e POSTGRES_PASSWORD=postgres \
105116
-e POSTGRES_DB=postgres \
106117
-p 5432:5432 \
107-
postgres-plpgsql-check:latest
118+
postgres-language-server-dev:latest
108119
# Wait for postgres to be ready
109120
for _ in {1..30}; do
110121
if docker exec postgres pg_isready -U postgres; then

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ site/
5151

5252
biome-main/
5353
.review/
54+
pglinter_repo/
55+
.review/

.sqlx/query-0aba89d3e0ed2e4586b94ea8fe2def7cbde2c9e609d34c1bfcb87f50ed0f25ff.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-4f7d0241b0c52b2d6742b441e9ac98d80b50a02c30a54b30611ca40b99d51ab7.json

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)