From e5222867d82627fb8153dcf5f40bb3feb284e5a5 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Wed, 22 Jan 2025 00:33:23 -0600 Subject: [PATCH 1/3] resolve Rails 8 upgrade issues --- bin/dev | 30 +++- bin/setup | 4 + config/application.rb | 2 +- config/database.yml | 1 + config/environments/development.rb | 18 ++- config/environments/production.rb | 55 ++++++- config/environments/test.rb | 2 +- .../new_framework_defaults_6_1.rb | 64 --------- .../new_framework_defaults_7_0.rb | 135 ------------------ .../new_framework_defaults_7_2.rb | 72 ---------- .../new_framework_defaults_8_0.rb | 32 ----- config/puma.rb | 14 +- 12 files changed, 107 insertions(+), 322 deletions(-) delete mode 100644 config/initializers/new_framework_defaults_6_1.rb delete mode 100644 config/initializers/new_framework_defaults_7_0.rb delete mode 100644 config/initializers/new_framework_defaults_7_2.rb delete mode 100644 config/initializers/new_framework_defaults_8_0.rb diff --git a/bin/dev b/bin/dev index 5f91c205..bc3f590e 100755 --- a/bin/dev +++ b/bin/dev @@ -1,2 +1,30 @@ #!/usr/bin/env ruby -exec "./bin/rails", "server", *ARGV +# frozen_string_literal: true + +def installed?(process) + IO.popen "#{process} -v" +rescue Errno::ENOENT + false +end + +def run(process) + system "#{process} start -f Procfile.dev" +rescue Errno::ENOENT + warn <<~MSG + ERROR: + Please ensure `Procfile.dev` exists in your project! + MSG + exit! +end + +if installed? "overmind" + run "overmind" +elsif installed? "foreman" + run "foreman" +else + warn <<~MSG + NOTICE: + For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them. + MSG + exit! +end diff --git a/bin/setup b/bin/setup index be3db3c0..8dfadbb5 100755 --- a/bin/setup +++ b/bin/setup @@ -13,8 +13,12 @@ FileUtils.chdir APP_ROOT do # Add necessary setup steps to this file. puts "== Installing dependencies ==" + system! "gem install bundler --conservative" system("bundle check") || system!("bundle install") + # Install JavaScript dependencies + system! "bin/yarn" + # puts "\n== Copying sample files ==" # unless File.exist?("config/database.yml") # FileUtils.cp "config/database.yml.sample", "config/database.yml" diff --git a/config/application.rb b/config/application.rb index 412f2d5a..e7f75009 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ class Application < Rails::Application # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. - config.active_support.to_time_preserves_timezone = :zone + config.active_support.to_time_preserves_timezone = false # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") end diff --git a/config/database.yml b/config/database.yml index 2e31e04e..816178c8 100644 --- a/config/database.yml +++ b/config/database.yml @@ -31,6 +31,7 @@ default: &default development: <<: *default + database: react-webpack-rails-tutorial # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/config/environments/development.rb b/config/environments/development.rb index 7f5212be..d7291fd8 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -22,14 +22,13 @@ 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.cache_store = :null_store config.action_controller.perform_caching = false end - # Change to :null_store to avoid any caching. - config.cache_store = :memory_store - # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local @@ -39,12 +38,15 @@ # Make template changes take effect immediately. config.action_mailer.perform_caching = false - # Set localhost to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "localhost", port: 3000 } - # 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 @@ -63,6 +65,10 @@ # Annotate rendered view with file names. 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 diff --git a/config/environments/production.rb b/config/environments/production.rb index 38d2d68d..7b9742f3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -17,6 +17,14 @@ # Turn on fragment caching in view templates. config.action_controller.perform_caching = true + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + # Cache assets for far-future expiry since they are all digest stamped. config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } @@ -27,10 +35,10 @@ config.active_storage.service = :local # Assume all access to the app is happening through a SSL-terminating reverse proxy. - config.assume_ssl = true + # config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + # config.force_ssl = true # Skip http-to-https redirect for the default health check endpoint. # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } @@ -45,9 +53,6 @@ # Prevent health checks from clogging up the logs. config.silence_healthcheck_path = "/up" - # Don't log any deprecations. - config.active_support.report_deprecations = false - # Replace the default in-process memory cache store with a durable alternative. # config.cache_store = :mem_cache_store @@ -59,7 +64,7 @@ # config.action_mailer.raise_delivery_errors = false # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "example.com" } + # config.action_mailer.default_url_options = { host: "example.com" } # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. # config.action_mailer.smtp_settings = { @@ -74,11 +79,36 @@ # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true + # Don't log any deprecations. + # config.active_support.report_deprecations = false + + # 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 # Only use :id for inspections in production. - config.active_record.attributes_for_inspect = [:id] + # config.active_record.attributes_for_inspect = [:id] # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ @@ -88,4 +118,15 @@ # # Skip DNS rebinding protection for the default health check endpoint. # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + # 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 + + # Action Cable endpoint configuration + + config.action_cable.url = "wss://#{ENV['PRODUCTION_HOST']}/cable" + config.action_cable.allowed_request_origins = ["https://#{ENV['PRODUCTION_HOST']}"] end diff --git a/config/environments/test.rb b/config/environments/test.rb index 3b04bf52..012cc361 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -39,7 +39,7 @@ config.action_mailer.delivery_method = :test # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "example.com" } + # config.action_mailer.default_url_options = { host: "example.com" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb deleted file mode 100644 index b2df75ab..00000000 --- a/config/initializers/new_framework_defaults_6_1.rb +++ /dev/null @@ -1,64 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 6.1 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Support for inversing belongs_to -> has_many Active Record associations. -# Rails.application.config.active_record.has_many_inversing = true - -# Track Active Storage variants in the database. -# Rails.application.config.active_storage.track_variants = true - -# Apply random variation to the delay when retrying failed jobs. -# Rails.application.config.active_job.retry_jitter = 0.15 - -# Stop executing `after_enqueue`/`after_perform` callbacks if -# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. -# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true - -# Specify cookies SameSite protection level: either :none, :lax, or :strict. -# -# This change is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.1. -# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax - -# Generate CSRF tokens that are encoded in URL-safe Base64. -# -# This change is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.1. -# Rails.application.config.action_controller.urlsafe_csrf_tokens = true - -# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an -# UTC offset or a UTC time. -# ActiveSupport.utc_to_local_returns_utc_offset_times = true - -# Change the default HTTP status code to `308` when redirecting non-GET/HEAD -# requests to HTTPS in `ActionDispatch::SSL` middleware. -# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 - -# Make `form_with` generate non-remote forms by default. -# Rails.application.config.action_view.form_with_generates_remote_forms = false - -# Set the default queue name for the analysis job to the queue adapter default. -# Rails.application.config.active_storage.queues.analysis = nil - -# Set the default queue name for the purge job to the queue adapter default. -# Rails.application.config.active_storage.queues.purge = nil - -# Set the default queue name for the incineration job to the queue adapter default. -# Rails.application.config.action_mailbox.queues.incineration = nil - -# Set the default queue name for the routing job to the queue adapter default. -# Rails.application.config.action_mailbox.queues.routing = nil - -# Set the default queue name for the mail deliver job to the queue adapter default. -# Rails.application.config.action_mailer.deliver_later_queue_name = nil - -# Generate a `Link` header that gives a hint to modern browsers about -# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. -# Rails.application.config.action_view.preload_links_header = true diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb deleted file mode 100644 index eb40de82..00000000 --- a/config/initializers/new_framework_defaults_7_0.rb +++ /dev/null @@ -1,135 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. -# -# This file eases your Rails 7.0 framework defaults upgrade. -# -# Uncomment each configuration one by one to switch to the new default. -# Once your application is ready to run with all new defaults, you can remove -# this file and set the `config.load_defaults` to `7.0`. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. -# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html - -# `button_to` view helper will render `