database-doc-generator

👤 gitoftom 📦 v1.0.1 ⭐ 4.4 ⬇️ 1.3K 下载
💻 开发编程 免费 🔑 需 API Key

📖 技能介绍


name: database-doc-generator description: Generate professional database structure documentation from PostgreSQL databases. Creates Excel files with table schemas, column details, and formatting. Use when user needs to document database structure, export schema information, or create data dictionaries. Triggers on phrases like "generate database documentation", "export database schema", "create data dictionary", "database structure export", "PostgreSQL documentation".


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
  2. Use environment variables or secure configuration files for credentials
  3. Review all database connections before use
  4. This skill requires network access to PostgreSQL databases
  5. 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

# Method A: Virtual Environment (RECOMMENDED)
python -m venv venv-database-docs
source venv-database-docs/bin/activate  # On Windows: venv-database-docs\Scripts\activate

# Method B: With pinned versions for security
pip install -r requirements.txt

# Method C: Manual installation
pip install psycopg2-binary==2.9.9 pandas==2.2.1 openpyxl==3.1.2

Step 2: Security Validation (MANDATORY)

# Run comprehensive security check
python scripts/security_check.py

# Expected output: "SECURITY CHECK PASSED"
# If warnings appear, review and fix before proceeding

Step 2: Set Secure Credentials

NEVER hardcode credentials. Use environment variables:

# Set credentials via environment variables (RECOMMENDED)
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-EXAMPLE_PASSWORD

# Optional: Enable SSL for secure connections
export DB_SSLMODE=require

Step 3: Generate Documentation Securely

# Method A: Using environment variables (most secure)
python scripts/generate_database_doc.py

# Method B: With command-line arguments
python scripts/generate_database_doc.py \
  --host your-host \
  --database your-db \
  --user your-user \
  --EXAMPLE_PASSWORD your-EXAMPLE_PASSWORD

# Method C: Using secure config file
python scripts/generate_database_doc.py --config /path/to/secure_config.json

Step 4: Verify Output Security

# Check file permissions
ls -la output.xlsx

# Set secure permissions (Unix)
chmod 600 output.xlsx

Quick Start (Simplified)

  1. Install dependencies: bash pip install psycopg2-binary pandas openpyxl

  2. Set environment variables: bash export DB_HOST=localhost DB_NAME=mydb DB_USER=EXAMPLE_USER DB_PASSWORD=secret

  3. Run security check: bash python scripts/security_check.py

  4. Generate documentation: bash python scripts/generate_database_doc.py

  5. The skill will:

  6. Validate security configuration
  7. Connect to the database (with SSL if configured)
  8. Extract table structure information (read-only)
  9. Generate formatted Excel documentation
  10. Apply proper formatting
  11. Set secure file permissions when possible

Database Connection

The skill supports PostgreSQL databases. Provide connection details in this format:

{
    'host': 'your-host',
    'port': 5432,
    'database': 'your-database',
    'user': 'your-username',
    'EXAMPLE_PASSWORD': 'your-EXAMPLE_PASSWORD'
}

小葱技能站7w4.net每天更新,海量AI技能等你发现。

Output Features

The generated Excel file includes:

  1. Professional Formatting:
  2. Each table on a separate worksheet
  3. Table name as merged header cell above columns
  4. Auto-adjusted column widths for readability
  5. Clear column headers

  6. Column Information:

  7. Column name (代码)
  8. Data type (数据类型)
  9. Length/precision (长度)
  10. Mandatory flag (强制)
  11. Description/comment (注释)

  12. Default Values:

  13. varchar/character varying: Default length 2000
  14. timestamp/timestamptz/time/timetz: Default precision 6

Usage Examples

Example 1: Generate documentation for specific tables

Generate database documentation for tables: users, orders, products
Host: EXAMPLE_HOST, Port: 5432, Database: mydb
Username: EXAMPLE_USER, Password: EXAMPLE_PASSWORD

Example 2: Generate documentation for all tables

Create database structure documentation for all tables
Connection: localhost:5432/mydb
Credentials: EXAMPLE_USER/EXAMPLE_PASSWORD

Example 3: Export schema with custom output path

Export database schema to D:/docs/database.xlsx
Tables: customers, invoices, payments
Connection details: [provide details]

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: EXAMPLE_PATH/database_documentation.xlsx
  • 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

🤖 AI 评测

这个数据库文档生成工具质量不错,特别适合需要快速生成数据库结构文档的用户。它能把 PostgreSQL 数据库表结构自动转成带格式的 Excel 文件,表格清晰好看。最大的优点是安全意识很强,有专门的安全检查和凭据保护机制。不足之处是功能比较专一,目前只能用于 PostgreSQL 数据库,如果你用的是其他数据库就不太适用了。总体来说,对于 PostgreSQL 用户,这是一个值得信赖的工具。

📊 多维度评分

适应性4.4
规范性4.5
有效性4.3
可靠性4.3
可信度4.7

📁 包含文件 (20 个)

📄 .pre-commit-config.yaml 1.8 KB
📄 CREDENTIAL_HYGIENE.md 5.7 KB
📄 EMERGENCY_RESPONSE.md 5.8 KB
📄 FIXES_SUMMARY.md 4.8 KB
📄 INSTALLATION_SECURE.md 6.5 KB
📄 README.md 3.9 KB
📄 SECURITY.md 5.4 KB
📄 SKILL.md 6.3 KB
📄 _meta.json 141 B
📄 references/EXCEL_FORMATTING.md 8.6 KB
📄 references/SQL_QUERIES.md 5 KB
📄 references/USAGE_EXAMPLES.md 10.4 KB
📄 requirements-dev.txt 525 B
📄 requirements.txt 545 B
📄 scripts/clean_credentials.py 6.5 KB
📄 scripts/config_example.json 1.1 KB
📄 scripts/generate_database_doc.py 17.3 KB
📄 scripts/quick_generate.py 6.9 KB
📄 scripts/security_check.py 10.8 KB
📄 secure_config_template.json 2 KB