Skip to content

feat: remove availability relation from User model #22812

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

emrysal
Copy link
Contributor

@emrysal emrysal commented Jul 30, 2025

feat: remove availability relation from User model

Summary

This PR removes the availability Availability[] relation from the User model in the Prisma schema, along with the corresponding user and userId fields from the Availability model. This change simplifies the data model by eliminating a legacy fallback mechanism that was rarely used in favor of the more robust schedule-based availability system.

Key Changes:

  • Removed availability Availability[] field from User model in schema.prisma
  • Removed user and userId fields from Availability model in schema.prisma
  • Created database migration to handle schema changes
  • Updated getUserAvailability function to remove user.availability fallback logic
  • Fixed all TypeScript type errors in affected files
  • Updated test files to remove availability field references

⚠️ Behavioral Change: The getUserAvailability function previously fell back to user.availability when neither schedule nor eventType availability was present. This fallback has been removed - the function will now throw an error if schedule.availability is not available.

Review & Testing Checklist for Human

  • End-to-end booking flow testing - Verify that booking creation, rescheduling, and availability checking work correctly across different event types and user configurations
  • Verify behavioral change alignment - Confirm that removing the user.availability fallback aligns with the intended requirements and won't break existing user workflows
  • Database migration safety - Review the migration file to ensure it won't cause data loss or integrity issues in production
  • Search for missed references - Perform additional searches for any remaining references to user.availability in the codebase that might have been missed
  • Edge case testing - Test scenarios where schedule.availability might be null/undefined to ensure proper error handling

Recommended Test Plan:

  1. Test booking creation for individual users with different schedule configurations
  2. Test team event bookings with various availability setups
  3. Test rescheduling flows to ensure availability validation works
  4. Test edge cases with users who have no schedules or incomplete schedule data

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    schema["packages/prisma/schema.prisma<br/>User & Availability models"]:::major-edit
    migration["packages/prisma/migrations/.../migration.sql<br/>Database migration"]:::major-edit
    getUserAvail["packages/lib/getUserAvailability.ts<br/>Core availability logic"]:::major-edit
    userSelect["packages/prisma/selects/user.ts<br/>User query selections"]:::minor-edit
    getEventTypes["packages/features/bookings/lib/handleNewBooking/getEventTypesFromDB.ts<br/>Event type queries"]:::minor-edit
    defaultEvents["packages/lib/defaultEvents.ts<br/>Test data"]:::minor-edit
    builder["packages/lib/test/builder.ts<br/>Test utilities"]:::minor-edit
    
    schema --> migration
    schema --> getUserAvail
    schema --> userSelect
    getUserAvail --> getEventTypes
    schema --> defaultEvents
    schema --> builder
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

Co-Authored-By: alex@cal.com <me@alexvanandel.com>
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

This change set removes the direct relationship between users and availability data throughout the codebase and database schema. The availability property is eliminated from user-related objects, queries, and type definitions. Database migration scripts drop the userId column and its associated foreign key and index from the Availability table. The Prisma schema is updated to remove the relation between User and Availability, and all code that previously selected or relied on user.availability is refactored to use only schedule-based availability. Error handling related to missing availability in user or event type is removed. Additionally, references to userId in availability and override creation within schedule repositories are deleted. No new entities or interfaces are introduced.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Complexity label: Moderate
Rationale: The changes span database migrations, schema updates, and refactoring of related backend logic and tests. While conceptually straightforward, the removal of a core relation requires careful review to ensure consistency, data integrity, and that no code paths still expect user-based availability. The review involves cross-verifying schema, migration, selection logic, repository updates, and downstream usage.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ecaae8 and 4701035.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • apps/api/v2/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/api/v2/package.json
⏰ 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: Socket Security: Pull Request Alerts
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/remove-user-availability-relation-1753870278

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ❗️ migrations contains migration files label Jul 30, 2025
@keithwillcode keithwillcode added core area: core, team members only foundation labels Jul 30, 2025
Copy link

vercel bot commented Jul 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 31, 2025 6:24am
cal-eu ⬜️ Ignored (Inspect) Jul 31, 2025 6:24am

@emrysal emrysal marked this pull request as ready for review July 30, 2025 12:34
@emrysal emrysal requested review from a team as code owners July 30, 2025 12:34
@dosubot dosubot bot added the ✨ feature New feature or request label Jul 30, 2025
@emrysal
Copy link
Contributor Author

emrysal commented Jul 30, 2025

⚠️ Behavioral Change: The getUserAvailability function previously fell back to user.availability when neither schedule nor eventType availability was present. This fallback has been removed - the function will now throw an error if schedule.availability is not available.

Isn't actually a behavioural change, because the schedule availability should always be present (and if not, it's an empty array and no availability should be counted); and the schedule is always available now due to the fallback schedule which is there as a last resort.

@emrysal emrysal requested a review from a team as a code owner July 30, 2025 13:08
Copy link
Contributor

github-actions bot commented Jul 30, 2025

E2E results are ready!

Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedclassnames@​2.5.110010010079100

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only ✨ feature New feature or request foundation ❗️ migrations contains migration files ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants