Empty `dbgenerated()` still breaking for `Unsupported()` types
See original GitHub issueBug description
Using a default(dbgenerated())
on a column with type Unsupported("...")
where a Postgres generated column is manually added leads to Prisma migrate wanting to DROP DEFAULT
on that column, which is an error in pg.
Empty dbgenerated()
were broken for all column types in v4 and fixed recently here: https://github.com/prisma/prisma/issues/14799. Seems like the fix didn’t apply to Unsupported()
types.
How to reproduce
Clone & follow instructions here: https://github.com/jkcorrea/prisma-unsupported-dbgenerated-bug
Expected behavior
To not touch the defaults for any columns with default(dbgenerated()
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model table {
id String @id
hereBeDragons Unsupported("tsvector")? @default(dbgenerated())
}
Environment & setup
- OS: macOS
- Database: Postgres
- Node.js version: v16.15.1
Prisma Version
Happens on prisma v4+ (including v4.4
and v4.5
)
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Prisma v4 breaks support for empty `dbgenerated()` - invalid ...
Using Postgres generated columns via @default(dbgenerated()) with ... Empty dbgenerated() still breaking for Unsupported() types #15654.
Read more >Prisma schema API (Reference)
Default values that cannot yet be represented in the Prisma schema are represented by the dbgenerated() function when you use introspection.
Read more >Prisma 3.10.0 Release - GitClear
We're super excited to announce that Prisma version 3.10.0 supports reading and modifying embedded documents. Embedded documents will provide ...
Read more >Automatically add UUID relation on prisma create
The User and UserProfile depend on each other. I am trying to create a User that automatically creates a UserProfile with it, but...
Read more >Announcing Entity Framework Core 7 Preview 6: Performance ...
This isn't an easy decision to make – we try hard to never break users ... Add(new Blog { Name = "MyBlog", Posts...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Indeed, removing the generated column and using a trigger instead might be the actually best solution right now. Be aware that the trigger is not reflected in Prisma schema, so you need to put it into a migration file manually once or it will be missing on new deployments.
Thank you @janpio for the answer, I found this to be the cleanest solution at the moment:
GENERATED ALWAYS AS (to_tsvector('english'::regconfig, <column-name>)) STORED
from thecolumnName
and leave it as a simplecolumnName tsvector
.columnName
to the correct type before every INSERT.prisma db pull
should generatecolumnName Unsupported("tsvector")?
in my schema.prisma when runningprisma db pull
and always match the production database.This should allow me to follow the prisma guide and cleanly introduce
prisma migrate
to the existing database.I will update this comment if I’m successful 😄
EDIT: This was indeed the best solution I could find and it worked flawlessly. We were able to introduce prisma migrate to an existing database with lots of production data.
Thank you @jkcorrea!!