Created
April 16, 2024 23:09
-
-
Save megafarad/c63b0b0ddbc493261de69004c407abb5 to your computer and use it in GitHub Desktop.
Slick Evolutions Script for Slick-pg example project.
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
# --- !Ups | |
CREATE SCHEMA app; | |
CREATE TABLE app.document ( | |
id BIGSERIAL NOT NULL PRIMARY KEY, | |
content TEXT, | |
search_field tsvector | |
); | |
CREATE FUNCTION app.update_document_search_field() RETURNS TRIGGER AS $$ | |
BEGIN | |
NEW.search_field := to_tsvector(NEW.content);; | |
RETURN NEW;; | |
END;; | |
$$ LANGUAGE plpgsql; | |
CREATE TRIGGER tr_update_document_search_field | |
BEFORE INSERT OR UPDATE ON app.document | |
FOR EACH ROW EXECUTE FUNCTION app.update_document_search_field(); | |
CREATE INDEX document_result_search_idx ON app.document USING GIN(search_field); | |
# ---!Downs | |
DROP TABLE app.document; | |
DROP FUNCTION app.update_document_search_field(); | |
DROP SCHEMA app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment