Commit 234197345e820ff5dce814fcb95f50762d11a516
Committed by
Larissa Reis
1 parent
fde04c88
Exists in
master
and in
29 other branches
custom-forms: replace ruby code by sql on migration
Showing
1 changed file
with
17 additions
and
13 deletions
Show diff stats
plugins/custom_forms/db/migrate/20130823135600_add_select_field_type_to_custom_forms_plugin_fields.rb
... | ... | @@ -4,18 +4,10 @@ class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration |
4 | 4 | t.string :select_field_type |
5 | 5 | end |
6 | 6 | |
7 | - CustomFormsPlugin::Field.find_each do |f| | |
8 | - if !f.list && !f.multiple | |
9 | - f.select_field_type = :radio | |
10 | - elsif !f.list && f.multiple | |
11 | - f.select_field_type = :check_box | |
12 | - elsif f.list && !f.multiple | |
13 | - f.select_field_type = :select | |
14 | - else | |
15 | - f.select_field_type = :multiple_select | |
16 | - end | |
17 | - f.save! | |
18 | - end | |
7 | + update("UPDATE custom_forms_plugin_fields SET select_field_type='radio' WHERE list IS FALSE AND multiple IS FALSE") | |
8 | + update("UPDATE custom_forms_plugin_fields SET select_field_type='check_box' WHERE list IS FALSE AND multiple IS TRUE") | |
9 | + update("UPDATE custom_forms_plugin_fields SET select_field_type='select' WHERE list IS TRUE AND multiple IS FALSE") | |
10 | + update("UPDATE custom_forms_plugin_fields SET select_field_type='multiple_select' WHERE list IS TRUE AND multiple IS TRUE") | |
19 | 11 | |
20 | 12 | change_table :custom_forms_plugin_fields do |t| |
21 | 13 | t.remove :multiple, :list |
... | ... | @@ -23,6 +15,18 @@ class AddSelectFieldTypeToCustomFormsPluginFields < ActiveRecord::Migration |
23 | 15 | end |
24 | 16 | |
25 | 17 | def self.down |
26 | - raise ActiveRecord::IrreversibleMigration | |
18 | + change_table :custom_forms_plugin_fields do |t| | |
19 | + t.boolean :multiple | |
20 | + t.boolean :list | |
21 | + end | |
22 | + | |
23 | + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='radio'") | |
24 | + update("UPDATE custom_forms_plugin_fields SET list=FALSE, multiople=TRUE WHERE select_field_type='check_box'") | |
25 | + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=FALSE WHERE select_field_type='select'") | |
26 | + update("UPDATE custom_forms_plugin_fields SET list=TRUE, multiple=TRUE WHERE select_field_type='multiple_select'") | |
27 | + | |
28 | + change_table :custom_forms_plugin_fields do |t| | |
29 | + t.remove :select_fields_type | |
30 | + end | |
27 | 31 | end |
28 | 32 | end | ... | ... |