-
Notifications
You must be signed in to change notification settings - Fork 10.4k
chore: Add relation between a host and a membership for future cascades #22975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add relation between a host and a membership for future cascades #22975
Conversation
WalkthroughA database migration script was introduced that modifies the Estimated code review effort🎯 2 (Simple) | ⏱️ ~5-10 minutes Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Graphite Automations"Add foundation team as reviewer" took an action on this PR • (08/08/25)1 reviewer was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
packages/prisma/migrations/20250730091450_add_host_many_to_member_one_relation/migration.sql (4)
2-5
: PrefermembershipId
overmemberId
for clarity and consistency with the referenced table.The column references
Membership(id)
, so naming itmembershipId
avoids confusion with potential “member” or “user” IDs and improves readability.Apply this diff:
-ALTER TABLE "Host" ADD COLUMN "memberId" INTEGER; +ALTER TABLE "Host" ADD COLUMN "membershipId" INTEGER; -ALTER TABLE "Host" ADD CONSTRAINT "Host_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE "Host" ADD CONSTRAINT "Host_membershipId_fkey" FOREIGN KEY ("membershipId") REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE;
2-2
: Nullability/backfill planThe column is nullable. If every Host should eventually belong to a Membership, plan a backfill and a follow-up migration to add NOT NULL and validate data. If optional by design, disregard.
Would you like a backfill script template (SQL + staged constraint hardening)?
5-5
: Reduce locking during FK addition (optional, production safety)On large tables, adding a validated FK can hold stronger locks. Consider adding the FK NOT VALID, then validating separately to minimize blocking.
-ALTER TABLE "Host" ADD CONSTRAINT "Host_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE "Host" ADD CONSTRAINT "Host_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE NOT VALID; +ALTER TABLE "Host" VALIDATE CONSTRAINT "Host_memberId_fkey";Note: VALIDATE and CONCURRENT index creation generally require non-atomic migrations.
5-5
: Check whether ON UPDATE CASCADE is actually neededPrimary keys rarely update. If
Membership.id
is immutable, prefer ON UPDATE NO ACTION to simplify triggers and reduce overhead.-... REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE; +... REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/prisma/migrations/20250730091450_add_host_many_to_member_one_relation/migration.sql
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Install dependencies / Yarn install & cache
ALTER TABLE "Host" ADD COLUMN "memberId" INTEGER; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Host" ADD CONSTRAINT "Host_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Membership"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify type compatibility between Host.memberId and Membership.id and update Prisma schema accordingly
Ensure Membership.id
is INTEGER (or the exact same type) and that schema.prisma reflects this relation; mismatched types will fail at runtime.
Run this to confirm types and the schema linkage:
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate Prisma schema:"
fd -a schema.prisma
SCHEMA="$(fd -a schema.prisma | head -n 1)"
echo -e "\nMembership model (schema.prisma):"
rg -n -A 20 -B 2 $'^model\s+Membership\b' "$SCHEMA"
echo -e "\nHost model (schema.prisma):"
rg -n -A 20 -B 2 $'^model\s+Host\b' "$SCHEMA"
echo -e "\nDDL references to Membership (migrations):"
rg -n 'CREATE TABLE "Membership"|ALTER TABLE "Membership"|REFERENCES "Membership"' -A 3 -B 2
echo -e "\nAny FKs to Host (to assess cascade chains):"
rg -n 'REFERENCES "Host"' -A 2 -B 2
Length of output: 529
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Schema files found:"
fd -a schema.prisma
for SCHEMA in $(fd -a schema.prisma); do
echo -e "\n=== $SCHEMA ==="
echo "Membership model snippet:"
rg -n -A 5 -B 1 '^model\s+Membership\b' "$SCHEMA"
echo "Membership.id field:"
rg -n '^\s*id\s+' -A 2 -B 0 "$SCHEMA"
echo "Host model snippet:"
rg -n -A 5 -B 1 '^model\s+Host\b' "$SCHEMA"
echo "Host.memberId field:"
rg -n '^\s*memberId\s+' -A 2 -B 0 "$SCHEMA"
done
Length of output: 623
🏁 Script executed:
#!/bin/bash
set -euo pipefail
SCHEMA="packages/prisma/schema.prisma"
echo "Inspecting $SCHEMA"
echo "------------------------------"
echo -e "\nMembership model definition:"
rg -n -A5 -B1 '^model\s\+Membership\b' "$SCHEMA" || echo "No Membership model found"
echo -e "\nMembership.id field:"
rg -n '^\s*id\s\+' -A2 -B1 "$SCHEMA" || echo "No id field in Membership"
echo -e "\nHost model definition:"
rg -n -A5 -B1 '^model\s\+Host\b' "$SCHEMA" || echo "No Host model found"
echo -e "\nHost.memberId field:"
rg -n '^\s*memberId\s\+' -A2 -B1 "$SCHEMA" || echo "No memberId field in Host"
Length of output: 958
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Found Prisma schema files:"
fd -a schema.prisma
for SCHEMA in $(fd -a schema.prisma); do
echo -e "\n=== Inspecting $SCHEMA ==="
echo -e "\nAll model definitions:"
rg -n '^model ' -A2 "$SCHEMA" || echo " (no models found)"
echo -e "\nMembership model block:"
rg -n -A5 -B0 '^model Membership\b' "$SCHEMA" || echo " Membership model not found"
echo -e "\nMembership.id field:"
rg -n '^\s*id\s' -A2 "$SCHEMA" || echo " id field not found in Membership"
echo -e "\nHost model block:"
rg -n -A5 -B0 '^model Host\b' "$SCHEMA" || echo " Host model not found"
echo -e "\nHost.memberId field:"
rg -n '^\s*memberId\s' -A2 "$SCHEMA" || echo " memberId field not found in Host"
done
Length of output: 30347
Add Prisma relation mappings for Host.memberId ↔ Membership.id
Type compatibility is confirmed—both Membership.id
and Host.memberId
are Int
. However, your Prisma schema doesn’t yet declare the new foreign-key relation. Update packages/prisma/schema.prisma as follows:
• In the Host
model, after your existing memberId Int
field, add:
model Host {
…
- memberId Int
+ memberId Int?
+ member Membership? @relation(fields: [memberId], references: [id], onDelete: Cascade)
…
}
• In the Membership
model, add the back-relation:
model Membership {
id Int @id @default(autoincrement())
teamId Int
userId Int
accepted Boolean @default(false)
role MembershipRole
+ hosts Host[]
}
Then run prisma migrate dev
(or prisma db pull && prisma generate
) to sync your schema.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In
packages/prisma/migrations/20250730091450_add_host_many_to_member_one_relation/migration.sql
lines 2 to 5, you added a foreign key from Host.memberId to Membership.id but
did not update the Prisma schema. To fix this, open
packages/prisma/schema.prisma and in the Host model, add a relation field
referencing Membership after the memberId Int field. Then, in the Membership
model, add a back-relation field referencing Host. After updating the schema,
run prisma migrate dev or prisma db pull && prisma generate to sync the database
and Prisma client.
packages/prisma/migrations/20250730091450_add_host_many_to_member_one_relation/migration.sql
Outdated
Show resolved
Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
E2E results are ready! |
…es (calcom#22975) * chore: Add relation between a host and a membership for future cascades * Apply suggestion Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
What does this PR do?
Adds a simple new relation that when set cascades a membership deletion to the host record.