Skip to content
Snippets Groups Projects
Commit 44fef4fe authored by Jasper Maes's avatar Jasper Maes
Browse files

Remove rails 4 support in CI, Gemfiles, bin/ and config/

parent eafc8e2f
No related branches found
No related tags found
No related merge requests found
Showing
with 86 additions and 1469 deletions
Loading
Loading
@@ -77,18 +77,6 @@ stages:
- mysql:5.7
- redis:alpine
 
.rails4: &rails4
allow_failure: false
except:
variables:
- $CI_COMMIT_REF_NAME =~ /(^docs[\/-].*|.*-docs$)/
- $CI_COMMIT_REF_NAME =~ /(^qa[\/-].*|.*-qa$)/
- $CI_COMMIT_REF_NAME =~ /norails4/
- $RAILS5_DISABLED
variables:
BUNDLE_GEMFILE: "Gemfile.rails4"
RAILS5: "false"
# Skip all jobs except the ones that begin with 'docs/'.
# Used for commits including ONLY documentation changes.
# https://docs.gitlab.com/ce/development/documentation/#testing
Loading
Loading
@@ -180,18 +168,10 @@ stages:
<<: *rspec-metadata
<<: *use-pg
 
.rspec-metadata-pg-rails4: &rspec-metadata-pg-rails4
<<: *rspec-metadata-pg
<<: *rails4
.rspec-metadata-mysql: &rspec-metadata-mysql
<<: *rspec-metadata
<<: *use-mysql
 
.rspec-metadata-mysql-rails4: &rspec-metadata-mysql-rails4
<<: *rspec-metadata-mysql
<<: *rails4
.only-canonical-masters: &only-canonical-masters
only:
- master@gitlab-org/gitlab-ce
Loading
Loading
@@ -432,7 +412,6 @@ setup-test-env:
script:
- bundle exec ruby -Ispec -e 'require "spec_helper" ; TestEnv.init'
- scripts/gitaly-test-build # Do not use 'bundle exec' here
- BUNDLE_GEMFILE=Gemfile.rails4 bundle install $BUNDLE_INSTALL_FLAGS
artifacts:
expire_in: 7d
paths:
Loading
Loading
@@ -513,14 +492,6 @@ rspec-mysql:
<<: *rspec-metadata-mysql
parallel: 50
 
rspec-pg-rails4:
<<: *rspec-metadata-pg-rails4
parallel: 50
rspec-mysql-rails4:
<<: *rspec-metadata-mysql-rails4
parallel: 50
static-analysis:
<<: *dedicated-no-docs-no-db-pull-cache-job
dependencies:
Loading
Loading
@@ -565,12 +536,6 @@ downtime_check:
- /(^docs[\/-].*|.*-docs$)/
- /(^qa[\/-].*|.*-qa$)/
 
rails4_gemfile_lock_check:
<<: *dedicated-no-docs-no-db-pull-cache-job
<<: *except-docs-and-qa
script:
- scripts/rails4-gemfile-lock-check
ee_compat_check:
<<: *rake-exec
dependencies: []
Loading
Loading
# --- Special code for migrating to Rails 5.0 ---
def rails5?
!%w[0 false].include?(ENV["RAILS5"])
end
gem_versions = {}
gem_versions['activerecord_sane_schema_dumper'] = rails5? ? '1.0' : '0.2'
gem_versions['rails'] = rails5? ? '5.0.7' : '4.2.11'
gem_versions['rails-i18n'] = rails5? ? '~> 5.1' : '~> 4.0.9'
# The 2.0.6 version of rack requires monkeypatch to be present in
# `config.ru`. This can be removed once a new update for Rack
# is available that contains https://github.com/rack/rack/pull/1201.
gem_versions['rack'] = rails5? ? '2.0.6' : '1.6.11'
# --- The end of special code for migrating to Rails 5.0 ---
source 'https://rubygems.org'
 
gem 'rails', gem_versions['rails']
gem 'rails', '5.0.7'
gem 'rails-deprecated_sanitizer', '~> 1.0.3'
 
# Improves copy-on-write performance for MRI
Loading
Loading
@@ -28,11 +12,7 @@ gem 'responders', '~> 2.0'
gem 'sprockets', '~> 3.7.0'
 
# Default values for AR models
if rails5?
gem 'gitlab-default_value_for', '~> 3.1.1', require: 'default_value_for'
else
gem 'default_value_for', '~> 3.0.0'
end
gem 'gitlab-default_value_for', '~> 3.1.1', require: 'default_value_for'
 
# Supported DBs
gem 'mysql2', '~> 0.4.10', group: :mysql
Loading
Loading
@@ -159,7 +139,10 @@ gem 'icalendar'
gem 'diffy', '~> 3.1.0'
 
# Application server
gem 'rack', gem_versions['rack']
# The 2.0.6 version of rack requires monkeypatch to be present in
# `config.ru`. This can be removed once a new update for Rack
# is available that contains https://github.com/rack/rack/pull/1201.
gem 'rack', '2.0.6'
 
group :unicorn do
gem 'unicorn', '~> 5.1.0'
Loading
Loading
@@ -297,7 +280,7 @@ gem 'premailer-rails', '~> 1.9.7'
 
# I18n
gem 'ruby_parser', '~> 3.8', require: false
gem 'rails-i18n', gem_versions['rails-i18n']
gem 'rails-i18n', '~> 5.1'
gem 'gettext_i18n_rails', '~> 1.8.0'
gem 'gettext_i18n_rails_js', '~> 1.3'
gem 'gettext', '~> 3.2.2', require: false, group: :development
Loading
Loading
@@ -383,7 +366,7 @@ group :development, :test do
gem 'license_finder', '~> 5.4', require: false
gem 'knapsack', '~> 1.17'
 
gem 'activerecord_sane_schema_dumper', gem_versions['activerecord_sane_schema_dumper']
gem 'activerecord_sane_schema_dumper', '1.0'
 
gem 'stackprof', '~> 0.2.10', require: false
 
Loading
Loading
@@ -397,8 +380,7 @@ group :test do
gem 'email_spec', '~> 2.2.0'
gem 'json-schema', '~> 2.8.0'
gem 'webmock', '~> 2.3.2'
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 'rails-controller-testing'
gem 'sham_rack', '~> 1.3.6'
gem 'concurrent-ruby', '~> 1.1'
gem 'test-prof', '~> 0.2.5'
Loading
Loading
# BUNDLE_GEMFILE=Gemfile.rails4 bundle install
ENV["RAILS5"] = "false"
gemfile = File.expand_path("../Gemfile", __FILE__)
eval(File.read(gemfile), nil, gemfile)
This diff is collapsed.
#!/usr/bin/env ruby
# Remove this block when upgraded to rails 5.0.
if %w[0 false].include?(ENV["RAILS5"])
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
#!/usr/bin/env ruby
# Remove this block when upgraded to rails 5.0.
if %w[0 false].include?(ENV["RAILS5"])
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
#!/usr/bin/env ruby
 
# Remove these two lines below when upgraded to rails 5.0.
# Allow run `rspec` command as `RAILS5=1 rspec ...` instead of `BUNDLE_GEMFILE=Gemfile.rails5 rspec ...`
gemfile = %w[0 false].include?(ENV["RAILS5"]) ? "Gemfile.rails4" : "Gemfile"
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../#{gemfile}", __dir__)
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
Loading
Loading
#!/usr/bin/env ruby
 
def rails5?
!%w[0 false].include?(ENV["RAILS5"])
end
require "pathname"
 
# path to your application root.
APP_ROOT = Pathname.new File.expand_path("../../", __FILE__)
 
if rails5?
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
 
Dir.chdir APP_ROOT do
Loading
Loading
@@ -20,14 +14,8 @@ Dir.chdir APP_ROOT do
# Add necessary setup steps to this file:
 
puts "== Installing dependencies =="
if rails5?
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
else
system "gem install bundler --conservative"
system "bundle check || bundle install"
end
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
 
# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
Loading
Loading
@@ -35,27 +23,11 @@ Dir.chdir APP_ROOT do
# end
 
puts "\n== Preparing database =="
if rails5?
system! "bin/rails db:setup"
else
system "bin/rake db:reset"
end
system! "bin/rails db:setup"
 
puts "\n== Removing old logs and tempfiles =="
if rails5?
system! "bin/rails log:clear tmp:clear"
else
system "rm -f log/*"
system "rm -rf tmp/cache"
end
system! "bin/rails log:clear tmp:clear"
 
puts "\n== Restarting application server =="
if rails5?
system! "bin/rails restart"
else
system "touch tmp/restart.txt"
end
system! "bin/rails restart"
end
---
title: Remove rails 4 support in CI, Gemfiles, bin/ and config/
merge_request: 23717
author: Jasper Maes
type: other
Loading
Loading
@@ -8,7 +8,7 @@ module Gitlab
# This method is used for smooth upgrading from the current Rails 4.x to Rails 5.0.
# https://gitlab.com/gitlab-org/gitlab-ce/issues/14286
def self.rails5?
!%w[0 false].include?(ENV["RAILS5"])
true
end
 
class Application < Rails::Application
Loading
Loading
@@ -26,9 +26,6 @@ module Gitlab
# setting disabled
require_dependency Rails.root.join('lib/mysql_zero_date')
 
# This can be removed when we drop support for rails 4
require_dependency Rails.root.join('lib/rails4_migration_version')
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Loading
Loading
@@ -86,7 +83,7 @@ module Gitlab
# namespaces/users.
# https://github.com/rails/rails/blob/5-0-stable/actioncable/lib/action_cable.rb#L38
# Please change this value when configuring ActionCable for real usage.
config.action_cable.mount_path = "/-/cable" if rails5?
config.action_cable.mount_path = "/-/cable"
 
# Configure sensitive parameters which will be filtered from the log file.
#
Loading
Loading
@@ -213,8 +210,6 @@ module Gitlab
 
config.cache_store = :redis_store, caching_config_hash
 
config.active_record.raise_in_transactional_callbacks = true unless rails5?
config.active_job.queue_adapter = :sidekiq
 
# This is needed for gitlab-shell
Loading
Loading
def rails5?
!%w[0 false].include?(ENV["RAILS5"])
end
require 'rubygems' unless rails5?
gemfile = rails5? ? "Gemfile" : "Gemfile.rails4"
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../#{gemfile}", __dir__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
 
# Set up gems listed in the Gemfile.
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
Loading
Loading
# Load the rails application
 
# Remove this condition when upgraded to rails 5.0.
if %w[0 false].include?(ENV["RAILS5"])
require File.expand_path('application', __dir__)
else
require_relative 'application'
end
require_relative 'application'
 
# Initialize the rails application
Rails.application.initialize!
Loading
Loading
@@ -9,11 +9,7 @@ Rails.application.configure do
config.action_controller.perform_caching = true
 
# Disable Rails's static asset server (Apache or nginx will already do this)
if Gitlab.rails5?
config.public_file_server.enabled = false
else
config.serve_static_files = false
end
config.public_file_server.enabled = false
 
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
Loading
Loading
Loading
Loading
@@ -19,13 +19,8 @@ Rails.application.configure do
# Configure static asset server for tests with Cache-Control for performance
config.assets.compile = false if ENV['CI']
 
if Gitlab.rails5?
config.public_file_server.enabled = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
else
config.serve_static_files = true
config.static_cache_control = "public, max-age=3600"
end
config.public_file_server.enabled = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
 
# Show full error reports and disable caching
config.consider_all_requests_local = true
Loading
Loading
# Remove this initializer when upgraded to Rails 5.0
unless Gitlab.rails5?
module ActiveRecord
class PredicateBuilder
class ArrayHandler
module TypeCasting
def call(attribute, value)
# This is necessary because by default ActiveRecord does not respect
# custom type definitions (like our `ShaAttribute`) when providing an
# array in `where`, like in `where(commit_sha: [sha1, sha2, sha3])`.
model = attribute.relation&.engine
type = model.user_provided_columns[attribute.name] if model
value = value.map { |value| type.type_cast_for_database(value) } if type
super(attribute, value)
end
end
prepend TypeCasting
end
end
end
end
Loading
Loading
@@ -20,75 +20,73 @@
#
# This bug was fixed in Rails 5.1 by https://github.com/rails/rails/pull/24745/commits/aa062318c451512035c10898a1af95943b1a3803
 
if Gitlab.rails5?
if Rails.version.start_with?("5.1")
raise "Remove this monkey patch: #{__FILE__}"
end
if Rails.version.start_with?("5.1")
raise "Remove this monkey patch: #{__FILE__}"
end
 
# Copy-paste from https://github.com/kamipo/rails/blob/aa062318c451512035c10898a1af95943b1a3803/activerecord/lib/active_record/validations/uniqueness.rb
# including local fixes to make Rubocop happy again.
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
table = finder_class.arel_table
value = map_enum_attribute(finder_class, attribute, value)
# Copy-paste from https://github.com/kamipo/rails/blob/aa062318c451512035c10898a1af95943b1a3803/activerecord/lib/active_record/validations/uniqueness.rb
# including local fixes to make Rubocop happy again.
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
def validate_each(record, attribute, value)
finder_class = find_finder_class_for(record)
table = finder_class.arel_table
value = map_enum_attribute(finder_class, attribute, value)
 
relation = build_relation(finder_class, table, attribute, value)
relation = build_relation(finder_class, table, attribute, value)
 
if record.persisted?
if finder_class.primary_key
relation = relation.where.not(finder_class.primary_key => record.id_was || record.id)
else
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
end
if record.persisted?
if finder_class.primary_key
relation = relation.where.not(finder_class.primary_key => record.id_was || record.id)
else
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
end
end
 
relation = scope_relation(record, table, relation)
relation = relation.merge(options[:conditions]) if options[:conditions]
relation = scope_relation(record, table, relation)
relation = relation.merge(options[:conditions]) if options[:conditions]
 
if relation.exists?
error_options = options.except(:case_sensitive, :scope, :conditions)
error_options[:value] = value
if relation.exists?
error_options = options.except(:case_sensitive, :scope, :conditions)
error_options[:value] = value
 
record.errors.add(attribute, :taken, error_options)
end
rescue RangeError
record.errors.add(attribute, :taken, error_options)
end
rescue RangeError
end
 
protected
def build_relation(klass, table, attribute, value) #:nodoc:
if reflection = klass._reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.klass.primary_key] unless value.nil?
end
protected
 
# the attribute may be an aliased attribute
if klass.attribute_alias?(attribute)
attribute = klass.attribute_alias(attribute)
end
def build_relation(klass, table, attribute, value) #:nodoc:
if reflection = klass._reflect_on_association(attribute)
attribute = reflection.foreign_key
value = value.attributes[reflection.klass.primary_key] unless value.nil?
end
 
attribute_name = attribute.to_s
# the attribute may be an aliased attribute
if klass.attribute_alias?(attribute)
attribute = klass.attribute_alias(attribute)
end
 
column = klass.columns_hash[attribute_name]
cast_type = klass.type_for_attribute(attribute_name)
attribute_name = attribute.to_s
 
comparison =
if !options[:case_sensitive] && !value.nil?
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
klass.connection.case_insensitive_comparison(table, attribute, column, value)
else
klass.connection.case_sensitive_comparison(table, attribute, column, value)
end
column = klass.columns_hash[attribute_name]
cast_type = klass.type_for_attribute(attribute_name)
 
if value.nil?
klass.unscoped.where(comparison)
comparison =
if !options[:case_sensitive] && !value.nil?
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
klass.connection.case_insensitive_comparison(table, attribute, column, value)
else
bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
klass.unscoped.where(comparison, bind)
klass.connection.case_sensitive_comparison(table, attribute, column, value)
end
if value.nil?
klass.unscoped.where(comparison)
else
bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
klass.unscoped.where(comparison, bind)
end
end
end
Loading
Loading
Loading
Loading
@@ -65,7 +65,7 @@ elsif Gitlab::Database.mysql?
prepend RegisterDateTimeWithTimeZone
 
# Add the class `DateTimeWithTimeZone` so we can map `timestamp` to it.
class MysqlDateTimeWithTimeZone < (Gitlab.rails5? ? ActiveRecord::Type::DateTime : MysqlDateTime)
class MysqlDateTimeWithTimeZone < ActiveRecord::Type::DateTime
def type
:datetime_with_timezone
end
Loading
Loading
Loading
Loading
@@ -64,21 +64,13 @@ module ActiveRecord
 
# This is patched because we want `lock_version` default to `NULL`
# rather than `0`
if Gitlab.rails5?
class LockingType
def deserialize(value)
super
end
def serialize(value)
super
end
class LockingType
def deserialize(value)
super
end
else
class LockingType < SimpleDelegator
def type_cast_from_database(value)
super
end
def serialize(value)
super
end
end
end
Loading
Loading
# Remove this `if` condition when upgraded to rails 5.0.
# The body must be kept.
if Gitlab.rails5?
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )
# end
end
# Remove this file when upgraded to rails 5.0.
unless Gitlab.rails5?
module ActiveRecord
module Batches
# Differences from upstream: enumerator support was removed, and custom
# order/limit clauses are ignored without a warning.
def in_batches(of: 1000, start: nil, finish: nil, load: false)
raise "Must provide a block" unless block_given?
relation = self.reorder(batch_order).limit(of)
relation = relation.where(arel_table[primary_key].gteq(start)) if start
relation = relation.where(arel_table[primary_key].lteq(finish)) if finish
batch_relation = relation
loop do
if load
records = batch_relation.records
ids = records.map(&:id)
yielded_relation = self.where(primary_key => ids)
yielded_relation.load_records(records)
else
ids = batch_relation.pluck(primary_key)
yielded_relation = self.where(primary_key => ids)
end
break if ids.empty?
primary_key_offset = ids.last
raise ArgumentError.new("Primary key not included in the custom select clause") unless primary_key_offset
yield yielded_relation
break if ids.length < of
batch_relation = relation.where(arel_table[primary_key].gt(primary_key_offset))
end
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment