Repository navigation
fix(activity-logger): handle FK constraint violation for deleted pages - #211
Conversation
The activity_logs table has a foreign key constraint on pageId referencing the pages table. This was causing errors when: 1. A page was permanently deleted and activity was logged for the delete operation (the page no longer exists when the log is inserted) 2. Async fire-and-forget activity logging raced with page deletion (the page existed when logging was scheduled but was deleted before the async operation completed) Changes: - logPageActivity: Skip setting pageId for 'delete' operations since the page no longer exists. Audit info is preserved via resourceId/resourceTitle. - logActivity: Catch FK constraint violation (code 23503) on pageId and retry the insert without pageId. This handles race conditions gracefully where a page is deleted during async logging. Fixes foreign key constraint error: "insert or update on table activity_logs violates foreign key constraint activity_logs_pageId_pages_id_fk"
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughModified activity logger to handle foreign key constraint violations when pageId references deleted pages. Added retry logic that reinserts activity logs without pageId on constraint failure. For delete operations, pageId is intentionally omitted since the referenced page no longer exists. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx,json}📄 CodeRabbit inference engine (AGENTS.md)
Files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (3)
✏️ Tip: You can disable this entire section by setting 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 |
The activity_logs table has a foreign key constraint on pageId referencing the pages table. This was causing errors when:
A page was permanently deleted and activity was logged for the delete operation (the page no longer exists when the log is inserted)
Async fire-and-forget activity logging raced with page deletion (the page existed when logging was scheduled but was deleted before the async operation completed)
Changes:
logPageActivity: Skip setting pageId for 'delete' operations since the page no longer exists. Audit info is preserved via resourceId/resourceTitle.
logActivity: Catch FK constraint violation (code 23503) on pageId and retry the insert without pageId. This handles race conditions gracefully where a page is deleted during async logging.
Fixes foreign key constraint error:
"insert or update on table activity_logs violates foreign key constraint activity_logs_pageId_pages_id_fk"
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.