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

Merged
merged 41 commits into from
Sep 13, 2024

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 ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Sep 13, 2024 1:00pm
cal ⬜️ Ignored (Inspect) Visit Preview Sep 13, 2024 1:00pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Sep 13, 2024 1:00pm

@Amit91848
Copy link
Contributor

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

@keithwillcode keithwillcode requested a review from a team July 10, 2024 14:56
@keithwillcode keithwillcode added this to the v4.3 milestone Jul 10, 2024
@keithwillcode keithwillcode added High priority Created by Linear-GitHub Sync ready-for-e2e labels Jul 10, 2024
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-four 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 277.24 KB 504.94 KB 144.27% (🟢 -1.99%)
/apps/[slug] 294.54 KB 522.24 KB 149.21% (🟢 -2.07%)
/apps/[slug]/[...pages] 587 KB 814.7 KB 232.77% (🟢 -1.61%)
/apps/categories 254.29 KB 481.99 KB 137.71% (🟢 -1.79%)
/apps/categories/[category] 259.09 KB 486.79 KB 139.08% (🟢 -2.05%)
/apps/installation/[[...step]] 467.07 KB 694.77 KB 198.51% (🔴 +85.54%)
/apps/installed/[category] 278.22 KB 505.92 KB 144.55% (🟢 -1.82%)
/auth/saml-idp 12.22 KB 239.92 KB 68.55% (🟢 -20.80%)
/availability 426.64 KB 654.34 KB 186.95% (🟢 -1.65%)
/availability/[schedule] 410.51 KB 638.21 KB 182.34% (🟢 -1.66%)
/booking/[uid] 236.5 KB 464.2 KB 132.63% (🟡 +0.15%)
/booking/[uid]/embed 236.5 KB 464.2 KB 132.63% (🟡 +0.15%)
/bookings/[status] 324.3 KB 552 KB 157.71% (🟢 -1.68%)
/enterprise 254.34 KB 482.04 KB 137.73% (🟢 -1.79%)
/event-types 559.51 KB 787.21 KB 224.92% (🟢 -1.67%)
/event-types/[type] 435.38 KB 663.08 KB 189.45% (🟢 -1.76%)
/getting-started/[[...step]] 448.06 KB 675.76 KB 193.08% (🟡 +10.70%)
/insights 474.29 KB 701.99 KB 200.57% (🟢 -1.79%)
/more 253.85 KB 481.55 KB 137.59% (🟢 -1.79%)
/settings/admin 260.32 KB 488.02 KB 139.43% (🟢 -1.76%)
/settings/admin/apps 273.7 KB 501.4 KB 143.26% (🟢 -1.76%)
/settings/admin/apps/[category] 273.68 KB 501.38 KB 143.25% (🟢 -1.75%)
/settings/admin/flags 264.15 KB 491.85 KB 140.53% (🟢 -1.77%)
/settings/admin/impersonation 260.71 KB 488.41 KB 139.55% (🟢 -1.77%)
/settings/admin/lockedSMS 281.8 KB 509.5 KB 145.57% (🟢 -1.73%)
/settings/admin/lockedSMS/lockedSMSView 119.51 KB 347.21 KB 99.20% (🟢 -0.15%)
/settings/admin/oAuth 272.43 KB 500.13 KB 142.89% (🟢 -1.75%)
/settings/admin/oAuth/oAuthView 95.41 KB 323.11 KB 92.32% (🟢 -0.20%)
/settings/admin/orgMigrations/_OrgMigrationLayout 249.1 KB 476.8 KB 136.23% (🟢 -1.81%)
/settings/admin/orgMigrations/moveTeamToOrg 299.02 KB 526.72 KB 150.49% (🟢 -1.74%)
/settings/admin/orgMigrations/moveUserToOrg 318.85 KB 546.55 KB 156.16% (🟢 -1.71%)
/settings/admin/orgMigrations/removeTeamFromOrg 298.78 KB 526.48 KB 150.42% (🟢 -1.74%)
/settings/admin/orgMigrations/removeUserFromOrg 298.79 KB 526.5 KB 150.43% (🟢 -1.74%)
/settings/admin/organizations 262.2 KB 489.9 KB 139.97% (🟢 -1.76%)
/settings/admin/organizations/[id]/edit 260.87 KB 488.57 KB 139.59% (🟢 -1.76%)
/settings/admin/users 262.97 KB 490.67 KB 140.19% (🟢 -1.76%)
/settings/admin/users/[id]/edit 392.18 KB 619.88 KB 177.11% (🟢 -1.73%)
/settings/admin/users/add 391.85 KB 619.55 KB 177.01% (🟢 -1.72%)
/settings/billing 260.52 KB 488.22 KB 139.49% (🟢 -1.76%)
/settings/developer/api-keys 264.92 KB 492.62 KB 140.75% (🟢 -1.77%)
/settings/developer/webhooks 265.09 KB 492.79 KB 140.80% (🟢 -1.77%)
/settings/developer/webhooks/[id] 266.07 KB 493.77 KB 141.08% (🟢 -1.75%)
/settings/developer/webhooks/new 266.1 KB 493.8 KB 141.09% (🟢 -1.75%)
/settings/my-account/appearance 313.53 KB 541.23 KB 154.64% (🟢 -1.76%)
/settings/my-account/calendars 271.94 KB 499.64 KB 142.75% (🟢 -1.80%)
/settings/my-account/conferencing 272.85 KB 500.55 KB 143.01% (🟢 -1.80%)
/settings/my-account/general 376.02 KB 603.72 KB 172.49% (🟢 -1.76%)
/settings/my-account/out-of-office 265.55 KB 493.25 KB 140.93% (🟢 -1.77%)
/settings/my-account/profile 408.46 KB 636.16 KB 181.76% (🟢 -1.76%)
/settings/organizations/[id]/about 159.71 KB 387.41 KB 110.69% (🟡 +0.48%)
/settings/organizations/[id]/add-teams 159.7 KB 387.4 KB 110.68% (🟡 +0.49%)
/settings/organizations/admin-api 260.48 KB 488.18 KB 139.48% (🟢 -1.77%)
/settings/organizations/appearance 122.37 KB 350.07 KB 100.02% (🟢 -48.01%)
/settings/organizations/billing 260.56 KB 488.26 KB 139.50% (🟢 -1.76%)
/settings/organizations/dsync 293.18 KB 520.88 KB 148.82% (🟢 -1.76%)
/settings/organizations/general 348.87 KB 576.57 KB 164.73% (🟢 -1.75%)
/settings/organizations/members 400.04 KB 627.74 KB 179.36% (🟢 -1.76%)
/settings/organizations/new 159.71 KB 387.41 KB 110.69% (🟡 +0.48%)
/settings/organizations/privacy 266.07 KB 493.77 KB 141.08% (🟢 -1.77%)
/settings/organizations/profile 417 KB 644.7 KB 184.20% (🟡 +2.82%)
/settings/organizations/sso 271.15 KB 498.85 KB 142.53% (🟢 -1.77%)
/settings/organizations/teams/other 261.39 KB 489.09 KB 139.74% (🟢 -1.77%)
/settings/organizations/teams/other/[id]/appearance 273.29 KB 500.99 KB 143.14% (🟢 -1.72%)
/settings/organizations/teams/other/[id]/members 267.98 KB 495.68 KB 141.62% (🟢 -1.76%)
/settings/organizations/teams/other/[id]/profile 471.67 KB 699.38 KB 199.82% (🟢 -1.76%)
/settings/platform 258.95 KB 486.65 KB 139.04% (🟢 -1.78%)
/settings/platform/new 120.72 KB 348.42 KB 99.55% (🟡 +0.52%)
/settings/platform/oauth-clients/[clientId]/edit 257.26 KB 484.96 KB 138.56% (🟢 -1.79%)
/settings/platform/oauth-clients/create 256.4 KB 484.1 KB 138.31% (🟢 -1.78%)
/settings/security/impersonation 265.73 KB 493.43 KB 140.98% (🟢 -1.76%)
/settings/security/password 303.91 KB 531.61 KB 151.89% (🟢 -1.74%)
/settings/security/sso 270.6 KB 498.3 KB 142.37% (🟢 -1.76%)
/settings/security/two-factor-auth 269.21 KB 496.91 KB 141.97% (🟢 -1.76%)
/settings/teams 260.05 KB 487.75 KB 139.36% (🟢 -1.77%)
/settings/teams/[id]/appearance 273.27 KB 500.97 KB 143.14% (🟢 -1.72%)
/settings/teams/[id]/billing 260.56 KB 488.26 KB 139.50% (🟢 -1.76%)
/settings/teams/[id]/members 378.11 KB 605.81 KB 173.09% (🟢 -1.76%)
/settings/teams/[id]/profile 472.51 KB 700.21 KB 200.06% (🟢 -1.75%)
/settings/teams/new 193.04 KB 420.74 KB 120.21% (🟢 -1.81%)
/teams 254.08 KB 481.78 KB 137.65% (🟢 -1.79%)
/upgrade 254.2 KB 481.9 KB 137.69% (🟢 -1.79%)
/video/[uid] 291.23 KB 518.93 KB 148.27% (🟢 -0.17%)
/workflows 286.1 KB 513.8 KB 146.80% (🟢 -1.73%)
/workflows/[workflow] 414.39 KB 642.09 KB 183.45% (🟢 -1.50%)
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.

Comment on lines 8 to 10
const whereInput = where[key as any] as any;
let message;
if (!whereInput) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This always fails if a whereInput value is false, and you get an error without passing undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice find, @anikdhabal. And from Prisma's docs, with null, they won't ignore the params, only with undefined so this change is ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's true👍

@anikdhabal anikdhabal marked this pull request as ready for review September 13, 2024 11:58
@dosubot dosubot bot added automated-tests area: unit tests, e2e tests, playwright platform Anything related to our platform plan labels Sep 13, 2024
@graphite-app graphite-app bot requested a review from a team September 13, 2024 11:58
Copy link
Contributor

@anikdhabal anikdhabal left a comment

Choose a reason for hiding this comment

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

LGTM🚀

@keithwillcode keithwillcode merged commit fd8afbc into main Sep 13, 2024
38 of 39 checks passed
@keithwillcode keithwillcode deleted the chore/add-update-many-extension branch September 13, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automated-tests area: unit tests, e2e tests, playwright core area: core, team members only foundation High priority Created by Linear-GitHub Sync 🧹 Improvements Improvements to existing features. Mostly UX/UI platform Anything related to our platform plan ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants