fix(database): add user soft-delete and fix audit_logs FK constraint (closes #344) - #493
Open
beulah7717108-eng wants to merge 1 commit into
Open
Conversation
…loses XStreamRollz#344) - Add deleted_at TIMESTAMPTZ column to users table for GDPR-compliant soft-delete - Update audit_logs.user_id FK to ON DELETE SET NULL to prevent orphaned rows - Add idx_users_deleted_at partial index for efficient soft-delete filtering - Update UsersRepository: filter WHERE deleted_at IS NULL on all read queries - Add softDelete method to UsersRepository - Implement DELETE /users/me endpoint in UsersController with token revocation - Add USER_DELETE audit action to AuditAction enum - Update integration tests to verify deleted_at column exists - Create migration 2026082001 with up/down rollback support
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
Closes #344 — users table has no soft-delete: deleted users leave orphaned foreign keys.
Changes
Database
deleted_at TIMESTAMPTZcolumn to theuserstable for GDPR-compliant soft-deleteaudit_logs.user_idFK toON DELETE SET NULLto prevent orphaned rows when a user is deletedidx_users_deleted_atpartial index on non-null deleted_at values for efficient filtering2026082001_add_user_soft_deletewith up/down rollback supportdatabase/schema.sqlanddatabase/audit_logs.sqlto reflect the cumulative schema stateAPI
WHERE deleted_at IS NULLfilter to all read queries (findByEmail,findByUsername,findById,updateProfile,updatePasswordHash)softDelete(id)method that setsdeleted_at = NOW()deleteUser()method with token revocation and audit loggingDELETE /users/meendpoint (204 No Content, rate-limited)USER_DELETEaction for audit traildeleted_atcolumn existsTesting
IF EXISTS/IF NOT EXISTSguards)Migration