feat: add prepare-audit command (v4)#4
Merged
Conversation
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).
184c202 to
1d744ad
Compare
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.
Contributor
There was a problem hiding this comment.
wait why do we need this folder?
| ): | ||
| """Combine summary + modules + stats + not-odoo into a $db.json audit export. | ||
|
|
||
| Output goes to audits/$db.json by default (gitignored); override with |
Contributor
There was a problem hiding this comment.
Suggested change
| Output goes to audits/$db.json by default (gitignored); override with | |
| Output goes to ./$db.json by default (gitignored); override with |
Contributor
There was a problem hiding this comment.
end users of this tool will not be running it in the source code folder
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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>.jsonexport./odoo-dev:audit-dbskill (introbz/skills) which generates an HTML pre-audit report (most-used / unused modules detection).get_statsnow supportstop=0(noLIMIT) soprepare-auditdefaults 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
Test plan
make check(lint + format + type-check)make test(4 passed, includes newtest_prepare_audit_help)/odoo-dev:audit-dbintrobz/skills) — separate PR.