Skip to content
Snippets Groups Projects
Commit 625fb2f2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Add iids to milestones. Moved iids logic to separate concern

parent 0a0b0e1e
No related branches found
No related tags found
1 merge request!5081fixed command to update init script
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
Loading
Loading
@@ -16,8 +16,6 @@ module Issuable
 
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)}
Loading
Loading
@@ -47,15 +45,6 @@ module Issuable
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
Loading
Loading
Loading
Loading
@@ -17,8 +17,8 @@
#
 
class Issue < ActiveRecord::Base
include Issuable
include InternalId
 
belongs_to :project
validates :project, presence: true
Loading
Loading
Loading
Loading
@@ -23,8 +23,8 @@ require Rails.root.join("app/models/commit")
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"
Loading
Loading
Loading
Loading
@@ -13,6 +13,8 @@
#
 
class Milestone < ActiveRecord::Base
include InternalId
attr_accessible :title, :description, :due_date, :state_event, :author_id_of_changes
attr_accessor :author_id_of_changes
 
Loading
Loading
class AddInternalIdsToMilestones < ActiveRecord::Migration
def change
add_column :milestones, :iid, :integer
end
end
Loading
Loading
@@ -11,7 +11,7 @@
#
# 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
Loading
Loading
@@ -119,6 +119,7 @@ ActiveRecord::Schema.define(:version => 20130821090530) do
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"
Loading
Loading
Loading
Loading
@@ -29,5 +29,20 @@ task migrate_iids: :environment do
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'
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment