Sha256: 2726a0b813ee26c96775ce33c6602a36ae5c858afdd2155989a944e4f5cd960f

Contents?: true

Size: 829 Bytes

Versions: 5

Compression:

Stored size: 829 Bytes

Contents

class AddDigestToSources < ActiveRecord::Migration
  def self.up
    if ["mysql", "mysql2"].include? ActiveRecord::Base.connection.instance_values["config"][:adapter]
      execute "DROP INDEX value ON sources" if index_exists?(:sources, :value, :name => 'value')
    else
      remove_index(:sources, :value) if index_exists?(:sources, :value)
    end
    add_column :sources, :digest, :string
    Source.find_each {|m| m.update_attribute(:digest, Digest::SHA1.hexdigest(m.value)) }
    add_index :sources, :digest
  end

  def self.down
    remove_index :sources, :digest
    remove_column :sources, :digest
    if ["mysql", "mysql2"].include? ActiveRecord::Base.connection.instance_values["config"][:adapter]
      execute "ALTER TABLE sources ADD FULLTEXT (value)"
    else
      add_index :sources, :value
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/db/migrate/20130228145456_add_digest_to_sources.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/db/migrate/20130228145456_add_digest_to_sources.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/db/migrate/20130228145456_add_digest_to_sources.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/db/migrate/20130228145456_add_digest_to_sources.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/db/migrate/20130228145456_add_digest_to_sources.rb