Merge pull request #659 from opf/fix/queries_group_by_migration

[FIX] Queries group by migration
pull/638/head
meeee 11 years ago
commit 4cd13015bb
  1. 65
      db/migrate/20130917101922_migrate_query_tracker_references_to_type.rb
  2. 1
      doc/CHANGELOG.md

@ -16,7 +16,12 @@ require_relative 'migration_utils/utils'
class MigrateQueryTrackerReferencesToType < ActiveRecord::Migration
include Migration::Utils
COLUMNS = ['filters', 'column_names', 'sort_criteria', 'group_by']
COLUMNS = {
'filters' => { is_text_column: false },
'column_names' => { is_text_column: false },
'sort_criteria' => { is_text_column: false },
'group_by' => { is_text_column: true }
}
KEY = { 'tracker_id' => 'type_id', 'tracker' => 'type' }
def up
@ -35,24 +40,13 @@ class MigrateQueryTrackerReferencesToType < ActiveRecord::Migration
def update_tracker_reference(keys, columns)
Proc.new do |row|
columns.each do |column|
columns.keys.each do |column|
unless row[column].nil?
value = YAML.load row[column]
if value.is_a? Array
value.collect! do |e|
if e.is_a? Array
e.collect! {|v| keys.has_key?(v) ? keys[v] : v}
else
keys.has_key?(e.to_s) ? keys[e.to_s].to_sym : e
end
end
elsif value.is_a? Hash
keys.select {|k| value[k.to_s]}
.each_pair {|k, v| value[v] = value.delete k}
if columns[column][:is_text_column]
process_text_data(row, column, keys)
else
row[column] = process_yaml_data(row, column, keys)
end
row[column] = YAML.dump value
end
end
@ -60,10 +54,43 @@ class MigrateQueryTrackerReferencesToType < ActiveRecord::Migration
end
end
def process_yaml_data(row, column, keys)
value = YAML.load row[column]
if value.is_a? Array
value.collect! do |e|
if e.is_a? Array
e.collect! {|v| keys.has_key?(v) ? keys[v] : v}
else
keys.has_key?(e.to_s) ? keys[e.to_s].to_sym : e
end
end
elsif value.is_a? Hash
keys.select {|k| value[k.to_s]}
.each_pair {|k, v| value[v] = value.delete k}
end
YAML.dump value
end
def process_text_data(row, column, keys)
value = row[column]
keys.each_key do |k|
regex = Regexp.new(k)
replace = keys[k]
value.gsub!(regex, replace)
end
value
end
def update_tracker_references_with_keys(keys)
filter = COLUMNS.map{|c| "#{c} LIKE '%tracker%'"}
filter = COLUMNS.keys
.map{|c| "#{c} LIKE '%tracker%'"}
.join(" OR ")
update_column_values('queries', COLUMNS, update_tracker_reference(keys, COLUMNS), filter)
update_column_values('queries', COLUMNS.keys, update_tracker_reference(keys, COLUMNS), filter)
end
end

@ -29,6 +29,7 @@ See doc/COPYRIGHT.rdoc for more details.
# Changelog
* `#3018` Fix: Stored queries grouping by attribute is not working
* `#3020` Fix: E-mail Message-ID header is not unique for Work Package mails
* `#3030` Users preferences for order of comments is ignored on wp comments
* `#3032` Fix: Work package comments aren't editable by authors

Loading…
Cancel
Save