Skip to content

Add --db parameter support to CLI commands#304

Draft
himdel wants to merge 1 commit intoansible:develfrom
himdel:db
Draft

Add --db parameter support to CLI commands#304
himdel wants to merge 1 commit intoansible:develfrom
himdel:db

Conversation

@himdel
Copy link
Contributor

@himdel himdel commented Dec 18, 2025

Add a --db=json parameter to gather_automation_controller_billing_data and build_report commands to allow custom database connections via JSON configuration.

When not provided, defaults to existing Django connection as before.
When provided, it gets parsed as json, default values for ENGINE, HOST & PORT are added,
and it all gets passed to Django's ConnectionHandler.

The implementation uses a configurable singleton (metrics_utility/db.py), configured by the commands,
all previous usage of django.db.connection updated to use get_connection() instead

Example:

uv run python manage.py gather_automation_controller_billing_data \
    --db='{"NAME":"awx","USER":"admin","PASSWORD":"secret"}' \
    --since=2024-01-01

Assisted by Claude


wip test properly
see how far we are from dropping the awx dependency without breaking things

Add --db parameter to both gather_automation_controller_billing_data and build_report commands to allow custom database connections via JSON configuration. When not provided, defaults to existing Django connection behavior for full backward compatibility.

The implementation uses a configurable connection module (metrics_utility/db.py) that acts as a singleton, avoiding the need to pass connections through function parameters. All database usage updated to use get_connection() instead of importing django.db.connection directly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant