@@ -1,15 +1,15 | |||||
1 | class AddEnumerationsPosition < ActiveRecord::Migration |
|
1 | class AddEnumerationsPosition < ActiveRecord::Migration | |
2 | def self.up |
|
2 | def self.up | |
3 | add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position') |
|
3 | add_column(:enumerations, :position, :integer, :default => 1) unless Enumeration.column_names.include?('position') | |
4 | Enumeration.all.group_by(&:opt).each do |opt, enums| |
|
4 | Enumeration.all.group_by(&:opt).each do |opt, enums| | |
5 | enums.each_with_index do |enum, i| |
|
5 | enums.each_with_index do |enum, i| | |
6 | # do not call model callbacks |
|
6 | # do not call model callbacks | |
7 |
Enumeration.where({:id => enum.id}).update_all( |
|
7 | Enumeration.where({:id => enum.id}).update_all(:position => (i+1)) | |
8 | end |
|
8 | end | |
9 | end |
|
9 | end | |
10 | end |
|
10 | end | |
11 |
|
11 | |||
12 | def self.down |
|
12 | def self.down | |
13 | remove_column :enumerations, :position |
|
13 | remove_column :enumerations, :position | |
14 | end |
|
14 | end | |
15 | end |
|
15 | end |
@@ -1,15 +1,15 | |||||
1 | class AddCustomFieldsPosition < ActiveRecord::Migration |
|
1 | class AddCustomFieldsPosition < ActiveRecord::Migration | |
2 | def self.up |
|
2 | def self.up | |
3 | add_column(:custom_fields, :position, :integer, :default => 1) |
|
3 | add_column(:custom_fields, :position, :integer, :default => 1) | |
4 | CustomField.all.group_by(&:type).each do |t, fields| |
|
4 | CustomField.all.group_by(&:type).each do |t, fields| | |
5 | fields.each_with_index do |field, i| |
|
5 | fields.each_with_index do |field, i| | |
6 | # do not call model callbacks |
|
6 | # do not call model callbacks | |
7 |
CustomField.where({:id => field.id}).update_all( |
|
7 | CustomField.where({:id => field.id}).update_all(:position => (i+1)) | |
8 | end |
|
8 | end | |
9 | end |
|
9 | end | |
10 | end |
|
10 | end | |
11 |
|
11 | |||
12 | def self.down |
|
12 | def self.down | |
13 | remove_column :custom_fields, :position |
|
13 | remove_column :custom_fields, :position | |
14 | end |
|
14 | end | |
15 | end |
|
15 | end |
@@ -1,12 +1,12 | |||||
1 | class RemoveIssueStatusesIsDefault < ActiveRecord::Migration |
|
1 | class RemoveIssueStatusesIsDefault < ActiveRecord::Migration | |
2 | def up |
|
2 | def up | |
3 | remove_column :issue_statuses, :is_default |
|
3 | remove_column :issue_statuses, :is_default | |
4 | end |
|
4 | end | |
5 |
|
5 | |||
6 | def down |
|
6 | def down | |
7 | add_column :issue_statuses, :is_default, :boolean, :null => false, :default => false |
|
7 | add_column :issue_statuses, :is_default, :boolean, :null => false, :default => false | |
8 | # Restores the first status as default |
|
8 | # Restores the first status as default | |
9 |
default_status_id = IssueStatus.order( |
|
9 | default_status_id = IssueStatus.order(:position).pluck(:id).first | |
10 | IssueStatus.where(:id => default_status_id).update_all(:is_default => true) |
|
10 | IssueStatus.where(:id => default_status_id).update_all(:is_default => true) | |
11 | end |
|
11 | end | |
12 | end |
|
12 | end |
General Comments 0
You need to be logged in to leave comments.
Login now