Skip to content

fix(api): delete message reactions before purging a channel account - #524

Merged
setkyar merged 1 commit into
mainfrom
fix/purge-channel-account-reactions
Nov 23, 2026
Merged

setkyar merged 1 commit into
mainfrom
fix/purge-channel-account-reactions

Conversation

@setkyar

@setkyar setkyar commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #380.

Problem

message_reactions.channel_account_id references channel_accounts with ON DELETE RESTRICT, but purgeArchivedChannelAccount never deleted the reactions. Purging any archived Telegram (channel-neutral) account with even one reaction failed and rolled back every time.

Fix

Before deleting the messages and the account, delete:

  • the account's reactions, and
  • reactions on the account's messages that have no channel_account_id (message_id has no foreign key, so these would otherwise be left orphaned).

Everything stays inside the existing purge transaction.

Tests

  • Extended purge integration test: the archived account has a reaction with its channel_account_id and a legacy one without it. Both are deleted and the purge completes. A reaction belonging to another account survives.
  • Rebased on main. Typecheck, biome and channel-account-purge.integration.test.ts pass on a fresh Postgres 18.

Release

No migration. worker: skip.

message_reactions.channel_account_id references channel_accounts with
ON DELETE RESTRICT, but purgeArchivedChannelAccount never deleted the
reactions, so purging any archived Telegram account that had a single
reaction failed and rolled back every time.

Delete the account's reactions, and reactions on its messages that have
no channel_account_id (message_id has no foreign key), before the
messages and the account.

Fixes #380
@setkyar
setkyar force-pushed the fix/purge-channel-account-reactions branch from fe7a9c4 to 36acc5b Compare November 23, 2026 17:46
@setkyar
setkyar merged commit 275bd28 into main Nov 23, 2026
9 checks passed
@setkyar
setkyar deleted the fix/purge-channel-account-reactions branch November 23, 2026 18:03
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.

[Detail Bug] Channel account purge fails when reactions exist (FK RESTRICT blocks deletion)

1 participant