Class: AddIndexForPath

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/gitdocs/migration/004_add_index_for_path.rb

Class Method Summary collapse

Class Method Details

.upObject



2
3
4
5
6
7
8
9
# File 'lib/gitdocs/migration/004_add_index_for_path.rb', line 2

def self.up
  shares = Gitdocs::Configuration::Share.all.inject(Hash.new{|h,k| h[k] = []}) {|h, s| h[s.path] << s; h}
  shares.each do |path, shares|
    shares.shift
    shares.each(&:destroy) unless shares.empty?
  end
  add_index :shares, :path, :unique => true
end