🛤

Rails 4 から Rails 6 へ更新するためにやったこと

2023/04/01に公開

Gemfile内のgem 'rails'gem 'rails', '~> 6.1'へと書き換えた後にやってみたこと。

元々はRails4scaffoldして作ったささやかなものなので、大規模な移行には耐えられないと考えています。それでもやったこととして、ご参考になれば。

Rails 6へ更新後、素直に Railsのアップデート app:update をしてみる

rails app:update を実行して、一応比較をしながら結果的に全てをyにしています。
ほぼ脳死状態。

ログ

`app:update`を実行した際のログです。
rails app:update
    conflict  config/boot.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/boot.rb? (enter "h" for help) [Ynaqdhm] d
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

- require 'bundler/setup' # Set up gems listed in the Gemfile.
+ require "bundler/setup" # Set up gems listed in the Gemfile.
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/boot.rb? (enter "h" for help) [Ynaqdhm] Y
       force  config/boot.rb
       exist  config
    conflict  config/routes.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/routes.rb? (enter "h" for help) [Ynaqdhm] d
  Rails.application.routes.draw do
-   root      "people#index"
+   # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
-   resources :people
-   # The priority is based upon order of creation: first created -> highest priority.
-   # See how all your routes lay out with "rake routes".
-
-   # You can have the root of your site routed with "root"
-   # root 'welcome#index'
-
-   # Example of regular route:
-   #   get 'products/:id' => 'catalog#view'
-
-   # Example of named route that can be invoked with purchase_url(id: product.id)
-   #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
-   # Example resource route (maps HTTP verbs to controller actions automatically):
-   #   resources :products
-
-   # Example resource route with options:
-   #   resources :products do
-   #     member do
-   #       get 'short'
-   #       post 'toggle'
-   #     end
-   #
-   #     collection do
-   #       get 'sold'
-   #     end
-   #   end
-
-   # Example resource route with sub-resources:
-   #   resources :products do
-   #     resources :comments, :sales
-   #     resource :seller
-   #   end
-
-   # Example resource route with more complex sub-resources:
-   #   resources :products do
-   #     resources :comments
-   #     resources :sales do
-   #       get 'recent', on: :collection
-   #     end
-   #   end
-
-   # Example resource route with concerns:
-   #   concern :toggleable do
-   #     post 'toggle'
-   #   end
-   #   resources :posts, concerns: :toggleable
-   #   resources :photos, concerns: :toggleable
-
-   # Example resource route within a namespace:
-   #   namespace :admin do
-   #     # Directs /admin/products/* to Admin::ProductsController
-   #     # (app/controllers/admin/products_controller.rb)
-   #     resources :products
-   #   end
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/routes.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/routes.rb
    conflict  config/application.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/application.rb? (enter "h" for help) [Ynaqdhm] d
- require File.expand_path('../boot', __FILE__)
+ require_relative "boot"

  require "rails"
  # Pick the frameworks you want:
  require "active_model/railtie"
  require "active_job/railtie"
  require "active_record/railtie"
+ # require "active_storage/engine"
  require "action_controller/railtie"
  require "action_mailer/railtie"
+ # require "action_mailbox/engine"
+ # require "action_text/engine"
  require "action_view/railtie"
+ # require "action_cable/engine"
  require "sprockets/railtie"
- # require "rails/test_unit/railtie"
+ require "rails/test_unit/railtie"

  # Require the gems listed in Gemfile, including any gems
  # you've limited to :test, :development, or :production.
  Bundler.require(*Rails.groups)

  module HerokuRuby0124
    class Application < Rails::Application
-     # Settings in config/environments/* take precedence over those specified here.
+     # Initialize configuration defaults for originally generated Rails version.
-     # Application configuration should go into files in config/initializers
+     config.load_defaults 5.0
-     # -- all .rb files in that directory are automatically loaded.

-     # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+     # Configuration for the application, engines, and railties goes here.
-     # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+     #
-     # config.time_zone = 'Central Time (US & Canada)'
+     # These settings can be overridden in specific environments using the files
-
+     # in config/environments, which are processed later.
-     # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+     #
-     # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+     # config.time_zone = "Central Time (US & Canada)"
-     # config.i18n.default_locale = :de
+     # config.eager_load_paths << Rails.root.join("extras")
-
-     # Do not swallow errors in after_commit/after_rollback callbacks.
-     config.active_record.raise_in_transactional_callbacks = true
    end
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/application.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/application.rb
    conflict  config/environment.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environment.rb? (enter "h" for help) [Ynaqdhm] d
  # Load the Rails application.
- require File.expand_path('../application', __FILE__)
+ require_relative "application"

  # Initialize the Rails application.
  Rails.application.initialize!
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environment.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/environment.rb
       exist  config/environments
    conflict  config/environments/development.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/development.rb? (enter "h" for help) [Ynaqdhm] d
+ require "active_support/core_ext/integer/time"
+
  Rails.application.configure do
    # Settings specified here will take precedence over those in config/application.rb.

-   # In the development environment your application's code is reloaded on
+   # In the development environment your application's code is reloaded any time
-   # every request. This slows down response time but is perfect for development
+   # it changes. This slows down response time but is perfect for development
    # since you don't have to restart the web server when you make code changes.
    config.cache_classes = false

    # Do not eager load code on boot.
    config.eager_load = false

-   # Show full error reports and disable caching.
+   # Show full error reports.
-   config.consider_all_requests_local       = true
+   config.consider_all_requests_local = true
-   config.action_controller.perform_caching = false

+   # Enable/disable caching. By default caching is disabled.
+   # Run rails dev:cache to toggle caching.
+   if Rails.root.join('tmp', 'caching-dev.txt').exist?
+     config.action_controller.perform_caching = true
+     config.action_controller.enable_fragment_cache_logging = true
+
+     config.cache_store = :memory_store
+     config.public_file_server.headers = {
+       'Cache-Control' => "public, max-age=#{2.days.to_i}"
+     }
+   else
+     config.action_controller.perform_caching = false
+
+     config.cache_store = :null_store
+   end
+
    # Don't care if the mailer can't send.
    config.action_mailer.raise_delivery_errors = false

+   config.action_mailer.perform_caching = false
+
    # Print deprecation notices to the Rails logger.
    config.active_support.deprecation = :log

+   # Raise exceptions for disallowed deprecations.
+   config.active_support.disallowed_deprecation = :raise
+
+   # Tell Active Support which deprecation messages to disallow.
+   config.active_support.disallowed_deprecation_warnings = []
+
    # Raise an error on page load if there are pending migrations.
    config.active_record.migration_error = :page_load

+   # Highlight code that triggered database queries in logs.
+   config.active_record.verbose_query_logs = true
+
    # Debug mode disables concatenation and preprocessing of assets.
    # This option may cause significant delays in view rendering with a large
    # number of complex assets.
    config.assets.debug = true

-   # Asset digests allow you to set far-future HTTP expiration dates on all assets,
+   # Suppress logger output for asset requests.
-   # yet still be able to expire them through the digest params.
+   config.assets.quiet = true
-   config.assets.digest = true

-   # Adds additional error checking when serving assets at runtime.
+   # Raises error for missing translations.
-   # Checks for improperly declared sprockets dependencies.
+   # config.i18n.raise_on_missing_translations = true
-   # Raises helpful error messages.
-   config.assets.raise_runtime_errors = true

-   # Raises error for missing translations
+   # Annotate rendered view with file names.
-   # config.action_view.raise_on_missing_translations = true
+   # config.action_view.annotate_rendered_view_with_filenames = true
+
+   # Use an evented file watcher to asynchronously detect changes in source code,
+   # routes, locales, etc. This feature depends on the listen gem.
+   config.file_watcher = ActiveSupport::EventedFileUpdateChecker
+
+   # Uncomment if you wish to allow Action Cable access from any origin.
+   # config.action_cable.disable_request_forgery_protection = true
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/development.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/environments/development.rb
    conflict  config/environments/production.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/production.rb? (enter "h" for help) [Ynaqdhm] d
+ require "active_support/core_ext/integer/time"
+
  Rails.application.configure do
    # Settings specified here will take precedence over those in config/application.rb.

    # Code is not reloaded between requests.
    config.cache_classes = true

    # Eager load code on boot. This eager loads most of Rails and
    # your application in memory, allowing both threaded web servers
    # and those relying on copy on write to perform better.
    # Rake tasks automatically ignore this option for performance.
    config.eager_load = true

    # Full error reports are disabled and caching is turned on.
    config.consider_all_requests_local       = false
    config.action_controller.perform_caching = true

