--- /dev/null
+module InternalId
+ extend ActiveSupport::Concern
+
+ included do
+ validate :set_iid, on: :create
+ validates :iid, presence: true, numericality: true
+ end
+
+ def set_iid
+ max_iid = project.send(self.class.name.tableize).maximum(:iid)
+ self.iid = max_iid.to_i + 1
+ end
+
+ def to_param
+ iid.to_s
+ end
+end
validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 }
- validate :set_iid, on: :create
- validates :iid, presence: true, numericality: true
scope :authored, ->(user) { where(author_id: user) }
scope :assigned_to, ->(u) { where(assignee_id: u.id)}
end
end
- def set_iid
- max_iid = project.send(self.class.name.tableize).maximum(:iid)
- self.iid = max_iid.to_i + 1
- end
-
- def to_param
- iid.to_s
- end
-
def today?
Date.today == created_at.to_date
end
#
class Issue < ActiveRecord::Base
-
include Issuable
+ include InternalId
belongs_to :project
validates :project, presence: true
require Rails.root.join("lib/static_model")
class MergeRequest < ActiveRecord::Base
-
include Issuable
+ include InternalId
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
#
class Milestone < ActiveRecord::Base
+ include InternalId
+
attr_accessible :title, :description, :due_date, :state_event, :author_id_of_changes
attr_accessor :author_id_of_changes
--- /dev/null
+class AddInternalIdsToMilestones < ActiveRecord::Migration
+ def change
+ add_column :milestones, :iid, :integer
+ end
+end
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130821090530) do
+ActiveRecord::Schema.define(:version => 20130821090531) do
create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "state"
+ t.integer "iid"
end
add_index "milestones", ["due_date"], :name => "index_milestones_on_due_date"
end
puts 'done'
+ puts 'Milestones'.yellow
+ Milestone.where(iid: nil).find_each(batch_size: 100) do |m|
+ begin
+ m.set_iid
+ if m.update_attribute(:iid, m.iid)
+ print '.'
+ else
+ print 'F'
+ end
+ rescue
+ print 'F'
+ end
+ end
+
+ puts 'done'
end