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

Rebuild Prisma Client between upgrades #1155

Merged

Conversation

noire-munich
Copy link
Collaborator

Addresses issue #1083

@peterp peterp changed the title pr/prisma-problems-on-upgrade Rebuild Prisma Client between upgrades Sep 17, 2020
@peterp
Copy link
Contributor

peterp commented Sep 17, 2020

This covers the first part of the task, which is shutting down the api side, but I think we need to generate a new Prisma client after the upgrade has run!

Let me know if you need me to outline the steps here. :)

@noire-munich
Copy link
Collaborator Author

@peterp yes please do outline the steps, I'm still noobing a lot of my way through this x)

@thedavidprice
Copy link
Contributor

Hi gents!

Kill vs. Warn in case of server is running

If a running server is a part of the problem, might it be easier to simply:

  • check if server is running (note: we can do this by port, but users can specify a different port)
  • if running, refuse to run the upgrade command and message user to first shutdown servers

It's a personal preference, but I've always been a proponent of telling users they need to stop processes themselves instead of automatically doing it for them. Another option here could be to default to "warn if process is running" but have an option to "kill process if running".

Upgrade Prisma and Regenerate Client

  • It seemed the root of the problem was Prisma package/client in node_modules not being updated correctly, true? In that case, should this command delete node_modules/@prisma and node_modules/.prisma before running upgrades?
  • For regenerating the Prisma Client, let's pass that as an option as well in case a user prefers to upgrade without running yarn rw db up. E.g yarn rw upgrade --no-client. Make sense?

@peterp
Copy link
Contributor

peterp commented Sep 23, 2020

Kill vs. Warn in case of server is running

@thedavidprice Yeah, that makes sense, let's do that instead.

It seemed the root of the problem was Prisma package/client in node_modules not being updated correctly

The problem is that the user needs to regenerate the prisma client.

@thedavidprice
Copy link
Contributor

@noire-munich just checking back here. Any chance?

@noire-munich
Copy link
Collaborator Author

@thedavidprice nope not yet, I was keeping an eye more on #1154 lately.
Do we need either of them soon?

@thedavidprice
Copy link
Contributor

Do we need either of them soon?

We do not. Primarily wanted to make sure you saw the previous comments and they made sense!

re: Setup and #1154
Thanks again for getting the Setup command rolling! Super helpful and working well.

Other than waiting for a reply from Peter (btw, he's on vacation until next week), is there anything else you were waiting on?

I'm replying in that thread now.

@peterp
Copy link
Contributor

peterp commented Oct 10, 2020

@noire-munich Sorry, I completely missed your comment asking about the steps:

  1. Let the upgrade command run and complete.
  2. Run yarn rw db up (via exaca)
  3. Run yarn rw dev (which will kill the server if it's running) (via exaca)

@thedavidprice I thought a bit about your comments about warning the user about the running server and making them do it instead, but I think it's a lot more code and a bunch more complicated.

@noire-munich
Copy link
Collaborator Author

Hi guys!

Thanks again for getting the Setup command rolling! Super helpful and working well.

No problem \o/ glad about it :)

Other than waiting for a reply from Peter (btw, he's on vacation until next week), is there anything else you were waiting on?

Nope thank you, I'm a bit slow on my contributions lately because I'm focusing on a project RW based that I hope could make it to preprod during Q4 :p

@noire-munich Sorry, I completely missed your comment asking about the steps:

No more time off for you @peterp 😈 , seriously though, not a problem 😋 .

Aside from that, both options were clear, however @thedavidprice I would submit to @peterp latest proposal for a first draft, in the undying spirit of "getting things done" before "making them right" ( ok, wording has changed a bit since I last checked the roadmap :p ).

I'll go with it and make modifications if we are satisfied and want to push it a bit further, if it's ok with you both :)

@noire-munich
Copy link
Collaborator Author

@peterp I updated the code, I've left two things I'd like to sort out together:

  • the shutdown command feels irrelevant now that we reboot the dev server entirely, can you confirm? I'd remove it to reduce the time of the upgrade command, but to make things as clean as possible I'd shutdown the api and web sides entirely.

  • I used the execa.command, it throws, I thought of using maybe execa.commandSync since I don't think we'd do anything with stdout or stderr but I'm not sure this one throws. What do you think about it?

@peterp
Copy link
Contributor

peterp commented Oct 10, 2020

The shutdown command feels irrelevant now that we reboot the dev server entirely, can you confirm? I'd remove it to reduce the time of the upgrade command, but to make things as clean as possible I'd shutdown the api and web sides entirely.

It is indeed a bit irrelevant now, since attempting to start the dev-server will shut it down if it's already running.

I used the execa.command, it throws, I thought of using maybe execa.commandSync since I don't think we'd do anything with stdout or stderr but I'm not sure this one throws. What do you think about it?

I would suggest using the runCommandTask that we've got over here, you would just supply yarn rw db up as the whole command.

const success = await runCommandTask(
[
{
title: 'Migrate database up...',
cmd: 'yarn prisma',
args: [
'migrate up',
increment && `${increment}`,
'--experimental',
'--create-db',
autoApprove && '--auto-approve',
].filter(Boolean),
},
],
{ verbose }
)

@thedavidprice
Copy link
Contributor

@noire-munich and @peterp checking in to see if it's worth picking up work on this one? If so, let me know (especially if I can be of help).

@github-actions
Copy link

github-actions bot commented Feb 8, 2021

@noire-munich
Copy link
Collaborator Author

@thedavidprice @peterp
I've updated the PR and reduced it to only regenerating the Prisma client thanks to the handler David has posted a couple of days ago, which is now used in the dev command and comes with the replacement of rw db to rw prisma.
I believe it should be enough to fix the issue.

@thedavidprice
Copy link
Contributor

@noire-munich Thanks so much! And great to have you back 🚀

@dac09 Given some testing, this seems like a candidate for v0.25. Can you confirm on your end whether we should consider?

@dac09 dac09 added this to the v0.25.0 milestone Feb 9, 2021
Copy link
Collaborator

@dac09 dac09 left a comment

Choose a reason for hiding this comment

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

LGTM!

@thedavidprice
Copy link
Contributor

I'll take it from here. It's on my list for potentially including in v0.25 release. Thanks!

@thedavidprice
Copy link
Contributor

Fixed an outdated import path. Otherwise is working 🚀

Will merge once CI passes.

@thedavidprice thedavidprice merged commit 99e30f3 into redwoodjs:main Feb 10, 2021
@noire-munich
Copy link
Collaborator Author

@noire-munich Thanks so much! And great to have you back rocket

pleasure is mine ;)
and thanks guys for accepting it :)

dac09 added a commit to dac09/redwood that referenced this pull request Feb 12, 2021
…ender-p1

* 'main' of github.com:redwoodjs/redwood:
  v0.25.0
  yarn rw prisma commands now show a little tip (redwoodjs#1772)
  FIx typo (redwoodjs#1779)
  Ensure all data is removed during the teardown step (redwoodjs#1714)
  [v0.25] revert to @prisma/cli; recreate yarn.lock (redwoodjs#1774)
  use prisma db push for test DB (redwoodjs#1768)
  Disable --version and -v for prisma alias. (redwoodjs#1767)
  Rebuild Prisma Client between upgrades (redwoodjs#1155)
  upgrade Prisma v2.16.1 (redwoodjs#1766)
  [v0.25] Remove warning if you scaffold a model with a relation (redwoodjs#1757)
  [v0.25] Scaffolded many-to-many relationship fixes (redwoodjs#1758)
  add forrest and kim-adeline; update all contribs (redwoodjs#1763)
  Run clean and then build the js.
  Fix: applying afterQuery in storybook mocks (redwoodjs#1740)
  restructure and update Deploy command and change Setup Deploy command template [breaking] (redwoodjs#1747)
  Fixes prisma command when path has spaces
  Make tutorial work with workspaces.
  Add "packages/*" to the template.
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.

None yet

4 participants