refactor: move app-store dependent seed files from prisma to scripts#23799
refactor: move app-store dependent seed files from prisma to scripts#23799
Conversation
Walkthrough
Possibly related PRs
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield 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 resolvespackages/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", |
There was a problem hiding this comment.
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.
| process.exit(1); | ||
| }) | ||
| .finally(async () => { | ||
| await prisma.$disconnect(); |
There was a problem hiding this comment.
Are we losing this functionality?
There was a problem hiding this comment.
ah, that's a mistake, let me revert
There was a problem hiding this comment.
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.
📒 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 useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
scripts/seed-performance-testing.tsscripts/seed-app-store.tsscripts/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.tsscripts/seed-app-store.tsscripts/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.tsscripts/seed-app-store.tsscripts/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.
E2E results are ready! |
What does this PR do?
scriptsfolder.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?