fix bool values in customizable journals

7621676460 migrated the bool custom values stored in the db to real db values. Unfortunately, the values in the customizable_journals where all quoted which they should not have been.
pull/3823/head
Jens Ulferts 9 years ago
parent 3483c4d3fa
commit 83eb95ad48
  1. 45
      db/migrate/20151116110245_fix_customizable_bool_values.rb

@ -0,0 +1,45 @@
class FixCustomizableBoolValues < ActiveRecord::Migration
def up
update_customizable_values(quoted_true, unquoted_true, quoted_false, unquoted_false)
end
def down
update_customizable_values(unquoted_true, quoted_true, unquoted_false, quoted_false)
end
private
def update_customizable_values(old_true, new_true, old_false, new_false)
bool_custom_fields.each do |bool_custom_field|
alter(CustomizableJournal, bool_custom_field, old_false, new_false)
alter(CustomizableJournal, bool_custom_field, old_true, new_true)
end
end
def bool_custom_fields
@bool_custom_fields ||= CustomField.where(field_format: 'bool').all
end
def alter(scope, custom_field, old, new)
scope
.where(custom_field_id: custom_field.id,
value: old)
.update_all(value: new)
end
def quoted_false
ActiveRecord::Base.connection.quoted_false
end
def quoted_true
ActiveRecord::Base.connection.quoted_true
end
def unquoted_false
ActiveRecord::Base.connection.unquoted_false
end
def unquoted_true
ActiveRecord::Base.connection.unquoted_true
end
end
Loading…
Cancel
Save