annotate .svn/pristine/1a/1ae20ea87464b5769eed93f455558d2b0e19460e.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents 261b3d9a4903
children
rev   line source
Chris@1464 1 class AddUniqueIndexOnCustomFieldsProjects < ActiveRecord::Migration
Chris@1464 2 def up
Chris@1464 3 table_name = "#{CustomField.table_name_prefix}custom_fields_projects#{CustomField.table_name_suffix}"
Chris@1464 4 duplicates = CustomField.connection.select_rows("SELECT custom_field_id, project_id FROM #{table_name} GROUP BY custom_field_id, project_id HAVING COUNT(*) > 1")
Chris@1464 5 duplicates.each do |custom_field_id, project_id|
Chris@1464 6 # Removes duplicate rows
Chris@1464 7 CustomField.connection.execute("DELETE FROM #{table_name} WHERE custom_field_id=#{custom_field_id} AND project_id=#{project_id}")
Chris@1464 8 # And insert one
Chris@1464 9 CustomField.connection.execute("INSERT INTO #{table_name} (custom_field_id, project_id) VALUES (#{custom_field_id}, #{project_id})")
Chris@1464 10 end
Chris@1464 11
Chris@1464 12 if index_exists? :custom_fields_projects, [:custom_field_id, :project_id]
Chris@1464 13 remove_index :custom_fields_projects, [:custom_field_id, :project_id]
Chris@1464 14 end
Chris@1464 15 add_index :custom_fields_projects, [:custom_field_id, :project_id], :unique => true
Chris@1464 16 end
Chris@1464 17
Chris@1464 18 def down
Chris@1464 19 if index_exists? :custom_fields_projects, [:custom_field_id, :project_id]
Chris@1464 20 remove_index :custom_fields_projects, [:custom_field_id, :project_id]
Chris@1464 21 end
Chris@1464 22 add_index :custom_fields_projects, [:custom_field_id, :project_id]
Chris@1464 23 end
Chris@1464 24 end