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
-
Clone/Download the tool to your local machine
-
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 .
-
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
- Develop scripts in individual project repositories
- Scan repositories to see available scripts:
uvx db-archivist scan
- Consolidate scripts for deployment:
uvx db-archivist consolidate -p basicdata --pi pi07 --from-script 41 --to-script 46
- Check status before deployment:
uvx db-archivist status --pi pi07
- Deploy to TST (manually execute the consolidated script)
- Verify deployment:
uvx db-archivist db-status -e TST
- 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
- Repository not found: Check paths in
config.yaml - Permission denied: Ensure write access to target directories
- Database connection failed: Verify network access and credentials
- 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
- Test changes thoroughly with
--dry-runflags - Update documentation for new features
- Follow existing code patterns and error handling
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file db_archivist-0.0.2.tar.gz.
File metadata
- Download URL: db_archivist-0.0.2.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5741140e509f10cc8f4fe8b3c6627cb50e89ac96beebc77f67f714953667df57
|
|
| MD5 |
88b1f6160d5e71f41f1043246dbe87e6
|
|
| BLAKE2b-256 |
494b80742fa2921907a78f04177b5d4a834a880baf1f26bb22774e50293f273f
|
File details
Details for the file db_archivist-0.0.2-py3-none-any.whl.
File metadata
- Download URL: db_archivist-0.0.2-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc78bf13b6dff513c7e74b6f203e08a546a5f567ade677e0602f6a4430a0cb0c
|
|
| MD5 |
f3f33830f16673f6a770158b3df690e9
|
|
| BLAKE2b-256 |
221e500d0684dcd3f5f735882ba3fa304a6db92811b2dbb299c7e05c42509e13
|