Sha256: feee9da53c109b71e5f73143e648478e9920383c7d6bf36ffd68caf6e8950a10
Contents?: true
Size: 951 Bytes
Versions: 1
Compression:
Stored size: 951 Bytes
Contents
class AddNamesTriggerToAuthors < ActiveRecord::Migration def up execute <<-EOS -- feel free to customize this function if you want to join to columns from another table, for example CREATE OR REPLACE FUNCTION sp_update_names_vector() RETURNS trigger AS $$ begin new.names_vector := setweight(to_tsvector('names_search_config', coalesce(new.first_name,'')), 'A') || setweight(to_tsvector('names_search_config', coalesce(new.last_name,'')), 'A') ; return new; end $$ LANGUAGE plpgsql; EOS execute <<-EOS DROP TRIGGER IF EXISTS update_names_vector ON authors; CREATE TRIGGER update_names_vector BEFORE INSERT OR UPDATE ON authors FOR EACH ROW EXECUTE PROCEDURE sp_update_names_vector(); EOS end def down execute "DROP TRIGGER update_names_vector" execute "DROP FUNCTION sp_update_names_vector" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
search_steroids-0.0.1 | spec/dummy/db/migrate/20130621211357_add_names_trigger_to_authors.rb |