Skip to content

Conversation

@emrysal
Copy link
Contributor

@emrysal emrysal commented Dec 8, 2025

What does this PR do?

Splits the large prisma.team.create transaction in scripts/seed.ts (around L418) into smaller, separate operations to prevent transaction timeouts when seeding organizations with many members.

The original code created the organization along with all orgProfiles and memberships in a single nested Prisma create, which could timeout on large datasets.

Changes:

  1. Create organization (team) with just metadata and organizationSettings
  2. Create org profiles in batches of 50 using Promise.all
  3. Create memberships in batches of 100 using createMany
  4. Fetch created profiles to rebuild the member-profile mapping

Mandatory Tasks (DO NOT REMOVE)

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

How should this be tested?

  1. Run the seed script: yarn db-seed
  2. Verify organizations are created with all their profiles and memberships intact
  3. Test with a large number of org members to confirm no timeout occurs

Human Review Checklist

  • Verify the accepted ?? false fallback (line 468) is correct - original code passed accepted directly without fallback
  • Consider if partial failure handling is needed (the operations are no longer atomic across all steps)
  • Confirm the batch sizes (50 for profiles, 100 for memberships) are appropriate

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked if my changes generate no new warnings

Link to Devin run: https://app.devin.ai/sessions/ca372e66c88a44409019142f232172b2
Requested by: [email protected] (@emrysal)

The prisma.team.create call at L418 was creating the organization along with
all orgProfiles and memberships in a single large transaction, which could
timeout when there are many members.

This change splits the operation into smaller, separate transactions:
1. Create the organization (team) with just metadata and organizationSettings
2. Create org profiles in batches of 50 using Promise.all
3. Create memberships in batches of 100 using createMany
4. Fetch created profiles to rebuild the member-profile mapping

This approach avoids transaction timeouts while maintaining the same
functionality and data integrity.

Co-Authored-By: [email protected] <[email protected]>
@devin-ai-integration
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' or '@devin'.
  • 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

@vercel
Copy link

vercel bot commented Dec 8, 2025

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

Project Deployment Preview Comments Updated (UTC)
cal-companion Ready Ready Preview Comment Dec 8, 2025 4:12am
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Dec 8, 2025 4:12am
cal-eu Ignored Ignored Dec 8, 2025 4:12am

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.

2 issues found across 1 file

Prompt for AI agents (all 2 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="scripts/seed.ts">

<violation number="1" location="scripts/seed.ts:474">
P2: `profile.findMany` should explicitly `select` only `id`/`userId` instead of returning every column, per the repo’s Prisma query guidelines.</violation>

<violation number="2" location="scripts/seed.ts:485">
P2: Rebuilding `orgMembersInDBWithProfileId` is O(n²) because every member linearly searches `createdProfiles`. Build a lookup map (userId → profileId) once and read from it in O(1) per member.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@alishaz-polymath alishaz-polymath self-requested a review December 8, 2025 04:08
@alishaz-polymath alishaz-polymath dismissed their stale review December 8, 2025 04:08

Explicit select is preferred, pointed out by cubic

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
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.

3 participants