Browse Source

data migration

pull/1/head
Nicolae Claudius 11 years ago
parent
commit
a3d0e9eeb6
  1. 4
      app/models/concerns/stampable.rb
  2. 18
      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

18
db/seeds/development/domains.seeds.rb

@ -2,15 +2,17 @@ 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|
20.times do User.do_as(user) do
domain = FactoryGirl.build(:domain, :user => user) 20.times do
domain.setup(FactoryGirl.generate(:email)) domain = FactoryGirl.build(:domain, :user => user)
domain.save! domain.setup(FactoryGirl.generate(:email))
domain.soa_record.update_serial! domain.save!
end domain.soa_record.update_serial!
end
20.times do 20.times do
FactoryGirl.create(:a, :user => user, :domain => entrydns_org) FactoryGirl.create(:a, :user => user, :domain => entrydns_org)
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