Skip to content
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

chore: Add Prisma extension to block deleteMany/updateMany with undefined 'in' #15721

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

keithwillcode
Copy link
Contributor

@keithwillcode keithwillcode commented Jul 10, 2024

What does this PR do?

Adds a Prisma extension that will throw errors any time we try and call updateMany and the value for the in field is undefined.

Prisma's default behavior in this case is just to update all records.

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 added a Docs issue here 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?

  • Hit a part of the system that calls updateMany and ensure the functionality is fine

Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2024 10:30pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Jul 18, 2024 10:30pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Jul 18, 2024 10:30pm

@Amit91848
Copy link
Contributor

Ig this should be applied to deleteMany as well. DeleteMany without where would also delete all rows @keithwillcode

Copy link
Contributor

github-actions bot commented Jul 10, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Eighty Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/apps 276.93 KB 504.57 KB 144.16% (🟢 -2.07%)
/apps/[slug] 294.49 KB 522.13 KB 149.18% (🟢 -2.08%)
/apps/[slug]/[...pages] 586.75 KB 814.39 KB 232.68% (🟢 -1.68%)
/apps/categories 254.24 KB 481.88 KB 137.68% (🟢 -1.80%)
/apps/categories/[category] 259.05 KB 486.69 KB 139.05% (🟢 -2.07%)
/apps/installation/[[...step]] 466.94 KB 694.58 KB 198.45% (🔴 +85.51%)
/apps/installed/[category] 278.17 KB 505.82 KB 144.52% (🟢 -1.84%)
/auth/saml-idp 12.22 KB 239.87 KB 68.53% (🟢 -20.80%)
/availability 426.59 KB 654.23 KB 186.92% (🟢 -1.66%)
/availability/[schedule] 410.46 KB 638.1 KB 182.32% (🟢 -1.68%)
/bookings/[status] 324.25 KB 551.89 KB 157.68% (🟢 -1.70%)
/enterprise 254.3 KB 481.94 KB 137.70% (🟢 -1.80%)
/event-types 559.41 KB 787.05 KB 224.87% (🟢 -1.70%)
/event-types/[type] 435.77 KB 663.42 KB 189.55% (🟢 -1.65%)
/getting-started/[[...step]] 448.02 KB 675.66 KB 193.05% (🟡 +10.68%)
/insights 474.24 KB 701.88 KB 200.54% (🟢 -1.80%)
/more 253.8 KB 481.45 KB 137.56% (🟢 -1.80%)
/settings/admin 260.27 KB 487.92 KB 139.40% (🟢 -1.77%)
/settings/admin/apps 273.65 KB 501.29 KB 143.23% (🟢 -1.77%)
/settings/admin/apps/[category] 273.64 KB 501.28 KB 143.22% (🟢 -1.76%)
/settings/admin/flags 264.1 KB 491.74 KB 140.50% (🟢 -1.78%)
/settings/admin/impersonation 260.66 KB 488.31 KB 139.52% (🟢 -1.78%)
/settings/admin/lockedSMS 281.76 KB 509.4 KB 145.54% (🟢 -1.75%)
/settings/admin/oAuth 272.38 KB 500.02 KB 142.86% (🟢 -1.77%)
/settings/admin/orgMigrations/_OrgMigrationLayout 249.2 KB 476.84 KB 136.24% (🟢 -1.78%)
/settings/admin/orgMigrations/moveTeamToOrg 298.97 KB 526.62 KB 150.46% (🟢 -1.75%)
/settings/admin/orgMigrations/moveUserToOrg 318.8 KB 546.45 KB 156.13% (🟢 -1.73%)
/settings/admin/orgMigrations/removeTeamFromOrg 298.74 KB 526.38 KB 150.39% (🟢 -1.75%)
/settings/admin/orgMigrations/removeUserFromOrg 298.75 KB 526.39 KB 150.40% (🟢 -1.76%)
/settings/admin/organizations 262.16 KB 489.8 KB 139.94% (🟢 -1.78%)
/settings/admin/organizations/[id]/edit 260.82 KB 488.46 KB 139.56% (🟢 -1.78%)
/settings/admin/users 262.93 KB 490.57 KB 140.16% (🟢 -1.77%)
/settings/admin/users/[id]/edit 392.13 KB 619.77 KB 177.08% (🟢 -1.74%)
/settings/admin/users/add 391.8 KB 619.44 KB 176.98% (🟢 -1.74%)
/settings/billing 260.48 KB 488.12 KB 139.46% (🟢 -1.77%)
/settings/developer/api-keys 264.87 KB 492.51 KB 140.72% (🟢 -1.78%)
/settings/developer/webhooks 265.04 KB 492.69 KB 140.77% (🟢 -1.78%)
/settings/developer/webhooks/[id] 266.03 KB 493.67 KB 141.05% (🟢 -1.76%)
/settings/developer/webhooks/new 266.05 KB 493.69 KB 141.06% (🟢 -1.77%)
/settings/my-account/appearance 313.49 KB 541.13 KB 154.61% (🟢 -1.77%)
/settings/my-account/calendars 271.89 KB 499.54 KB 142.72% (🟢 -1.81%)
/settings/my-account/conferencing 272.8 KB 500.44 KB 142.98% (🟢 -1.81%)
/settings/my-account/general 375.98 KB 603.62 KB 172.46% (🟢 -1.77%)
/settings/my-account/out-of-office 265.5 KB 493.15 KB 140.90% (🟢 -1.78%)
/settings/my-account/profile 408.41 KB 636.05 KB 181.73% (🟢 -1.77%)
/settings/organizations/[id]/about 159.66 KB 387.3 KB 110.66% (🟡 +0.47%)
/settings/organizations/[id]/add-teams 159.65 KB 387.29 KB 110.66% (🟡 +0.47%)
/settings/organizations/admin-api 260.43 KB 488.07 KB 139.45% (🟢 -1.78%)
/settings/organizations/appearance 122.33 KB 349.97 KB 99.99% (🟢 -48.02%)
/settings/organizations/billing 260.51 KB 488.16 KB 139.47% (🟢 -1.77%)
/settings/organizations/dsync 293.14 KB 520.78 KB 148.79% (🟢 -1.77%)
/settings/organizations/general 348.82 KB 576.46 KB 164.70% (🟢 -1.77%)
/settings/organizations/members 400 KB 627.64 KB 179.33% (🟢 -1.77%)
/settings/organizations/new 159.66 KB 387.31 KB 110.66% (🟡 +0.47%)
/settings/organizations/privacy 266.03 KB 493.67 KB 141.05% (🟢 -1.78%)
/settings/organizations/profile 413.29 KB 640.93 KB 183.12% (🟡 +1.76%)
/settings/organizations/sso 271.1 KB 498.75 KB 142.50% (🟢 -1.78%)
/settings/organizations/teams/other 261.34 KB 488.98 KB 139.71% (🟢 -1.78%)
/settings/organizations/teams/other/[id]/appearance 273.24 KB 500.88 KB 143.11% (🟢 -1.73%)
/settings/organizations/teams/other/[id]/members 267.94 KB 495.58 KB 141.59% (🟢 -1.77%)
/settings/organizations/teams/other/[id]/profile 471.66 KB 699.3 KB 199.80% (🟢 -1.77%)
/settings/platform 258.9 KB 486.54 KB 139.01% (🟢 -1.80%)
/settings/platform/new 120.67 KB 348.31 KB 99.52% (🟡 +0.51%)
/settings/platform/oauth-clients/[clientId]/edit 257.21 KB 484.85 KB 138.53% (🟢 -1.80%)
/settings/platform/oauth-clients/create 256.35 KB 483.99 KB 138.28% (🟢 -1.80%)
/settings/security/impersonation 265.68 KB 493.32 KB 140.95% (🟢 -1.78%)
/settings/security/password 303.87 KB 531.51 KB 151.86% (🟢 -1.75%)
/settings/security/sso 270.55 KB 498.19 KB 142.34% (🟢 -1.78%)
/settings/security/two-factor-auth 269.16 KB 496.8 KB 141.94% (🟢 -1.77%)
/settings/teams 260.01 KB 487.65 KB 139.33% (🟢 -1.78%)
/settings/teams/[id]/appearance 273.23 KB 500.87 KB 143.11% (🟢 -1.73%)
/settings/teams/[id]/billing 260.51 KB 488.16 KB 139.47% (🟢 -1.77%)
/settings/teams/[id]/members 378.06 KB 605.7 KB 173.06% (🟢 -1.77%)
/settings/teams/[id]/profile 472.44 KB 700.08 KB 200.02% (🟢 -1.77%)
/settings/teams/new 193 KB 420.64 KB 120.18% (🟢 -1.83%)
/teams 254.03 KB 481.67 KB 137.62% (🟢 -1.80%)
/upgrade 254.15 KB 481.79 KB 137.66% (🟢 -1.80%)
/video/[uid] 291.18 KB 518.83 KB 148.24% (🟢 -0.18%)
/workflows 286.06 KB 513.7 KB 146.77% (🟢 -1.74%)
/workflows/[workflow] 414.34 KB 641.98 KB 183.42% (🟢 -1.52%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

@keithwillcode
Copy link
Contributor Author

Ig this should be applied to deleteMany as well. DeleteMany without where would also delete all rows @keithwillcode

Yes absolutely. I was looking through the code base and we have a few deleteMany. Was planning to add here.

Great call out 🙏🏼

zomars
zomars previously approved these changes Jul 11, 2024
Copy link
Member

@zomars zomars left a comment

Choose a reason for hiding this comment

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

LGTM. Worthwhile to prevent this in the future.

…-many.ts

Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
@keithwillcode
Copy link
Contributor Author

Just noticed while testing it out that if from is undefined that also causes update on all rows.

Tried the following and it updated all records. I think then we should throw error if where.from is undefined also.

No complaint from typescript as well.

await prisma.tempOrgRedirect.updateMany({
    where: {
      from: undefined,
    },
    data: {
      enabled: true,
    },
  });

Yes according to Prisma, any values specified as undefined are completely ignored/removed from the query builder and so you get this result. Can update this extension to check more aggressively.

@keithwillcode keithwillcode modified the milestones: v4.3, v4.4 Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core area: core, team members only foundation High priority Created by Linear-GitHub Sync 🧹 Improvements Improvements to existing features. Mostly UX/UI ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants