-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
prisma/migrations/20210119212729_fix_ids_in_tsvectors/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- Update | ||
UPDATE "Document" SET "documentTsVector" = | ||
(setweight(to_tsvector(coalesce("documentTitle",'')), 'A') || | ||
setweight(to_tsvector(coalesce("documentDescription",'')), 'B') || | ||
setweight(to_tsvector(coalesce("documentOriginalID",'')), 'C') || | ||
setweight(to_tsvector(coalesce("documentTranscript",'')), 'D'))::TEXT; | ||
|
||
-- Update | ||
UPDATE "Event" SET "eventTsVector" = | ||
(setweight(to_tsvector(coalesce("eventTitle",'')), 'A') || | ||
setweight(to_tsvector(coalesce("eventDescription",'')), 'B') || | ||
setweight(to_tsvector(coalesce("id"::text,'')), 'C'))::TEXT; | ||
|
||
|
||
--Create or replace function | ||
CREATE OR REPLACE FUNCTION ts_document_trigger() RETURNS trigger AS $$ | ||
begin | ||
new."documentTsVector" := | ||
(setweight(to_tsvector('pg_catalog.english', coalesce(new."documentTitle",'')), 'A') || | ||
setweight(to_tsvector('pg_catalog.english', coalesce(new."documentDescription",'')), 'B') || | ||
setweight(to_tsvector('pg_catalog.english', coalesce(new."documentOriginalID",'')), 'C') || | ||
setweight(to_tsvector('pg_catalog.english', coalesce(new."documentTranscript",'')), 'D'))::text; | ||
return new; | ||
end | ||
$$ LANGUAGE plpgsql; | ||
|
||
--Drop trigger | ||
DROP TRIGGER IF EXISTS ts_document ON "Document"; | ||
--Create trigger | ||
CREATE TRIGGER ts_document BEFORE INSERT OR UPDATE ON "Document" FOR EACH ROW EXECUTE PROCEDURE ts_document_trigger(); | ||
|
||
|
||
--Create or replace function | ||
CREATE OR REPLACE FUNCTION ts_event_trigger() RETURNS trigger AS $$ | ||
begin | ||
new."eventTsVector" := | ||
(setweight(to_tsvector('pg_catalog.english', coalesce(new."eventTitle",'')), 'A') || | ||
setweight(to_tsvector('pg_catalog.english', coalesce(new."eventDescription",'')), 'B') || | ||
setweight(to_tsvector('pg_catalog.english', coalesce(new."id"::text,'')), 'C'))::text; | ||
return new; | ||
end | ||
$$ LANGUAGE plpgsql; | ||
|
||
--Drop trigger | ||
DROP TRIGGER IF EXISTS ts_event ON "Event"; | ||
|
||
--Create trigger | ||
CREATE TRIGGER ts_event BEFORE INSERT OR UPDATE ON "Event" FOR EACH ROW EXECUTE PROCEDURE ts_event_trigger(); |