Commit 625fb2f2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add iids to milestones. Moved iids logic to separate concern

parent 0a0b0e1e
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
...@@ -16,8 +16,6 @@ module Issuable ...@@ -16,8 +16,6 @@ module Issuable
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 } 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 :authored, ->(user) { where(author_id: user) }
scope :assigned_to, ->(u) { where(assignee_id: u.id)} scope :assigned_to, ->(u) { where(assignee_id: u.id)}
...@@ -47,15 +45,6 @@ module Issuable ...@@ -47,15 +45,6 @@ module Issuable
end end
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? def today?
Date.today == created_at.to_date Date.today == created_at.to_date
end end
......
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
# #
class Issue < ActiveRecord::Base class Issue < ActiveRecord::Base
include Issuable include Issuable
include InternalId
belongs_to :project belongs_to :project
validates :project, presence: true validates :project, presence: true
......
...@@ -23,8 +23,8 @@ require Rails.root.join("app/models/commit") ...@@ -23,8 +23,8 @@ require Rails.root.join("app/models/commit")
require Rails.root.join("lib/static_model") require Rails.root.join("lib/static_model")
class MergeRequest < ActiveRecord::Base class MergeRequest < ActiveRecord::Base
include Issuable include Issuable
include InternalId
belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project"
belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project"
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
# #
class Milestone < ActiveRecord::Base class Milestone < ActiveRecord::Base
include InternalId
attr_accessible :title, :description, :due_date, :state_event, :author_id_of_changes attr_accessible :title, :description, :due_date, :state_event, :author_id_of_changes
attr_accessor :author_id_of_changes attr_accessor :author_id_of_changes
......
class AddInternalIdsToMilestones < ActiveRecord::Migration
def change
add_column :milestones, :iid, :integer
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
...@@ -119,6 +119,7 @@ ActiveRecord::Schema.define(:version => 20130821090530) do ...@@ -119,6 +119,7 @@ ActiveRecord::Schema.define(:version => 20130821090530) do
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "state" t.string "state"
t.integer "iid"
end end
add_index "milestones", ["due_date"], :name => "index_milestones_on_due_date" add_index "milestones", ["due_date"], :name => "index_milestones_on_due_date"
......
...@@ -29,5 +29,20 @@ task migrate_iids: :environment do ...@@ -29,5 +29,20 @@ task migrate_iids: :environment do
end end
end 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' puts 'done'
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment