Skip to content

Comments

refactor: move app-store dependent seed files from prisma to scripts#23799

Merged
hbjORbj merged 4 commits intomainfrom
refactor/move-prisma-seed-to-scripts
Sep 12, 2025
Merged

refactor: move app-store dependent seed files from prisma to scripts#23799
hbjORbj merged 4 commits intomainfrom
refactor/move-prisma-seed-to-scripts

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Sep 12, 2025

What does this PR do?

  • In prisma package, seed.ts, seed-app-store.ts and seed-performance-testing.ts import appstore. This PR migrates them to scripts folder.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A - I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Verify Prisma seeding still works (uses new scripts/seed.ts):
yarn workspace @calcom/prisma generate-schemas
yarn workspace @calcom/prisma db-seed
  1. Verify app-store seed points to scripts/seed-app-store.ts:
yarn workspace @calcom/prisma seed-app-store
  1. Sanity-run performance seed (small side-effect, creates one heavy user):
npx ts-node --transpile-only scripts/seed-performance-testing.ts

@hbjORbj hbjORbj requested a review from a team as a code owner September 12, 2025 14:27
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 12, 2025

Walkthrough

  • packages/prisma/package.json: Updated script references to use centralized scripts — seed-app-store and prisma.seed now point to ../../scripts/seed-app-store.ts and ../../scripts/seed.ts.
  • scripts/*.ts: Switched local relative imports to package-scoped imports (@calcom/prisma, @calcom/prisma/client, @calcom/prisma/enums) and adjusted helper import paths to ../packages/prisma/*; scripts/seed-app-store.ts now uses path.resolve for dotenv; minor formatting/newline changes in some files.

Possibly related PRs

  • feat: (PBAC) Add db seed  #22704: Adjusts Prisma seeding tooling and seed.ts/package.json scripts, overlapping with this PR’s seed script path and import refactors.

Pre-merge checks (2 passed, 1 warning)

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title concisely and accurately summarizes the main change: moving app-store dependent seed files from the prisma package into the repository-level scripts directory, matching the raw_summary and PR objectives and containing no extraneous or misleading information.
Description Check ✅ Passed The PR description is directly related to the changeset: it explains that seed files were migrated from the prisma package to scripts, includes the mandatory checklist, and provides concrete testing commands, so it is not off-topic.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/move-prisma-seed-to-scripts

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.

@graphite-app graphite-app bot requested a review from a team September 12, 2025 14:27
@hbjORbj hbjORbj changed the title refactor: move prisma seed to scripts refactor: move some seed files from prisma to scripts Sep 12, 2025
@keithwillcode keithwillcode added core area: core, team members only foundation labels Sep 12, 2025
@hbjORbj hbjORbj changed the title refactor: move some seed files from prisma to scripts refactor: move app-store dependend seed files from prisma to scripts Sep 12, 2025
@pull-request-size pull-request-size bot added size/M and removed size/S labels Sep 12, 2025
@vercel
Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 12, 2025 2:38pm
cal-eu Ignored Ignored Sep 12, 2025 2:38pm

@hbjORbj hbjORbj changed the title refactor: move app-store dependend seed files from prisma to scripts refactor: move app-store dependendt seed files from prisma to scripts Sep 12, 2025
@hbjORbj hbjORbj changed the title refactor: move app-store dependendt seed files from prisma to scripts refactor: move app-store dependent seed files from prisma to scripts Sep 12, 2025
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/seed.ts (1)

393-409: Fix Promise.all misuse (nested array not awaited).

You’re passing an array containing an array of promises, so user creation isn’t awaited and errors may be lost.

Apply this diff:

-  await Promise.all([
-    usersOutsideOrg.map(async (user) => {
-      return await prisma.user.create({
-        data: {
-          username: user.username,
-          name: user.name,
-          email: user.email,
-          emailVerified: new Date(),
-          password: {
-            create: {
-              hash: await hashPassword(user.username),
-            },
-          },
-        },
-      });
-    }),
-  ]);
+  await Promise.all(
+    usersOutsideOrg.map(async (user) =>
+      prisma.user.create({
+        data: {
+          username: user.username,
+          name: user.name,
+          email: user.email,
+          emailVerified: new Date(),
+          password: {
+            create: {
+              hash: await hashPassword(user.username),
+            },
+          },
+        },
+      })
+    )
+  );
🧹 Nitpick comments (2)
scripts/seed.ts (2)

454-459: Narrow Prisma select to only needed fields.

members isn’t used; orgProfiles only needs id and userId. This reduces payload and complies with our “select-only” guideline.

-  select: {
-    id: true,
-    members: true,
-    orgProfiles: true,
-  },
+  select: {
+    id: true,
+    orgProfiles: { select: { id: true, userId: true } },
+  },

1378-1378: Trim trailing space and add newline at EOF.

Avoid lint noise.

-  }); 
+  });
+
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 74288b0 and 9261c5f.

📒 Files selected for processing (2)
  • packages/prisma/package.json (1 hunks)
  • scripts/seed.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • scripts/seed.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • scripts/seed.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • scripts/seed.ts
🧠 Learnings (2)
📚 Learning: 2025-09-09T03:29:43.025Z
Learnt from: emrysal
PR: calcom/cal.com#23692
File: packages/lib/server/service/InsightsBookingBaseService.ts:16-16
Timestamp: 2025-09-09T03:29:43.025Z
Learning: In the Cal.com codebase, readonlyPrisma is still an instance of PrismaClient, making type changes from `typeof readonlyPrisma` to `PrismaClient` less critical since they are fundamentally compatible types.

Applied to files:

  • scripts/seed.ts
📚 Learning: 2025-09-03T11:54:05.409Z
Learnt from: supalarry
PR: calcom/cal.com#23514
File: apps/api/v2/src/ee/bookings/2024-08-13/services/bookings.service.ts:579-582
Timestamp: 2025-09-03T11:54:05.409Z
Learning: In calcom/cal.com bookings repository methods, when Prisma select uses `eventType: true`, all eventType fields including seatsShowAttendees are automatically included in the selection. Explicit field selection is not required when using `true` for nested relations.

Applied to files:

  • scripts/seed.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (2)
packages/prisma/package.json (1)

47-47: Approve — centralized seed path resolves

packages/prisma's ../../scripts/seed.ts resolves to repo-root/scripts/seed.ts (resolved: /home/jailuser/git/scripts/seed.ts).

scripts/seed.ts (1)

14-21: Good move to package-scoped imports and shared helpers.

This reduces duplication and clarifies dependencies; the relative paths from scripts/ to packages/prisma look correct.

"generate-schemas": "prisma generate && prisma format",
"post-install": "yarn generate-schemas",
"seed-app-store": "ts-node --transpile-only ./seed-app-store.ts",
"seed-app-store": "ts-node --transpile-only ../../scripts/seed-app-store.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is backwards now but better than the code being that way. Perhaps we migrate these commands at some point to be out of this package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we losing this functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, that's a mistake, let me revert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done done

@hbjORbj hbjORbj enabled auto-merge (squash) September 12, 2025 14:45
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/seed.ts (1)

393-410: Promise.all not awaiting inner promises.

Promise.all([arrayOfPromises]) resolves immediately with the array, skipping awaits. Pass the array directly.

-  await Promise.all([
-    usersOutsideOrg.map(async (user) => {
-      return await prisma.user.create({
-        data: {
-          username: user.username,
-          name: user.name,
-          email: user.email,
-          emailVerified: new Date(),
-          password: {
-            create: {
-              hash: await hashPassword(user.username),
-            },
-          },
-        },
-      });
-    }),
-  ]);
+  await Promise.all(
+    usersOutsideOrg.map(async (user) => {
+      return prisma.user.create({
+        data: {
+          username: user.username,
+          name: user.name,
+          email: user.email,
+          emailVerified: new Date(),
+          password: {
+            create: {
+              hash: await hashPassword(user.username),
+            },
+          },
+        },
+      });
+    })
+  );
🧹 Nitpick comments (7)
scripts/seed-app-store.ts (2)

244-245: Prefer named export over default export.

Align with repo guideline to avoid default exports. Rename the exported function and update its call below, and adjust the import in scripts/seed.ts.

Apply:

-export default async function main() {
+export async function mainAppStore() {

And at the bottom:

-main()
+mainAppStore()

Then in scripts/seed.ts:

-import mainAppStore from "./seed-app-store";
+import { mainAppStore } from "./seed-app-store";

400-402: Safer enum membership check.

Using the in operator on enums can be brittle; prefer value membership against Object.values to avoid key/value pitfalls.

-  const validatedCategories = app.categories.filter(
-    (category): category is AppCategories => category in AppCategories
-  );
+  const validatedCategories = app.categories.filter(
+    (category): category is AppCategories =>
+      (Object.values(AppCategories) as string[]).includes(category as string)
+  );
scripts/seed-performance-testing.ts (2)

1-5: Update run command in the header to match new location.

Current instruction assumes running from scripts/; most folks run from repo root.

- *  Run it as `npx ts-node --transpile-only ./seed-performance-testing.ts`
+ *  Run it as `npx ts-node --transpile-only scripts/seed-performance-testing.ts`

325-325: Trim trailing whitespace.

Minor formatting nit.

-createAUserWithManyBookings(); 
+createAUserWithManyBookings();
scripts/seed.ts (3)

41-50: Prisma: select only needed fields.

You only check existence; avoid fetching full records.

Example:

return prisma.team.findFirst({
  where: { metadata: { path: ["requestedSlug"], equals: slug } },
  select: { id: true },
});

74-96: Prisma: minimize selected fields on upserts.

setupPlatformUser only needs id/username later. Reduce payload.

Example:

const platformUser = await prisma.user.upsert({
  where: { email_username: { email: user.email, username: user.username } },
  update: userData,
  create: userData,
  select: { id: true, username: true },
});

1369-1372: Optional: align with named export if you adopt it.

If you switch seed-app-store.ts to a named export, update this import (Line 20) and keep this call as-is.

Run locally:

  • yarn workspace @calcom/prisma db-seed
  • yarn workspace @calcom/prisma seed-app-store
    Confirm both complete without TS errors.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9261c5f and c13586a.

📒 Files selected for processing (4)
  • packages/prisma/package.json (2 hunks)
  • scripts/seed-app-store.ts (1 hunks)
  • scripts/seed-performance-testing.ts (2 hunks)
  • scripts/seed.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/prisma/package.json
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • scripts/seed-performance-testing.ts
  • scripts/seed-app-store.ts
  • scripts/seed.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • scripts/seed-performance-testing.ts
  • scripts/seed-app-store.ts
  • scripts/seed.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • scripts/seed-performance-testing.ts
  • scripts/seed-app-store.ts
  • scripts/seed.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Production builds / Build API v1
  • GitHub Check: Production builds / Build API v2
  • GitHub Check: Production builds / Build Web App
  • GitHub Check: Tests / Unit
  • GitHub Check: Production builds / Build Atoms
  • GitHub Check: Type check / check-types
🔇 Additional comments (5)
scripts/seed-app-store.ts (2)

9-11: Good move to package-scoped imports.

Using the shared Prisma client and enums via package paths is correct and prevents multi-client instantiation.


13-13: Env path resolution LGTM.

Using path.resolve with __dirname after relocating the script ensures the .env.appStore is loaded from repo root.

scripts/seed-performance-testing.ts (1)

14-14: Import path change LGTM.

The new relative path to seed-utils matches the script’s new location.

scripts/seed.ts (2)

11-14: Package-scoped Prisma imports LGTM.

This ensures consistent client reuse and typed enums/types throughout the seed.


19-19: Type-only import breaks typeof usage; switch to value import.

You use z.infer, which requires the value symbol. import type will cause TS errors.

-import type { teamMetadataSchema } from "../packages/prisma/zod-utils";
+import { teamMetadataSchema } from "../packages/prisma/zod-utils";
⛔ Skipped due to learnings
Learnt from: hbjORbj
PR: calcom/cal.com#23475
File: packages/lib/payment/shouldChargeNoShowCancellationFee.ts:3-3
Timestamp: 2025-09-12T07:17:03.498Z
Learning: When using `z.infer<typeof ZodSchema>` pattern in TypeScript, the schema can be imported as a type-only import because the `typeof` operation happens at the type level during compilation, not at runtime. This is a common and valid pattern in Zod-based codebases.
Learnt from: hbjORbj
PR: calcom/cal.com#23475
File: packages/lib/payment/shouldChargeNoShowCancellationFee.ts:3-3
Timestamp: 2025-09-12T07:17:03.498Z
Learning: When using `z.infer<typeof ZodSchema>` in TypeScript, the `typeof` is a type-level operator resolved at compile time, not a runtime operation. This means the schema can be imported as `import type` because the `typeof` computation happens entirely within TypeScript's type system during compilation.
Learnt from: hbjORbj
PR: calcom/cal.com#23475
File: packages/app-store/_utils/CRMRoundRobinSkip.ts:3-3
Timestamp: 2025-09-12T07:16:30.576Z
Learning: `z.infer<typeof Schema>` in type annotations works correctly with type-only imports because TypeScript resolves the typeof expression at compile time in type positions, not requiring the runtime schema value.
Learnt from: hbjORbj
PR: calcom/cal.com#23475
File: packages/features/credentials/handleDeleteCredential.ts:5-10
Timestamp: 2025-09-12T07:15:58.030Z
Learning: When EventTypeAppMetadataSchema is used only in z.infer<typeof EventTypeAppMetadataSchema> type annotations or type casts, it can be imported as a type-only import since this usage is purely at the TypeScript type level and doesn't require the runtime value.

@github-actions
Copy link
Contributor

E2E results are ready!

@hbjORbj hbjORbj merged commit 1fee903 into main Sep 12, 2025
45 checks passed
@hbjORbj hbjORbj deleted the refactor/move-prisma-seed-to-scripts branch September 12, 2025 17:27
This was referenced Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants