Skip to content

cleanup(seed): remove organization seeding from scripts/seed.ts#29009

Draft
romitg2 wants to merge 6 commits intocalcom:mainfrom
romitg2:refactor/seed-drop-org-seeding
Draft

cleanup(seed): remove organization seeding from scripts/seed.ts#29009
romitg2 wants to merge 6 commits intocalcom:mainfrom
romitg2:refactor/seed-drop-org-seeding

Conversation

@romitg2
Copy link
Copy Markdown
Member

@romitg2 romitg2 commented Apr 26, 2026

What This Does

  • Removes the organization fixtures from scripts/seed.ts.
  • Removes the Acme per-host location seed that depends on those organization fixtures.
  • Repoints the seeded API key setup away from the removed org fixtures.
  • Removes the organization creation helper that becomes unused after the cleanup.

Seed Verification

Command run:

yarn workspace @calcom/prisma db-reset

Result:

  • Database reset completed.
  • Migrations applied successfully.
  • Seed completed successfully.

Log excerpt:

🌱  The seed command has been executed.

@romitg2 romitg2 added ready-for-e2e run-ci Approve CI to run for external contributors labels Apr 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 26, 2026

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

Unknown release type "cleanup" found in pull request title "cleanup(seed): remove organization seeding from scripts/seed.ts". 

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@romitg2 romitg2 added run-ci Approve CI to run for external contributors and removed run-ci Approve CI to run for external contributors labels Apr 26, 2026
@romitg2 romitg2 marked this pull request as ready for review April 26, 2026 19:30
@romitg2 romitg2 enabled auto-merge (squash) April 26, 2026 19:31
@romitg2 romitg2 requested a review from sahitya-chandra April 26, 2026 19:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

📝 Walkthrough

Walkthrough

The seeding script (scripts/seed.ts) removes extensive organization-focused demo seeding logic, including the createOrganizationAndAddMembersAndTeams function and its invocations for multiple organizations (Acme and Dunder Mifflin). This eliminates seeding for associated users, profiles, memberships, events, schedules, teams, host-locations, and API keys. In replacement, a new function ensureProUserHasApiKeySeeded is introduced, and the main() function is updated to seed only an API key for a specific user account. All changes are local to the script with no modifications to exported or public entity declarations.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing organization seeding from the seed script.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about what was removed and verification that the seed still works correctly.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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)
scripts/seed.ts (1)

138-145: Tighten the Prisma query and prefer findUnique with an explicit select.

User.email carries a unique constraint, so findUnique is the correct lookup primitive here, and per the repo guideline Prisma reads should select only the fields they consume (just id in this case) to avoid pulling the full row (including sensitive columns). Also consider logging when the user is missing so failed seeds are visible rather than silently skipped.

♻️ Proposed refactor
 async function ensureProUserHasApiKeySeeded() {
-  const proUser = await prisma.user.findFirst({
-    where: { email: "pro@example.com" },
-  });
-  if (proUser) {
-    await seedApiKey(proUser.id, "0123456789abcdef0123456789abcdef");
-  }
+  const proUser = await prisma.user.findUnique({
+    where: { email: "pro@example.com" },
+    select: { id: true },
+  });
+  if (!proUser) {
+    console.log("⚠️  pro@example.com not found, skipping API key seeding.");
+    return;
+  }
+  await seedApiKey(proUser.id, "0123456789abcdef0123456789abcdef");
 }

As per coding guidelines: "Use select instead of include in Prisma queries for performance and security" and "Use early returns to reduce nesting".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/seed.ts` around lines 138 - 145, In ensureProUserHasApiKeySeeded
replace prisma.user.findFirst with prisma.user.findUnique and use an explicit
select { id: true } so only the id is fetched; use an early return if no user is
found and log that fact (e.g., via processLogger or existing logger) instead of
silently skipping, and continue to call seedApiKey(proUser.id,
"0123456789abcdef0123456789abcdef") when the user exists.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/seed.ts`:
- Line 719: The removal of the Acme organization and owner1-acme user from
main() breaks two downstream scripts; either restore the Acme seeding in main()
or update the dependent scripts/docs to stop assuming those entities exist. Fix
option A: re-add the Acme org + owner1-acme seeding where main() runs other
seeds (so ensureProUserHasApiKeySeeded() and peers still run against a
consistent seed surface), recreating the org/team with slug "acme" and the user
"owner1-acme" (and its org profile). Fix option B: modify scripts
seed-booking-audit.ts and prepare-local-for-delegation-credentials-testing.js to
either create their required org/user fixtures at runtime or to reference an
existing seeded test user/org (remove hard-coded "owner1-acme" / "acme"
assumptions) and update any docs referencing those scripts; ensure error checks
that previously threw "User owner1-acme not found..." and "has no organization
profile" are removed or replaced with fixture-creation logic.

---

Nitpick comments:
In `@scripts/seed.ts`:
- Around line 138-145: In ensureProUserHasApiKeySeeded replace
prisma.user.findFirst with prisma.user.findUnique and use an explicit select {
id: true } so only the id is fetched; use an early return if no user is found
and log that fact (e.g., via processLogger or existing logger) instead of
silently skipping, and continue to call seedApiKey(proUser.id,
"0123456789abcdef0123456789abcdef") when the user exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a92dd2e8-d170-42d8-b3fa-4d897e4fbb1a

📥 Commits

Reviewing files that changed from the base of the PR and between 987fe91 and c9883e0.

📒 Files selected for processing (1)
  • scripts/seed.ts

Comment thread scripts/seed.ts

await ensureAcmeOwnerHasApiKeySeeded();
await seedPerHostLocationsInAcmeOrg();
await ensureProUserHasApiKeySeeded();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find any remaining references to the Acme org / owner1-acme user / dunder org
# across scripts, docs, and tests so we can tell whether they need updates too.
rg -nP --hidden -g '!**/node_modules/**' \
  -e '\bowner1-acme\b' \
  -e '"acme"' \
  -e "'acme'" \
  -e '\bdunder\b' \
  -e 'isOrganization\s*:\s*true' \
  -e 'createOrganizationAndAddMembersAndTeams'

Repository: calcom/cal.diy

Length of output: 10728


🏁 Script executed:

# Check if these two scripts were modified/removed in the PR and verify their current state
git ls-files scripts/ | grep -E "(seed-booking-audit|prepare-local-for-delegation)"

Repository: calcom/cal.diy

Length of output: 148


🏁 Script executed:

# Examine the current state of both scripts to see if they've been updated
head -50 scripts/seed-booking-audit.ts
tail -30 scripts/seed-booking-audit.ts

Repository: calcom/cal.diy

Length of output: 2543


🏁 Script executed:

# Check the prepare-local-for-delegation-credentials-testing.js script
head -50 scripts/prepare-local-for-delegation-credentials-testing.js

Repository: calcom/cal.diy

Length of output: 1859


🏁 Script executed:

# Look at the specific area in seed.ts mentioned in the review (line 719)
sed -n '700,750p' scripts/seed.ts

Repository: calcom/cal.diy

Length of output: 781


🏁 Script executed:

# Search for where Acme org was created in seed.ts to confirm it's been removed
rg -n 'createOrganizationAndAddMembersAndTeams|Acme|owner1-acme' scripts/seed.ts | head -20

Repository: calcom/cal.diy

Length of output: 40


🏁 Script executed:

# Check the git diff to see what was actually changed in seed.ts
git diff --no-index /dev/null scripts/seed.ts 2>/dev/null | grep -A5 -B5 'ensureProUserHasApiKeySeeded' | head -30

Repository: calcom/cal.diy

Length of output: 634


Two seed scripts will break after Acme org/owner1-acme seeding is removed.

After this PR, scripts/seed-booking-audit.ts and scripts/prepare-local-for-delegation-credentials-testing.js will fail. Both scripts have hard-coded dependencies on the Acme organization and owner1-acme user that are no longer produced by main():

  • scripts/seed-booking-audit.ts (lines 389–407) fails with "User owner1-acme not found. Run the main seed first." or "User owner1-acme has no organization profile."
  • scripts/prepare-local-for-delegation-credentials-testing.js (lines 1–42) fails when it cannot find owner1-acme@example.com or the team with slug: "acme", isOrganization: true.

Either update or remove these scripts (and any docs referencing them) in this PR, or restore the Acme org seeding to keep the seed surface consistent.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/seed.ts` at line 719, The removal of the Acme organization and
owner1-acme user from main() breaks two downstream scripts; either restore the
Acme seeding in main() or update the dependent scripts/docs to stop assuming
those entities exist. Fix option A: re-add the Acme org + owner1-acme seeding
where main() runs other seeds (so ensureProUserHasApiKeySeeded() and peers still
run against a consistent seed surface), recreating the org/team with slug "acme"
and the user "owner1-acme" (and its org profile). Fix option B: modify scripts
seed-booking-audit.ts and prepare-local-for-delegation-credentials-testing.js to
either create their required org/user fixtures at runtime or to reference an
existing seeded test user/org (remove hard-coded "owner1-acme" / "acme"
assumptions) and update any docs referencing those scripts; ensure error checks
that previously threw "User owner1-acme not found..." and "has no organization
profile" are removed or replaced with fixture-creation logic.

@romitg2 romitg2 marked this pull request as draft April 26, 2026 19:36
auto-merge was automatically disabled April 26, 2026 19:36

Pull request was converted to draft

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.

@github-actions github-actions Bot added the Stale label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-e2e run-ci Approve CI to run for external contributors size/XL Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants