Skip to content

Commit 778178e

Browse files
authored
Drop support for Active Record 6.0 and older (#183)
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 2a69627 commit 778178e

File tree

15 files changed

+34
-217
lines changed

15 files changed

+34
-217
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: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -89,61 +89,3 @@ jobs:
8989
DATABASE_PORT: 3306
9090
DATABASE_USERNAME: github
9191
DATABASE_PASSWORD: github
92-
93-
test-unsupported:
94-
name: "Active Record ${{ matrix.active_record }} + Ruby ${{ matrix.ruby }}"
95-
needs: [test-supported]
96-
runs-on: ubuntu-latest
97-
services:
98-
mysql:
99-
image: mysql
100-
env:
101-
MYSQL_ROOT_PASSWORD: github
102-
MYSQL_USER: github
103-
MYSQL_PASSWORD: github
104-
MYSQL_DATABASE: active_record_doctor_primary
105-
options: >-
106-
--health-cmd "mysqladmin ping -h 127.0.0.1"
107-
--health-interval 10s
108-
--health-timeout 5s
109-
--health-retries 5
110-
ports:
111-
- 3306:3306
112-
strategy:
113-
matrix:
114-
ruby: ["2.4", "2.5", "2.6", "2.7"]
115-
active_record: ["4.2", "5.0", "5.1", "5.2", "6.0"]
116-
exclude:
117-
- ruby: "2.7"
118-
active_record: "4.2"
119-
- ruby: "2.4"
120-
active_record: "6.0"
121-
include:
122-
- ruby: "3.0"
123-
active_record: "6.0"
124-
- ruby: "3.1"
125-
active_record: "6.0"
126-
- ruby: "3.2"
127-
active_record: "6.0"
128-
env:
129-
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.activerecord-${{ matrix.active_record }}.x
130-
steps:
131-
- uses: actions/checkout@v4
132-
- uses: ruby/setup-ruby@v1
133-
with:
134-
ruby-version: ${{ matrix.ruby }}
135-
rubygems: ${{ (matrix.ruby == '2.4' || matrix.ruby == '2.5' || matrix.ruby == '2.6') && '3.2.3' || '' }}
136-
bundler-cache: true
137-
- name: Prepare the database
138-
run: |
139-
mysqladmin -h127.0.0.1 -uroot -pgithub create active_record_doctor_secondary
140-
mysql -h127.0.0.1 -uroot -pgithub -e "GRANT ALL PRIVILEGES ON active_record_doctor_secondary.* TO 'github'"
141-
- name: Run the test suite against MySQL
142-
run: bundle exec rake test:mysql2
143-
env:
144-
# We can't use localhost because that makes the MySQL client try
145-
# connecting via a Unix socket instead of TCP.
146-
DATABASE_HOST: 127.0.0.1
147-
DATABASE_PORT: 3306
148-
DATABASE_USERNAME: github
149-
DATABASE_PASSWORD: github

.github/workflows/postgresql.yml

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -92,63 +92,3 @@ jobs:
9292
DATABASE_PORT: 5432
9393
DATABASE_USERNAME: github
9494
DATABASE_PASSWORD: github
95-
96-
test-unsupported:
97-
name: "Active Record ${{ matrix.active_record }} + Ruby ${{ matrix.ruby }}"
98-
needs: [test-supported]
99-
runs-on: ubuntu-latest
100-
services:
101-
postgres:
102-
image: postgres
103-
env:
104-
POSTGRES_DB: active_record_doctor_primary
105-
POSTGRES_USER: github
106-
POSTGRES_PASSWORD: github
107-
options: >-
108-
--health-cmd pg_isready
109-
--health-interval 10s
110-
--health-timeout 5s
111-
--health-retries 5
112-
ports:
113-
- 5432:5432
114-
strategy:
115-
matrix:
116-
ruby: ["2.4", "2.5", "2.6", "2.7"]
117-
active_record: ["4.2", "5.0", "5.1", "5.2", "6.0"]
118-
exclude:
119-
- ruby: "2.7"
120-
active_record: "4.2"
121-
- ruby: "2.4"
122-
active_record: "6.0"
123-
include:
124-
- ruby: "3.0"
125-
active_record: "6.0"
126-
- ruby: "3.1"
127-
active_record: "6.0"
128-
- ruby: "3.2"
129-
active_record: "6.0"
130-
env:
131-
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.activerecord-${{ matrix.active_record }}.x
132-
steps:
133-
- uses: actions/checkout@v4
134-
- uses: ruby/setup-ruby@v1
135-
with:
136-
ruby-version: ${{ matrix.ruby }}
137-
rubygems: ${{ (matrix.ruby == '2.4' || matrix.ruby == '2.5' || matrix.ruby == '2.6') && '3.2.3' || '' }}
138-
bundler-cache: true
139-
- name: Prepare PostgreSQL
140-
if: startsWith(matrix.active_record, '6.') || startsWith(matrix.active_record, '7.')
141-
run: createdb active_record_doctor_secondary
142-
env:
143-
PGHOST: localhost
144-
PGPORT: 5432
145-
PGUSER: github
146-
PGPASSWORD: github
147-
PGDATABASE: postgres
148-
- name: Run the test suite against PostgreSQL
149-
run: bundle exec rake test:postgresql
150-
env:
151-
DATABASE_HOST: localhost
152-
DATABASE_PORT: 5432
153-
DATABASE_USERNAME: github
154-
DATABASE_PASSWORD: github

.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

@@ -27,11 +27,6 @@ Gem::Specification.new do |s|
2727
s.add_development_dependency "pg", "~> 1.5.6"
2828
s.add_development_dependency "railties", ACTIVE_RECORD_SPEC
2929
s.add_development_dependency "rake", "~> 12.3.3"
30+
s.add_development_dependency "rubocop", "~> 1.57.1"
3031
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
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)