Skip to content

feat: add stats command#2

Merged
nilshamerlinck merged 2 commits into
mainfrom
feat/stats
May 15, 2026
Merged

feat: add stats command#2
nilshamerlinck merged 2 commits into
mainfrom
feat/stats

Conversation

@xaviedoanhduy
Copy link
Copy Markdown
Member

@xaviedoanhduy xaviedoanhduy commented May 14, 2026

Summary

  • New command odoo-db stats <db> — per-table record counts, sizes, and year breakdown
  • Options: --years N (default 3), --top N (default 20 tables by size)
  • Per-table metrics: total records, table size, index sizes, attachment sizes (dedup by checksum)
  • Per-year record counts for last N years
  • Footer row with totals across top N tables
  • Column legend explaining each metric
  • Maps table names to Odoo model names via ir_model
  • Uses sql.Identifier + make_interval for safe dynamic SQL
  • Supports text (rich table), json, prometheus output formats

Test plan

  • odoo-db stats <db> — shows top 20 tables with all metrics
  • odoo-db stats <db> --years 5 --top 10 — custom years/top
  • Footer row shows correct totals
  • odoo-db --output-format json stats <db> — JSON output
  • odoo-db --output-format prometheus stats <db> — Prometheus output
  • Tested on Odoo 16, 17, 18, 19

Implement odoo-db CLI for local Odoo database management.

Commands: list, modules, crons, jobs, users, locks
- list: all local Odoo DBs with version, neutralized status; --verbose adds module/user count
- modules: installed modules with version
- crons: active scheduled actions
- jobs: queue job counts by state
- users: active users with online/away/offline status (via bus_presence or mail_presence)
- locks: active DB locks with blocked/blocking PIDs and queries

Features:
- psycopg3 Unix socket connection (peer auth, no credentials)
- Output formats: text (rich table with borders), json, prometheus
- Logging: --log-level/--log-file, auto-created logs dir
- Friendly error messages for DB connection failures
- GitHub Actions: CI tests (pytest), pre-commit, semantic release to PyPI
- Smoke tests for CLI help commands
…eakdown

New command: odoo-db stats <db> [--years N] [--top N]

- Top N tables by size with: total records, table size, index sizes,
  attachment sizes (dedup by checksum), and per-year record counts
- Detects Odoo tables via pg_attribute (create_date column)
- Maps table names to Odoo model names via ir_model
- Uses sql.Identifier + make_interval for safe dynamic SQL
- Footer row showing totals across top N tables
- Column legend explaining each metric
- Supports text (rich table), json, prometheus output formats
- Tested on Odoo 16, 17, 18, 19
@nilshamerlinck nilshamerlinck merged commit d58bc66 into main May 15, 2026
5 checks passed
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.

2 participants