@indiekitai/pg-dash 0.3.6 → 0.3.8

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.
package/README.md CHANGED
@@ -2,19 +2,26 @@
2
2
 
3
3
  # pg-dash
4
4
 
5
- **The AI-native PostgreSQL health checker.** One command to audit your database, 14 MCP tools for AI-assisted optimization, CI integration for automated checks.
5
+ **The AI-native PostgreSQL health checker.** One command to audit your database, 18 MCP tools for AI-assisted optimization, CI integration for automated checks.
6
6
 
7
7
  Not another monitoring dashboard — pg-dash is built to fit into your **AI coding workflow**:
8
8
 
9
9
  ```
10
- Developer writes a migration → CI runs pg-dash check →
11
- Finds missing indexesMCP tool suggests fix PR comment
10
+ Developer writes a migration → pg-dash check-migration (pre-flight)
11
+ CI runs pg-dash check Finds missing indexes
12
+ MCP tool suggests fix → PR comment
12
13
  ```
13
14
 
14
15
  ```bash
15
16
  # One-shot health check
16
17
  npx @indiekitai/pg-dash check postgres://user:pass@host/db
17
18
 
19
+ # Check migration safety before running it
20
+ npx @indiekitai/pg-dash check-migration ./migrations/015_add_index.sql
21
+
22
+ # Compare two environments (local vs staging)
23
+ npx @indiekitai/pg-dash diff-env --source postgres://localhost/db --target postgres://staging/db
24
+
18
25
  # AI assistant (Claude/Cursor) via MCP
19
26
  pg-dash-mcp postgres://user:pass@host/db
20
27
 
@@ -40,7 +47,7 @@ The Dashboard is there when you need it. But the real power is in the CLI, MCP,
40
47
  | pganalyze | $149+/mo | SaaS signup | ❌ | ❌ |
41
48
  | Grafana+Prometheus | Free | 3 services | ❌ | ❌ |
42
49
  | pgAdmin | Free | Complex UI | ❌ | ❌ |
43
- | **pg-dash** | **Free** | **One command** | **14 MCP tools** | **`--ci --diff`** |
50
+ | **pg-dash** | **Free** | **One command** | **18 MCP tools** | **`--ci --diff`** |
44
51
 
45
52
  ## Features
46
53
 
@@ -93,8 +100,25 @@ The Dashboard is there when you need it. But the real power is in the CLI, MCP,
93
100
  - Auto-detects Slack vs Discord webhook URLs
94
101
  - Configure via `--slack-webhook` or `--discord-webhook`
95
102
 
103
+ ### 🛡️ Migration Safety Check
104
+ - Analyze a migration SQL file for risks before running it
105
+ - Detects: `CREATE INDEX` without `CONCURRENTLY` (lock risk), `ADD COLUMN NOT NULL` without `DEFAULT`, `DROP TABLE`, `TRUNCATE`, `DELETE`/`UPDATE` without `WHERE`
106
+ - Dynamic checks: connects to DB to verify referenced tables exist, estimates lock time based on actual row counts
107
+ - CI-ready: `--ci` flag emits `::error::` / `::warning::` GitHub Actions annotations
108
+
109
+ ### 🧠 Query Intelligence
110
+ - `pg_dash_analyze_query` — runs `EXPLAIN ANALYZE`, detects Seq Scans on large tables, auto-generates `CREATE INDEX CONCURRENTLY` suggestions with benefit ratings
111
+ - `pg_dash_query_regressions` — finds queries that got >50% slower vs historical baseline (requires `pg_stat_statements`)
112
+ - EXPLAIN Modal in dashboard shows index suggestions inline
113
+
114
+ ### 🔄 Multi-Env Diff
115
+ - Compare schema and health between two PostgreSQL environments (local vs staging, staging vs prod)
116
+ - Detects: missing/extra tables, missing/extra columns, column type mismatches, missing/extra indexes
117
+ - `--health` flag adds health score comparison and unique issues per environment
118
+ - `pg_dash_compare_env` MCP tool: ask your AI "what's different between local and staging?"
119
+
96
120
  ### 🤖 MCP Server
97
- - 14 tools for AI agent integration
121
+ - 18 tools for AI agent integration
98
122
  - `pg-dash-mcp postgres://...` — works with Claude, Cursor, etc.
99
123
 
100
124
  ### 🖥️ CLI
@@ -106,11 +130,16 @@ pg-dash postgres://user:pass@host/db
106
130
  pg-dash check postgres://user:pass@host/db
107
131
  pg-dash check postgres://... --format json --threshold 70
108
132
 
133
+ # Migration safety check
134
+ pg-dash check-migration ./migrations/015_add_index.sql
135
+ pg-dash check-migration ./migrations/015_add_index.sql postgres://... --ci
136
+
137
+ # Multi-env schema diff
138
+ pg-dash diff-env --source postgres://localhost/db --target postgres://staging/db
139
+ pg-dash diff-env --source postgres://... --target postgres://... --health --format md
140
+
109
141
  # Schema changes
110
142
  pg-dash schema-diff postgres://user:pass@host/db
111
-
112
- # JSON dump
113
- pg-dash postgres://... --json
114
143
  ```
115
144
 
116
145
  ## Quick Start
@@ -132,9 +161,11 @@ Opens your browser at `http://localhost:3480` with the full dashboard.
132
161
  ## CLI Options
133
162
 
134
163
  ```
135
- pg-dash <connection-string> Start dashboard
136
- pg-dash check <connection-string> Run health check and exit
137
- pg-dash schema-diff <connection-string> Show schema changes
164
+ pg-dash <connection-string> Start dashboard
165
+ pg-dash check <connection-string> Run health check and exit
166
+ pg-dash check-migration <file> [conn] Analyze migration SQL for risks
167
+ pg-dash diff-env --source <url> --target <url> Compare two environments
168
+ pg-dash schema-diff <connection-string> Show schema changes
138
169
 
139
170
  Options:
140
171
  -p, --port <port> Dashboard port (default: 3480)
@@ -152,6 +183,10 @@ Options:
152
183
  --query-stats-interval <min> Query stats snapshot interval in minutes (default: 5)
153
184
  --slack-webhook <url> Slack webhook URL for alert notifications
154
185
  --discord-webhook <url> Discord webhook URL for alert notifications
186
+ --ci Output GitHub Actions annotations (check, check-migration, diff-env)
187
+ --diff Compare with last snapshot (check command)
188
+ --snapshot-path <path> Path to snapshot file for --diff
189
+ --health Include health comparison (diff-env)
155
190
  -v, --version Show version
156
191
  ```
157
192
 
@@ -167,7 +202,7 @@ pg-dash-mcp postgres://user:pass@host/db
167
202
  PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
168
203
  ```
169
204
 
170
- ### Available Tools (14)
205
+ ### Available Tools (18)
171
206
 
172
207
  | Tool | Description |
173
208
  |------|-------------|
@@ -185,6 +220,10 @@ PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
185
220
  | `pg_dash_table_sizes` | Table sizes with data/index breakdown (top 30) |
186
221
  | `pg_dash_export` | Export full health report (JSON or Markdown) |
187
222
  | `pg_dash_diff` | Compare current health with last saved snapshot |
223
+ | `pg_dash_check_migration` | Analyze migration SQL for lock risks, missing tables, destructive ops |
224
+ | `pg_dash_analyze_query` | Deep EXPLAIN analysis with automatic index suggestions |
225
+ | `pg_dash_query_regressions` | Detect queries that degraded >50% vs historical baseline |
226
+ | `pg_dash_compare_env` | Compare schema and health between two database environments |
188
227
 
189
228
  ## MCP Setup
190
229
 
package/README.zh-CN.md CHANGED
@@ -2,19 +2,26 @@
2
2
 
3
3
  # pg-dash
4
4
 
5
- **AI 原生的 PostgreSQL 健康检查工具。** 一条命令审计数据库,14 个 MCP 工具让 AI 帮你优化,CI 集成自动检查。
5
+ **AI 原生的 PostgreSQL 健康检查工具。** 一条命令审计数据库,18 个 MCP 工具让 AI 帮你优化,CI 集成自动检查。
6
6
 
7
7
  不是又一个监控面板 —— pg-dash 是为 **AI 编程工作流** 设计的:
8
8
 
9
9
  ```
10
- 开发者写了一个 migration → CI 跑 pg-dash check
11
- 发现缺失索引 MCP 工具建议修复PR comment
10
+ 开发者写了一个 migration → pg-dash check-migration(执行前检查)→
11
+ CI pg-dash check发现缺失索引
12
+ MCP 工具建议修复 → PR comment
12
13
  ```
13
14
 
14
15
  ```bash
15
16
  # 一次性健康检查
16
17
  npx @indiekitai/pg-dash check postgres://user:pass@host/db
17
18
 
19
+ # 执行 migration 前检查风险
20
+ npx @indiekitai/pg-dash check-migration ./migrations/015_add_index.sql
21
+
22
+ # 对比两个环境(本地 vs 预发)
23
+ npx @indiekitai/pg-dash diff-env --source postgres://localhost/db --target postgres://staging/db
24
+
18
25
  # AI 助手(Claude/Cursor)通过 MCP 调用
19
26
  pg-dash-mcp postgres://user:pass@host/db
20
27
 
@@ -40,7 +47,7 @@ Dashboard 需要时可以用。但真正的核心能力在 CLI、MCP 和 CI。
40
47
  | pganalyze | $149+/月 | SaaS 注册 | ❌ | ❌ |
41
48
  | Grafana+Prometheus | 免费 | 配置 3 个服务 | ❌ | ❌ |
42
49
  | pgAdmin | 免费 | 界面复杂 | ❌ | ❌ |
43
- | **pg-dash** | **免费** | **一条命令** | **14 个 MCP 工具** | **`--ci --diff`** |
50
+ | **pg-dash** | **免费** | **一条命令** | **18 个 MCP 工具** | **`--ci --diff`** |
44
51
 
45
52
  ## 功能
46
53
 
@@ -93,8 +100,25 @@ Dashboard 需要时可以用。但真正的核心能力在 CLI、MCP 和 CI。
93
100
  - 自动识别 Slack / Discord webhook URL
94
101
  - 通过 `--slack-webhook` 或 `--discord-webhook` 配置
95
102
 
103
+ ### 🛡️ Migration 安全检查
104
+ - 执行迁移前分析 SQL 文件的风险
105
+ - 检测:`CREATE INDEX`(无 `CONCURRENTLY` 会锁表)、`ADD COLUMN NOT NULL`(无 DEFAULT 会失败)、`DROP TABLE`、`TRUNCATE`、无 WHERE 的 `DELETE`/`UPDATE`
106
+ - 动态检查:连接数据库验证被引用表是否存在,根据实际行数估算锁表时间
107
+ - CI 友好:`--ci` 输出 `::error::` / `::warning::` GitHub Actions 注解
108
+
109
+ ### 🧠 查询智能诊断
110
+ - `pg_dash_analyze_query` —— 运行 `EXPLAIN ANALYZE`,检测大表的 Seq Scan,自动生成带 benefit 评级的 `CREATE INDEX CONCURRENTLY` 建议
111
+ - `pg_dash_query_regressions` —— 找出比历史基线慢超过 50% 的查询(需要 `pg_stat_statements`)
112
+ - 面板 EXPLAIN 弹窗内联展示索引建议
113
+
114
+ ### 🔄 多环境对比
115
+ - 对比两个 PostgreSQL 环境的 Schema 和健康状态(本地 vs 预发、预发 vs 生产)
116
+ - 检测:缺失/多余的表、缺失/多余的列、列类型不匹配、缺失/多余的索引
117
+ - `--health` 参数额外对比健康分和各环境独有的问题
118
+ - `pg_dash_compare_env` MCP 工具:直接问 AI "本地和预发有什么差异?"
119
+
96
120
  ### 🤖 MCP Server
97
- - 8 个工具,支持 AI Agent 集成
121
+ - 18 个工具,支持 AI Agent 集成
98
122
  - `pg-dash-mcp postgres://...` —— 可配合 Claude、Cursor 等使用
99
123
 
100
124
  ### 🖥️ CLI
@@ -106,11 +130,16 @@ pg-dash postgres://user:pass@host/db
106
130
  pg-dash check postgres://user:pass@host/db
107
131
  pg-dash check postgres://... --format json --threshold 70
108
132
 
133
+ # Migration 安全检查
134
+ pg-dash check-migration ./migrations/015_add_index.sql
135
+ pg-dash check-migration ./migrations/015_add_index.sql postgres://... --ci
136
+
137
+ # 多环境 Schema 对比
138
+ pg-dash diff-env --source postgres://localhost/db --target postgres://staging/db
139
+ pg-dash diff-env --source postgres://... --target postgres://... --health --format md
140
+
109
141
  # Schema 变更
110
142
  pg-dash schema-diff postgres://user:pass@host/db
111
-
112
- # JSON 输出
113
- pg-dash postgres://... --json
114
143
  ```
115
144
 
116
145
  ## 快速开始
@@ -132,9 +161,11 @@ pg-dash --host localhost --user postgres --db mydb --port 3480
132
161
  ## CLI 参数
133
162
 
134
163
  ```
135
- pg-dash <connection-string> 启动面板
136
- pg-dash check <connection-string> 运行健康检查并退出
137
- pg-dash schema-diff <connection-string> 显示 Schema 变更
164
+ pg-dash <connection-string> 启动面板
165
+ pg-dash check <connection-string> 运行健康检查并退出
166
+ pg-dash check-migration <file> [conn] 检查 migration SQL 的风险
167
+ pg-dash diff-env --source <url> --target <url> 对比两个环境
168
+ pg-dash schema-diff <connection-string> 显示 Schema 变更
138
169
 
139
170
  Options:
140
171
  -p, --port <port> 面板端口(默认:3480)
@@ -148,10 +179,14 @@ Options:
148
179
  --data-dir <dir> 数据目录(默认:~/.pg-dash)
149
180
  -i, --interval <sec> 采集间隔(默认:30)
150
181
  --threshold <score> check 命令的分数阈值(默认:70)
151
- -f, --format <fmt> 输出格式:text|json(默认:text)
182
+ -f, --format <fmt> 输出格式:text|json|md(默认:text)
152
183
  --query-stats-interval <min> 查询统计快照间隔,单位分钟(默认:5)
153
184
  --slack-webhook <url> Slack webhook URL,用于告警通知
154
185
  --discord-webhook <url> Discord webhook URL,用于告警通知
186
+ --ci 输出 GitHub Actions 注解(check、check-migration、diff-env)
187
+ --diff 与上次快照对比(check 命令)
188
+ --snapshot-path <path> --diff 使用的快照文件路径
189
+ --health 包含健康对比(diff-env)
155
190
  -v, --version 显示版本
156
191
  ```
157
192
 
@@ -167,7 +202,7 @@ pg-dash-mcp postgres://user:pass@host/db
167
202
  PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
168
203
  ```
169
204
 
170
- ### 可用工具(14 个)
205
+ ### 可用工具(18 个)
171
206
 
172
207
  | 工具 | 描述 |
173
208
  |------|------|
@@ -185,6 +220,10 @@ PG_DASH_CONNECTION_STRING=postgres://... pg-dash-mcp
185
220
  | `pg_dash_table_sizes` | 表大小(数据/索引拆分,前 30) |
186
221
  | `pg_dash_export` | 导出完整健康报告(JSON 或 Markdown) |
187
222
  | `pg_dash_diff` | 与上次快照对比当前健康状态 |
223
+ | `pg_dash_check_migration` | 分析 migration SQL 的锁表风险、缺失表、破坏性操作 |
224
+ | `pg_dash_analyze_query` | 深度 EXPLAIN 分析,自动生成索引建议 |
225
+ | `pg_dash_query_regressions` | 检测比历史基线慢超过 50% 的查询 |
226
+ | `pg_dash_compare_env` | 对比两个数据库环境的 Schema 和健康状态 |
188
227
 
189
228
  ## MCP 配置
190
229