Class: AddIndexForPath

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

Overview

rubocop:disable all

Class Method Summary collapse

Class Method Details

.upObject



6
7
8
9
10
11
12
13
# File 'lib/gitdocs/migration/004_add_index_for_path.rb', line 6

def self.up
  shares = Gitdocs::Share.all.reduce(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