Skip to content

fix(db): keep a profile's role and organization to the server - #1317

Merged
gkhngyk merged 2 commits into
mainfrom
fix/profiles-server-columns
Oct 21, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
fix/profiles-server-columns

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Summary

A profile's role and organization_id are set by the server:

  • Roles change through team management (updateMemberRole), with the service role.
  • Joining an organization goes through an invitation (acceptInvitation), with the service role.
  • Leaving is a removal (removeMember), with the service role.

A member's own profile update covers their name, avatar and onboarding state. The one organization a person sets for themselves is the first one, in onboarding (createOrganization, the onboarding page), right after creating it.

Migration 00228 adds a before update trigger on profiles (guard_profile_server_columns). For any caller without the service role:

  • role can't change;
  • organization_id can only go from null to an organization that has no other member yet.

organization_has_other_members is the security-definer helper for that check. The trigger itself runs as the caller.

It's applied on the hosted DB. Checked there in rolled-back transactions as authenticated:

  • a member's role change is refused;
  • a member's move to another organization is refused;
  • a member's name change goes through;
  • a user without an organization can join the one they just created, but not one with members;
  • the same changes with the service role go through.

Related issue

None.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Onboarding with a new account: creating the organization still lands on the dashboard.
  2. Settings → Team: invite, accept, change a role and remove a member all work as before.
  3. Settings → Profile: the name change saves.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

schema.sql is rebuilt with build-schema.sh, and the helper is added to types/supabase.ts.

🤖 Generated with Claude Code

https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

Roles change through team management and a person joins an organization
through an invitation, both with the service role. A member's own profile
update now leaves role alone, and sets organization_id only from null to
an organization with no other member yet, as onboarding does. Applied on
the hosted DB.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 21, 2026
@gkhngyk
gkhngyk merged commit 8273174 into main Oct 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant