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

Update jest setup for Prisma's multiSchema #10014

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zaiyou12
Copy link
Contributor

@zaiyou12 zaiyou12 commented Feb 15, 2024

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 feature multiSchema.

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.

  • Extract Model Schemas: Since Prisma 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.
  • Update Teardown Logic: Modified the teardown function to utilize the extracted schema information, prefixing SQL commands with the correct schema name.

@zaiyou12 zaiyou12 marked this pull request as draft February 15, 2024 04:00
@zaiyou12 zaiyou12 changed the title Update jest setup for Prisma's multiSchema #10009 Update jest setup for Prisma's multiSchema Feb 15, 2024
@zaiyou12 zaiyou12 marked this pull request as ready for review February 15, 2024 05:09
@ahaywood
Copy link
Contributor

@zaiyou12 thanks for taking the time to submit this PR, excited to take a look at your code...

@dthyresson dthyresson self-requested a review February 26, 2024 17:00
@dthyresson dthyresson self-assigned this Feb 26, 2024
@thedavidprice thedavidprice added the contributor-pr Use to automatically add PRs to the "Contributor PRs" Project Board label Mar 26, 2024
- Use qualifiedName variable
- yarn lint --fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor-pr Use to automatically add PRs to the "Contributor PRs" Project Board
Projects
Status: Ready
Status: Stalled
Development

Successfully merging this pull request may close these issues.

None yet

4 participants