Skip to content

fix: add database setup for platform settings in local development #22456

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 10 commits into
base: main
Choose a base branch
from

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Jul 13, 2025

What does this PR do?

Fixes platform settings access in local development environment by providing proper database configuration. This resolves the "Subscription needed" error and 500 response from OAuth clients API.

Fixes #22423

Before:

Platform settings shows "Subscription needed"
OAuth clients API returns 500 error

After:

Platform settings accessible
OAuth clients API returns 200 success

Mandatory Tasks
I have self-reviewed the code
I have updated the developer docs in /docs
I confirm the fix is verified by accessing platform settings successfully

steps to apply fix:

  • Connect to your PostgreSQL database
  • Run the SQL commands from quick-fix.sql
  • Restart your Cal.com server
  • Navigate to /settings/platform - should work now!
  • The fix is database configuration, not code changes. Your platform settings will be accessible immediately after running the SQL script.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jul 13, 2025
@graphite-app graphite-app bot requested a review from a team July 13, 2025 18:56
@CLAassistant
Copy link

CLAassistant commented Jul 13, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ naaa760
✅ kart1ka
❌ nehaaaa8


nehaaaa8 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

vercel bot commented Jul 13, 2025

Someone is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 1 issue across 1 file. Review it in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

quick-fix.sql Outdated
"subscriptionId",
"plan"
) VALUES (
1, -- Replace with your team ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding the ID as 1 in the PlatformBilling insert may cause a primary key conflict or insert/update the wrong record if the user's team ID is not 1. The comment suggests replacement, but the risk of user error is high.

@dosubot dosubot bot added platform Anything related to our platform plan 🐛 bug Something isn't working labels Jul 13, 2025
@graphite-app graphite-app bot requested a review from a team July 13, 2025 18:57
Copy link

graphite-app bot commented Jul 13, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/13/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (07/13/25)

1 label was added to this PR based on Keith Williams's automation.

"Add platform team as reviewer" took an action on this PR • (07/13/25)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

"""

Walkthrough

A new SQL script has been added to configure platform-related settings for a team in the database. The script identifies the team, enables the platform feature, updates or inserts billing information, and sets a license key in the deployment table, ensuring idempotency with conflict handling. Additionally, a new asynchronous function was introduced in the seed script to enable the platform feature and billing records for existing teams associated with admin users, and to insert or update a deployment license key, integrating this setup into the main seed workflow.

Changes

File(s) Change Summary
quick-fix.sql Added SQL script to set team as platform-enabled, update billing info, and insert license key.
packages/prisma/seed.ts Added enablePlatformForExistingTeams function to seed script to enable platform and billing for existing teams and insert deployment license key; invoked in main seed workflow.

Assessment against linked issues

Objective Addressed Explanation
Enable platform settings for a team by updating relevant DB tables to allow local access (#22423)
Insert or update dummy license key in Deployment table for local testing (#22423)
Insert or update PlatformBilling info for the team for local setup (#22423)

Poem

A script hops in, quick as can be,
To grant platform powers for all to see.
Billing and keys, all set with care,
So local hosts can test and dare.
With SQL magic, the settings align—
Now platform features work just fine!
🐇✨
"""


🪧 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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

♻️ Duplicate comments (1)
quick-fix.sql (1)

10-24: Hard-coded primary key in PlatformBilling can collide with existing rows.
This was mentioned in a previous review and is still unresolved.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5854de3 and 8e45a19.

📒 Files selected for processing (1)
  • quick-fix.sql (1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.27.2)
quick-fix.sql

30-30: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ 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). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Security Check

quick-fix.sql Outdated
Comment on lines 7 to 9
-- Step 2: Enable platform for your team (replace 1 with your actual team ID from step 1)
UPDATE "Team" SET "isPlatform" = true WHERE id = 1;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid hard-coding the team ID — parametrize or pass as a psql variable.

Blindly updating id = 1 risks clobbering the wrong team on multi-tenant/dev DBs. Accept the ID returned from Step 1 instead, e.g.:

\set team_id 123            -- ← paste the value from Step 1
UPDATE "Team"
SET    "isPlatform" = true
WHERE  id = :team_id;
🤖 Prompt for AI Agents
In quick-fix.sql around lines 7 to 9, the team ID is hard-coded as 1 in the
UPDATE statement, which risks updating the wrong record. Modify the script to
accept the team ID as a psql variable by adding a \set command to define the
team_id variable with the value from Step 1, then update the query to use WHERE
id = :team_id instead of a fixed number.

Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naaa760 can you please address the potential issues suggested by coderabbit. Marking it draft until then. Feel free to rfr.

Copy link
Contributor

@keithwillcode keithwillcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey appreciate the PR. Let’s move these queries to seed.ts.

@naaa760 naaa760 requested a review from a team as a code owner July 16, 2025 03:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/prisma/seed.ts (1)

633-633: Consider using environment variable validation for the license key.

The fallback license key is hardcoded, which could pose security risks if this accidentally runs in production environments.

Consider adding validation to ensure this only runs in development:

   // Set license key from environment variable
-  const licenseKey = process.env.CALCOM_LICENSE_KEY || "59c0bed7-8b21-4280-8514-e022fbfc24c7";
+  if (process.env.NODE_ENV === "production" && !process.env.CALCOM_LICENSE_KEY) {
+    throw new Error("CALCOM_LICENSE_KEY environment variable is required in production");
+  }
+  const licenseKey = process.env.CALCOM_LICENSE_KEY || "59c0bed7-8b21-4280-8514-e022fbfc24c7";
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e45a19 and 1e43fda.

📒 Files selected for processing (1)
  • packages/prisma/seed.ts (2 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). (3)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Security Check
🔇 Additional comments (1)
packages/prisma/seed.ts (1)

1406-1406: Good placement of the platform setup function.

Calling enablePlatformForExistingTeams() at the end of the main seeding process ensures that platform features are enabled after all users and teams have been created.

@naaa760
Copy link
Author

naaa760 commented Jul 16, 2025

Issues Resolved

Original Bug:

Platform settings showed "Subscription needed"
OAuth clients API returned 500

Fixes:

  1. Hard-coded team ID → Dynamic admin team
  2. Hard-coded license key → Uses process.env.CALCOM_LICENSE_KEY
  3. DB operations → Wrapped in prisma.$transaction()
  4. No error handling → Added try...catch with logging
  5. SQL file → Moved to packages/prisma/seed.ts

Result:

Platform settings work locally
OAuth API returns 200
No hard-coded secrets
Production-ready

To apply: Run npx prisma db seed and set CALCOM_LICENSE_KEY.

Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a question.

@kart1ka kart1ka marked this pull request as draft July 16, 2025 15:05
@naaa760
Copy link
Author

naaa760 commented Jul 16, 2025

@kart1ka
you're absolutely right! I've removed the redundant quick-fix.sql file since the solution is now properly integrated into the seed file. Thanks for catching that!

@naaa760 naaa760 marked this pull request as ready for review July 16, 2025 16:00
@anikdhabal anikdhabal added the Low priority Created by Linear-GitHub Sync label Jul 16, 2025
@dosubot dosubot bot added the docs area: docs, documentation, cal.com/docs label Jul 16, 2025
Copy link
Contributor

github-actions bot commented Aug 3, 2025

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Aug 3, 2025
@github-actions github-actions bot removed the Stale label Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working community Created by Linear-GitHub Sync docs area: docs, documentation, cal.com/docs Low priority Created by Linear-GitHub Sync platform Anything related to our platform plan self-hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot access Platform settings when locally hosting
6 participants