-   # Enable Rack::Cache to put a simple HTTP cache in front of your application
+   # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
-   # Add `rack-cache` to your Gemfile before enabling this.
+   # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
-   # For large-scale production use, consider using a caching reverse proxy like
+   # config.require_master_key = true
-   # NGINX, varnish or squid.
-   # config.action_dispatch.rack_cache = true

    # Disable serving static files from the `/public` folder by default since
    # Apache or NGINX already handles this.
-   config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
+   config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

-   # Compress JavaScripts and CSS.
+   # Compress CSS using a preprocessor.
-   config.assets.js_compressor = :uglifier
    # config.assets.css_compressor = :sass

    # Do not fallback to assets pipeline if a precompiled asset is missed.
    config.assets.compile = false

-   # Asset digests allow you to set far-future HTTP expiration dates on all assets,
+   # Enable serving of images, stylesheets, and JavaScripts from an asset server.
-   # yet still be able to expire them through the digest params.
+   # config.asset_host = 'http://assets.example.com'
-   config.assets.digest = true

-   # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
-
    # Specifies the header that your server uses for sending files.
    # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
    # config.force_ssl = true

-   # Use the lowest log level to ensure availability of diagnostic information
+   # Include generic and useful information about system operation, but avoid logging too much
-   # when problems arise.
+   # information to avoid inadvertent exposure of personally identifiable information (PII).
-   config.log_level = :debug
+   config.log_level = :info

    # Prepend all log lines with the following tags.
-   # config.log_tags = [ :subdomain, :uuid ]
+   config.log_tags = [ :request_id ]

-   # Use a different logger for distributed setups.
-   # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
-
    # Use a different cache store in production.
    # config.cache_store = :mem_cache_store

-   # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+   # Use a real queuing backend for Active Job (and separate queues per environment).
-   # config.action_controller.asset_host = 'http://assets.example.com'
+   # config.active_job.queue_adapter     = :resque
+   # config.active_job.queue_name_prefix = "heroku_ruby0124_production"

+   config.action_mailer.perform_caching = false
+
    # Ignore bad email addresses and do not raise email delivery errors.
    # Set this to true and configure the email server for immediate delivery to raise delivery errors.
    # config.action_mailer.raise_delivery_errors = false

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
    # the I18n.default_locale when a translation cannot be found).
    config.i18n.fallbacks = true

    # Send deprecation notices to registered listeners.
    config.active_support.deprecation = :notify

+   # Log disallowed deprecations.
+   config.active_support.disallowed_deprecation = :log
+
+   # Tell Active Support which deprecation messages to disallow.
+   config.active_support.disallowed_deprecation_warnings = []
+
    # Use default logging formatter so that PID and timestamp are not suppressed.
    config.log_formatter = ::Logger::Formatter.new

+   # Use a different logger for distributed setups.
+   # require "syslog/logger"
+   # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
+
+   if ENV["RAILS_LOG_TO_STDOUT"].present?
+     logger           = ActiveSupport::Logger.new(STDOUT)
+     logger.formatter = config.log_formatter
+     config.logger    = ActiveSupport::TaggedLogging.new(logger)
+   end
+
    # Do not dump schema after migrations.
    config.active_record.dump_schema_after_migration = false
+
+   # Inserts middleware to perform automatic connection switching.
+   # The `database_selector` hash is used to pass options to the DatabaseSelector
+   # middleware. The `delay` is used to determine how long to wait after a write
+   # to send a subsequent read to the primary.
+   #
+   # The `database_resolver` class is used by the middleware to determine which
+   # database is appropriate to use based on the time delay.
+   #
+   # The `database_resolver_context` class is used by the middleware to set
+   # timestamps for the last write to the primary. The resolver uses the context
+   # class timestamps to determine how long to wait before reading from the
+   # replica.
+   #
+   # By default Rails will store a last write timestamp in the session. The
+   # DatabaseSelector middleware is designed as such you can define your own
+   # strategy for connection switching and pass that into the middleware through
+   # these configuration options.
+   # config.active_record.database_selector = { delay: 2.seconds }
+   # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
+   # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/production.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/environments/production.rb
    conflict  config/environments/test.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/test.rb? (enter "h" for help) [Ynaqdhm] d
+ require "active_support/core_ext/integer/time"
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+
  Rails.application.configure do
    # Settings specified here will take precedence over those in config/application.rb.

-   # The test environment is used exclusively to run your application's
-   # test suite. You never need to work with it otherwise. Remember that
-   # your test database is "scratch space" for the test suite and is wiped
-   # and recreated between test runs. Don't rely on the data there!
    config.cache_classes = true

    # Do not eager load code on boot. This avoids loading your whole application
    # just for the purpose of running a single test. If you are using a tool that
    # preloads Rails for running tests, you may have to set it to true.
    config.eager_load = false

-   # Configure static file server for tests with Cache-Control for performance.
+   # Configure public file server for tests with Cache-Control for performance.
-   config.serve_static_files   = true
+   config.public_file_server.enabled = true
-   config.static_cache_control = 'public, max-age=3600'
+   config.public_file_server.headers = {
+     'Cache-Control' => "public, max-age=#{1.hour.to_i}"
+   }

    # Show full error reports and disable caching.
    config.consider_all_requests_local       = true
    config.action_controller.perform_caching = false
+   config.cache_store = :null_store

    # Raise exceptions instead of rendering exception templates.
    config.action_dispatch.show_exceptions = false

    # Disable request forgery protection in test environment.
    config.action_controller.allow_forgery_protection = false

+   config.action_mailer.perform_caching = false
+
    # Tell Action Mailer not to deliver emails to the real world.
    # The :test delivery method accumulates sent emails in the
    # ActionMailer::Base.deliveries array.
    config.action_mailer.delivery_method = :test

-   # Randomize the order test cases are executed.
-   config.active_support.test_order = :random
-
    # Print deprecation notices to the stderr.
    config.active_support.deprecation = :stderr

-   # Raises error for missing translations
+   # Raise exceptions for disallowed deprecations.
-   # config.action_view.raise_on_missing_translations = true
+   config.active_support.disallowed_deprecation = :raise
+
+   # Tell Active Support which deprecation messages to disallow.
+   config.active_support.disallowed_deprecation_warnings = []
+
+   # Raises error for missing translations.
+   # config.i18n.raise_on_missing_translations = true
+
+   # Annotate rendered view with file names.
+   # config.action_view.annotate_rendered_view_with_filenames = true
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/environments/test.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/environments/test.rb
       exist  config/initializers
      create  config/initializers/application_controller_renderer.rb
    conflict  config/initializers/assets.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/assets.rb? (enter "h" for help) [Ynaqdhm] d
  # Be sure to restart your server when you modify this file.

  # Version of your assets, change this if you want to expire all your assets.
  Rails.application.config.assets.version = '1.0'

- # Add additional assets to the asset load path
+ # Add additional assets to the asset load path.
  # Rails.application.config.assets.paths << Emoji.images_path

  # Precompile additional assets.
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
+ # application.js, application.css, and all non-JS/CSS in the app/assets
- # Rails.application.config.assets.precompile += %w( search.js )
+ # folder are already added.
+ # Rails.application.config.assets.precompile += %w( admin.js admin.css )
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/assets.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/initializers/assets.rb
    conflict  config/initializers/backtrace_silencers.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/backtrace_silencers.rb? (enter "h" for help) [Ynaqdhm] d
  # Be sure to restart your server when you modify this file.

  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+ # Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) }

- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code
- # Rails.backtrace_cleaner.remove_silencers!
+ # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'".
+ Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"]
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/backtrace_silencers.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
    conflict  config/initializers/cookies_serializer.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/cookies_serializer.rb? (enter "h" for help) [Ynaqdhm] d
  # Be sure to restart your server when you modify this file.

+ # Specify a serializer for the signed and encrypted cookie jars.
+ # Valid options are :json, :marshal, and :hybrid.
  Rails.application.config.action_dispatch.cookies_serializer = :json
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/cookies_serializer.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
    conflict  config/initializers/filter_parameter_logging.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/filter_parameter_logging.rb? (enter "h" for help) [Ynaqdhm] d
  # Be sure to restart your server when you modify this file.

  # Configure sensitive parameters which will be filtered from the log file.
- Rails.application.config.filter_parameters += [:password]
+ Rails.application.config.filter_parameters += [
+   :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
+ ]
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/filter_parameter_logging.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/initializers/filter_parameter_logging.rb
   identical  config/initializers/inflections.rb
   identical  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_1.rb
      create  config/initializers/permissions_policy.rb
    conflict  config/initializers/wrap_parameters.rb
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/wrap_parameters.rb? (enter "h" for help) [Ynaqdhm] d
  # Be sure to restart your server when you modify this file.

  # This file contains settings for ActionController::ParamsWrapper which
  # is enabled by default.

  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
  ActiveSupport.on_load(:action_controller) do
-   wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+   wrap_parameters format: [:json]
  end

  # To enable root element in JSON for ActiveRecord objects.
  # ActiveSupport.on_load(:active_record) do
- #  self.include_root_in_json = true
+ #   self.include_root_in_json = true
  # end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/initializers/wrap_parameters.rb? (enter "h" for help) [Ynaqdhm] y
       force  config/initializers/wrap_parameters.rb
       exist  config/locales
    conflict  config/locales/en.yml
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/locales/en.yml? (enter "h" for help) [Ynaqdhm] d
  # Files in the config/locales directory are used for internationalization
  # and are automatically loaded by Rails. If you want to use locales other
  # than English, add the necessary files in this directory.
  #
  # To use the locales, use `I18n.t`:
  #
  #     I18n.t 'hello'
  #
  # In views, this is aliased to just `t`:
  #
  #     <%= t('hello') %>
  #
  # To use a different locale, set it with `I18n.locale`:
  #
  #     I18n.locale = :es
  #
  # This would use the information in config/locales/es.yml.
  #
+ # The following keys must be escaped otherwise they will not be retrieved by
+ # the default I18n backend:
+ #
+ # true, false, on, off, yes, no
+ #
+ # Instead, surround them with single quotes.
+ #
+ # en:
+ #   'true': 'foo'
+ #
  # To learn more, please read the Rails Internationalization guide
- # available at http://guides.rubyonrails.org/i18n.html.
+ # available at https://guides.rubyonrails.org/i18n.html.

  en:
    hello: "Hello world"
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config/locales/en.yml? (enter "h" for help) [Ynaqdhm] y
       force  config/locales/en.yml
    conflict  config.ru
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config.ru? (enter "h" for help) [Ynaqdhm] d
  # This file is used by Rack-based servers to start the application.

- require ::File.expand_path('../config/environment', __FILE__)
+ require_relative "config/environment"
+
  run Rails.application
+ Rails.application.load_server
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/config.ru? (enter "h" for help) [Ynaqdhm] y
       force  config.ru
      remove  config/initializers/cors.rb
       exist  bin
    conflict  bin/rails
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/rails? (enter "h" for help) [Ynaqdhm] d
  #!/usr/bin/env ruby
- APP_PATH = File.expand_path('../../config/application', __FILE__)
+ APP_PATH = File.expand_path('../config/application', __dir__)
- require_relative '../config/boot'
+ require_relative "../config/boot"
- require 'rails/commands'
+ require "rails/commands"
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/rails? (enter "h" for help) [Ynaqdhm] y
       force  bin/rails
    conflict  bin/rake
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/rake? (enter "h" for help) [Ynaqdhm] d
  #!/usr/bin/env ruby
- require_relative '../config/boot'
+ require_relative "../config/boot"
- require 'rake'
+ require "rake"
  Rake.application.run
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/rake? (enter "h" for help) [Ynaqdhm] y
       force  bin/rake
    conflict  bin/setup
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/setup? (enter "h" for help) [Ynaqdhm] d
  #!/usr/bin/env ruby
- require 'pathname'
+ require "fileutils"

  # path to your application root.
- APP_ROOT = Pathname.new File.expand_path('../../',  __FILE__)
+ APP_ROOT = File.expand_path('..', __dir__)

- Dir.chdir APP_ROOT do
+ def system!(*args)
-   # This script is a starting point to setup your application.
+   system(*args) || abort("\n== Command #{args} failed ==")
-   # Add necessary setup steps to this file:
+ end

-   puts "== Installing dependencies =="
+ FileUtils.chdir APP_ROOT do
-   system "gem install bundler --conservative"
+   # This script is a way to set up or update your development environment automatically.
-   system "bundle check || bundle install"
+   # This script is idempotent, so that you can run it at any time and get an expectable outcome.
+   # Add necessary setup steps to this file.

