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