Skip to content

refactor: let users share the ID of their profile, as organizations do - #1345

Merged
mnapoli merged 1 commit into
productionfrom
feat/user-profile-ids
Oct 31, 2026
Merged

mnapoli merged 1 commit into
productionfrom
feat/user-profile-ids

Conversation

@mnapoli

@mnapoli mnapoli commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

First layer of letting organizations post commits (#938). Organizations already share their profile's ID, but users had their own, linked to their profile by github_id. Now each user shares their profile's ID too. Every user ID is then a profile ID, so a commit, and later a star, a follow or a mute, can point to profiles and mean a person or an organization alike, without rewriting existing data.

No behavior change.

Changes

  • Migration:
    • Each user's profile takes the ID of its user. Nothing pointed to user profiles' IDs yet.
    • users.id becomes a foreign key to profiles.id, like organizations.id.
    • It locks users and profiles against writes for the update, about 12k rows, so no user signs up with another ID before the foreign key is in place.
  • New users get their profile's ID when they sign up, sign in locally, or are a bot (Tom, World). The same goes for the factories and seeders.
  • User::profile(), Profile::user() and the joins between users and profiles link by ID. Joins that only went through users to reach a profile now join profiles directly. github_id stays on users for bans and timeouts.

Validation

All local, on Postgres 18 with pgvector (as CI):

  • php -d memory_limit=-1 vendor/bin/pest --parallel --ci --coverage --exactly=100.0 --passthru-php="'-d' 'memory_limit=-1'": 5195 passed, coverage 100.0%.
  • composer test:lint, composer test:types (PHPStan 0 errors), composer test:type-coverage (100%), bun run test:unit (791 passed).
  • The migration on a database recreating today's state, where user profiles' IDs differ from their users': before, 0 of 3 users matched their profile's ID; after, all 3 did, and the foreign key exists.

No UI change, so no device check or screenshots.

Independent review

CODE: PASS from a separate read-only review on 8dd60f13 (base 3c7e4bb0), after one round of notes:

  • The migration now locks profiles, users, the order a sign-in writes them, so a sign-in can't deadlock with it.
  • A test now checks that signing up gives the user its profile's ID.

It checked that only organization profiles are referenced, so rewriting user profiles' IDs orphans nothing. It also checked that every user already has a profile, so the foreign key validates, and that the joins moved to IDs return the same rows.

Non-blocking: the migration sets no lock_timeout, so writes to users and profiles queue behind it if a long transaction holds them.

Limitations

  • A sign-up served by the old code during the deploy gets a user ID that isn't its profile's, so it fails on the new foreign key for those few seconds.
Decisions for organization commits (#938), made before building
  • Who can post as an organization? Admins and members: anyone listed on the org's dev/null page. The list admins manage is the permission, with no new setting.
  • What do readers see? Only the organization, like a brand account. The person who posted is recorded for moderation and accountability.
  • What can an organization do? Post top-level commits, reply, quote and schedule commits as the org. Starring as the org comes later (below).
  • How does a member post as the org? With a "Post as" picker in the composer (themselves, or each org they can post for), defaulting to themselves.
  • Who is notified of replies, stars, quotes and mentions of the org and its commits? All its admins and members, in their own notifications.
  • Who can delete an org commit? Any admin or member.
  • Where do members see who posted an org commit? Nowhere in v1: it's stored, not shown.
  • What does moderation act on? The poster's account: timeouts and bans hit the person, which also stops them posting as the org. No org-level ban in v1.
  • Starring as the org? Later: members star as themselves for now. Stars are keyed on users and feed levels, pasteis and notifications, so it's a project of its own.
  • Do blocks and mutes apply to org commits? No: blocking or muting the person who posted doesn't hide the org's commits, as that would reveal who posted. Orgs can't be muted in v1; you unfollow them.
  • API? It follows the internal model, built for the long term: breaking changes are fine.
  • How is the author stored? Each commit's author_id points to the profile it's from, a person or an organization, and user_id stays the account that posted it. Each person's profile takes their user's id, as organizations already share theirs, so profile ids cover everyone. A column that should later accept organizations, like who starred or whom someone follows, then only repoints its foreign key without rewriting data. We rejected two columns (user_id + organization_id, one more organization_* column per feature) and a polymorphic author (no foreign key).
  • Naming? author_id + user_id, like stars.user_id and scheduled_commits.user_id for the account that did it.
  • What does the picker look like? The composer's avatar becomes the switcher for members of an org; picking the org swaps in its square avatar. Nothing changes for people in no org.
  • Does it remember the last choice? No: every commit and reply starts as yourself, so posting as the org is always deliberate.
  • How is it split? Stacked PRs, each reviewable and deployable on its own.

Settled while planning, and accepted:

  • Org commits live at /@laravel/commits/{id}, and the org page gets a Commits tab, first and the default, before Mentions.
  • Approval follows the poster's reputation, as for their own commits.
  • A scheduled org commit is canceled if its poster has left the org by then.
  • For the org's members, an org commit counts as their own: they can delete it, and can't star, report, vote in or give pasteis to it.
  • Org commits have no pasteis, and don't count toward the poster's levels, streaks or achievements.
  • When GitHub deletes an org, its commits are erased like a deleted account's. A poster who deletes their account only unlinks from the org commits they posted.
  • No first-commit notification for orgs, no posting as an org from the CLI, no RSS feed for orgs yet.
  • The stack has four layers, so each stays reviewable: profile ids, commit authors, the author in the props and the API, then posting as an org.

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency in how accounts are matched with profiles across search, mentions, activity, exports, and other account-related views.
    • Updated account creation and profile updates to keep account and profile records correctly linked, helping related information appear under the right account.

@mnapoli
mnapoli added this pull request to stack #1347 October 31, 2026 16:56
@coderabbitai

coderabbitai Bot commented Oct 31, 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: 08d8d284-78ec-4090-8009-14a7d7120629
Commits

Reviewing files that changed from the base of the PR and between 3c7e4bb and 8dd60f1.

Files selected for processing: 19
  • app/Actions/CreateExport.php
  • app/Actions/CreateLocalUser.php
  • app/Actions/CreateTomFriendship.php
  • app/Actions/CreateWorldReply.php
  • app/Actions/UpdateOrCreateUser.php
  • app/Models/Profile.php
  • app/Models/User.php
  • app/Queries/ActivityBreakdownsQuery.php
  • app/Queries/MentionSuggestionsQuery.php
  • app/Queries/OperationsEventsQuery.php
  • app/Queries/SitemapQuery.php
  • app/Queries/UserSearchQuery.php
  • database/factories/UserFactory.php
  • database/migrations/2026_10_31_150000_give_user_profiles_the_id_of_their_user.php
  • database/seeders/OperationsSeeder.php
  • database/seeders/StressSeeder.php
  • tests/Feature/ScheduledCommitsTest.php
  • tests/Unit/Actions/UpdateOrCreateUserTest.php
  • tests/Unit/Queries/DevelopersCountQueryTest.php

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

Walkthrough

The migration aligns matching profile and user IDs and adds a foreign key. User creation paths, model relationships, and queries now use IDs to associate users with profiles.

Changes: Shared Profile and User IDs

Layer / File(s) Summary
Align IDs in migration and creation paths
database/migrations/*, app/Actions/*, database/factories/UserFactory.php, database/seeders/*, tests/*
The migration aligns profile IDs with matching user IDs and adds a foreign key. Creation paths, factories, and seeders use profile IDs for users. Related tests check the ID relationship and use generated IDs.
Use IDs in relationships and queries
app/Models/*, app/Actions/CreateExport.php, app/Queries/*
Model relationships, route binding, and queries use profile and user IDs instead of GitHub IDs to associate records. Operations queries use direct profile joins, with the described inner and left join behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Suggested reviewers: xheaven, nunomaduro, jubianchi

Merge Risk: Minimal · up to 8dd60

Existing users and profiles will share IDs, with normal lookups preserved after migration. No merge-blocking issue was established.

Security architecture risk: Moderate · up to 8dd60

The shared-ID design strengthens account-to-profile consistency and preserves existing account IDs. However, requests holding a profile loaded before the migration could miss profile deletion after its ID changes. Deployment must prevent that overlap or otherwise preserve account-erasure guarantees. No cross-account access or privilege expansion was established.

Retained concerns

  • Medium · security · inferred: If an account-deletion request retains an eagerly loaded profile across the migration, its cached profile ID becomes obsolete. DeleteUser locks a freshly queried User but continues using the original instance, deletes the user, and then deletes the cached profile. That final deletion can match no row, leaving mirrored personal profile data after successful account deletion. The transaction and foreign key protect normal ordering but do not prevent this stale-key case. Whether production deployment excludes this overlap is unresolved; the exposure is introduced by the new primary-key rewrite.
Security review details

Security Blast Radius

  • inferred — The identified privacy exposure is limited to accounts whose deletion retains an old profile instance across the key rewrite. The affected data is the remaining profile row, including mirrored handle, name, biography, location, and website. No cross-account privilege gain or credential exposure was established.

Security Findings and Attack Paths

  • inferred — An authenticated own-account deletion can receive a success response after DeleteUser completes. If its cached profile key predates the migration, account deletion can commit without removing the rekeyed profile. Direct profile lookup for biography links also does not require a surviving User, although broader public exposure of residual fields was not established.

Trust Boundaries and Controls

  • inferred — The inspected principal remains the User row, whose ID is preserved. Moderation continues using github_id, while normal creation binds the profile and user in one transaction. The new database constraint fails closed for old independent-ID inserts rather than granting another profile's identity.

Resilience and Maintainability Implications

  • inferred — Normal account erasure deletes the user before its profile in one transaction, respecting the new foreign key. This is strong counterevidence against a general deletion regression, but it does not resolve migration-spanning stale instances because the locked query result is not used to replace the original User or its loaded profile.

Hardening Proposals

  • proposed — Make the rekey a coordinated deployment boundary: drain requests and workers holding profile instances before the rewrite, or refresh the authoritative profile identity before lifecycle writes. Verify that an erasure crossing the transition removes both rows, and document forward recovery after migration interruption.
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: aligning user IDs with profile IDs, consistent with organizations.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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 10 functions across 19 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 merged commit 462b079 into production Oct 31, 2026
11 checks passed
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.

2 participants