Browse Source

data migration

pull/1/head
Nicolae Claudius 11 years ago
parent
commit
a3d0e9eeb6
  1. 4
      app/models/concerns/stampable.rb
  2. 2
      db/seeds/development/domains.seeds.rb
  3. 11
      lib/tasks/data.rake

4
app/models/concerns/stampable.rb

@ -10,10 +10,10 @@ module Stampable
end end
def set_creator_attribute def set_creator_attribute
self.creator = User.current self.creator = User.current unless creator_id?
end end
def set_updator_attribute def set_updator_attribute
self.updator = User.current self.updator = User.current unless updator_id? && updator_id_changed?
end end
end end

2
db/seeds/development/domains.seeds.rb

@ -2,6 +2,7 @@ after 'development:users' do
entrydns_org = Domain.find_by_name(Settings.host_domains.first) entrydns_org = Domain.find_by_name(Settings.host_domains.first)
User.all.each do |user| User.all.each do |user|
User.do_as(user) do
20.times do 20.times do
domain = FactoryGirl.build(:domain, :user => user) domain = FactoryGirl.build(:domain, :user => user)
domain.setup(FactoryGirl.generate(:email)) domain.setup(FactoryGirl.generate(:email))
@ -13,5 +14,6 @@ after 'development:users' do
FactoryGirl.create(:a, :user => user, :domain => entrydns_org) FactoryGirl.create(:a, :user => user, :domain => entrydns_org)
end end
end end
end
end end

11
lib/tasks/data.rake

@ -0,0 +1,11 @@
desc "Data migrations"
namespace :data do
task :versions_sync => :environment do
PaperTrail::Version.where.not(object: nil).find_each do |version|
if !version.creator_id? && !version.updator_id? && (object = version.reify) &&
object.respond_to?(:creator_id) && object.respond_to?(:updator_id)
version.update(creator_id: object.creator_id, updator_id: object.updator_id)
end
end
end
end
Loading…
Cancel
Save