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
[Bug?]: Multi-Schema Support in Jest Setup for Multi-Schema Prisma project #10009
Comments
Hey @zaiyou12 thanks for the awesome write up! Indeed we never designed for Prisma's I couldn't quite get your reproduction working out of the box. After git cloning, yarn installing, and setting up
One thing I could try that I didn't yet is These days we're trying to focus on RSCs but if you're happy to make a PR for this feature (you seem quite familiar with the code already!), I can try to find some time to review it, I may just not be swift. |
Hello @jtoar , Thank you so much for taking the time to review the issue. I'm glad to contribute and help improve support for Prisma's multiSchema feature in RedwoodJS. I've identified and corrected a mistake in the Regarding the contribution of a PR for this feature, I fully understand the team's current focus and priorities and I am also very much looking forward to the next version. Although I have not personally encountered any issues thus far, I am closely monitoring the related discussions on GitHub. If there are any specific concerns or scenarios you believe should be addressed, I welcome your insights. Once again, thank you for your time and consideration. I am working on preparing the enhancements for review and will submit the PR as soon as it is ready. |
Hi @zaiyou12 and thanks also for brining this up. I was curious if you had tried the Since this will |
Hi @dthyresson, Thank you very much for your suggestion and for taking the time to engage with this issue. I followed your advice and tried implementing the reset test strategy as described in the RedwoodJs docs, hoping it would address the multi-schema support challenge in the Jest setup. I updated my issue-reproduction repository to reflect this approach. (d15a999) Unfortunately, after applying the reset test strategy and running my tests again, the issue still persists. Here's a brief overview of the steps I followed after your recommendation:
Despite these efforts, I'm still facing challenges with multi-schema support in the Jest setup for my Prisma project. The tests fail to recognize or correctly interact with tables in the secondary schema, leading to the same errors as before. Could there be another aspect of Prisma's multi-schema handling or Jest configuration that we're overlooking? I'm keen on any further insights or alternative suggestions you or anyone else might have to help overcome this hurdle. Thank you once again for your support. |
What's not working?
Description
In multi-schema Prisma projects, the
teardown
process in Jest setup files does not dynamically handle schema prefixes, leading to issues when trying to clean up test data. This is relevant for projects that using Prisma's preview featuremultiSchema
.(In fact, there's nothing wrong with using only single schema. I just got greedy to use Prisma's preview feature, as the number of DB tables grew 🤣)
Problem
The original teardown logic in the Jest setup file does not account for models located in different schemas, resulting in errors during the test cleanup phase. Specifically, the error occurs when attempting to delete data from tables without specifying the correct schema prefix, leading to failed tests due to unresolved table references.
Error
Quick fix
To address this issue, I've made quick fix to the jest.setup.js configuration to dynamically extract schema information from the Prisma schema file and apply this information during the teardown process. This ensures that raw SQL commands are executed against the correct schema, allowing for proper cleanup of test data across multiple schemas.
Changes Made
getDMMF
doesn't return schema with table name, I need to implement a function extractModelSchemas to parse the Prisma schema file and extract model-to-schema mappings. This function uses regular expressions to find model definitions and their @@Schema annotations.Now my RedwoodJs project fully support Multi-Schema Prisma.
How do we reproduce the bug?
public repo
Prerequisites
DATABASE_URL
andTEST_DATABASE_URL
pointing to your PostgreSQL instance.Installation
git clone https://github.com/zaiyou12/redwood-multi-schema cd redwood-multi-schema yarn install
Reproducing the error
yarn rw prisma migrate dev yarn rw test api posts
You should encounter the following error:
What's your environment? (If it applies)
Mac, Postgres on Docker container
Are you interested in working on this?
The text was updated successfully, but these errors were encountered: