Skip to content

fix: cascade channel_messages on packet delete - #96

Merged
446564 merged 1 commit into
MeshCore-Beacon:devfrom
MrAlders0n:fix/channel-messages-cascade
Aug 11, 2026
Merged

fix: cascade channel_messages on packet delete#96
446564 merged 1 commit into
MeshCore-Beacon:devfrom
MrAlders0n:fix/channel-messages-cascade

Conversation

@MrAlders0n

@MrAlders0n MrAlders0n commented Aug 5, 2026

Copy link
Copy Markdown
Member

Suggested title: Fix packet retention by adding ON DELETE CASCADE to channel_messages FK

What this PR does

channel_messages.packet_hash references packets with no ON DELETE action, and nothing ever deletes from channel_messages. So any packet carrying a channel message can never age out. Since DeleteOldPackets is a single statement, one blocked row kills the whole delete:

ERROR: update or delete on table "packets" violates foreign key constraint
"channel_messages_packet_hash_fkey" on table "channel_messages" (SQLSTATE 23503)

End result is packet retention silently fails every cleanup tick once your channel traffic is older than your retention window. Easy to miss on a newer deployment since nothing has expired yet. I only found it after lowering retention on a DB that had grown to 83 GB.

Migration 023 recreates the FK with ON DELETE CASCADE, same as packet_observations already does. Channel messages now age out with their packets. Used DROP CONSTRAINT IF EXISTS so it stays idempotent if you already patched this by hand.

Testing notes

Migration only, so sqlc generate is a no-op. Verified on a live deployment, both FKs on packets now show confdeltype = 'c' and the hourly cleanup went from failing every tick to done in a few seconds.

Heads up if your DB has been stuck for a while: the first cleanup after the fix does the entire backlog in one statement and can take a long time. Don't restart the app mid purge, it rolls the whole thing back. And plain DELETE doesn't give space back to the OS, so run a VACUUM FULL after if you actually want the files to shrink.

@MrAlders0n
MrAlders0n requested a review from 446564 as a code owner August 5, 2026 14:12
@MrAlders0n MrAlders0n closed this Aug 7, 2026
@MrAlders0n
MrAlders0n deleted the fix/channel-messages-cascade branch August 7, 2026 13:13
@MrAlders0n
MrAlders0n restored the fix/channel-messages-cascade branch August 7, 2026 14:08
@MrAlders0n MrAlders0n reopened this Aug 7, 2026
@446564
446564 merged commit c6d23a2 into MeshCore-Beacon:dev Aug 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants