Skip to content

feat(schema): add ownership tracking to organization entity - #219

Merged
mijinummi merged 1 commit into
MD-Creative-Production:mainfrom
patrickNwafo:feat/issue-112-organization-ownership
Aug 20, 2026
Merged

feat(schema): add ownership tracking to organization entity#219
mijinummi merged 1 commit into
MD-Creative-Production:mainfrom
patrickNwafo:feat/issue-112-organization-ownership

Conversation

@patrickNwafo

@patrickNwafo patrickNwafo commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

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>
@mijinummi

Copy link
Copy Markdown
Collaborator

LGTM

@mijinummi
mijinummi merged commit 9238fc4 into MD-Creative-Production:main Aug 20, 2026
13 checks passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Aug 20, 2026
3 tasks
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.

Create Organization Entity

2 participants