From a08f25c475fbb44e708e34b178a1bd4f45093882 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 6 May 2020 15:49:11 -0500 Subject: [PATCH] houdini_upgrade strips out the model file changes --- .../lib/tasks/houdini_upgrade_tasks.rake | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gems/houdini_upgrade/lib/tasks/houdini_upgrade_tasks.rake b/gems/houdini_upgrade/lib/tasks/houdini_upgrade_tasks.rake index 037a3ab8..f99ad45a 100644 --- a/gems/houdini_upgrade/lib/tasks/houdini_upgrade_tasks.rake +++ b/gems/houdini_upgrade/lib/tasks/houdini_upgrade_tasks.rake @@ -38,7 +38,7 @@ end sh "rails houdini_upgrade:migrate_uploads" Rake::Task["houdini_upgrade:create_backup_uploader_migration"].invoke Rake::Task["db:migrate"].invoke - + Rake::Task["houdini_upgrade:cleanup_upgrade_files"].invoke end task :cw_to_activestorage, [:aws_bucket, :aws_region, :aws_assethost] do |t, args| @@ -121,11 +121,20 @@ end end task :cleanup_upgrade_files do - FileUtils.rm_r "app/uploaders" - FileUtils.rm "config/initializers/carrierwave.rb" + FileUtils.rm_r "app/uploaders" if (File.exists?("app/uploaders")) + FileUtils.rm "config/initializers/carrierwave.rb" if (File.exists?("config/initializers/carrierwave.rb")) gemfile_lines = File.readlines("Gemfile").select{|i| !i.include?("gem 'carrierwave'") && !i.include?("gem 'carrierwave-aws'")} - File.write('Gemfile', gemfile_lines.join("\n")) + File.write('Gemfile', gemfile_lines.join()) cleanup_model_files end + def cleanup_model_files + filename_roots = HoudiniUpgrade::UPLOADERS_TO_MIGRATE.map{|i| i.name.singularize} + filename_roots.each do |f| + filename = "app/models/#{f}.rb" + file_contents = File.read(filename) + file_contents = file_contents.sub(/\#\#\#MIGRATION_FIELDS_BEGIN(.*)\#\#\#MIGRATION_FIELDS_END/mx, '') + File.write(filename, file_contents) + end + end end