Skip to content

feat: add prepare-audit command (v4)#4

Merged
nilshamerlinck merged 2 commits into
mainfrom
feat/prepare-audit
May 15, 2026
Merged

feat: add prepare-audit command (v4)#4
nilshamerlinck merged 2 commits into
mainfrom
feat/prepare-audit

Conversation

@xaviedoanhduy
Copy link
Copy Markdown
Member

Summary

  • New odoo-db prepare-audit <db> command that bundles DB summary, installed modules, per-table stats, and non-Odoo objects (custom views, triggers, functions, procedures) into a single <db>.json export.
  • The JSON is the file the lead uploads/gives us, and feeds the upcoming /odoo-dev:audit-db skill (in trobz/skills) which generates an HTML pre-audit report (most-used / unused modules detection).
  • get_stats now supports top=0 (no LIMIT) so prepare-audit defaults to capturing all tables — required to detect low-record / unused modules.

Refs T67696 (v4).

Payload shape

{
  "db": "...",
  "version": "19.0",
  "neutralized": false,
  "module_count": 20,
  "user_count": 1,
  "generated_at": "2026-05-15T...",
  "modules": [{ "name": "...", "version": "..." }],
  "stats": { "db_size": "...", "years": [...], "tables": [...] },
  "not_odoo": { "views": [...], "triggers": [...], "functions": [...], "procedures": [...] }
}

Usage

odoo-db prepare-audit my_db                       # writes ./my_db.json
odoo-db --output-file /tmp/audit.json prepare-audit my_db
odoo-db prepare-audit my_db --years 5 --top 200   # narrow scope

Test plan

  • make check (lint + format + type-check)
  • make test (4 passed, includes new test_prepare_audit_help)
  • Live run against a real local Odoo DB (v19) — wrote ~38KB JSON, 102 tables, 20 modules, 0 non-Odoo objects.
  • Skill side (/odoo-dev:audit-db in trobz/skills) — separate PR.

Add `odoo-db prepare-audit <db>` that combines DB summary, installed
modules, per-table stats, and non-Odoo objects (custom views, triggers,
functions, procedures) into a single JSON export. This is the file the
lead uploads/gives us, and feeds the upcoming `/odoo-dev:audit-db`
skill that generates an HTML pre-audit report (most-used / unused
modules detection).

- New command: `odoo-db prepare-audit DB [--years N] [--top N]`
- Default output: `audits/<DB>.json` (gitignored, mirrors `logs/`
  pattern with `.gitkeep`); override via `--output-file`.
- Always JSON regardless of `--output-format`.
- `get_stats` now supports `top=0` (no `LIMIT`), so the audit defaults
  to capturing all tables — required to detect low-record / unused
  modules.

Compact JSON payload (~40-45% reduction on real DBs):
- Empty tables (`total_records == 0`) keep only `table`, `model`,
  `total_size_bytes`.
- Non-empty tables drop `table_size_bytes` (redundant); zero
  `index_size_bytes` / `attachment_size_bytes` are dropped.
- `year_counts` drops zero-count entries; key removed entirely when
  all years are zero. Top-level `stats.years[]` still advertises the
  measurement window.
- Index/attachment `sum()` results cast to `int` so JSON emits real
  numbers instead of quoted Decimal strings.

Consumers (the audit-db skill) should access dropped numeric fields
via `.get(key, 0)`.

Tooling:
- Align `ruff.toml` `target-version` to `py310` to match the project's
  `requires-python = ">=3.10"` and prevent the linter from rewriting
  `timezone.utc` to `datetime.UTC` (3.11+ only) and breaking CI.

Refs T67696 (v4).
@xaviedoanhduy xaviedoanhduy marked this pull request as ready for review May 15, 2026 09:51
Use `rich.progress.track` to render a transient progress bar (on
stderr) while iterating over per-table queries in `get_stats`. Gives
users live feedback on large databases where the per-table loop can
take minutes.

The bar auto-disables in non-TTY contexts (CI, piped output) and
writes to stderr, so JSON/Prometheus output on stdout is unaffected.

Also merged the previously separate `year_counts` and `count(*)`
loops into a single pass so the progress bar reflects a single
combined per-table scan rather than two sequential passes.
@nilshamerlinck nilshamerlinck merged commit b02d856 into main May 15, 2026
5 checks passed
Comment thread audits/.gitkeep
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why do we need this folder?

Comment thread odoo_db/main.py
):
"""Combine summary + modules + stats + not-odoo into a $db.json audit export.

Output goes to audits/$db.json by default (gitignored); override with
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Output goes to audits/$db.json by default (gitignored); override with
Output goes to ./$db.json by default (gitignored); override with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end users of this tool will not be running it in the source code folder

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