From 28beb28a785a47f78806fc79cbbbac2a5dea6c88 Mon Sep 17 00:00:00 2001 From: rubic0n Date: Sat, 23 Jan 2021 00:19:47 -0600 Subject: [PATCH] Upgrade to Rails 6 - Added listen gem because rails app:update failed without it - Removes nsa gem because it requires activesupport < 6 Oddly, there's a newer version per GitHub that's not on RubyGems that raises the requirement to < 7. But, we need a new release before we can use that. - Upgrade rails-i18n to v6, for Rails 6 compatibility - Remove redis-rails since it requires Rails < 6, but we can just use the regular Rails :redis_cache_store that was introduced in 5.2. - Run `rails app:update` - Had to weed through the `config/environments` changes to pick up newly added settings, while not losing settings that were intentionally configured - This generated config/initializers/new_framework_defaults_6_0.rb. The goal is to uncomment all of the settings in that file. Once they're all uncommented, delete the file and edit config/application.rb's load_defaults to be 6.0. - force_ssl controller method is deprecated in favor of a Rails config setting. - bin/setup was generated by Rails - Verbose query logging in development is really helpful. It shows you what line of code caused a query to execute. - Calling establish_connection after worker boot isn't necessary with ActiveRecord anymore. ActiveRecord handles it gracefully. - Rails generated a migration to add a foreign key for ActiveStorage. Gab currently doesn't use ActiveStorage, and instead uses Paperclip (since ActiveStorage didn't exist when Mastadon started). So, this change isn't relevant to Gab. - Added ` || ''` in the profiles controller, because I was unable to save a change to a newly created profile. (This probably explains the 500 error I received on prod Gab recently.) --- Gemfile | 8 +- Gemfile.lock | 265 +++++++++--------- app/controllers/application_controller.rb | 6 - .../settings/profiles_controller.rb | 2 +- bin/setup | 14 +- config/cable.yml | 10 + config/environments/development.rb | 10 +- config/environments/production.rb | 34 ++- config/environments/test.rb | 3 + .../new_framework_defaults_6_0.rb | 53 ++++ config/initializers/statsd.rb | 2 +- config/puma.rb | 6 - config/storage.yml | 34 +++ ..._attachments_for_blob_id.active_storage.rb | 10 + db/schema.rb | 12 +- 15 files changed, 306 insertions(+), 163 deletions(-) create mode 100644 config/cable.yml create mode 100644 config/initializers/new_framework_defaults_6_0.rb create mode 100644 config/storage.yml create mode 100644 db/migrate/20210123050026_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb diff --git a/Gemfile b/Gemfile index 0de8faf1..3b85f197 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ ruby '>= 2.4.0', '< 2.7.0' gem 'pkg-config', '~> 1.3' gem 'puma', '~> 5.0' -gem 'rails', '~> 5.2.3' +gem 'rails', '6.0.3.4' gem 'thor', '~> 0.20' gem 'hamlit-rails', '~> 0.2' @@ -59,7 +59,7 @@ gem 'kaminari', '~> 1.1' gem 'link_header', '~> 0.0' gem 'mime-types', '~> 3.2', require: 'mime/types/columnar' gem 'nokogiri', '~> 1.10' -gem 'nsa', '~> 0.2' +# gem 'nsa', '~> 0.2' gem 'oj', '~> 3.7' gem 'ostatus2', '~> 2.0' gem 'ox', '~> 2.10' @@ -68,7 +68,7 @@ gem 'pundit', '~> 2.0' gem 'premailer-rails' gem 'rack-attack', '~> 6.0' gem 'rack-cors', '~> 1.0', require: 'rack/cors' -gem 'rails-i18n', '~> 5.1' +gem 'rails-i18n', '~> 6.0.0' gem 'rails-settings-cached', '~> 0.6' gem 'redis', '~> 4.2', require: ['redis', 'redis/connection/hiredis'] gem 'mario-redis-lock', '~> 1.2', require: 'redis_lock' @@ -127,6 +127,7 @@ group :development do gem 'better_errors', '~> 2.5' gem 'binding_of_caller', '~> 0.7' gem 'bullet', '~> 6.0' + gem 'listen' gem 'letter_opener', '~> 1.7' gem 'letter_opener_web', '~> 1.3' gem 'memory_profiler' @@ -146,7 +147,6 @@ end group :production do gem 'lograge', '~> 0.11' - gem 'redis-rails', '~> 5.0' end gem 'concurrent-ruby', require: false diff --git a/Gemfile.lock b/Gemfile.lock index e8dff848..e61f0d49 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,53 +15,67 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (5.2.4.4) - actionpack (= 5.2.4.4) + actioncable (6.0.3.4) + actionpack (= 6.0.3.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.4) - actionpack (= 5.2.4.4) - actionview (= 5.2.4.4) - activejob (= 5.2.4.4) + actionmailbox (6.0.3.4) + actionpack (= 6.0.3.4) + activejob (= 6.0.3.4) + activerecord (= 6.0.3.4) + activestorage (= 6.0.3.4) + activesupport (= 6.0.3.4) + mail (>= 2.7.1) + actionmailer (6.0.3.4) + actionpack (= 6.0.3.4) + actionview (= 6.0.3.4) + activejob (= 6.0.3.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.4) - actionview (= 5.2.4.4) - activesupport (= 5.2.4.4) + actionpack (6.0.3.4) + actionview (= 6.0.3.4) + activesupport (= 6.0.3.4) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.4) - activesupport (= 5.2.4.4) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.3.4) + actionpack (= 6.0.3.4) + activerecord (= 6.0.3.4) + activestorage (= 6.0.3.4) + activesupport (= 6.0.3.4) + nokogiri (>= 1.8.5) + actionview (6.0.3.4) + activesupport (= 6.0.3.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - active_model_serializers (0.10.11) - actionpack (>= 4.1, < 6.1) - activemodel (>= 4.1, < 6.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + active_model_serializers (0.10.12) + actionpack (>= 4.1, < 6.2) + activemodel (>= 4.1, < 6.2) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) active_record_query_trace (1.8) - activejob (5.2.4.4) - activesupport (= 5.2.4.4) + activejob (6.0.3.4) + activesupport (= 6.0.3.4) globalid (>= 0.3.6) - activemodel (5.2.4.4) - activesupport (= 5.2.4.4) - activerecord (5.2.4.4) - activemodel (= 5.2.4.4) - activesupport (= 5.2.4.4) - arel (>= 9.0) - activestorage (5.2.4.4) - actionpack (= 5.2.4.4) - activerecord (= 5.2.4.4) + activemodel (6.0.3.4) + activesupport (= 6.0.3.4) + activerecord (6.0.3.4) + activemodel (= 6.0.3.4) + activesupport (= 6.0.3.4) + activestorage (6.0.3.4) + actionpack (= 6.0.3.4) + activejob (= 6.0.3.4) + activerecord (= 6.0.3.4) marcel (~> 0.3.1) - activesupport (5.2.4.4) + activesupport (6.0.3.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) airbrussh (1.4.0) @@ -69,23 +83,22 @@ GEM annotate (2.7.5) activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 13.0) - arel (9.0.0) ast (2.4.1) attr_encrypted (3.1.0) encryptor (~> 3.0.0) av (0.9.0) cocaine (~> 0.5.3) aws-eventstream (1.1.0) - aws-partitions (1.404.0) - aws-sdk-core (3.110.0) + aws-partitions (1.418.0) + aws-sdk-core (3.111.2) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.39.0) + aws-sdk-kms (1.41.0) aws-sdk-core (~> 3, >= 3.109.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.86.0) + aws-sdk-s3 (1.87.0) aws-sdk-core (~> 3, >= 3.109.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) @@ -103,17 +116,17 @@ GEM ffi (~> 1.10.0) bootsnap (1.5.1) msgpack (~> 1.0) - brakeman (4.10.0) - browser (5.1.0) + brakeman (4.10.1) + browser (5.3.0) builder (3.2.4) - bullet (6.1.0) + bullet (6.1.3) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundler-audit (0.7.0.1) bundler (>= 1.2.0, < 3) thor (>= 0.18, < 2) byebug (11.1.3) - capistrano (3.14.1) + capistrano (3.15.0) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -143,26 +156,29 @@ GEM activesupport (>= 4.0) elasticsearch (>= 2.0.0) elasticsearch-dsl - chunky_png (1.3.14) + chunky_png (1.4.0) cld3 (3.2.6) ffi (>= 1.1.0, < 1.12.0) climate_control (0.2.0) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) coderay (1.1.3) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) connection_pool (2.2.3) - crack (0.4.4) + crack (0.4.5) + rexml crass (1.0.6) - css_parser (1.7.1) + css_parser (1.8.0) addressable - debug_inspector (0.0.3) - derailed_benchmarks (1.8.1) + dead_end (1.1.3) + debug_inspector (1.0.0) + derailed_benchmarks (2.0.0) benchmark-ips (~> 2) + dead_end get_process_mem (~> 0) heapy (~> 0) - memory_profiler (~> 0) - mini_histogram (>= 0.2.1) + memory_profiler (>= 0, < 2) + mini_histogram (>= 0.3.0) rack (>= 1) rake (> 10, < 14) ruby-statistics (>= 2.1) @@ -183,7 +199,7 @@ GEM devise (>= 4.0.0) rpam2 (~> 4.0) diff-lcs (1.4.4) - docile (1.3.2) + docile (1.3.5) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) doorkeeper (5.4.0) @@ -193,13 +209,13 @@ GEM dotenv (= 2.7.6) railties (>= 3.2) e2mmap (0.1.0) - elasticsearch (7.10.0) - elasticsearch-api (= 7.10.0) - elasticsearch-transport (= 7.10.0) - elasticsearch-api (7.10.0) + elasticsearch (7.10.1) + elasticsearch-api (= 7.10.1) + elasticsearch-transport (= 7.10.1) + elasticsearch-api (7.10.1) multi_json elasticsearch-dsl (0.1.9) - elasticsearch-transport (7.10.0) + elasticsearch-transport (7.10.1) faraday (~> 1) multi_json encryptor (3.0.0) @@ -210,11 +226,13 @@ GEM fabrication (2.21.1) faker (1.9.6) i18n (>= 0.7) - faraday (1.1.0) + faraday (1.3.0) + faraday-net_http (~> 1.0) multipart-post (>= 1.2, < 3) ruby2_keywords + faraday-net_http (1.0.1) fast_blank (1.0.0) - fastimage (2.2.0) + fastimage (2.2.1) ffi (1.10.0) fog-core (2.1.0) builder @@ -229,10 +247,10 @@ GEM fog-json (>= 1.0) ipaddress (>= 0.8) formatador (0.2.5) - fugit (1.4.1) + fugit (1.4.2) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - fuubar (2.5.0) + fuubar (2.5.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) get_process_mem (0.2.7) @@ -244,7 +262,7 @@ GEM http (~> 3.0) nokogiri (~> 1.8) oj (~> 3.0) - hamlit (2.13.0) + hamlit (2.14.2) temple (>= 0.8.2) thor tilt @@ -275,9 +293,9 @@ GEM httplog (1.4.3) rack (>= 1.0) rainbow (>= 2.0.0) - i18n (1.8.5) + i18n (1.8.7) concurrent-ruby (~> 1.0) - i18n-tasks (0.9.31) + i18n-tasks (0.9.33) activesupport (>= 4.0.2) ast (>= 2.1.0) erubi @@ -291,16 +309,16 @@ GEM ipaddress (0.8.3) iso-639 (0.3.5) jmespath (1.4.0) - json (2.3.1) + json (2.5.1) json-canonicalization (0.2.0) - json-ld (3.1.5) + json-ld (3.1.7) htmlentities (~> 4.3) json-canonicalization (~> 0.2) link_header (~> 0.0, >= 0.0.8) multi_json (~> 1.14) rack (~> 2.0) rdf (~> 3.1) - json-ld-preloaded (3.1.3) + json-ld-preloaded (3.1.4) json-ld (~> 3.1) rdf (~> 3.1) jsonapi-renderer (0.2.2) @@ -326,23 +344,26 @@ GEM letter_opener (~> 1.0) railties (>= 3.2) link_header (0.0.8) + listen (3.4.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) lograge (0.11.2) actionpack (>= 4) activesupport (>= 4) railties (>= 4) request_store (~> 1.0) - loofah (2.8.0) + loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - makara (0.4.1) + makara (0.5.0) activerecord (>= 3.0.0) marcel (0.3.3) mimemagic (~> 0.3.2) mario-redis-lock (1.2.1) redis (>= 3.0.5) - memory_profiler (0.9.14) + memory_profiler (1.0.0) method_source (1.0.0) microformats (4.2.1) json (~> 2.2) @@ -353,8 +374,8 @@ GEM mimemagic (0.3.5) mini_histogram (0.3.1) mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.14.2) + mini_portile2 (2.5.0) + minitest (5.14.3) msgpack (1.3.3) multi_json (1.15.0) multipart-post (2.1.1) @@ -363,16 +384,12 @@ GEM net-ssh (>= 2.6.5, < 7.0.0) net-ssh (6.1.0) nio4r (2.5.4) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) nokogumbo (2.0.4) nokogiri (~> 1.8, >= 1.8.4) - nsa (0.2.7) - activesupport (>= 4.2, < 6) - concurrent-ruby (~> 1.0, >= 1.0.2) - sidekiq (>= 3.5) - statsd-ruby (~> 1.4, >= 1.4.0) - oj (3.10.16) + oj (3.11.0) omniauth (1.9.1) hashie (>= 3.4.6) rack (>= 1.6.2, < 3) @@ -388,7 +405,7 @@ GEM addressable (~> 2.5) http (~> 3.0) nokogiri (~> 1.8) - ox (2.13.4) + ox (2.14.1) paperclip (6.1.0) activemodel (>= 4.2.0) activesupport (>= 4.2.0) @@ -401,7 +418,7 @@ GEM parallel (1.20.1) parallel_tests (2.32.0) parallel - parser (2.7.2.0) + parser (3.0.0.0) ast (~> 2.4.1) pastel (0.8.0) tty-color (~> 0.5) @@ -426,11 +443,12 @@ GEM pry-rails (0.3.9) pry (>= 0.10.4) public_suffix (4.0.6) - puma (5.1.0) + puma (5.1.1) nio4r (~> 2.0) pundit (2.1.0) activesupport (>= 3.0.0) raabro (1.4.0) + racc (1.5.2) rack (2.2.3) rack-attack (6.3.1) rack (>= 1.0, < 3) @@ -440,18 +458,20 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.4.4) - actioncable (= 5.2.4.4) - actionmailer (= 5.2.4.4) - actionpack (= 5.2.4.4) - actionview (= 5.2.4.4) - activejob (= 5.2.4.4) - activemodel (= 5.2.4.4) - activerecord (= 5.2.4.4) - activestorage (= 5.2.4.4) - activesupport (= 5.2.4.4) + rails (6.0.3.4) + actioncable (= 6.0.3.4) + actionmailbox (= 6.0.3.4) + actionmailer (= 6.0.3.4) + actionpack (= 6.0.3.4) + actiontext (= 6.0.3.4) + actionview (= 6.0.3.4) + activejob (= 6.0.3.4) + activemodel (= 6.0.3.4) + activerecord (= 6.0.3.4) + activestorage (= 6.0.3.4) + activesupport (= 6.0.3.4) bundler (>= 1.3.0) - railties (= 5.2.4.4) + railties (= 6.0.3.4) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -462,47 +482,31 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails-i18n (5.1.3) + rails-i18n (6.0.0) i18n (>= 0.7, < 2) - railties (>= 5.0, < 6) + railties (>= 6.0.0, < 7) rails-settings-cached (0.7.2) rails (>= 4.2.0) - railties (5.2.4.4) - actionpack (= 5.2.4.4) - activesupport (= 5.2.4.4) + railties (6.0.3.4) + actionpack (= 6.0.3.4) + activesupport (= 6.0.3.4) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.0.0) rake (12.3.3) rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) - rdf (3.1.7) + rdf (3.1.9) hamster (~> 3.0) link_header (~> 0.0, >= 0.0.8) rdf-normalize (0.4.0) rdf (~> 3.1) - redcarpet (3.5.0) + redcarpet (3.5.1) redis (4.2.5) - redis-actionpack (5.2.0) - actionpack (>= 5, < 7) - redis-rack (>= 2.1.0, < 3) - redis-store (>= 1.1.0, < 2) - redis-activesupport (5.2.0) - activesupport (>= 3, < 7) - redis-store (>= 1.3, < 2) redis-namespace (1.8.0) redis (>= 3.0.4) - redis-rack (2.1.3) - rack (>= 2.0.8, < 3) - redis-store (>= 1.2, < 2) - redis-rails (5.0.2) - redis-actionpack (>= 5.0, < 6) - redis-activesupport (>= 5.0, < 6) - redis-store (>= 1.2, < 2) - redis-store (1.9.0) - redis (>= 4, < 5) regexp_parser (1.8.2) request_store (1.5.0) rack (>= 1.4) @@ -543,16 +547,16 @@ GEM rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.3.0) + rubocop-ast (1.4.0) parser (>= 2.7.1.5) - ruby-progressbar (1.10.1) + ruby-progressbar (1.11.0) ruby-saml (1.11.0) nokogiri (>= 1.5.10) ruby-statistics (2.1.2) - ruby2_keywords (0.0.2) - rufus-scheduler (3.6.0) + ruby2_keywords (0.0.4) + rufus-scheduler (3.7.0) fugit (~> 1.1, >= 1.1.6) - sanitize (5.2.1) + sanitize (5.2.3) crass (~> 1.0.2) nokogiri (>= 1.8.0) nokogumbo (~> 2.0) @@ -563,7 +567,7 @@ GEM rb-inotify (~> 0.9, >= 0.9.7) scss_lint (0.59.0) sass (~> 3.5, >= 3.5.5) - sidekiq (6.1.2) + sidekiq (6.1.3) connection_pool (>= 2.2.2) rack (~> 2.0) redis (>= 4.2.0) @@ -585,7 +589,7 @@ GEM simple_form (4.1.0) actionpack (>= 5.0) activemodel (>= 5.0) - simplecov (0.20.0) + simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) @@ -598,15 +602,14 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.21.1) + sshkit (1.21.2) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) stackprof (0.2.16) - statsd-ruby (1.4.0) stoplight (2.1.3) streamio-ffmpeg (3.0.2) multi_json (~> 1.8) - strong_migrations (0.7.3) + strong_migrations (0.7.6) activerecord (>= 5) temple (0.8.2) terminal-table (2.0.0) @@ -622,7 +625,7 @@ GEM tty-command (0.10.0) pastel (~> 0.8) tty-cursor (0.7.1) - tty-prompt (0.22.0) + tty-prompt (0.23.0) pastel (~> 0.8) tty-reader (~> 0.8) tty-reader (0.9.0) @@ -632,18 +635,18 @@ GEM tty-screen (0.8.1) twitter-text (1.14.7) unf (~> 0.1.0) - tzinfo (1.2.8) + tzinfo (1.2.9) thread_safe (~> 0.1) - tzinfo-data (1.2020.4) + tzinfo-data (1.2020.6) tzinfo (>= 1.0.0) unf (0.1.4) unf_ext unf_ext (0.0.7.7) unicode-display_width (1.7.0) - uniform_notifier (1.13.0) + uniform_notifier (1.13.2) warden (1.2.9) rack (>= 2.0.9) - webmock (3.10.0) + webmock (3.11.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -660,6 +663,7 @@ GEM wisper (2.0.1) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.4.2) PLATFORMS ruby @@ -718,6 +722,7 @@ DEPENDENCIES letter_opener (~> 1.7) letter_opener_web (~> 1.3) link_header (~> 0.0) + listen lograge (~> 0.11) makara (~> 0.4) mario-redis-lock (~> 1.2) @@ -726,7 +731,6 @@ DEPENDENCIES mime-types (~> 3.2) net-ldap (~> 0.10) nokogiri (~> 1.10) - nsa (~> 0.2) oj (~> 3.7) omniauth (~> 1.9) omniauth-cas (~> 1.1) @@ -748,15 +752,14 @@ DEPENDENCIES pundit (~> 2.0) rack-attack (~> 6.0) rack-cors (~> 1.0) - rails (~> 5.2.3) + rails (= 6.0.3.4) rails-controller-testing (~> 1.0) - rails-i18n (~> 5.1) + rails-i18n (~> 6.0.0) rails-settings-cached (~> 0.6) rdf-normalize (~> 0.3) redcarpet (~> 3.4) redis (~> 4.2) redis-namespace (~> 1.5) - redis-rails (~> 5.0) rqrcode (~> 0.10) rspec-rails (~> 3.8) rspec-sidekiq (~> 3.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f621bff5..f1e67e8e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,8 +5,6 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - force_ssl if: :https_enabled? - include Localized include UserTrackingConcern include SessionTrackingConcern @@ -31,10 +29,6 @@ class ApplicationController < ActionController::Base private - def https_enabled? - Rails.env.production? - end - def store_current_location store_location_for(:user, request.url) if request.format == :html end diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index 0624f4d5..9e1b3d18 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -25,7 +25,7 @@ class Settings::ProfilesController < Settings::BaseController AccountUsernameChange.create!( account: @account, from_username: @account.username, - to_username: params[:account][:username] + to_username: params[:account][:username] || '' ) end diff --git a/bin/setup b/bin/setup index fc77b080..5853b5ea 100755 --- a/bin/setup +++ b/bin/setup @@ -1,6 +1,5 @@ #!/usr/bin/env ruby require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -9,22 +8,25 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime 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') - system!('yarn install') + + # Install JavaScript dependencies + # system('bin/yarn') # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 00000000..7163e4c2 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: gab_social_production diff --git a/config/environments/development.rb b/config/environments/development.rb index 0791b82a..2e09fee7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,7 +17,7 @@ Rails.application.configure do if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true - config.cache_store = :redis_store, ENV['REDIS_URL'], REDIS_CACHE_PARAMS + config.cache_store = :redis_cache_store, REDIS_CACHE_PARAMS.merge(url: ENV['REDIS_URL']) config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}", @@ -38,6 +38,9 @@ Rails.application.configure do config.x.vapid_private_key = vapid_key.private_key config.x.vapid_public_key = vapid_key.public_key + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -49,6 +52,9 @@ Rails.application.configure do # 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. @@ -76,6 +82,8 @@ Rails.application.configure do # Otherwise, use letter_opener, which launches a browser window to view sent mail. config.action_mailer.delivery_method = (ENV['HEROKU'] || ENV['VAGRANT'] || ENV['REMOTE_DEV']) ? :letter_opener_web : :letter_opener + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.after_initialize do Bullet.enable = true Bullet.bullet_logger = true diff --git a/config/environments/production.rb b/config/environments/production.rb index a692578b..071543bd 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -41,9 +41,20 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + # Allow to specify public IP of reverse proxy if it's needed config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split.map { |item| IPAddr.new(item) } if ENV['TRUSTED_PROXY_IP'].present? + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # 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 # when problems arise. config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info').to_sym @@ -52,7 +63,7 @@ Rails.application.configure do config.log_tags = [:request_id] # Use a different cache store in production. - config.cache_store = :redis_store, ENV['CACHE_REDIS_URL'], REDIS_CACHE_PARAMS + config.cache_store = :redis_cache_store, REDIS_CACHE_PARAMS.merge(url: ENV['CACHE_REDIS_URL']) # 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. @@ -102,4 +113,25 @@ Rails.application.configure do } config.x.otp_secret = ENV.fetch('OTP_SECRET') + + # 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 diff --git a/config/environments/test.rb b/config/environments/test.rb index a35cadcf..6f591d93 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -27,6 +27,9 @@ Rails.application.configure do # and should not be used. config.cache_store = :memory_store + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb new file mode 100644 index 00000000..d45195a0 --- /dev/null +++ b/config/initializers/new_framework_defaults_6_0.rb @@ -0,0 +1,53 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.0 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. + +# Don't force requests from old versions of IE to be UTF-8 encoded. +Rails.application.config.action_view.default_enforce_utf8 = false + +# Embed purpose and expiry metadata inside signed and encrypted +# cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.0. +# Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. +# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false + +# Return false instead of self when enqueuing is aborted from a callback. +Rails.application.config.active_job.return_false_on_aborted_enqueue = true + +# Send Active Storage analysis and purge jobs to dedicated queues. +Rails.application.config.active_storage.queues.analysis = :active_storage_analysis +Rails.application.config.active_storage.queues.purge = :active_storage_purge + +# When assigning to a collection of attachments declared via `has_many_attached`, replace existing +# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. +Rails.application.config.active_storage.replace_on_assign_to_many = true + +# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. +# +# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), +# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. +# If you send mail in the background, job workers need to have a copy of +# MailDeliveryJob to ensure all delivery jobs are processed properly. +# Make sure your entire app is migrated and stable on 6.0 before using this setting. +Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" + +# Enable the same cache key to be reused when the object being cached of type +# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) +# of the relation's cache key into the cache version to support recycling cache key. +Rails.application.config.active_record.collection_cache_versioning = true + + +# The Rails 6 default autoloader is Zeitwerk. Zeitwerk has specific expectations on where certain +# classes should be defined. It also requires that constants are not autoloaded in initializers. +# Enabling Zeitwerk would be good, but it'll take some work. Using the :classic autoloader gives +# us the same autoloading that Rails 5.2 had. +# Rails.application.config.autoloader = :zeitwerk +Rails.application.config.autoloader = :classic diff --git a/config/initializers/statsd.rb b/config/initializers/statsd.rb index 17f23956..52a0b1f6 100644 --- a/config/initializers/statsd.rb +++ b/config/initializers/statsd.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if ENV['STATSD_ADDR'].present? +if false && ENV['STATSD_ADDR'].present? host, port = ENV['STATSD_ADDR'].split(':') statsd = ::Statsd.new(host, port) diff --git a/config/puma.rb b/config/puma.rb index 1afdb1c6..e941ae13 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -12,10 +12,4 @@ workers ENV.fetch('WEB_CONCURRENCY') { 2 } preload_app! -on_worker_boot do - ActiveSupport.on_load(:active_record) do - ActiveRecord::Base.establish_connection - end -end - plugin :tmp_restart diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 00000000..d32f76e8 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/migrate/20210123050026_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb b/db/migrate/20210123050026_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb new file mode 100644 index 00000000..ff5d72c7 --- /dev/null +++ b/db/migrate/20210123050026_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb @@ -0,0 +1,10 @@ +# This migration comes from active_storage (originally 20180723000244) +class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0] + def up + return if foreign_key_exists?(:active_storage_attachments, column: :blob_id) + + if table_exists?(:active_storage_blobs) + add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 32e23867..d5769f47 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,15 +2,15 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_01_17_210100) do +ActiveRecord::Schema.define(version: 2021_01_23_050026) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql"