Skip to content

Instantly share code, notes, and snippets.

@jamiecook
Last active November 17, 2015 05:29
Show Gist options
  • Save jamiecook/204ddd204043c5991ec5 to your computer and use it in GitHub Desktop.
Save jamiecook/204ddd204043c5991ec5 to your computer and use it in GitHub Desktop.
How to do data migration for site mixup
def read_site_ids(filename)
CSV.parse(File.read(filename), headers: true).map { |row| row.first.to_i }
end
site_ids_currently_pending = read_site_ids('pre_narendra_pending_sites.csv') # -> https://docs.google.com/spreadsheets/d/1vfCPqUGrnAT_wTjZdOAPxidXBHlZmzuoDj3Isi1PQBo/edit?usp=sharing
site_ids_to_remain_altered_and_archived = read_site_ids('archived_and_altered_sites.csv') # https://docs.google.com/spreadsheets/d/1moV7ImXYfQSq_LOOoGuhHORIwBGBN2_uJdddBcosQfE/edit#gid=867017539
site_ids_to_remain_altered = [122292, 136994, 137577, 137767]
# Update 11464 sites to be changed => authorised
site_ids_to_be_authorised = site_ids_currently_pending - site_ids_to_remain_altered - site_ids_to_remain_altered_and_archived
Site.where(id: site_ids_to_be_authorised).update_all(site_authorisation_id: SiteAuthorisation::AUTHORISED.id)
# Update 4 sites to be ALTERED
Site.where(id: site_ids_to_remain_altered).update_all(site_authorisation_id: SiteAuthorisation::ALTERED.id)
# Update 531 sites to be ALTERED AND ARCHIVED
Site.where(id: site_ids_to_remain_altered).update_all(site_authorisation_id: SiteAuthorisation::REJECTED.id,
archived_flag: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment