Correct bug in the upgrade process where we sometimes overwrite part of a model class
This commit is contained in:
parent
4625aef641
commit
3c78022724
2 changed files with 8 additions and 7 deletions
|
@ -18,16 +18,17 @@ class CwToActivestorageGenerator < Rails::Generators::Base
|
||||||
|
|
||||||
def include_uploaders
|
def include_uploaders
|
||||||
file_and_search = [
|
file_and_search = [
|
||||||
["campaign.rb", "class Campaign < ApplicationRecord\n"],
|
["campaign.rb", "class Campaign < ApplicationRecord"],
|
||||||
["profile.rb", "class Profile < ApplicationRecord\n"],
|
["profile.rb", "class Profile < ApplicationRecord"],
|
||||||
['nonprofit.rb', "class Nonprofit < ApplicationRecord\n"],
|
['nonprofit.rb', "class Nonprofit < ApplicationRecord"],
|
||||||
['image_attachment.rb', "class ImageAttachment < ApplicationRecord\n"],
|
['image_attachment.rb', "class ImageAttachment < ApplicationRecord"],
|
||||||
['event.rb', "class Event < ApplicationRecord\n"]
|
['event.rb', "class Event < ApplicationRecord"]
|
||||||
]
|
]
|
||||||
file_and_search
|
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|
|
.each do |filename, find_string|
|
||||||
gsub_file("app/models/#{filename}",find_string ) do |match|
|
gsub_file("app/models/#{filename}",find_string ) do |match|
|
||||||
|
match << "\n"
|
||||||
match << File.read(Pathname(File.expand_path('templates', __dir__, )) + 'models' + "#{filename}")
|
match << File.read(Pathname(File.expand_path('templates', __dir__, )) + 'models' + "#{filename}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -166,7 +166,7 @@ RUBY
|
||||||
filename_roots.each do |f|
|
filename_roots.each do |f|
|
||||||
filename = "app/models/#{f}.rb"
|
filename = "app/models/#{f}.rb"
|
||||||
file_contents = File.read(filename)
|
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)
|
File.write(filename, file_contents)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue