question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty `dbgenerated()` still breaking for `Unsupported()` types

See original GitHub issue

Bug 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:open
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Dec 13, 2022

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.

1reaction
zakariamofaddelcommented, Dec 20, 2022

Thank you @janpio for the answer, I found this to be the cleanest solution at the moment:

  • From the prod database I will remove the GENERATED ALWAYS AS (to_tsvector('english'::regconfig, <column-name>)) STORED from the columnName and leave it as a simple columnName tsvector.
  • Always in prod I will then set a trigger, as @jkcorrea suggested, that will take care of setting the columnName to the correct type before every INSERT.
  • Now running prisma db pull should generate columnName Unsupported("tsvector")? in my schema.prisma when running prisma 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!!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found