diff --git a/plugins/custom_forms/db/migrate/20130823135600_add_select_field_type_to_custom_forms_plugin_fields.rb b/plugins/custom_forms/db/migrate/20130823135600_add_select_field_type_to_custom_forms_plugin_fields.rb index 528ba0f..af696cb 100644 --- a/plugins/custom_forms/db/migrate/20130823135600_add_select_field_type_to_custom_forms_plugin_fields.rb +++ b/plugins/custom_forms/db/migrate/20130823135600_add_select_field_type_to_custom_forms_plugin_fields.rb @@ -4,18 +4,10 @@ class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration t.string :select_field_type end - CustomFormsPlugin::Field.find_each do |f| - if !f.list && !f.multiple - f.select_field_type = :radio - elsif !f.list && f.multiple - f.select_field_type = :check_box - elsif f.list && !f.multiple - f.select_field_type = :select - else - f.select_field_type = :multiple_select - end - f.save! - end + update("UPDATE custom_forms_plugin_fields SET select_field_type='radio' WHERE list IS FALSE AND multiple IS FALSE") + update("UPDATE custom_forms_plugin_fields SET select_field_type='check_box' WHERE list IS FALSE AND multiple IS TRUE") + update("UPDATE custom_forms_plugin_fields SET select_field_type='select' WHERE list IS TRUE AND multiple IS FALSE") + update("UPDATE custom_forms_plugin_fields SET select_field_type='multiple_select' WHERE list IS TRUE AND multiple IS TRUE") change_table :custom_forms_plugin_fields do |t| t.remove :multiple, :list @@ -23,6 +15,18 @@ class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration end def self.down - raise ActiveRecord::IrreversibleMigration + change_table :custom_forms_plugin_fields do |t| + t.boolean :multiple + t.boolean :list + end + + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='radio'") + update("UPDATE custom_forms_plugin_fields SET list=FALSE, multiople=TRUE WHERE select_field_type='check_box'") + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='select'") + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=TRUE WHERE select_field_type='multiple_select'") + + change_table :custom_forms_plugin_fields do |t| + t.remove :select_fields_type + end end end -- libgit2 0.21.2