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

[Bug?]: Prisma View compatibility #9580

Open
1 task done
majimaccho opened this issue Nov 28, 2023 · 6 comments
Open
1 task done

[Bug?]: Prisma View compatibility #9580

majimaccho opened this issue Nov 28, 2023 · 6 comments
Assignees
Labels
bug/confirmed We have confirmed this is a bug topic/testing

Comments

@majimaccho
Copy link
Contributor

What's not working?

Since View of Databases is being a feature of prisma, I think it should be supported by Redwood.js.
However, Redwood.js causes error with api test when using View.

The reason why it fails is that Redwood.js internally uses getDMMF method of prisma internal package to clean up db data and it does not distinguish table or view.

It's obviously issues of prisma but Redwood.js needs to handle it correctly.

I've already raised above it on prisma's preview feature feadback.
prisma/prisma#17335 (comment)

How do we reproduce the bug?

No response

What's your environment? (If it applies)

No response

Are you interested in working on this?

  • I'm interested in working on this
@majimaccho majimaccho added the bug/needs-info More information is needed for reproduction label Nov 28, 2023
@majimaccho
Copy link
Contributor Author

For now we can probably solve this issue by catching error below.

Raw query failed. Code: 55000. Message: `db error: ERROR: cannot delete from view

@dac09
Copy link
Collaborator

dac09 commented Nov 28, 2023

Thanks @majimaccho for the issue, and ofcourse the analysis behind it - much appreciated!

I would say let's wait to hear back from the Prisma team as views are still a preview feature, before we implement anything.

@cannikin - could I hand this over to you to track?

@dac09 dac09 added topic/testing bug/needs-info More information is needed for reproduction bug/confirmed We have confirmed this is a bug and removed bug/needs-info More information is needed for reproduction labels Nov 28, 2023
@cannikin
Copy link
Member

Hello! So your only concern at this point is the failing tests? Did you want to try and come up with a PR that addresses it? Until Prisma adds something to getDMMF() you could catch that error here: https://github.com/redwoodjs/redwood/blob/main/packages/testing/config/jest/api/jest.setup.js#L141-L156

You can see that we already expect some errors for foreign key relationships, you could add another catch block for the error you identified above.

@majimaccho
Copy link
Contributor Author

@cannikin @dac09 Thank you for your kind and quick feedback.

Yeah, I already checked the jest.config.js and some error codes are catched and pushed to stack.

Of cause I can add something to catch the error.

However, the error code I got was below.

Raw query failed. Code: `55000`. Message: `db error: ERROR: cannot delete from view "pro_answer_all_values_view"
    DETAIL: Views that do not select from a single table or view are not automatically updatable.
    HINT: To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.`

According to PostgreSQL's documentation The error code 55000 is object_not_in_prerequisite_state and not specifically for the error deleting views.

So the easiest way to handle this issue is that I just add scripts to check if the entire error message starts with Raw query failed. Code: 55000. Message: db error: ERROR: cannot delete from view `.

It's just works on PostgreSQL but maybe not on MySQL or others.

@cannikin
Copy link
Member

cannikin commented Nov 29, 2023

Any solution we come up with will need to work with MySQL and SQLite as well...did you want to try applying your same schema to those two databases as well, running the tests, and adding those errors to the catch?

@majimaccho
Copy link
Contributor Author

@cannikin
Yeah, I can take it if you give me some time (like in this year).

But for short term, I escaped from this problem by using INSTEAD OF DELETE trigger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug topic/testing
Projects
None yet
Development

No branches or pull requests

3 participants