Skip to content

Commit

Permalink
#8 Fix ids in tsvector migration
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jan 19, 2021
1 parent c950cfb commit 86a9fd0
Showing 1 changed file with 48 additions and 0 deletions.
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();

0 comments on commit 86a9fd0

Please sign in to comment.