I’m using the prisma preview feature views for making prisma models for querying SQL views as if they were a relation like a table created from models. However this feature may not be totally supported yet and I’m hopeful that this inquiry can inform some positive changes in my code base.
I have created a view manually in psql and I have generated an SDL and graphql service handler. The problem is when I run a prisma reset. It seems to execute this fine but then it automatically runs my seed script and this throws an error attempting to validate my schema.
yarn rw exec seed results in the following error
error: Error validating: This line is invalid. It does not start with any known Prisma schema keyword.
--> schema.prisma:337
|
336 |
337 | view DailyRevenue {
338 | id String @id
|
// ... other validation error messages of fields defined in the `view` block
error: The preview feature "views" is not known. Expected one of: fullTextSearch, fullTextIndex, tracing, metrics, orderByNulls, filteredRelationCount, fieldReference, postgresqlExtensions, clientExtensions, deno, extendedWhereUnique
--> schema.prisma:9
|
8 | binaryTargets = "native"
9 | previewFeatures = ["views"]
It seems like this should work and generate a file as the console output first looks fine then delayed it spits out the
[schema.prisma]
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
previewFeatures = ["views"]
}
// ..... other schema definitions
view DailyRevenue {
id String @id
eventId Int
establishmentId Int
date DateTime
sumAmount Decimal @db.Money
itemCount Int
}
It seems like not all of the cli tools are receiving the --preview-feature command line flag. The following commands work fine: yarn rw prisma migrate reset yarn rw prisma migrate dev yarn rw g sdl DailyRevenue
Oh I think I fixed it. I found some remaining dependencies in the api package.json that I hadn’t switched from @redwoodjs 3.8.0 to 4.3.0. Once I updated those remaining dependencies it worked fine. I appreciate your quick response!
For reference what I discovered that helped diagnose this was two entries in my yarn.lock for @prisma/client, one for 4.11.0 and one for 4.7.0 and they were present from a direct dependency specified in my web package.json to "@redwoodjs/auth": "3.8.0",. I needed to update all references to redwoodjs dependencies because the major version update wasn’t matched by the ^ and this direct dependency only worked for that explicit version.