From 74cccf5eb05185ea93dd7e9454967ccbfe6430aa Mon Sep 17 00:00:00 2001 From: maebeale Date: Thu, 5 Mar 2026 10:59:31 -0500 Subject: [PATCH] Show FileMaker code instead of internal ID on org form - Replace internal_id field with filemaker_code on organization form - Update strong params to permit filemaker_code instead of internal_id - Add rake task to migrate existing internal_id values to filemaker_code Co-Authored-By: Claude Opus 4.6 --- app/controllers/organizations_controller.rb | 2 +- app/views/organizations/_form.html.erb | 4 +- ...migrate_internal_id_to_filemaker_code.rake | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 lib/tasks/migrate_internal_id_to_filemaker_code.rake diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 7ed3c28b8..46f3fd723 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -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, diff --git a/app/views/organizations/_form.html.erb b/app/views/organizations/_form.html.erb index d5ef7b191..a99902220 100644 --- a/app/views/organizations/_form.html.erb +++ b/app/views/organizations/_form.html.erb @@ -199,8 +199,8 @@ <% if allowed_to?(:manage?, Organization) %>
- <%= 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" } %> diff --git a/lib/tasks/migrate_internal_id_to_filemaker_code.rake b/lib/tasks/migrate_internal_id_to_filemaker_code.rake new file mode 100644 index 000000000..5ef965e3a --- /dev/null +++ b/lib/tasks/migrate_internal_id_to_filemaker_code.rake @@ -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