Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def set_organization
def organization_params
params.require(:organization).permit(
:name, :description, :start_date, :end_date, :mission_vision_values,
:agency_type, :agency_type_other, :internal_id, :logo, :notes, :email, :website_url,
:agency_type, :agency_type_other, :filemaker_code, :logo, :notes, :email, :website_url,
:organization_status_id, :location_id, :windows_type_id,
:profile_show_sectors, :profile_show_email, :profile_show_phone,
:profile_show_website, :profile_show_description, :profile_show_workshops,
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@

<% if allowed_to?(:manage?, Organization) %>
<div class="admin-only bg-blue-100">
<%= f.input :internal_id,
label: "Internal Organization ID",
<%= f.input :filemaker_code,
label: "FileMaker Project ID",
input_html: {
class: "rounded-md border-gray-300 bg-blue-100 shadow-sm focus:ring-blue-500 focus:border-blue-500"
} %>
Expand Down
38 changes: 38 additions & 0 deletions lib/tasks/migrate_internal_id_to_filemaker_code.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace :organizations do
desc "Migrate internal_id to filemaker_code for organizations"
task migrate_internal_id_to_filemaker_code: :environment do
puts "Starting migration of internal_id to filemaker_code..."
puts "Environment: #{Rails.env}"
puts "==============================================="

migrated_count = 0
commented_count = 0
skipped_count = 0

Organization.where.not(internal_id: [ nil, "" ]).find_each do |org|
internal_stripped = org.internal_id.strip
filemaker_stripped = org.filemaker_code&.strip

if !filemaker_stripped.present? && internal_stripped.present?
org.update!(filemaker_code: internal_stripped)
migrated_count += 1
puts "Migrated org #{org.id} (#{org.name}): filemaker_code set to '#{internal_stripped}'"
elsif internal_stripped != filemaker_stripped
org.comments.create!(
body: "Data migration note: internal_id '#{org.internal_id}' did not match filemaker_code '#{org.filemaker_code}'"
)
commented_count += 1
puts "Mismatch org #{org.id} (#{org.name}): internal_id='#{org.internal_id}' vs filemaker_code='#{org.filemaker_code}' — comment added"
else
skipped_count += 1
puts "Skipped org #{org.id} (#{org.name}): values already match"
end
end

puts "==============================================="
puts "Migration complete!"
puts "Migrated: #{migrated_count}"
puts "Mismatches commented: #{commented_count}"
puts "Skipped (already matching): #{skipped_count}"
end
end