Merged
Conversation
Adds a mechanism for grouping related audit log entries together and attaching an optional note to describe the batch. Uses a shared `_history_json` groups table with a `current` sentinel column that triggers look up via subquery. - New `_history_json` table: id, note, current (indexed) - Audit tables gain `[group]` column (FK to groups table) - All three triggers (INSERT/UPDATE/DELETE) include group subquery - `change_group(conn, note=None)` context manager for Python API - `get_history()` and `get_row_history()` return group/group_note - `populate()` respects active change group - 16 new tests covering all grouping scenarios - Updated README with schema docs, usage examples, API reference - Showboat demo document https://claude.ai/code/session_0173nuhzUEdDinKYkVybuy3h
If multiple rows somehow had current=1, the scalar subquery would silently pick an arbitrary one. Two fixes: 1. Partial unique index on current WHERE current = 1 — prevents multiple active groups at the database level 2. ORDER BY id DESC LIMIT 1 on all group subqueries — deterministic even if the constraint is somehow bypassed Belt and suspenders. https://claude.ai/code/session_0173nuhzUEdDinKYkVybuy3h
The partial unique index on current WHERE current = 1 already makes multiple active groups impossible. The ORDER BY id DESC LIMIT 1 was redundant — it masked a state that can't happen. Simpler subquery. https://claude.ai/code/session_0173nuhzUEdDinKYkVybuy3h
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.
(It fixed the design flaw: "Your design was fundamentally sound. The one change I made: triggers don’t auto-create groups. Instead they just look up (SELECT id FROM [_history_json] WHERE current = 1) — which returns NULL when no group is active. This sidesteps the “how to clean up at transaction end” problem entirely".)
Adds a mechanism for grouping related audit log entries together and
attaching an optional note to describe the batch. Uses a shared
_history_jsongroups table with acurrentsentinel column thattriggers look up via subquery.
_history_jsontable: id, note, current (indexed)[group]column (FK to groups table)change_group(conn, note=None)context manager for Python APIget_history()andget_row_history()return group/group_notepopulate()respects active change grouphttps://claude.ai/code/session_0173nuhzUEdDinKYkVybuy3h