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

fix: generate client at runtime #44

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

Josh-Walker-GM
Copy link
Contributor

Problem
We generate the prisma client as part of redwood build - as is standard for redwood projects. However, we then ship this in the dist to end users. The prisma client is platform/architecture specific. This means, as an example, that the prisma client built for my M2 MacBook is not working for users that are running on amd64 ubuntu.

Changes

  1. We only copy over the schema and the migrations during our studio:package step.
  2. We generate the prisma client when studio starts, similar to how we migrate and seed when studio starts

Notes
You might consider this wasteful from a performance point of view. The client likely only needs to be generated once for the user as the underlying platform/arch isn't likely to change. For now, I think this is acceptable and can be made more performant in a future chore - this is intended to fix the bug that users are experiencing right now.

The server file had to be updated to make use of dynamic imports in place of static imports. This is because the prisma client does not exist when the server file is loaded - only after a certain point in the execution of the server file does the client get generated. As a result static imports and any level of nested static imports of the prisma client will throw an error. Dynamically importing the functions that access the DB in this one file seems like an okay compromise.

@Josh-Walker-GM Josh-Walker-GM self-assigned this Feb 26, 2024
@Josh-Walker-GM
Copy link
Contributor Author

Oh and I haven't explicitly tested this where I pull publish the package from one platform/arch and then use it from another. This is because I simply don't have an easy way to do that and I have some level of confidence that this will indeed fix the issue.

I am happy to test it once we publish and then we can revert if this doesn't fix the issue or introduces more issues itself.

@Josh-Walker-GM
Copy link
Contributor Author

@Tobbe - Thoughts on merging this one as is and then following up with an improved approach?

@Tobbe Tobbe merged commit 74bb3fe into main Mar 6, 2024
@Tobbe Tobbe deleted the jgmw-fix/runtime-generate-prisma-client branch March 6, 2024 21:19
@Ventajou
Copy link

Hi @dthyresson is there a way to use this now or do we need to wait for a new version of Studio to be released?

@Josh-Walker-GM
Copy link
Contributor Author

Hey all 👋

We just released 11.4.0 if you could try that out it should fix this problem 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants