Skip to content

Commit 6555e2f

Browse files
committed
Drop support for Active Record 6.0 and older
This commit drops support for ancient Versions of Active Record. Maintaining backwards compatibility with them became too expensive and negatively influenced the pace of new development. Assuming Active Record 6.1 or newer, we were able to remove certain conditionals from the code base. Additionally, almost all mentions of older versions of active record in the rails were removed from the code.
1 parent bb22c7b commit 6555e2f

File tree

15 files changed

+37
-100
lines changed

15 files changed

+37
-100
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: ruby/setup-ruby@v1
1717
with:
18-
ruby-version: 3.0
18+
ruby-version: "3.3"
1919
bundler-cache: true
2020
- run: bundle exec rake rubocop

.github/workflows/mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292

9393
test-unsupported:
9494
name: "Active Record ${{ matrix.active_record }} + Ruby ${{ matrix.ruby }}"
95-
needs: [test-supported]
95+
continue-on-error: true
9696
runs-on: ubuntu-latest
9797
services:
9898
mysql:

.github/workflows/postgresql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595

9696
test-unsupported:
9797
name: "Active Record ${{ matrix.active_record }} + Ruby ${{ matrix.ruby }}"
98-
needs: [test-supported]
98+
continue-on-error: true
9999
runs-on: ubuntu-latest
100100
services:
101101
postgres:

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# We upgrade to new versions of rubocop manually so it won't harm to enable all
22
# new cops.
33
AllCops:
4-
TargetRubyVersion: 2.4
4+
TargetRubyVersion: 2.5
55
NewCops: enable
66
SuggestExtensions: false
77

Rakefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ end
1818

1919
Bundler::GemHelper.install_tasks
2020

21-
begin
22-
require "rubocop/rake_task"
23-
rescue LoadError
24-
# We don't mind not having Rubocop in CI when testing against an older version
25-
# of Ruby and Rails.
26-
else
27-
RuboCop::RakeTask.new
28-
end
21+
require "rubocop/rake_task"
22+
RuboCop::RakeTask.new
2923

3024
require "rake/testtask"
3125

active_record_doctor.gemspec

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path("lib", __dir__)
44

55
require "active_record_doctor/version"
66

7-
ACTIVE_RECORD_SPEC = ">= 4.2.0"
7+
ACTIVE_RECORD_SPEC = ">= 6.1.0"
88

99
Gem::Specification.new do |s|
1010
s.name = "active_record_doctor"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
1818

1919
s.metadata["rubygems_mfa_required"] = "true"
2020

21-
s.required_ruby_version = ">= 2.1.0"
21+
s.required_ruby_version = ">= 2.5.0"
2222

2323
s.add_dependency "activerecord", ACTIVE_RECORD_SPEC
2424

@@ -28,10 +28,5 @@ Gem::Specification.new do |s|
2828
s.add_development_dependency "railties", ACTIVE_RECORD_SPEC
2929
s.add_development_dependency "rake", "~> 12.3.3"
3030
s.add_development_dependency "transient_record", "~> 2.0.0"
31-
32-
# We don't install rubocop in CI because we test against older Rubies that
33-
# are incompatible with Rubocop.
34-
if ENV["CI"].nil? || ENV["LINT"]
35-
s.add_development_dependency "rubocop", "~> 1.57.1"
36-
end
31+
s.add_development_dependency "rubocop", "~> 1.57.1"
3732
end

lib/active_record_doctor/detectors/base.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ def not_null_check_constraint_exists?(table, column)
136136
end
137137

138138
def check_constraints(table_name)
139-
# ActiveRecord 6.1+
140-
if connection.respond_to?(:supports_check_constraints?) && connection.supports_check_constraints?
139+
if connection.supports_check_constraints?
141140
connection.check_constraints(table_name).select(&:validated?).map(&:expression)
142141
elsif Utils.postgresql?(connection)
143142
definitions =
@@ -256,15 +255,8 @@ def each_foreign_key(table_name)
256255
end
257256

258257
def each_table(except: [])
259-
tables =
260-
if ActiveRecord::VERSION::STRING >= "5.1"
261-
connection.tables
262-
else
263-
connection.data_sources
264-
end
265-
266258
log("Iterating over tables") do
267-
tables.each do |table|
259+
connection.tables.each do |table|
268260
case
269261
when ignored?(table, except)
270262
log("#{table} - ignored via the configuration; skipping")

lib/active_record_doctor/detectors/missing_unique_indexes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def validations_without_indexes
6565
# put true literally.
6666
case_sensitive = validator.options.fetch(:case_sensitive, true)
6767

68-
# ActiveRecord < 5.0 does not support expression indexes,
69-
# so this will always be a false positive.
68+
# Avoid a false positive if expression indexes are unsupported.
7069
next if !case_sensitive && Utils.expression_indexes_unsupported?
7170

7271
validator.attributes.each do |attribute|

lib/active_record_doctor/utils.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ def mysql?(connection = ActiveRecord::Base.connection)
1212
end
1313

1414
def expression_indexes_unsupported?(connection = ActiveRecord::Base.connection)
15-
(ActiveRecord::VERSION::STRING < "5.0") ||
16-
# Active Record is unable to correctly parse expression indexes for MySQL.
17-
(mysql?(connection) && ActiveRecord::VERSION::STRING < "7.1")
15+
# Active Record is unable to correctly parse expression indexes for MySQL.
16+
(mysql?(connection) && ActiveRecord::VERSION::STRING < "7.1")
1817
end
1918
end
2019
end

lib/generators/active_record_doctor/add_indexes/add_indexes_generator.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def content(table, indexes)
4747
# rubocop rule below.
4848

4949
<<MIGRATION
50-
class IndexForeignKeysIn#{table.camelize} < ActiveRecord::Migration#{migration_version}
50+
class IndexForeignKeysIn#{table.camelize} < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
5151
def change
5252
#{add_indexes(table, indexes)}
5353
end
@@ -71,13 +71,5 @@ def add_index(table, columns)
7171
" add_index :#{table}, #{columns.inspect}"
7272
end
7373
end
74-
75-
def migration_version
76-
if ActiveRecord::VERSION::STRING >= "5.1"
77-
"[#{ActiveRecord::Migration.current_version}]"
78-
else
79-
""
80-
end
81-
end
8274
end
8375
end

0 commit comments

Comments
 (0)