Skip to content

refactor: keep the author of commits until the code that deletes a profile clears it - #1376

Merged
mnapoli merged 1 commit into
productionfrom
refactor/plain-commit-author-fk
Nov 1, 2026
Merged

mnapoli merged 1 commit into
productionfrom
refactor/plain-commit-author-fk

Conversation

@mnapoli

@mnapoli mnapoli commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of letting organizations post commits (#938): deleting a profile no longer clears the author of its commits in the database. DeleteUser and DeleteOrganization already clear it in code before deleting the profile, so a deletion path that forgets to now fails, instead of leaving a live commit without its author.

ON DELETE SET NULL on commits.author_id was only there for #1346's deploy window, while code that posted commits without an author was still running. That code is gone, and the app's rule is that deletion logic lives in code.

Changes

  • Migration: commits_author_id_foreign becomes a plain foreign key, with no action on delete.
    • It is replaced in one statement, so commits always have a foreign key. It is added NOT VALID, then validated in a separate statement, so the scan doesn't hold up new commits.
    • It runs outside a transaction and can be run again.
  • Code paths that delete a profile: I checked them and none needed a change.
    • DeleteUser clears author_id on the tombstones it leaves.
    • DeleteOrganization deletes the organization's commits and clears their author before deleting the profile.
    • Nothing else deletes a profile.
  • Tests:
    • The existing tests already check that DeleteUser and DeleteOrganization leave no commit pointing at the deleted profile. With the plain key, they would now also fail on any missed cleanup.
    • One new test checks the rule itself: deleting a profile that commits still point to fails.

Limitations

  • No user-visible change.

Summary by CodeRabbit

  • Bug Fixes
    • Profiles referenced as commit authors can no longer be deleted, preserving commit author information. Deleting a profile that is still associated with a commit is rejected.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ceaa985-e2c1-49b5-a56e-56b7dd256f3c
Commits

Reviewing files that changed from the base of the PR and between bdd1c12 and f123ffe.

Files selected for processing: 2
  • database/migrations/2026_11_01_120000_keep_the_author_of_commits_until_deleted_in_code.php
  • tests/Unit/Models/ProfileTest.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The migration replaces the foreign key from commit authors to profiles and validates the constraint separately. A profile model test checks that deleting a profile referenced by a commit raises a QueryException.

Changes: Commit Author Profile Constraint

Layer / File(s) Summary
Foreign key and profile deletion check
database/migrations/2026_11_01_120000_keep_the_author_of_commits_until_deleted_in_code.php, tests/Unit/Models/ProfileTest.php
The migration runs outside a transaction, replaces the commit-author foreign key with a NOT VALID constraint, then validates it. The test checks that deleting a profile referenced by a commit raises a QueryException mentioning commits_author_id_foreign.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: xheaven

Merge Risk: Minimal · up to f123f

No actionable merge-blocking risk was found in the constraint change.

Security architecture risk: Low · up to f123f

The change strengthens protection against deleting profiles while commits still reference them. Existing deletion workflows clear those references transactionally. No introduced security weakness was identified, but recovery after an interrupted migration and production locking behavior remain unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The constraint applies to the shared commits-to-profiles relationship, covering both user and organization authors rather than a single account. Its changed effect is to reject missed cleanup, not to grant access or expand an application's deletion authority.

Trust Boundaries and Controls

  • inferred — The database becomes a backstop for application-owned author cleanup: a deletion path that misses an author reference fails instead of silently removing attribution. This strengthens the inspected integrity boundary without changing request authentication or authorization code.

Resilience and Maintainability Implications

  • inferred — A concurrent author reference surviving cleanup cannot produce an orphan through profile deletion: foreign-key enforcement blocks or rejects the deletion. Failure within either inspected deletion transaction rolls back its database cleanup. This contains integrity failures, although production contention and retry behavior remain unverified.
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: commit authors remain until profile-deletion code clears them.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@mnapoli
mnapoli marked this pull request as ready for review November 1, 2026 16:11
@mnapoli
mnapoli merged commit 3796724 into production Nov 1, 2026
10 checks passed
@mnapoli
mnapoli deleted the refactor/plain-commit-author-fk branch November 1, 2026 16:23
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.

1 participant