From d2b436376c92a86859c19d66eb395c2ef2ac977b Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Mon, 17 Dec 2018 11:31:36 +0100 Subject: [PATCH 1/6] Upgrade to rails 5.2 --- Gemfile | 6 +- Gemfile.lock | 111 +++++++++--------- .../active_record_verbose_query_logs.rb | 56 --------- 3 files changed, 61 insertions(+), 112 deletions(-) delete mode 100644 config/initializers/active_record_verbose_query_logs.rb --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,7 @@ gem 'pg', '~> 0.19' if ENV["DB"] == "all" || ENV["DB"] == "postgres" gem 'rugged', '~> 0.27' -gem 'grape-path-helpers', '~> 1.0' +gem 'grape-path-helpers', '~> 1.1' gem 'faraday', '~> 0.12' @@ -323,7 +323,7 @@ gem 'awesome_print', require: false gem 'fuubar', '~> 2.2.0' - gem 'database_cleaner', '~> 1.5.0' + gem 'database_cleaner', '~> 1.7.0' gem 'factory_bot_rails', '~> 4.8.2' gem 'rspec-rails', '~> 3.7' gem 'rspec-retry', '~> 0.4.5' @@ -376,7 +376,7 @@ gem 'rails-controller-testing' if rails5? # Rails5 only gem. gem 'test_after_commit', '~> 1.1' unless rails5? # Remove this gem when migrated to rails 5.0. It's been integrated to rails 5.0. gem 'sham_rack', '~> 1.3.6' - gem 'concurrent-ruby', '~> 1.1' + #gem 'concurrent-ruby' gem 'test-prof', '~> 0.2.5' gem 'rspec_junit_formatter' end --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,41 +4,45 @@ RedCloth (4.3.2) abstract_type (0.0.7) ace-rails-ap (4.1.2) - actioncable (5.0.7) - actionpack (= 5.0.7) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7) - actionpack (= 5.0.7) - actionview (= 5.0.7) - activejob (= 5.0.7) + actioncable (5.2.2) + actionpack (= 5.2.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7) - actionview (= 5.0.7) - activesupport (= 5.0.7) + actionpack (5.2.2) + actionview (= 5.2.2) + activesupport (= 5.2.2) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7) - activesupport (= 5.0.7) + actionview (5.2.2) + activesupport (= 5.2.2) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7) - activesupport (= 5.0.7) + activejob (5.2.2) + activesupport (= 5.2.2) globalid (>= 0.3.6) - activemodel (5.0.7) - activesupport (= 5.0.7) - activerecord (5.0.7) - activemodel (= 5.0.7) - activesupport (= 5.0.7) - arel (~> 7.0) + activemodel (5.2.2) + activesupport (= 5.2.2) + activerecord (5.2.2) + activemodel (= 5.2.2) + activesupport (= 5.2.2) + arel (>= 9.0) activerecord_sane_schema_dumper (1.0) rails (>= 5, < 6) - activesupport (5.0.7) + activestorage (5.2.2) + actionpack (= 5.2.2) + activerecord (= 5.2.2) + marcel (~> 0.3.1) + activesupport (5.2.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -52,7 +56,7 @@ public_suffix (>= 2.0.2, < 4.0) aes_key_wrap (1.0.1) akismet (2.0.0) - arel (7.1.4) + arel (9.0.0) asana (0.8.1) faraday (~> 0.9) faraday_middleware (~> 0.9) @@ -140,7 +144,7 @@ css_parser (1.5.0) addressable daemons (1.2.6) - database_cleaner (1.5.3) + database_cleaner (1.7.0) debug_inspector (0.0.3) debugger-ruby_core_source (1.3.8) deckar01-task_list (2.0.0) @@ -183,7 +187,6 @@ encryptor (3.0.0) equalizer (0.0.11) erubi (1.7.1) - erubis (2.7.0) escape_utils (1.2.1) et-orbi (1.0.3) tzinfo @@ -253,8 +256,8 @@ fog-xml (0.1.3) fog-core nokogiri (>= 1.5.11, < 2.0.0) - font-awesome-rails (4.7.0.1) - railties (>= 3.2, < 5.1) + font-awesome-rails (4.7.0.4) + railties (>= 3.2, < 6.0) foreman (0.84.0) thor (~> 0.19.1) formatador (0.2.5) @@ -326,8 +329,8 @@ grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) - grape-path-helpers (1.0.6) - activesupport (>= 4, < 5.1) + grape-path-helpers (1.1.0) + activesupport grape (~> 1.0) rake (~> 12) grape_logging (1.7.0) @@ -381,7 +384,7 @@ json (~> 1.8) multi_xml (>= 0.5.2) httpclient (2.8.3) - i18n (1.1.1) + i18n (1.2.0) concurrent-ruby (~> 1.0) icalendar (2.4.1) ice_nine (0.11.2) @@ -449,9 +452,11 @@ loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) mail_room (0.9.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) memoist (0.16.0) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) @@ -621,19 +626,20 @@ rack rack-proxy (0.6.0) rack - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7) - actioncable (= 5.0.7) - actionmailer (= 5.0.7) - actionpack (= 5.0.7) - actionview (= 5.0.7) - activejob (= 5.0.7) - activemodel (= 5.0.7) - activerecord (= 5.0.7) - activesupport (= 5.0.7) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.2) + actioncable (= 5.2.2) + actionmailer (= 5.2.2) + actionpack (= 5.2.2) + actionview (= 5.2.2) + activejob (= 5.2.2) + activemodel (= 5.2.2) + activerecord (= 5.2.2) + activestorage (= 5.2.2) + activesupport (= 5.2.2) bundler (>= 1.3.0) - railties (= 5.0.7) + railties (= 5.2.2) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.2) actionpack (~> 5.x, >= 5.0.1) @@ -649,15 +655,15 @@ rails-i18n (5.1.1) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) - railties (5.0.7) - actionpack (= 5.0.7) - activesupport (= 5.0.7) + railties (5.2.2) + actionpack (= 5.2.2) + activesupport (= 5.2.2) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) raindrops (0.18.0) - rake (12.3.1) + rake (12.3.2) rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -922,7 +928,7 @@ hashdiff webpack-rails (0.9.11) railties (>= 3.2.0) - websocket-driver (0.6.5) + websocket-driver (0.7.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.3) wikicloth (0.8.1) @@ -969,10 +975,9 @@ chronic (~> 0.10.2) chronic_duration (~> 0.10.6) commonmarker (~> 0.17) - concurrent-ruby (~> 1.1) connection_pool (~> 2.0) creole (~> 0.5.0) - database_cleaner (~> 1.5.0) + database_cleaner (~> 1.7.0) deckar01-task_list (= 2.0.0) device_detector devise (~> 4.4) @@ -1020,7 +1025,7 @@ gpgme (~> 2.0.18) grape (~> 1.1.0) grape-entity (~> 0.7.1) - grape-path-helpers (~> 1.0) + grape-path-helpers (~> 1.1) grape_logging (~> 1.7) graphiql-rails (~> 1.4.10) graphql (~> 1.8.0) @@ -1095,7 +1100,7 @@ rack-cors (~> 1.0.0) rack-oauth2 (~> 1.2.1) rack-proxy (~> 0.6.0) - rails (= 5.0.7) + rails (= 5.2.2) rails-controller-testing rails-deprecated_sanitizer (~> 1.0.3) rails-i18n (~> 5.1) --- a/config/initializers/active_record_verbose_query_logs.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -# This is backport of https://github.com/rails/rails/pull/26815/files -# Enabled by default for every non-production environment - -module ActiveRecord - class LogSubscriber - module VerboseQueryLogs - def debug(progname = nil, &block) - return unless super - - log_query_source - end - - def log_query_source - source_line, line_number = extract_callstack(caller_locations) - - if source_line - if defined?(::Rails.root) - app_root = "#{::Rails.root}/".freeze - source_line = source_line.sub(app_root, "") - end - - logger.debug(" ↳ #{source_line}:#{line_number}") - end - end - - def extract_callstack(callstack) - line = callstack.find do |frame| - frame.absolute_path && !ignored_callstack(frame.absolute_path) - end - - offending_line = line || callstack.first - [ - offending_line.path, - offending_line.lineno, - offending_line.label - ] - end - - LOG_SUBSCRIBER_FILE = ActiveRecord::LogSubscriber.method(:logger).source_location.first - RAILS_GEM_ROOT = File.expand_path("../../../..", LOG_SUBSCRIBER_FILE) + "/" - APP_CONFIG_ROOT = File.expand_path("..", __dir__) + "/" - - def ignored_callstack(path) - path.start_with?(APP_CONFIG_ROOT, RAILS_GEM_ROOT, RbConfig::CONFIG["rubylibdir"]) - end - end - - if Rails.version.start_with?("5.2") - raise "Remove this monkey patch: #{__FILE__}" - else - prepend(VerboseQueryLogs) unless Rails.env.production? - end - end -end --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -25,7 +25,7 @@ }.freeze TYPE_AND_FORMAT_PAIRS = { - archive: :zip, + archive: :zip_file, metadata: :gzip, trace: :raw, junit: :gzip, @@ -91,7 +91,7 @@ enum file_format: { raw: 1, - zip: 2, + zip_file: 2, # FIXME gzip: 3 } --- a/config/initializers/active_record_data_types.rb +++ b/config/initializers/active_record_data_types.rb @@ -22,7 +22,7 @@ # # When schema dumping, `timestamptz` columns will be output as # `t.datetime_with_timezone`. - def initialize_type_map(mapping) + def initialize_type_map(mapping = type_map) super mapping mapping.register_type 'timestamptz' do |_, _, sql_type| --- a/config/initializers/ar_speed_up_migration_checking.rb +++ b/config/initializers/ar_speed_up_migration_checking.rb @@ -1,18 +1,18 @@ -if Rails.env.test? - require 'active_record/migration' - - module ActiveRecord - class Migrator - class << self - alias_method :migrations_unmemoized, :migrations - - # This method is called a large number of times per rspec example, and - # it reads + parses `db/migrate/*` each time. Memoizing it can save 0.5 - # seconds per spec. - def migrations(paths) - (@migrations ||= migrations_unmemoized(paths)).dup - end - end - end - end -end +#if Rails.env.test? +# require 'active_record/migration' +# +# module ActiveRecord +# class Migrator +# class << self +# alias_method :migrations_unmemoized, :migrations +# +# # This method is called a large number of times per rspec example, and +# # it reads + parses `db/migrate/*` each time. Memoizing it can save 0.5 +# # seconds per spec. +# def migrations(paths) +# (@migrations ||= migrations_unmemoized(paths)).dup +# end +# end +# end +# end +#end --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -24,6 +24,7 @@ # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = false +# FIXME - check all callbacks - https://stackoverflow.com/questions/49744200/nomethoderror-undefined-method-halt-callback-chains-on-return-false-for-acti # Do not halt callback chains when a callback returns false. Previous versions had true. - ActiveSupport.halt_callback_chains_on_return_false = true +# ActiveSupport.halt_callback_chains_on_return_false = true end --- a/config/initializers/postgresql_cte.rb +++ b/config/initializers/postgresql_cte.rb @@ -94,8 +94,8 @@ end end - def build_arel - arel = super() + def build_arel(aliases) + arel = super(aliases) build_with(arel) if @values[:with] --- a/config/initializers/postgresql_opclasses_support.rb +++ b/config/initializers/postgresql_opclasses_support.rb @@ -81,7 +81,7 @@ if index_name.length > max_index_length raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters" end - if table_exists?(table_name) && index_name_exists?(table_name, index_name, false) + if table_exists?(table_name) && index_name_exists?(table_name, index_name) raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists" end index_columns = quoted_columns_for_index(column_names, options).join(", ") --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -243,7 +243,7 @@ optional :artifact_type, type: String, desc: %q(The type of artifact), default: 'archive', values: Ci::JobArtifact.file_types.keys optional :artifact_format, type: String, desc: %q(The format of artifact), - default: 'zip', values: Ci::JobArtifact.file_formats.keys + default: 'zip_file', values: Ci::JobArtifact.file_formats.keys optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse)) optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse)) --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -49,7 +49,7 @@ # need to be added to the application settings. To prevent Rake tasks # and other callers from failing, use any loaded settings and return # defaults for missing columns. - if ActiveRecord::Migrator.needs_migration? + if ActiveRecord::Base.connection.migration_context.needs_migration? return fake_application_settings(current_settings&.attributes) end --- a/config/initializers/active_record_preloader.rb +++ b/config/initializers/active_record_preloader.rb @@ -1,15 +1,15 @@ -module ActiveRecord - module Associations - class Preloader - module NoCommitPreloader - def preloader_for(reflection, owners, rhs_klass) - return NullPreloader if rhs_klass == ::Commit - - super - end - end - - prepend NoCommitPreloader - end - end -end +#module ActiveRecord +# module Associations +# class Preloader +# module NoCommitPreloader +# def preloader_for(reflection, owners, rhs_klass) +# return NullPreloader if rhs_klass == ::Commit +# +# super +# end +# end +# +# prepend NoCommitPreloader +# end +# end +#end --- /dev/null +++ b/db/migrate/20181006004100_import_common_metrics_nginx_vts.rb @@ -0,0 +1,15 @@ +class ImportCommonMetricsNginxVts < ActiveRecord::Migration[4.2] + include Gitlab::Database::MigrationHelpers + + require Rails.root.join('db/importers/common_metrics_importer.rb') + + DOWNTIME = false + + def up + Importers::CommonMetricsImporter.new.execute + end + + def down + # no-op + end +end --- a/config/initializers/static_files.rb +++ b/config/initializers/static_files.rb @@ -1,26 +1,17 @@ app = Rails.application -if (Gitlab.rails5? && app.config.public_file_server.enabled) || app.config.serve_static_files +if app.config.public_file_server.enabled # The `ActionDispatch::Static` middleware intercepts requests for static files # by checking if they exist in the `/public` directory. # We're replacing it with our `Gitlab::Middleware::Static` that does the same, # except ignoring `/uploads`, letting those go through to the GitLab Rails app. - if Gitlab.rails5? - app.config.middleware.swap( - ActionDispatch::Static, - Gitlab::Middleware::Static, - app.paths["public"].first, - headers: app.config.public_file_server.headers - ) - else - app.config.middleware.swap( - ActionDispatch::Static, - Gitlab::Middleware::Static, - app.paths["public"].first, - app.config.static_cache_control - ) - end + app.config.middleware.swap( + ActionDispatch::Static, + Gitlab::Middleware::Static, + app.paths["public"].first, + headers: app.config.public_file_server.headers + ) # If webpack-dev-server is configured, proxy webpack's public directory # instead of looking for static assets --- a/db/post_migrate/20181010133639_backfill_store_project_full_path_in_repo.rb +++ b/db/post_migrate/20181010133639_backfill_store_project_full_path_in_repo.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class BackfillStoreProjectFullPathInRepo < ActiveRecord::Migration +class BackfillStoreProjectFullPathInRepo < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181101191341_create_clusters_applications_cert_manager.rb +++ b/db/migrate/20181101191341_create_clusters_applications_cert_manager.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateClustersApplicationsCertManager < ActiveRecord::Migration +class CreateClustersApplicationsCertManager < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181115140140_add_encrypted_runners_token_to_settings.rb +++ b/db/migrate/20181115140140_add_encrypted_runners_token_to_settings.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddEncryptedRunnersTokenToSettings < ActiveRecord::Migration +class AddEncryptedRunnersTokenToSettings < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181116050532_knative_external_ip.rb +++ b/db/migrate/20181116050532_knative_external_ip.rb @@ -3,7 +3,7 @@ # See http://doc.gitlab.com/ce/development/migration_style_guide.html # for more information on how to write migrations for GitLab. -class KnativeExternalIp < ActiveRecord::Migration +class KnativeExternalIp < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181108091549_cleanup_environments_external_url.rb +++ b/db/migrate/20181108091549_cleanup_environments_external_url.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CleanupEnvironmentsExternalUrl < ActiveRecord::Migration +class CleanupEnvironmentsExternalUrl < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181116141415_add_encrypted_runners_token_to_namespaces.rb +++ b/db/migrate/20181116141415_add_encrypted_runners_token_to_namespaces.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddEncryptedRunnersTokenToNamespaces < ActiveRecord::Migration +class AddEncryptedRunnersTokenToNamespaces < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181116141504_add_encrypted_runners_token_to_projects.rb +++ b/db/migrate/20181116141504_add_encrypted_runners_token_to_projects.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddEncryptedRunnersTokenToProjects < ActiveRecord::Migration +class AddEncryptedRunnersTokenToProjects < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181119081539_add_merge_request_id_to_ci_pipelines.rb +++ b/db/migrate/20181119081539_add_merge_request_id_to_ci_pipelines.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddMergeRequestIdToCiPipelines < ActiveRecord::Migration +class AddMergeRequestIdToCiPipelines < ActiveRecord::Migration[4.2] DOWNTIME = false def up --- a/db/migrate/20181120091639_add_foreign_key_to_ci_pipelines_merge_requests.rb +++ b/db/migrate/20181120091639_add_foreign_key_to_ci_pipelines_merge_requests.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddForeignKeyToCiPipelinesMergeRequests < ActiveRecord::Migration +class AddForeignKeyToCiPipelinesMergeRequests < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181120151656_add_token_encrypted_to_ci_runners.rb +++ b/db/migrate/20181120151656_add_token_encrypted_to_ci_runners.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddTokenEncryptedToCiRunners < ActiveRecord::Migration +class AddTokenEncryptedToCiRunners < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181121101842_add_ci_builds_partial_index_on_project_id_and_status.rb +++ b/db/migrate/20181121101842_add_ci_builds_partial_index_on_project_id_and_status.rb @@ -3,7 +3,7 @@ # See http://doc.gitlab.com/ce/development/migration_style_guide.html # for more information on how to write migrations for GitLab. -class AddCiBuildsPartialIndexOnProjectIdAndStatus < ActiveRecord::Migration +class AddCiBuildsPartialIndexOnProjectIdAndStatus < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181121101843_remove_redundant_ci_builds_partial_index.rb +++ b/db/migrate/20181121101843_remove_redundant_ci_builds_partial_index.rb @@ -3,7 +3,7 @@ # See http://doc.gitlab.com/ce/development/migration_style_guide.html # for more information on how to write migrations for GitLab. -class RemoveRedundantCiBuildsPartialIndex < ActiveRecord::Migration +class RemoveRedundantCiBuildsPartialIndex < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/migrate/20181123144235_create_suggestions.rb +++ b/db/migrate/20181123144235_create_suggestions.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSuggestions < ActiveRecord::Migration +class CreateSuggestions < ActiveRecord::Migration[4.2] DOWNTIME = false def change --- a/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb +++ b/db/post_migrate/20181026091631_migrate_forbidden_redirect_uris.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class MigrateForbiddenRedirectUris < ActiveRecord::Migration +class MigrateForbiddenRedirectUris < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false --- a/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb +++ b/db/post_migrate/20181121111200_schedule_runners_token_encryption.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ScheduleRunnersTokenEncryption < ActiveRecord::Migration +class ScheduleRunnersTokenEncryption < ActiveRecord::Migration[4.2] include Gitlab::Database::MigrationHelpers DOWNTIME = false