Commit da29b595e64d29a3a032095b7457c9ebbc972034
1 parent
1e4cabef
Exists in
master
and in
29 other branches
pg_search: fix down on migration
Showing
1 changed file
with
4 additions
and
4 deletions
Show diff stats
plugins/pg_search/db/migrate/20130320010063_create_indexes_for_search.rb
| 1 | class CreateIndexesForSearch < ActiveRecord::Migration | 1 | class CreateIndexesForSearch < ActiveRecord::Migration |
| 2 | + SEARCHABLES = %w[ article comment qualifier national_region certifier profile license scrap category ] | ||
| 3 | + KLASSES = SEARCHABLES.map {|searchable| searchable.camelize.constantize } | ||
| 2 | def self.up | 4 | def self.up |
| 3 | - searchables = %w[ article comment qualifier national_region certifier profile license scrap category ] | ||
| 4 | - klasses = searchables.map {|searchable| searchable.camelize.constantize } | ||
| 5 | - klasses.each do |klass| | 5 | + KLASSES.each do |klass| |
| 6 | fields = klass.pg_search_plugin_fields | 6 | fields = klass.pg_search_plugin_fields |
| 7 | execute "create index pg_search_plugin_#{klass.name.singularize.downcase} on #{klass.table_name} using gin(to_tsvector('simple', #{fields}))" | 7 | execute "create index pg_search_plugin_#{klass.name.singularize.downcase} on #{klass.table_name} using gin(to_tsvector('simple', #{fields}))" |
| 8 | end | 8 | end |
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def self.down | 11 | def self.down |
| 12 | - klasses.each do |klass| | 12 | + KLASSES.each do |klass| |
| 13 | execute "drop index pg_search_plugin_#{klass.name.singularize.downcase}" | 13 | execute "drop index pg_search_plugin_#{klass.name.singularize.downcase}" |
| 14 | end | 14 | end |
| 15 | end | 15 | end |