Sha256: 9dd9d77dd9ca94c27fda4d19c8a52b1b9e8c26fda9da7d0be9f7ebcab517e9e8

Contents?: true

Size: 768 Bytes

Versions: 49

Compression:

Stored size: 768 Bytes

Contents

class UpdateCustomFieldNames < ActiveRecord::Migration
  def up
    fields = {}

    Spotlight::CustomField.find_each do |f|
      f.update(field: f.send(:field_name))
      fields[f.solr_field] = f
    end

    Spotlight::SolrDocumentSidecar.find_each do |f|
      f.data.select { |k, v| fields.has_key? k }.each do |k, v|
        f.data[fields[k].send(:field_name)] = f.data.delete(k)
      end
    end
  end

  def down
    fields = {}

    Spotlight::CustomField.find_each do |f|
      fields[f.field] = f
      f.update(field: f.send(:solr_field))
    end

    Spotlight::SolrDocumentSidecar.find_each do |f|
      f.data.select { |k, v| fields.has_key? k }.each do |k, v|
        f.data[fields[k].send(:solr_field)] = f.data.delete(k)
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
blacklight-spotlight-0.34.1 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.34.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.33.3 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.33.2 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.33.1 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.33.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.32.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.31.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.30.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.29.1 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.29.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.28.3 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.28.2 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.28.1 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.28.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.27.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.26.1 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.26.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.25.0 db/migrate/20151124105543_update_custom_field_names.rb
blacklight-spotlight-0.24.0 db/migrate/20151124105543_update_custom_field_names.rb