Add migration to dismiss inbox items for closed branches
Intent: Introduce a data-cleanup migration that transitions branch inbox items from 'inbox' to 'dismissed' state when the associated branch is no longer open, preventing stale inbox entries from accumulating.
Affected files: crates/pika-news/migrations/0019_dismiss_closed_branch_inbox.sql
@@ -0,0 +1,11 @@
+UPDATE branch_inbox_states
+SET state = 'dismissed',
+ reason = 'branch_closed',
+ dismissed_at = COALESCE(dismissed_at, CURRENT_TIMESTAMP),
+ updated_at = CURRENT_TIMESTAMP
+WHERE state = 'inbox'
+ AND branch_id IN (
+ SELECT id
+ FROM branch_records
+ WHERE state != 'open'
+ );
A new migration 0019_dismiss_closed_branch_inbox.sql is added. It bulk-updates all branch_inbox_states rows that are still in the 'inbox' state but belong to branches whose state is no longer 'open'. These rows are transitioned to 'dismissed' with reason 'branch_closed', using COALESCE on dismissed_at to preserve any previously recorded timestamp.
This is a one-time data cleanup that ensures closed branches don't leave dangling inbox items for users.