Skip to content

RM-220: Fix guild purge failing on foreign keys and dropped tables - #41

Open
biast12 wants to merge 2 commits into
masterfrom
RM-220
Open

RM-220: Fix guild purge failing on foreign keys and dropped tables#41
biast12 wants to merge 2 commits into
masterfrom
RM-220

Conversation

@biast12

@biast12 biast12 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

PurgeGuildData has a hardcoded table list that nothing keeps in sync with the schema. It was correct when written (ea0f319, 2026-01-06) and has drifted since, so guild purges fail and the guild is retried every 6 hours forever.

Two independent faults:

  1. DELETE FROM tickets raises 23503. The 2026.08 release (53077b5) added ticket_message_counts with FOREIGN KEY(guild_id, ticket_id) REFERENCES tickets(...) and no ON DELETE action, and never added it to the purge list. webhooks has the same FK shape and is in the list, but sits 41 entries after tickets — dormant only because webhook rows exist solely for open tickets.
  2. Five names in the list have no CREATE TABLE any more. 53077b5 deleted the archive_channel, naming_scheme, ticket_limit, ticket_permissions and welcome_messages wrappers but left them in guildpurge.go. A DELETE against a missing relation raises 42P01 and aborts the whole transaction.

For: TicketsBot-cloud/cleanupdaemon#4

Type of Change

  • Bug fix
  • New feature
  • Breaking change

Checklist

  • My code follows the style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Refactors guild purge into explicit indirect, ordered, and legacy table groups to prevent FK violations and cover previously missed guild-scoped data (including panel children, KB, labels, and experiment/gallery records). Adds a shared purge helper with per-table logging and relation existence checks so missing legacy tables no longer abort the whole purge transaction. Also updates module metadata and bumps `github.com/TicketsBot-cloud/common` (with local replace) plus `golang.org/x/sys`.
@biast12
biast12 requested a review from a team as a code owner September 4, 2026 16:36
@github-actions github-actions Bot added needs:gomod_comment go.mod has uncommented local replace directives type:bug Bug Fixes labels Sep 4, 2026
@BenHall-1

Copy link
Copy Markdown
Member

Good to bump common when you're ready @biast12

@biast12

biast12 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Bumped!!!

@github-actions github-actions Bot removed the needs:gomod_comment go.mod has uncommented local replace directives label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants