GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(cli): warn on mismatch of global and local versions upon generate command by akhill10 · Pull Request #20951 · prisma/orm

Conversation

@akhill10

@akhill10 akhill10 commented Sep 4, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
  • Compared the versions of global and local versions of prisma. If the versions doesn't match throw a warning.
  • Upon user confirmation ( press any key ) it continues of execution of generate command.

Fixes #1911
/claim #1911

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@akhill10
feat: warn on mismatch of global and local versions
72ec88b
@akhill10
akhill10 requested a review from a team as a code owner September 4, 2023 18:32
@akhill10
akhill10 requested review from Druue and SevInf and removed request for a team September 4, 2023 18:32
@algora-pbc algora-pbc Bot mentioned this pull request Sep 4, 2023
Warn on mismatch between global prisma and local prisma or @prisma/client #1911
Closed
@CLAassistant

CLAassistant commented Sep 4, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jharrell
jharrell suggested changes Sep 5, 2023
View reviewed changes

@jharrell jharrell left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@akhill10 thank you for your first PR!

However, I will need to request changes. This PR should do the following:

If a user is running prisma generate, meaning the generate command run from prisma that is globally installed (npm i -g prisma) and the local version of prisma and/or @prisma/client differ from the globally installed version, we should explicitly require the user to confirm they want to proceed.

Please make the following changes:

  1. check against globally installed prisma not .prisma/client
  2. check against locally installed prisma and @prisma/client (checking the package.json is probably a good first step)
  3. Please ask for explicit confirmation from the user. Y/y/yes/etc. Not any key.
  4. Please provide tests that fail on main and pass after your implementation

Thank you for your time!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

akhill10 reacted with thumbs up emoji akhill10 reacted with eyes emoji
All reactions
  • 👍 1 reaction
  • 👀 1 reaction
@akhill10
feat(cli/generate): warn on version mismatch of global prisma with lo…
5c18084
…cal prisma/prisma@client
@akhill10

akhill10 commented Sep 6, 2023

Copy link
Copy Markdown
Author

@jharrell Thanks for the feedback. Updated the PR with the requested changes.

  • I was able to test it locally via contribution guide, Please watch the video below

https://www.loom.com/share/6c2def1c11164690a314dc456182c466?sid=138bb99a-8e3e-4332-adfe-27e8933872b1

  • I need help in writing the tests through spec files. Can you please help me with the steps on how to set up different global and local versions through jest?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10
akhill10 requested a review from jharrell September 6, 2023 12:47
@akhill10 akhill10 changed the title feat: warn on mismatch of global and local versions upon generate command feat(cli): warn on mismatch of global and local versions upon generate command Sep 7, 2023
@algora-pbc algora-pbc Bot added the 🙋 Bounty claim label Sep 8, 2023
@akhill10

akhill10 commented Sep 9, 2023

Copy link
Copy Markdown
Author

Hi @jharrell, did you get a chance to look at this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jharrell
Merge branch 'main' into feat/warn-on-mismatch-of-global-local-versions
b38f986
@jharrell

jharrell commented Sep 12, 2023

Copy link
Copy Markdown

@akhill10 thank you very much for the loom video and apologies for the delay on my end!

For this case, I think you should only test what is needed. That is to say, mock the results of isCurrentBinInstalledGlobally, getInstalledPrismaClientVersion, and getLocalPrismaVersion to show in the case of a mismatch we require specific confirmation.

akhill10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10

akhill10 commented Sep 14, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@jharrell I tried mocking the functions but result is not giving the mocked results in the generate.test.ts

//imports
import { Generate, getLocalPrismaVersion } from '../../Generate'
import { getInstalledPrismaClientVersion } from '../../utils/getClientVersion'

it('should warn on mismatch of global version and local client version', async () => {
    ctx.fixture('example-project')
    const versions = { getInstalledPrismaClientVersion, isCurrentBinInstalledGlobally, getLocalPrismaVersion }
    jest.spyOn(versions, 'getInstalledPrismaClientVersion').mockReturnValue(Promise.resolve('0.0.1'))
    jest.spyOn(versions, 'isCurrentBinInstalledGlobally').mockReturnValue('npm')
    jest.spyOn(versions, 'getLocalPrismaVersion').mockReturnValue(Promise.resolve('0.0.2'))

    const data = await ctx.cli('generate')
    expect(data.stdout).toMatchInlineSnapshot(`warn: Global [email protected] and Local @prisma/[email protected] don't match. This might lead to unexpected behavior. Would you like to proceed ? [yes/no]`)
});

Its still getting the example-project version value i.e 0.0.0 rather than 0.0.1. am I doing anything wrong here ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jharrell

jharrell commented Sep 14, 2023

Copy link
Copy Markdown

@akhill10 I'm not sure. Please push your changes to this branch so that I can review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10
test: warn on mismatch of global and local versions
c3c43cf
@akhill10

akhill10 commented Sep 14, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@jharrell Pushed the test case commit. Please take a look

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10

akhill10 commented Sep 19, 2023

Copy link
Copy Markdown
Author

Hello @jharrell , did you get a chance to review this? am I doing anything wrong in mocking the functions ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jharrell
Merge branch 'main' into feat/warn-on-mismatch-of-global-local-versions
42d6c00
@jharrell

jharrell commented Sep 20, 2023

Copy link
Copy Markdown

Have you tried using .mock instead of .spyOn?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10

akhill10 commented Sep 20, 2023

Copy link
Copy Markdown
Author

Yeah, I did but no luck.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jharrell

jharrell commented Sep 26, 2023

Copy link
Copy Markdown

Unfortunately, I'm not sure here. We'll need a way to mock these calls before we move forward.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10

akhill10 commented Sep 29, 2023

Copy link
Copy Markdown
Author

Okay thank you, I try will some alternative approaches.
If am stuck, Any help from prisma team members would be appreciated.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akhill10
Merge branch 'main' into feat/warn-on-mismatch-of-global-local-versions
b13f3b7
@SevInf SevInf added the PR: Improvement label Mar 20, 2024
@janpio janpio removed the 🙋 Bounty claim label Jun 10, 2024
@jharrell
jharrell removed their request for review June 10, 2024 17:10
@jharrell
jharrell requested review from jharrell and removed request for jharrell June 10, 2024 17:11
@wmadden

wmadden commented Jan 28, 2025

Copy link
Copy Markdown
Contributor

Hi @akhill10,

It looks like there haven't been any updates since @jharrell's last message to you. I'm closing this PR for now as part of our ongoing efforts to reduce the number of open issues and PRs in the repo.

If you feel like this is a mistake, feel free to reopen the PR and address the comments :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@wmadden wmadden closed this Jan 28, 2025
Iceshen87 pushed a commit to Iceshen87/prisma that referenced this pull request Mar 3, 2026
EthanHan
feat(cli): warn on mismatch between global prisma and local versions
3510b8b
Fixes prisma#1911

When using a globally installed prisma CLI with a different local
@prisma/client or prisma version, users will now see a warning message.

Implementation:
- Added versionMismatchChecker.ts with dependency injection for testability
- Modified Generate.ts to check version mismatch before running generate
- Added comprehensive test suite (11 tests, all passing)

The solution uses dependency injection to make the version checking
functions mockable in tests, addressing the issue from the previous
attempt in PR prisma#20951 where jest.spyOn could not properly mock the
module-level functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@SevInf SevInf Awaiting requested review from SevInf SevInf is a code owner automatically assigned from prisma/orm-ts-maintain
@Druue Druue Awaiting requested review from Druue Druue is a code owner automatically assigned from prisma/orm-ts-maintain
1 more reviewer
@jharrell jharrell jharrell requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

PR: Improvement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Warn on mismatch between global prisma and local prisma or @prisma/client

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@akhill10 @CLAassistant @jharrell @wmadden @janpio @SevInf
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.