SuperAPI AI 工具集

postgresql-crud

数据与分析

查看项目

更新于 10-16 05:46

技能介绍

用途:通过保存的本地 profile 安全地检查、查询和修改 PostgreSQL 数据。基于 Bash 脚本与 psql CLI,不依赖 Python、psycopg 或 jq。

主要能力:保存可复用的连接配置;直连 PostgreSQL;通过 SSH 隧道连接私有主机;SSH 远程执行(数据库 URL 存在于服务器上的 .env 中);schema 检查;select、insert、update、delete 及原始 SQL。输出 JSON 到 stdout,并默认保存到 ./out/postgresql-crud-<UTC 时间戳>-<pid>.json。

使用方式:配置 profile 使用 configure,支持 direct、ssh-remote、ssh-tunnel 三种模式,可加 --test-connection 验证。用 list-profiles 查看(已脱敏)、remove-profile 删除。schema 命令列出表或列,默认 schema 为 public。select 支持 --where、--param、--columns、--order-by、--desc、--limit。insert/update/delete 先 dry-run,确认后加 --execute。原始写 SQL 需同时加 --execute 和 --allow-raw-write。

安全规则:凭据不存入仓库,profile 存于 ~/.config/postgresql-crud/profiles/<profile>.conf(0600);不打印密码或完整 URL;优先只读;写操作先 dry-run 并显式确认;readonly profile 不得用于写;update/delete 需 --where,除非显式确认全表并加 --allow-full-table;过滤条件使用参数占位符。

限制:需要 bash、本地 psql(直连/隧道)、ssh(隧道/远程)、远程 bash 与 psql(远程)。标识符仅限简单 PostgreSQL 标识符及可选 schema.table。该脚本不是迁移工具,除非用户明确要求原始 SQL 并承担风险,否则不用于 schema 变更。ssh-remote 若远程 bash、psql 或 remote_cwd 缺失/无效,应停止并报告。ssh-tunnel 使用 ssh -N -L 并在命令结束时关闭隧道。