chore(coderd/database): add pruning for orphaned chat file_ids entries#23985
Draft
chore(coderd/database): add pruning for orphaned chat file_ids entries#23985
Conversation
Add a new DeleteOrphanedChatFiles SQL query that removes chat_files rows older than 24 hours that are not referenced by any non-deleted chat message's content. Register this as a periodic job in the dbpurge package, following the existing pattern used by other purge operations. The query scans the JSONB content array of chat_messages for file_id references and preserves any chat_files still in use.
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.
Summary
Add a
dbpurgejob that periodically deletes orphanedchat_filesrows — files uploaded for chats but no longer referenced by any non-deleted chat message.Changes
DeleteOrphanedChatFilesincoderd/database/queries/chatfiles.sql: deleteschat_filesrows older than 24 hours that are not referenced by any non-deletedchat_messagescontent (JSONBfile_idfield).purgeTickloop with a 24-hour age threshold, matching the pattern of other purge jobs (logging, metrics).rbac.ResourceSystem/policy.ActionDeletein dbauthz, consistent with other bulk-delete operations.TestDeleteOrphanedChatFilesvalidates three scenarios: orphaned old file (deleted), referenced old file (kept), recent orphaned file (kept).Closes #23910