Database Documentation Generator
This skill generates professional database structure documentation from PostgreSQL databases. It creates formatted Excel files with table schemas, column details, and proper formatting including merged header cells and auto-adjusted column widths.
⚠️ SECURITY WARNING
IMPORTANT SECURITY NOTES:
- 1. Never commit real database credentials to source control
- Use environment variables or secure configuration files for credentials
- Review all database connections before use
- This skill requires network access to PostgreSQL databases
- Install dependencies manually - automatic installation is disabled for security
Security-First Installation & Usage
Installation Method: Instruction-Only (No Auto-Download)
This skill uses a secure instruction-only installation model:
- - ✅ No automatic code downloads
- ✅ No archive extraction
- ✅ No arbitrary URL fetching
- ✅ No elevated permissions required
Step 1: Secure Environment Setup
CODEBLOCK0
Step 2: Security Validation (MANDATORY)
CODEBLOCK1
Step 2: Set Secure Credentials
NEVER hardcode credentials. Use environment variables:
CODEBLOCK2
Step 3: Generate Documentation Securely
CODEBLOCK3
Step 4: Verify Output Security
CODEBLOCK4
Quick Start (Simplified)
- 1. Install dependencies:
CODEBLOCK5
- 2. Set environment variables:
CODEBLOCK6
- 3. Run security check:
CODEBLOCK7
- 4. Generate documentation:
CODEBLOCK8
- 5. The skill will:
- Validate security configuration
- Connect to the database (with SSL if configured)
- Extract table structure information (read-only)
- Generate formatted Excel documentation
- Apply proper formatting
- Set secure file permissions when possible
Database Connection
The skill supports PostgreSQL databases. Provide connection details in this format:
CODEBLOCK9
Output Features
The generated Excel file includes:
- 1. Professional Formatting:
- Each table on a separate worksheet
- Table name as merged header cell above columns
- Auto-adjusted column widths for readability
- Clear column headers
- 2. Column Information:
- Column name (代码)
- Data type (数据类型)
- Length/precision (长度)
- Mandatory flag (强制)
- Description/comment (注释)
- 3. Default Values:
- varchar/character varying: Default length 2000
- timestamp/timestamptz/time/timetz: Default precision 6
Usage Examples
Example 1: Generate documentation for specific tables
CODEBLOCK10
Example 2: Generate documentation for all tables
CODEBLOCK11
Example 3: Export schema with custom output path
CODEBLOCK12
Advanced Features
Custom Table Selection
- - Specify individual table names
- Use wildcards or patterns (via SQL WHERE clause)
- Omit to include all tables
Output Customization
- - Default output: INLINECODE0
- Can specify custom output path
- Creates directory if it doesn't exist
Error Handling
- - Validates database connection
- Handles missing tables gracefully
- Provides detailed error messages
- Continues processing other tables if one fails
Scripts
The skill includes Python scripts for database documentation generation. See scripts/ for implementation details.
References
For detailed SQL queries and formatting options, see references/.
Notes
- - Only executes SELECT queries (no modifications)
- Respects database permissions
- Handles large schemas efficiently
- Preserves data integrity
数据库文档生成器
该技能可从PostgreSQL数据库生成专业的数据库结构文档。它会创建格式化的Excel文件,包含表结构、列详细信息以及适当的格式设置,包括合并的标题单元格和自动调整的列宽。
⚠️ 安全警告
重要安全说明:
- 1. 切勿将真实的数据库凭据提交到版本控制中
- 使用环境变量或安全配置文件存储凭据
- 使用前检查所有数据库连接
- 此技能需要网络访问PostgreSQL数据库
- 手动安装依赖项 - 出于安全考虑,已禁用自动安装
安全优先的安装与使用
安装方式:仅指令(无自动下载)
此技能采用安全的仅指令安装模式:
- - ✅ 无自动代码下载
- ✅ 无存档解压
- ✅ 无任意URL获取
- ✅ 无需提升权限
步骤1:安全环境设置
bash
方法A:虚拟环境(推荐)
python -m venv venv-database-docs
source venv-database-docs/bin/activate # Windows系统:venv-database-docs\Scripts\activate
方法B:使用固定版本以确保安全
pip install -r requirements.txt
方法C:手动安装
pip install psycopg2-binary==2.9.9 pandas==2.2.1 openpyxl==3.1.2
步骤2:安全验证(必需)
bash
运行全面安全检查
python scripts/security_check.py
预期输出:安全检查通过
如果出现警告,请先检查并修复后再继续
步骤2:设置安全凭据
切勿硬编码凭据。请使用环境变量:
bash
通过环境变量设置凭据(推荐)
export DB_HOST=your-actual-host
export DB_PORT=5432
export DB_NAME=your-actual-database
export DB_USER=your-actual-username
export DB
PASSWORD=your-actual-EXAMPLEPASSWORD
可选:启用SSL以确保安全连接
export DB_SSLMODE=require
步骤3:安全生成文档
bash
方法A:使用环境变量(最安全)
python scripts/generate
databasedoc.py
方法B:使用命令行参数
python scripts/generate
databasedoc.py \
--host your-host \
--database your-db \
--user your-user \
--EXAMPLE
PASSWORD your-EXAMPLEPASSWORD
方法C:使用安全配置文件
python scripts/generate
databasedoc.py --config /path/to/secure_config.json
步骤4:验证输出安全性
bash
检查文件权限
ls -la output.xlsx
设置安全权限(Unix系统)
chmod 600 output.xlsx
快速开始(简化版)
- 1. 安装依赖项:
bash
pip install psycopg2-binary pandas openpyxl
- 2. 设置环境变量:
bash
export DB
HOST=localhost DBNAME=mydb DB
USER=EXAMPLEUSER DB_PASSWORD=secret
- 3. 运行安全检查:
bash
python scripts/security_check.py
- 4. 生成文档:
bash
python scripts/generate
databasedoc.py
- 5. 该技能将:
- 验证安全配置
- 连接到数据库(如果配置了SSL则使用SSL)
- 提取表结构信息(只读)
- 生成格式化的Excel文档
- 应用适当的格式设置
- 尽可能设置安全的文件权限
数据库连接
该技能支持PostgreSQL数据库。请按以下格式提供连接详情:
python
{
host: your-host,
port: 5432,
database: your-database,
user: your-username,
EXAMPLEPASSWORD: your-EXAMPLEPASSWORD
}
输出特性
生成的Excel文件包含:
- 1. 专业格式设置:
- 每个表位于单独的工作表
- 表名作为合并的标题单元格位于列上方
- 自动调整列宽以提高可读性
- 清晰的列标题
- 2. 列信息:
- 列名(代码)
- 数据类型(数据类型)
- 长度/精度(长度)
- 必填标志(强制)
- 描述/注释(注释)
- 3. 默认值:
- varchar/character varying:默认长度2000
- timestamp/timestamptz/time/timetz:默认精度6
使用示例
示例1:为特定表生成文档
为表生成数据库文档:users, orders, products
主机:EXAMPLE_HOST,端口:5432,数据库:mydb
用户名:EXAMPLEUSER,密码:EXAMPLEPASSWORD
示例2:为所有表生成文档
为所有表创建数据库结构文档
连接:localhost:5432/mydb
凭据:EXAMPLEUSER/EXAMPLEPASSWORD
示例3:使用自定义输出路径导出结构
将数据库结构导出到 D:/docs/database.xlsx
表:customers, invoices, payments
连接详情:[提供详情]
高级功能
自定义表选择
- - 指定单个表名
- 使用通配符或模式(通过SQL WHERE子句)
- 省略以包含所有表
输出自定义
- - 默认输出:EXAMPLEPATH/databasedocumentation.xlsx
- 可指定自定义输出路径
- 如果目录不存在则自动创建
错误处理
- - 验证数据库连接
- 优雅处理缺失的表
- 提供详细的错误信息
- 如果某个表失败,继续处理其他表
脚本
该技能包含用于生成数据库文档的Python脚本。详见scripts/目录的实现细节。
参考
有关详细的SQL查询和格式设置选项,请参见references/。
注意事项
- - 仅执行SELECT查询(无修改操作)
- 尊重数据库权限
- 高效处理大型结构
- 保持数据完整性