Skip to main content

Database Script Manager CLI for managing scripts across multiple repositories with deployment tracking

Project description

Database Script Manager CLI

A comprehensive CLI tool for managing database scripts across multiple repositories with deployment tracking and automated documentation.

Features

🚀 Script Consolidation: Automatically consolidate scripts from individual project repositories to the centralized db-scripts repository 🔒 Transaction Safety: Wrap all scripts in transactions with proper error handling 📊 Database Tracking: Track script execution with detailed logging in the database 📝 Automated Documentation: Automatically update README files in versions repository 📋 Deployment Reports: Generate comprehensive deployment status reports 🔍 Cross-Repository Visibility: See deployment status across all projects and environments

Installation

Option 1: Using uvx (Recommended)

The easiest way to use the tool is with uvx, which runs it directly without global installation:

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Option 1a: Run directly with uvx
uvx db-archivist --help
uvx db-archivist scan

# Option 1b: Use the convenience script (shorter commands)
chmod +x db-archivist.sh
./db-archivist.sh --help
./db-archivist.sh scan

Option 2: Traditional Installation

  1. Clone/Download the tool to your local machine

  2. Install with uv:

    # Install uv if needed
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # Install the tool
    uv pip install -e .
    
    # Or install with pip
    pip install -e .
    
  3. Run the tool:

    db-archivist --help
    

Configuration

On first run, the tool will create a config.yaml file with default settings. Update the paths to match your repository structure:

repositories:
  scripts_repo: "../db-scripts"
  versions_repo: "../versions"

projects:
  -basicdata:
    source_repo: "../basicdata-backend"
    source_path: "database/dev"
    script_path: "app_basicdata"
    versions_path: "basicdata"
  -tool-workflow:
    source_repo: "../tool-backend"
    source_path: "database/DEV"
    script_path: "app_tool"
    versions_path: "tool"

database_tracking:
  enabled: true
  table_name: "script_execution_log"
  view_name: "v_script_execution_status"

environments:
  - TST
  - HMG
  - PRD

Usage

🔍 Scan Repositories

Scan all configured repositories to see available scripts:

uvx db-archivist scan

📦 Consolidate Scripts

Consolidate scripts from a project repository for a specific PI:

# Consolidate specific range of scripts
uvx db-archivist consolidate -p -basicdata-supplies --pi gpsub-pi07 --from-script 41 --to-script 46

# Consolidate all scripts (dry run first)
uvx db-archivist consolidate -p -basicdata-supplies --pi gpsub-pi07 --dry-run

📊 Check Status

Check deployment status across projects and environments:

# Status for specific PI
uvx db-archivist status --pi pi07

# Status for specific project
uvx db-archivist status -p basicdata

# Overall status with database verification
uvx db-archivist status --check-database

# Status for specific environment
uvx db-archivist status -e PRD

📋 Generate Reports

Generate deployment reports:

# Report for specific PI
uvx db-archivist deployment-report --pi pi07

# Report for specific PI and environment
uvx db-archivist deployment-report --pi pi07 -e PRD

📦 Create Deployment Packages

Create deployment packages with all necessary scripts:

uvx db-archivist package --pi pi07 -e PRD -o ./deployments

🗄️ Database Operations

Set up database tracking (run once per environment):

uvx db-archivist setup-tracking

Check database execution status:

# Check all environments
uvx db-archivist db-status

# Check specific environment
uvx db-archivist db-status -e TST

Generated Output

Consolidated Scripts

The tool generates consolidated scripts with:

  • Transaction wrapping (BEGIN/COMMIT)
  • Database tracking with execution logging
  • Error handling and rollback on failure
  • Individual script sections with clear headers
  • GPSUB ticket references

Example output structure:

-db-scripts/
└── scripts/
    └── pi07/
        └── postgres/
            └── u/
                └── app_basicdata/
                    ├── 41-46-CONSOLIDATED.sql  # Main consolidated script
                    ├── 41-UPDATE(1439).sql
                    ├── 42-UPDATE(1525).sql
                    ├── ...
                    └── README.md  # Auto-generated documentation

Documentation Updates

Automatically updates -versions README files with:

  • Script deployment tables
  • GitHub links to scripts
  • Deployment dates per environment
  • Version tracking

Database Tracking

Creates tracking tables with:

-- Query execution status
SELECT * FROM script_execution_log 
WHERE pi_number = 'pi07' 
ORDER BY execution_date DESC;

-- Use the view for formatted output
SELECT * FROM v_script_execution_status 
WHERE pi_number = 'pi07';

Command Reference

Command Description Example
scan Scan all repositories for scripts uvx db-archivist scan
consolidate Consolidate scripts for a PI uvx db-archivist consolidate -p project --pi pi07
status Show deployment status uvx db-archivist status --pi pi07
deployment-report Generate deployment report uvx db-archivist deployment-report --pi pi07
package Create deployment package uvx db-archivist package --pi pi07 -e PRD
db-status Check database execution logs uvx db-archivist db-status -e TST
setup-tracking Setup database tracking uvx db-archivist setup-tracking

Example Workflow

  1. Develop scripts in individual project repositories
  2. Scan repositories to see available scripts:
    uvx db-archivist scan
    
  3. Consolidate scripts for deployment:
    uvx db-archivist consolidate -p basicdata --pi pi07 --from-script 41 --to-script 46
    
  4. Check status before deployment:
    uvx db-archivist status --pi pi07
    
  5. Deploy to TST (manually execute the consolidated script)
  6. Verify deployment:
    uvx db-archivist db-status -e TST
    
  7. Promote to HMG and PRD following the same process

Error Handling

The tool includes comprehensive error handling:

  • Validation of repository paths and configurations
  • Rollback on script consolidation errors
  • Connection timeouts for database operations
  • Detailed error messages with troubleshooting guidance

Database Requirements

  • PostgreSQL 9.6 or higher
  • Permissions to create tables and views
  • Network access to database servers

Troubleshooting

Common Issues

  1. Repository not found: Check paths in config.yaml
  2. Permission denied: Ensure write access to target directories
  3. Database connection failed: Verify network access and credentials
  4. Scripts not found: Check source repository paths and script naming

Debug Mode

Add --verbose flag to any command for detailed logging:

uvx db-archivist status --pi pi07 --verbose

Contributing

  1. Test changes thoroughly with --dry-run flags
  2. Update documentation for new features
  3. Follow existing code patterns and error handling
  4. Add tests for new functionality

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_archivist-0.0.4.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_archivist-0.0.4-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file db_archivist-0.0.4.tar.gz.

File metadata

  • Download URL: db_archivist-0.0.4.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.1

File hashes

Hashes for db_archivist-0.0.4.tar.gz
Algorithm Hash digest
SHA256 f108defa40bc483cf9f29651ec27690cbc3733c471fbccc8cbdfc635b328fad8
MD5 e388a02c52d42288202dff7e003c2028
BLAKE2b-256 d1f1beb5f75fa7a785a231dc0eba29f6dc147bf93e8ba01b32854486c4de5070

See more details on using hashes here.

File details

Details for the file db_archivist-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for db_archivist-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ac462f6e355b368f5ea0e0c8a046f1c55b08835a5266b325c9a4cc1658c9ce02
MD5 905eedcb8b5723cba12a45bca8ee8b62
BLAKE2b-256 d9ff447bba144503d26fe78c9beff65b2852c1574ca47fc52e0df20c0e0c0a18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page