+   puts '== Installing dependencies =='
+   system! 'gem install bundler --conservative'
+   system('bundle check') || system!('bundle install')
+
    # puts "\n== Copying sample files =="
-   # unless File.exist?("config/database.yml")
+   # unless File.exist?('config/database.yml')
-   #   system "cp config/database.yml.sample config/database.yml"
+   #   FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
    # end

    puts "\n== Preparing database =="
-   system "bin/rake db:setup"
+   system! 'bin/rails db:prepare'

    puts "\n== Removing old logs and tempfiles =="
-   system "rm -f log/*"
+   system! 'bin/rails log:clear tmp:clear'
-   system "rm -rf tmp/cache"

    puts "\n== Restarting application server =="
-   system "touch tmp/restart.txt"
+   system! 'bin/rails restart'
  end
Retrying...
Overwrite /Users/sho/working/ruby/work/heroku_ruby_0124/bin/setup? (enter "h" for help) [Ynaqdhm] y
       force  bin/setup
      create  bin/spring
      create  bin/yarn
      remove  bin/spring
      remove  bin/yarn

After this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app.

Web(アプリケーション)サーバを指定しないと起動しない

私の記憶が定かではないのですが、Rails 4のときは特段指定しなくとも適当にWebアプリケーションサーバが起動されていた気がします。なんとなくデフォルトでそのようになっていたのでしょうが、古すぎて記憶にありません。少なくとも、私のRailsアプリケーションは、今回の更新によって、Web(アプリケーション)サーバを指定しないことには起動しませんでした。

起動時のコマンドは、次のようにGemfileへ利用するアプリケーションを追加して、起動時のコマンドに -u pumaを指定しました。特にこれだというのはなく、前もpuma使ってた気がするな程度の選択です。ひとまず動けばいい。

Gemfile
gem 'puma'
起動コマンド
bundle exec rails server -p $PORT -e $RAILS_ENV -u puma

地味にHeroku上で動かしているアプリケーションだったので、Procfileも次のようにしています。

Procfile
web:bundle exec rails server -p $PORT -e $RAILS_ENV -u puma

config.file_watcher が悪さをして、Rails Serverが起動できない

本当か分からないのですが、developmentの環境においてこの機能を使えるようにしていると、なぜか実行できません。
注釈することで、この状況を回避できるようになりました。

Cannot Load Such File -- Listen (LoadError)によってrails Sできない!

/config/environment/development.rb
この機能を注釈する
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

config.file_watcherが何をするのか、本家の内容をひも解いてみました。

config.reload_classes_only_on_changetrueの場合に、ファイルシステム上のファイル更新検出に使われるクラスを指定します。デフォルトのRailsではActiveSupport::FileUpdateChecker、およびActiveSupport::EventedFileUpdateChecker(これはlistenに依存します)が指定されます。カスタムクラスはこのActiveSupport::FileUpdateChecker APIに従わなければなりません。
(Rails アプリケーションを設定する - Railsガイド)

うーん。よく分からない。理由が分からないのでもやもやする。

StandardError: Directly inheriting from ActiveRecord::Migration is not supported. エラーが発生した時の対処

rails Dbmigrateをする際に発生したDirectly Inheriting From ActiveRecordMigration Is Not supported.の解決法

Rails 5.0, 6.0で書き方が変わってしまったため、対処が必要ということです。

db/migrate/20170122100043_create_people.rb
class CreatePeople < ActiveRecord::Migration[6.0] # [6.0]を追加
  def change
    create_table :people do |t|
      t.string :name
      t.date :birth
      t.string :home
      t.float :height
      t.string :office

      t.timestamps null: false
    end
  end
end

マイグレーションファイルの日付見て気がついたんですけど、このソースコード6年前に作ったんですね。そりゃ何も覚えてないわ。

config/routes がきれいさっぱりなくなってた

Scaffoldで作成してたconfig/routes.rb内がきれいさっぱり無くなっていました。
仕方がないので、次のようにresourcesを追加して元に戻しました。

config/routes.rb
Rails.application.routes.draw do
  resources :people
end

以上で、わが家のRails 4アプリケーションはひとまず動くようになりました。とさ。

Discussion