Refactor database models and update foreign key constraints#1552
Open
LuisMend12 wants to merge 2 commits into
Open
Refactor database models and update foreign key constraints#1552LuisMend12 wants to merge 2 commits into
LuisMend12 wants to merge 2 commits into
Conversation
Member
|
Preferably we would actually wipe these things out prior to deleting the bot; deleting a user should delete that user's data, not leave it dangling |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When attempting to delete certain bots, the deletion would silently fail or throw a database error. This happened because several foreign key constraints on related tables (messages, message reactions, user channel states, and eco accounts) were set to NO ACTION on delete. If a bot had any planet member activity — messages sent, reactions left, channel states recorded — the database would refuse to delete the bot's member record, blocking the entire deletion.
Fix
Updated the foreign key constraints on author_member_id and planet_member_id columns in the affected tables to use SET NULL on delete instead of NO ACTION. A database migration was added to apply these changes. Now when a bot is deleted, related records have their foreign key columns nulled out rather than preventing the operation.
Affected tables:
messages.author_member_id
message_reactions.author_member_id
user_channel_states.member_id
eco_accounts.planet_member_id