Add aggregated Postgres writer for status change topic#189
Add aggregated Postgres writer for status change topic#189kevinwallimann wants to merge 10 commits into
Conversation
WalkthroughAdds a Postgres aggregation feature for status_change events: a new ADR document describing the job table design, an upsert SQL query with merge semantics, writer dispatch logic to persist events, schema/config updates, and comprehensive integration tests. ChangesStatus Change Aggregation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant EventGate
participant WriterPostgres
participant Postgres
Client->>EventGate: POST status_change event
EventGate->>WriterPostgres: _write_topic(TOPIC_STATUS_CHANGE, event)
WriterPostgres->>WriterPostgres: _upsert_status_change(event)
WriterPostgres->>WriterPostgres: map event_type to created_at/started_at/finished_at
WriterPostgres->>Postgres: execute upsert_status_change (ON CONFLICT job_id DO UPDATE)
Postgres-->>WriterPostgres: aggregated job row upserted
WriterPostgres-->>EventGate: commit
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a7f6b26 to
83fb752
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
adr/001-status-change-db/001-status-change-db.md (1)
51-59: 🩺 Stability & Availability | 🔵 TrivialVerify FK constraints don't break out-of-order parent-child event processing.
The ADR defines FK constraints on
parent_job_idandinitial_job_id, but also states events may be received out-of-order during failure scenarios. If a child job event arrives before its parent event, the FK constraint would reject the insert. The integration test schema intentionally omits these constraints, so this scenario is untested. Confirm whether parent-child event ordering is guaranteed in production, or whether the FK constraints should be deferred or removed.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@adr/001-status-change-db/001-status-change-db.md` around lines 51 - 59, The FK constraints on parent_job_id and initial_job_id in the ADR may conflict with out-of-order event arrival, so review the intended production ordering guarantees before keeping them as immediate constraints. Update the schema/design in the ADR to either state that parent events always exist first, or change the FK approach to deferred enforcement or remove the constraints; reference the job relationship constraints and the event processing flow described in the status-change DB design.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@adr/001-status-change-db/001-status-change-db.md`:
- Around line 51-59: The FK constraints on parent_job_id and initial_job_id in
the ADR may conflict with out-of-order event arrival, so review the intended
production ordering guarantees before keeping them as immediate constraints.
Update the schema/design in the ADR to either state that parent events always
exist first, or change the FK approach to deferred enforcement or remove the
constraints; reference the job relationship constraints and the event processing
flow described in the status-change DB design.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 548c66cc-bac2-47cc-949d-a932af83f3d8
📒 Files selected for processing (9)
DEVELOPER.mdadr/001-status-change-db/001-status-change-db.mdconf/access.jsonsrc/utils/constants.pysrc/writers/sql/inserts.sqlsrc/writers/writer_postgres.pytests/integration/conftest.pytests/integration/schemas/postgres_schema.pytests/integration/test_status_change_writer.py
Overview
Release Notes
Related
Closes #188
Summary by CodeRabbit
New Features
Bug Fixes
Documentation