-
Notifications
You must be signed in to change notification settings - Fork 965
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
Jest tests for api do not work when prisma schema has non-nullable relations #924
Comments
Aaaah, good point, I think we should drop all the tables and recreate from scratch, @RobertBroersma ? |
Good catch! @peterp The reason for the weird hacky delete everything loop is because removing and re-creating the entire DB by running Prisma doesn't have a cleaning command yet, but I think they're working on it? [Insert reference to ticket] A raw SQL query that truncates all tables sounds like a good solution, but I guess that wouldn't work on some NoSQL DB in the future... at which point we could change it? |
@RobertBroersma Looks like you already have a relevant issue at #782. Sorry I missed this. These two issues can probably be merged. |
@hemildesai They are related, but my ticket is still under the impression that the hack works 😅 I guess we should fix the hack until prisms releases the method described in #782 |
@RobertBroersma Makes sense! |
I was just about to create an issue for this when I decided to search first :-) I'm running in the exact same problem. I created a test repo that shows when / how the problem manifest itself: https://github.com/jvanbaarsen/constraint-example. The workaround I used for now was to make the relation optional, so you get something like this: model User {
id Int @id @default(autoincrement())
email String @unique
Task Task[]
}
model Task {
id Int @id @default(autoincrement())
title String
owner User? @relation(fields: [ownerId], references: [id])
ownerId Int?
} The downside of this approach is that "combined" unique constraints don't work, so you cant add a @hemildesai I'm curious, how did you currently solve this problem? |
@jvanbaarsen The hack I used was just to order the Prisma schema. I haven't checked if Prisma has added an option to clear the entire db. If it has, you could use that. |
There have been some updates to Prisma's CLI. Looks like
|
@cannikin Do you think this was closed by the series of scenario-teardown PRs you did? |
@jtoar yep this should be fixed, we now delete in a way that works for foreign key constraints! |
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [eslint-plugin-jsx-a11y](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y) | [`6.7.1` -> `6.8.0`](https://renovatebot.com/diffs/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/eslint-plugin-jsx-a11y/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/eslint-plugin-jsx-a11y/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>jsx-eslint/eslint-plugin-jsx-a11y (eslint-plugin-jsx-a11y)</summary> ### [`v6.8.0`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/CHANGELOG.md#v680---2023-11-01) [Compare Source](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/compare/v6.7.1...v6.8.0) ##### Merged - Allow `title` attribute or `aria-label` attribute instead of accessible child in the "anchor-has-content" rule [`#727`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/727) ##### Fixed - \[Docs] `aria-activedescendant-has-tabindex`: align with changes from [#​708](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/708) [`#924`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/924) - \[Fix] `control-has-associated-label`: don't accept whitespace as an accessible label [`#918`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/918) ##### Commits - \[Tests] migrate helper parsers function from `eslint-plugin-react` [`ce4d57f`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/ce4d57f853ce7f71bd31edaa524eeb3ff1d27cf1) - \[Refactor] use `es-iterator-helpers` [`52de824`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/52de82403752bb2ccbcac3379925650a0112d4af) - \[New] `mouse-events-have-key-events`: add `hoverInHandlers`/`hoverOutHandlers` config [`db64898`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/db64898fa591f17827053ad3c2ddeafdf7297dd6) - \[New] add `polymorphicPropName` setting for polymorphic components [`fffb05b`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/fffb05b38c8eee926ee758e9ceb9eae4e697fbdd) - \[Fix] `isNonInteractiveElement`: Upgrade aria-query to 5.3.0 and axobject-query to 3.2.1 [`64bfea6`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/64bfea6352a704470a760fa6ea25cfc5a50414db) - \[Refactor] use `hasown` instead of `has` [`9a8edde`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/9a8edde7f2e80b7d104dd576f91526c6c4cbebb9) - \[actions] update used actions [`10c061a`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/10c061a70cac067641e3a084d0fb464960544505) - \[Dev Deps] update `@babel/cli`, `@babel/core`, `@babel/eslint-parser`, `@babel/plugin-transform-flow-strip-types`, `@babel/register`, `aud`, `eslint-doc-generator`, `eslint-plugin-import`, `minimist` [`6d5022d`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/6d5022d4894fa88d3c15c8b858114e8b2a8a440f) - \[Dev Deps] update `@babel/cli`, `@babel/core`, `@babel/eslint-parser`, `@babel/register`, `eslint-doc-generator`, `eslint-plugin-import` [`4dc7f1e`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/4dc7f1e5c611aeea2f81dc50d4ec0b206566181a) - \[New] `anchor-has-content`: Allow title attribute OR aria-label attribute [`e6bfd5c`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/e6bfd5cb7c060fcaf54ede85a1be74ebe2f60d1e) - \[patch] `mouse-events-have-key-events`: rport the attribute, not the node [`eadd70c`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/eadd70cb1d0478c24538ee7604cf5493a96c0715) - \[Deps] update `@babel/runtime`, `array-includes`, `array.prototype.flatmap`, `object.entries`, `object.fromentries` [`46ffbc3`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/46ffbc38512be4ed3db2f0fcd7d21af830574f63) - \[Deps] update `@babel/runtime`, `axobject-query`, `jsx-ast-utils`, `semver` [`5999555`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/5999555714f594c0fccfeeab2063c2658d9e4392) - \[Fix] pin `aria-query` and `axe-core` to fix failing tests on main [`8d8f016`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/8d8f0169dbaaa28143cf936cba3046c6e53fa134) - \[patch] move `semver` from Deps to Dev Deps [`4da13e7`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/4da13e79743ad2e1073fc2bb682197e1ba6dbea3) - \[Deps] update `ast-types-flow` [`b755318`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/b755318e675e73a33b1bb7ee809abc88c1927408) - \[Dev Deps] update `eslint-plugin-import` [`f1c976b`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/f1c976b6af2d4f5237b481348868a5216e169296) - \[Deps] unpin `language-tags` [`3d1d26d`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/3d1d26d89d492947cbf69f439deec9e7cfaf9867) - \[Docs] `no-static-element-interactions`: tabIndex is written tabindex [`1271153`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/1271153653ada3f8d95b8e39f0164d5b255abea0) - \[Deps] Upgrade ast-types-flow to mitigate Docker user namespacing problems [`f0d2ddb`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/f0d2ddb65f21278ad29be43fb167a1092287b4b1) - \[Dev Deps] pin `jackspeak` since 2.1.2+ depends on npm aliases, which kill the install process in npm < 6 [`0c278f4`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/0c278f4805ec18d8ee4d3e8dfa2f603a28d7e113) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [eslint-plugin-jsx-a11y](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y) | [`6.7.1` -> `6.8.0`](https://renovatebot.com/diffs/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/eslint-plugin-jsx-a11y/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/eslint-plugin-jsx-a11y/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/eslint-plugin-jsx-a11y/6.7.1/6.8.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>jsx-eslint/eslint-plugin-jsx-a11y (eslint-plugin-jsx-a11y)</summary> ### [`v6.8.0`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/CHANGELOG.md#v680---2023-11-01) [Compare Source](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/compare/v6.7.1...v6.8.0) ##### Merged - Allow `title` attribute or `aria-label` attribute instead of accessible child in the "anchor-has-content" rule [`#727`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/727) ##### Fixed - \[Docs] `aria-activedescendant-has-tabindex`: align with changes from [#​708](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/708) [`#924`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/924) - \[Fix] `control-has-associated-label`: don't accept whitespace as an accessible label [`#918`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/918) ##### Commits - \[Tests] migrate helper parsers function from `eslint-plugin-react` [`ce4d57f`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/ce4d57f853ce7f71bd31edaa524eeb3ff1d27cf1) - \[Refactor] use `es-iterator-helpers` [`52de824`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/52de82403752bb2ccbcac3379925650a0112d4af) - \[New] `mouse-events-have-key-events`: add `hoverInHandlers`/`hoverOutHandlers` config [`db64898`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/db64898fa591f17827053ad3c2ddeafdf7297dd6) - \[New] add `polymorphicPropName` setting for polymorphic components [`fffb05b`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/fffb05b38c8eee926ee758e9ceb9eae4e697fbdd) - \[Fix] `isNonInteractiveElement`: Upgrade aria-query to 5.3.0 and axobject-query to 3.2.1 [`64bfea6`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/64bfea6352a704470a760fa6ea25cfc5a50414db) - \[Refactor] use `hasown` instead of `has` [`9a8edde`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/9a8edde7f2e80b7d104dd576f91526c6c4cbebb9) - \[actions] update used actions [`10c061a`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/10c061a70cac067641e3a084d0fb464960544505) - \[Dev Deps] update `@babel/cli`, `@babel/core`, `@babel/eslint-parser`, `@babel/plugin-transform-flow-strip-types`, `@babel/register`, `aud`, `eslint-doc-generator`, `eslint-plugin-import`, `minimist` [`6d5022d`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/6d5022d4894fa88d3c15c8b858114e8b2a8a440f) - \[Dev Deps] update `@babel/cli`, `@babel/core`, `@babel/eslint-parser`, `@babel/register`, `eslint-doc-generator`, `eslint-plugin-import` [`4dc7f1e`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/4dc7f1e5c611aeea2f81dc50d4ec0b206566181a) - \[New] `anchor-has-content`: Allow title attribute OR aria-label attribute [`e6bfd5c`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/e6bfd5cb7c060fcaf54ede85a1be74ebe2f60d1e) - \[patch] `mouse-events-have-key-events`: rport the attribute, not the node [`eadd70c`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/eadd70cb1d0478c24538ee7604cf5493a96c0715) - \[Deps] update `@babel/runtime`, `array-includes`, `array.prototype.flatmap`, `object.entries`, `object.fromentries` [`46ffbc3`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/46ffbc38512be4ed3db2f0fcd7d21af830574f63) - \[Deps] update `@babel/runtime`, `axobject-query`, `jsx-ast-utils`, `semver` [`5999555`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/5999555714f594c0fccfeeab2063c2658d9e4392) - \[Fix] pin `aria-query` and `axe-core` to fix failing tests on main [`8d8f016`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/8d8f0169dbaaa28143cf936cba3046c6e53fa134) - \[patch] move `semver` from Deps to Dev Deps [`4da13e7`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/4da13e79743ad2e1073fc2bb682197e1ba6dbea3) - \[Deps] update `ast-types-flow` [`b755318`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/b755318e675e73a33b1bb7ee809abc88c1927408) - \[Dev Deps] update `eslint-plugin-import` [`f1c976b`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/f1c976b6af2d4f5237b481348868a5216e169296) - \[Deps] unpin `language-tags` [`3d1d26d`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/3d1d26d89d492947cbf69f439deec9e7cfaf9867) - \[Docs] `no-static-element-interactions`: tabIndex is written tabindex [`1271153`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/1271153653ada3f8d95b8e39f0164d5b255abea0) - \[Deps] Upgrade ast-types-flow to mitigate Docker user namespacing problems [`f0d2ddb`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/f0d2ddb65f21278ad29be43fb167a1092287b4b1) - \[Dev Deps] pin `jackspeak` since 2.1.2+ depends on npm aliases, which kill the install process in npm < 6 [`0c278f4`](https://togithub.com/jsx-eslint/eslint-plugin-jsx-a11y/commit/0c278f4805ec18d8ee4d3e8dfa2f603a28d7e113) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Currently,
prisma
does not support cascading deletes - See prisma/prisma#2810You can add
ON DELETE CASCADE
manually, but that runs into prisma/prisma#2057So, if your model has non nullable relations without cascade,
yarn rw test api
fails because the setup https://github.com/redwoodjs/redwood/blob/main/packages/core/src/configs/node/jest.setup.js#L13-L17 tries to invokedeleteMany
on all models in the order that they're defined inschema.prisma
. If this order tries to delete a parent model first, we get an error likeOne hacky workaround is to order the models appropriately in
schema.prisma
, but would love to have a proper solution for this issue. Another option would be to run a raw SQL query to empty the db. I am not sure if prisma has a command to empty the database. If it does, we can directly use that ideally.This issue may still persist after prisma supports
CASCADE
because not all users would want to cascade on delete.The text was updated successfully, but these errors were encountered: