Skip to content

Instantly share code, notes, and snippets.

@cwjenkins
Last active August 29, 2015 14:25
Show Gist options
  • Save cwjenkins/5dd56eb0e81db5f1f078 to your computer and use it in GitHub Desktop.
Save cwjenkins/5dd56eb0e81db5f1f078 to your computer and use it in GitHub Desktop.
Migration script
accounts = (AccountRepository.pluck(:subdomain) -['lc7', 'policaro', 'dvnt', 'gds', 'countryhills', 'halman', 'entertech', 'autogroup', 'muskokachrysler', 'multipayroll', 'july8mike', 'amanda', 'nchem'])
accounts.each do |account|
Apartment::Database.switch account
entries = EntryRepository.connection.exec_query('select e.* from entry_repository e INNER JOIN user_repository u ON e.user_id=u.id where e.deleted_at IS NULL ORDER BY e.time;')
request = Request.new
entries.each do |row|
request.current_user = UserRepository.with_deleted.where(id: row["user_id"]).first
next if request.current_user.nil?
request.current_account = AccountRepository.where(subdomain: account).first
request.action = row["action"].parameterize.underscore
request.time = Time.parse(row["time"]) - 4.hour
request.device_id = row["device_id"]
EntryRepository.find(row["id"]).destroy
RecordTime.new(request).call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment