Update jest setup for Prisma's multiSchema #10014
Open
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.
issue #10009
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
.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.Changelogs
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.getDMMF
doesn't return schema with table name, I need to implement a functionextractModelSchemas
to parse the Prisma schema file and extract model-to-schema mappings. This function uses regular expressions to find model definitions and theirschema
annotations.