Skip to content

Commit 1d8bfbf

Browse files
committed
Add config, filters, HTML reports, diffs, and watch mode
1 parent 62d2098 commit 1d8bfbf

18 files changed

Lines changed: 1717 additions & 206 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dist/
99
.local.env
1010
.env
1111
.env.local
12+
.analyzerrc.json
1213

1314
# Reports
1415
reports/*.md

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Dependabot configuration for npm + GitHub Actions
2525
- MIT license
2626
- Makefile with common development targets
27+
- Config-file support via `.analyzerrc.json`, global fallback config, and named connection profiles
28+
- Schema and table filters for scoped PostgreSQL analysis runs
29+
- Self-contained HTML report generation with light/dark mode and sortable sections
30+
- Report diffing against previous JSON snapshots with delta summaries
31+
- Watch mode for polling-safe commands with refresh intervals and countdown feedback
32+
- `pnpm analyze:html` and `pnpm analyze:watch` convenience scripts
33+
34+
### Changed
35+
36+
- Full analysis output can now generate Markdown, JSON, and optional HTML reports from the same run
37+
- Compare mode accepts saved JSON reports and wrapped CLI JSON output when diffing snapshots
38+
39+
### Fixed
40+
41+
- Explicit `--profile` selection now overrides sourced environment connection defaults for the active run

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ export DB_SSL=true
9696
# export PGPASSWORD=...
9797
```
9898

99+
### Config file (`.analyzerrc.json`)
100+
101+
Place `.analyzerrc.json` in your project root (or `~/.config/db-analyzer/config.json` for global settings).
102+
Copy `analyzerrc.example.json` to get started:
103+
104+
```bash
105+
cp analyzerrc.example.json .analyzerrc.json
106+
```
107+
108+
Connection profiles let you switch databases without re-typing flags:
109+
110+
```bash
111+
# use a named profile
112+
. ./.env && npx ts-node index.ts -c health --profile prod
113+
114+
# or with npm script
115+
pnpm analyze:health -- --profile staging
116+
```
117+
118+
CLI flags always win. When you explicitly select a profile with `--profile`, that
119+
profile's connection fields override sourced environment defaults for that run.
120+
99121
---
100122

101123
## Usage
@@ -119,6 +141,8 @@ pnpm analyze:tables # Largest tables
119141
pnpm analyze:fk # Foreign keys without indexes
120142
pnpm analyze:connections # Connection statistics
121143
pnpm analyze:config # PostgreSQL configuration
144+
pnpm analyze:html # Full analysis + Markdown + HTML reports
145+
pnpm analyze:watch # Live health dashboard (refreshes every 30s)
122146

123147
# Server info
124148
pnpm server:info
@@ -190,6 +214,13 @@ npx ts-node index.ts -h localhost -p 5432 -d mydb -U postgres -W secret --ssl -j
190214
| `--user` | `-U` | Database user | `postgres` |
191215
| `--password` | `-W` | Database password | - |
192216
| `--ssl` | | Enable SSL | `false` |
217+
| `--profile` | | Use a named connection profile from `.analyzerrc.json` | - |
218+
| `--config` | | Path to a config file | auto-search |
219+
| `--schemas` | | Comma-separated schema names to analyze | all |
220+
| `--tables` | | Comma-separated table names to analyze | all |
221+
| `--compare` | | Path to a previous JSON report for diffing | - |
222+
| `--html` | | Also generate an HTML report | `false` |
223+
| `--watch` | | Poll interval in seconds (enables watch mode) | - |
193224
| `--command` | `-c` | Run a single command (see table) | `full` |
194225
| `--json` | `-j` | JSON output | `false` |
195226
| `--quiet` | `-q` | Suppress progress output | `false` |
@@ -241,6 +272,40 @@ Saved to `./reports/db-analysis-{timestamp}.md`.
241272
}
242273
```
243274

275+
### HTML report
276+
277+
Generated by `pnpm analyze:html` or `pnpm analyze -- --html`. Includes the same content
278+
as the Markdown report in a self-contained HTML file with:
279+
280+
- Light/dark mode (follows OS preference)
281+
- Color-coded severity badges
282+
- Collapsible sections
283+
- Sortable tables
284+
- No external dependencies — share as a single file
285+
286+
Saved to `./reports/db-analysis-{timestamp}.html`.
287+
288+
### Report diff
289+
290+
Compare two snapshots to see what changed:
291+
292+
```bash
293+
# save a baseline
294+
pnpm analyze
295+
296+
# later, compare
297+
pnpm analyze -- --compare ./reports/db-analysis-2026-01-01.json
298+
```
299+
300+
Output:
301+
```
302+
⬆️ Health score 72 → 85 (+13) ✓ better
303+
⬇️ Cache hit ratio 99.1% → 98.2% (-0.9%) ✗ worse
304+
↔️ Slow queries 8 → 8 no change
305+
⚠️ New issues (1): idx_products_old (unused index)
306+
✓ Resolved (2): idx_users_tmp, idx_orders_status_old
307+
```
308+
244309
---
245310

246311
## Health score

analyzerrc.example.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"profiles": {
3+
"local": {
4+
"host": "localhost",
5+
"port": 5432,
6+
"database": "mydb",
7+
"user": "postgres"
8+
},
9+
"prod": {
10+
"host": "prod.db.internal",
11+
"database": "mydb",
12+
"user": "readonly",
13+
"ssl": true
14+
}
15+
},
16+
"defaultProfile": "local",
17+
"thresholds": {
18+
"cacheHitRatio": { "warning": 95, "critical": 90 },
19+
"indexHitRatio": { "warning": 95, "critical": 90 },
20+
"deadTuplesRatio": { "warning": 5, "critical": 10 }
21+
},
22+
"slowQueryThreshold": 100,
23+
"minIndexScans": 50,
24+
"output": "./reports"
25+
}

0 commit comments

Comments
 (0)