Correct bug in the upgrade process where we sometimes overwrite part of a model class

This commit is contained in:
Eric 2020-05-12 17:00:17 -05:00
parent 4625aef641
commit 3c78022724
2 changed files with 8 additions and 7 deletions

View file

@ -18,16 +18,17 @@ class CwToActivestorageGenerator < Rails::Generators::Base
def include_uploaders
file_and_search = [
["campaign.rb", "class Campaign < ApplicationRecord\n"],
["profile.rb", "class Profile < ApplicationRecord\n"],
['nonprofit.rb', "class Nonprofit < ApplicationRecord\n"],
['image_attachment.rb', "class ImageAttachment < ApplicationRecord\n"],
['event.rb', "class Event < ApplicationRecord\n"]
["campaign.rb", "class Campaign < ApplicationRecord"],
["profile.rb", "class Profile < ApplicationRecord"],
['nonprofit.rb', "class Nonprofit < ApplicationRecord"],
['image_attachment.rb', "class ImageAttachment < ApplicationRecord"],
['event.rb', "class Event < ApplicationRecord"]
]
file_and_search
.select{|filename, _| !File.read("app/models/#{filename}").include?('###MIGRATION_FIELDS_BEGIN')}\
.select{|filename, _| !File.read("app/models/#{filename}").include?('###MIGRATION_FIELDS_BEGIN')}
.each do |filename, find_string|
gsub_file("app/models/#{filename}",find_string ) do |match|
match << "\n"
match << File.read(Pathname(File.expand_path('templates', __dir__, )) + 'models' + "#{filename}")
end
end

View file

@ -166,7 +166,7 @@ RUBY
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_contents = file_contents.sub(/\n\#\#\#MIGRATION_FIELDS_BEGIN(.*)\#\#\#MIGRATION_FIELDS_END/mx, '')
File.write(filename, file_contents)
end
end