Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrations #73

Merged
merged 12 commits into from Nov 13, 2016
3 changes: 1 addition & 2 deletions db/migrations/20161026_1154_add_secondary_index_to_users.rb
Expand Up @@ -38,8 +38,7 @@ def update
}
],
projection: {
projection_type: "ALL",
non_key_attributes: []
projection_type: "ALL"
},
provisioned_throughput: {
read_capacity_units: Dynamoid::Config.read_capacity,
Expand Down
Expand Up @@ -16,18 +16,23 @@ def update
)
end

general_info_ids = GeneralInfo.all.map(&:id)
logger.info "Updating #{general_info_ids.length} GeneralInfo records ..."
general_info_ids.each do |id|
gis = GeneralInfo.all
logger.info "Updating #{gis.length} GeneralInfo records ..."
gis.each do |gi|
# First, rename contracting_for_ori field to ori.
begin
client.update_item(
table_name: "#{Dynamoid.config.namespace}_general_infos",
key: { 'id' => id },
key: { 'id' => gi.id },
update_expression: "SET ori = contracting_for_ori REMOVE contracting_for_ori",
condition_expression: "attribute_exists (contracting_for_ori)"
)
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
logger.debug " Skipping #{id} because it has no contracting_for_ori"
# Then, for any incidents who don't have an explicit ori defined,
# take the user's ORI.
logger.debug " #{gi.id} has no contracting_for_ori - setting its ori to user's ori: #{gi.incident.user.ori}"
gi.ori = gi.incident.user.ori
gi.save!
end
end

Expand Down
35 changes: 35 additions & 0 deletions db/migrations/20161111_1415_involved_person_copy_changes.rb
@@ -0,0 +1,35 @@
# Renames several fields for InvolvedCivilians and InvolvedOfficers.
class InvolvedPersonCopyChanges < DynamoDB::Migration::Unit
def update
logger = Logger.new(STDOUT)

logger.info "Running migration #{self.class.name}:"

civilians = InvolvedCivilian.all
logger.info "Updating #{civilians.length} InvolvedCivilian records ..."
civilians.each do |civilian|
if civilian.resistance_type == 'Resistance'
civilian.resistance_type = 'Active resistance'
end

if civilian.custody_status == 'In custody'
civilian.custody_status = 'In custody (other)'
end

civilian.save(validation: false)
end

officers = InvolvedOfficer.all
logger.info "Updating #{officers.length} InvolvedOfficer records ..."
officers.each do |officer|
officer.officer_used_force_reason = officer.officer_used_force_reason.map do |reason|
reason == 'To effect arrest' ? 'To effect arrest or take into custody' : reason
end

officer.save(validation: false)
end

logger.info 'Done!'
logger.info '================================'
end
end