Sha256: 6e82516493f73b9f5bbae17ecc574332abc29386fbab018a1196c155a99c67b3

Contents?: true

Size: 854 Bytes

Versions: 1

Compression:

Stored size: 854 Bytes

Contents

class <%= migration_class_name %> < ActiveRecord::Migration
  def up
    execute <<-EOS
    CREATE OR REPLACE FUNCTION <%=trigger_sp_name %>() RETURNS trigger AS $$
    begin
      new.original_tsquery = plainto_tsquery('<%=alias_search_config_name%>', coalesce(new.original,''));
      new.substitution_tsquery = plainto_tsquery('<%=alias_search_config_name%>', coalesce(new.substitution,''));
      return new;
    end
    $$ LANGUAGE plpgsql;
    EOS
    execute <<-EOS
    DROP TRIGGER IF EXISTS <%=trigger_name %> ON <%=aliases_name %>;
    CREATE TRIGGER <%=trigger_name %> BEFORE INSERT OR UPDATE
        ON <%=aliases_name %> FOR EACH ROW EXECUTE PROCEDURE <%=trigger_sp_name %>();
    EOS
  end
  
  def down
    execute "DROP TRIGGER <%=trigger_name %> on <%=aliases_name %>;"
    execute "DROP FUNCTION <%=trigger_sp_name(); %>"    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search_steroids-0.0.1 lib/generators/search_context/templates/add_aliases_trigger_migration.rb