Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ts_vector trigger
class CreateBookmarks < ActiveRecord::Migration
def change
create_table :bookmarks do |t|
t.integer :user_id
t.string :title
t.string :description
t.string :sku
t.integer :number
t.integer :timestamp
t.boolean :global
t.tsvector :search_vector
t.timestamps
end
execute <<-EOS
CREATE INDEX bookmark_search_idx ON bookmarks USING gin(search_vector)
EOS
execute <<-EOS
CREATE TRIGGER bookmark_vector_update BEFORE INSERT OR UPDATE
ON bookmarks
FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(search_vector, 'pg_catalog.english',
title, description);
EOS
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment