Skip to content

Commit 65086e6

Browse files
committed
Delete position default 1 and other customization from Redmine CustomFieldEnumeration model
1 parent 3110f86 commit 65086e6

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

app/models/text_block.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class TextBlock < ActiveRecord::Base
55

66
validates :name, presence: true
77
validate :name_uniqueness
8-
validates_numericality_of :position, :only_integer => true
9-
before_create :set_position
108

119
scope :sorted, ->{ order(Arel.sql('project_id IS NOT NULL, project_id ASC, position ASC')) }
1210

@@ -23,14 +21,4 @@ def name_uniqueness
2321
errors.add :name, I18n.t('model.text_block.name_uniqueness')
2422
end
2523
end
26-
27-
def set_position
28-
if project_id.present?
29-
max = self.class.where(:project_id => project_id).maximum(:position) || 0
30-
self.position = max + 1
31-
else
32-
max = self.class.where(:project_id => nil).maximum(:position) || 0
33-
self.position = max + 1
34-
end
35-
end
3624
end

db/migrate/20230325132825_add_position_to_text_blocks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class AddPositionToTextBlocks < ActiveRecord::Migration[5.2]
22
def change
3-
add_column :text_blocks, :position, :integer, :default => 1
3+
add_column :text_blocks, :position, :integer
44
# # After executing "rake redmine:plugins:migrate", execute the following on "rails console", if keeping the existing positions is important:
55
# res = TextBlock.connection.select_all("SELECT id, name, project_id, row_number() over(PARTITION by project_id) AS position FROM #{TextBlock.table_name}")
66
# res.rows.each{|row| TextBlock.connection.execute("UPDATE #{TextBlock.table_name} SET position=#{row[3]} WHERE id=#{row[0]}")}

0 commit comments

Comments
 (0)