feat(schema): add ownership tracking to organization entity - #219
Merged
mijinummi merged 1 commit intoAug 20, 2026
Conversation
Closes MD-Creative-Production#112. The Organization and Membership models already existed (added alongside the team invitation system), but nothing recorded which user owns an organization. Add a required `ownerId` on Organization, a `owner` relation to User, and the reverse `ownedOrganizations` relation, so ownership can be enforced/queried directly instead of inferred from membership roles. - prisma/schema.prisma: Organization.ownerId (required, FK -> User), User.ownedOrganizations reverse relation, index on ownerId. - prisma/migrations/20260819223047_add_organization_ownership: new migration, verified by applying it against a throwaway Postgres instance on top of the existing migration history. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
|
LGTM |
3 tasks
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.
Organization Ownership Tracking — Issue #112
Added ownership tracking to the Organization entity in prisma/schema.prisma, closing the last gap in issue #112. The Organization and Membership models already existed from the earlier team-invitation work, but no field recorded which user actually owns an organization.
Changes
Organization.ownerId — new required field, foreign key to User.id, indexed.
Organization.owner — relation to User (named OrganizationOwner).
User.ownedOrganizations — reverse relation back to Organization.
New migration — prisma/migrations/20260819223047_add_organization_ownership/migration.sql, adding the column, index, and foreign key constraint.
Verification
Validated the schema with prisma format / prisma validate.
Spun up a throwaway Postgres container, applied the existing 3 migrations, then applied the new one and confirmed via prisma migrate diff that it changes only the organizations table.
Regenerated the Prisma client and ran npm run build:backend — clean, no type errors.
Ran the invitations test suite (closest existing consumer of Organization/Membership) — 51 tests passed.
Confirmed no existing code creates Organization rows, so making ownerId required doesn't break anything.
Notes
Kept the change schema-only, matching the issue's stated scope.
Did not add a new OWNER role to either of the codebase's two existing Role enums — that's application-layer work outside this issue's scope.
Found unrelated pre-existing migration drift on main (ApiKey, ProtocolHealthMetric, ProtocolHealthAlert, ReputationScore exist in the schema but were never committed as migrations) — left untouched and flagged separately.
Closes #112