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
Empty dbgenerated()
still breaking for Unsupported()
types
#15654
Comments
In case this helps others, I was trying to have a "full text search" Set a default empty tsvector & Gin indexmodel table {
id String @id
stuff String?
fts Unsupported("tsvector")? @default(dbgenerated("''::tsvector"))
@@index([fts], type: Gin)
} Manually add an update/insert triggerCREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS btree_gin;
create or replace function update_table_fts() returns trigger as $$
begin
NEW.fts := to_tsvector('english',
NEW.id::text
|| ' ' || COALESCE(NEW."stuff", '')
);
RETURN NEW;
end; $$ language plpgsql security definer set search_path = public, pg_temp;
drop trigger if exists "update_fts" on "table";
create trigger "update_fts"
before insert or update on "table"
for each row
execute function update_table_fts(); Pretty simple and honestly I'm fine with using this until the coming Prisma FTS improvements land. |
I am facing this exact issue, is there any update on this?
EDIT: |
The easiest way to not get this behavior is to datasource db {
provider = "postgresql"
url = "postgres://postgres:prisma@localhost:5438/postgres"
}
model table {
id String @id
hereBeDragons Unsupported("tsvector")? @default(dbgenerated("to_tsvector('english'::regconfig, id)"))
} Now, the next migrate will not try to drop the default constraint. Although an empty |
@pimeys This is what I have been doing, the problem is that when running
|
The workaround from @pimeys will not work here unfortunately, as the underlying SQL does not actually represent a "default" that we could create via
or
Using
(via Slack discussion with @zakariamofaddel: https://prisma.slack.com/archives/CA491RJH0/p1670931902950529) |
I think you have 2 options how to deal with this for now. Both are not super great. Both are also untested, so let me know how it goes:
Please let me know if one of these options work - if not we need to dig a bit deeper. I think this is the feature request to track support for generated columns properly: #6336 |
Thank you @janpio for the answer, I found this to be the cleanest solution at the moment:
This should allow me to follow the prisma guide and cleanly introduce I will update this comment if I'm successful 😄 EDIT: Thank you @jkcorrea!! |
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. |
Thanks a lot for sharing this! This method works perfectly, shall stick to it until we have support for GENERATED. |
Bug description
Using a
default(dbgenerated())
on a column with typeUnsupported("...")
where a Postgres generated column is manually added leads to Prisma migrate wanting toDROP DEFAULT
on that column, which is an error in pg.Empty
dbgenerated()
were broken for all column types in v4 and fixed recently here: #14799. Seems like the fix didn't apply toUnsupported()
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
Environment & setup
Prisma Version
Happens on prisma v4+ (including
v4.4
andv4.5
)The text was updated successfully, but these errors were encountered: