Skip to content

Commit 7888f4f

Browse files
authored
Merge pull request rails#28172 from kamipo/deprecate_supports_migrations
Deprecate `supports_migrations?` on connection adapters
2 parents c462ada + 322a4a1 commit 7888f4f

File tree

13 files changed

+306
-338
lines changed

13 files changed

+306
-338
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate `supports_migrations?` on connection adapters.
2+
3+
*Ryuta Kamizono*
4+
15
* Fix regression of #1969 with SELECT aliases in HAVING clause.
26

37
*Eugene Kenny*

activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ def adapter_name
232232
self.class::ADAPTER_NAME
233233
end
234234

235-
# Does this adapter support migrations?
236-
def supports_migrations?
237-
false
235+
def supports_migrations? # :nodoc:
236+
true
238237
end
238+
deprecate :supports_migrations?
239239

240240
def supports_primary_key? # :nodoc:
241241
true

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ def mariadb? # :nodoc:
8989
/mariadb/i.match?(full_version)
9090
end
9191

92-
# Returns true, since this connection adapter supports migrations.
93-
def supports_migrations?
94-
true
95-
end
96-
9792
def supports_bulk_alter? #:nodoc:
9893
true
9994
end

activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ def native_database_types #:nodoc:
281281
NATIVE_DATABASE_TYPES
282282
end
283283

284-
# Returns true, since this connection adapter supports migrations.
285-
def supports_migrations?
286-
true
287-
end
288-
289284
def set_standard_conforming_strings
290285
execute("SET standard_conforming_strings = on", "SCHEMA")
291286
end

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ def supports_statement_cache?
117117
true
118118
end
119119

120-
# Returns true, since this connection adapter supports migrations.
121-
def supports_migrations? #:nodoc:
122-
true
123-
end
124-
125120
def requires_reloading?
126121
true
127122
end

activerecord/lib/active_record/migration.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,10 @@ def initialize(app)
548548
end
549549

550550
def call(env)
551-
if connection.supports_migrations?
552-
mtime = ActiveRecord::Migrator.last_migration.mtime.to_i
553-
if @last_check < mtime
554-
ActiveRecord::Migration.check_pending!(connection)
555-
@last_check = mtime
556-
end
551+
mtime = ActiveRecord::Migrator.last_migration.mtime.to_i
552+
if @last_check < mtime
553+
ActiveRecord::Migration.check_pending!(connection)
554+
@last_check = mtime
557555
end
558556
@app.call(env)
559557
end
@@ -1098,8 +1096,6 @@ def move(direction, migrations_paths, steps)
10981096
end
10991097

11001098
def initialize(direction, migrations, target_version = nil)
1101-
raise StandardError.new("This database does not yet support migrations") unless Base.connection.supports_migrations?
1102-
11031099
@direction = direction
11041100
@target_version = target_version
11051101
@migrated_versions = nil

activerecord/lib/active_record/railties/databases.rake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ db_namespace = namespace :db do
288288
current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
289289
ActiveRecord::Tasks::DatabaseTasks.structure_dump(current_config, filename)
290290

291-
if ActiveRecord::Base.connection.supports_migrations? &&
292-
ActiveRecord::SchemaMigration.table_exists?
291+
if ActiveRecord::SchemaMigration.table_exists?
293292
File.open(filename, "a") do |f|
294293
f.puts ActiveRecord::Base.connection.dump_schema_information
295294
f.print "\n"
Lines changed: 107 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,143 @@
11
require "cases/helper"
22

3-
if ActiveRecord::Base.connection.supports_migrations?
3+
class ActiveRecordSchemaTest < ActiveRecord::TestCase
4+
self.use_transactional_tests = false
5+
6+
setup do
7+
@original_verbose = ActiveRecord::Migration.verbose
8+
ActiveRecord::Migration.verbose = false
9+
@connection = ActiveRecord::Base.connection
10+
ActiveRecord::SchemaMigration.drop_table
11+
end
412

5-
class ActiveRecordSchemaTest < ActiveRecord::TestCase
6-
self.use_transactional_tests = false
13+
teardown do
14+
@connection.drop_table :fruits rescue nil
15+
@connection.drop_table :nep_fruits rescue nil
16+
@connection.drop_table :nep_schema_migrations rescue nil
17+
@connection.drop_table :has_timestamps rescue nil
18+
@connection.drop_table :multiple_indexes rescue nil
19+
ActiveRecord::SchemaMigration.delete_all rescue nil
20+
ActiveRecord::Migration.verbose = @original_verbose
21+
end
722

8-
setup do
9-
@original_verbose = ActiveRecord::Migration.verbose
10-
ActiveRecord::Migration.verbose = false
11-
@connection = ActiveRecord::Base.connection
12-
ActiveRecord::SchemaMigration.drop_table
13-
end
23+
def test_has_primary_key
24+
old_primary_key_prefix_type = ActiveRecord::Base.primary_key_prefix_type
25+
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
26+
assert_equal "version", ActiveRecord::SchemaMigration.primary_key
1427

15-
teardown do
16-
@connection.drop_table :fruits rescue nil
17-
@connection.drop_table :nep_fruits rescue nil
18-
@connection.drop_table :nep_schema_migrations rescue nil
19-
@connection.drop_table :has_timestamps rescue nil
20-
@connection.drop_table :multiple_indexes rescue nil
21-
ActiveRecord::SchemaMigration.delete_all rescue nil
22-
ActiveRecord::Migration.verbose = @original_verbose
28+
ActiveRecord::SchemaMigration.create_table
29+
assert_difference "ActiveRecord::SchemaMigration.count", 1 do
30+
ActiveRecord::SchemaMigration.create version: 12
2331
end
32+
ensure
33+
ActiveRecord::SchemaMigration.drop_table
34+
ActiveRecord::Base.primary_key_prefix_type = old_primary_key_prefix_type
35+
end
2436

25-
def test_has_primary_key
26-
old_primary_key_prefix_type = ActiveRecord::Base.primary_key_prefix_type
27-
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
28-
assert_equal "version", ActiveRecord::SchemaMigration.primary_key
29-
30-
ActiveRecord::SchemaMigration.create_table
31-
assert_difference "ActiveRecord::SchemaMigration.count", 1 do
32-
ActiveRecord::SchemaMigration.create version: 12
37+
def test_schema_define
38+
ActiveRecord::Schema.define(version: 7) do
39+
create_table :fruits do |t|
40+
t.column :color, :string
41+
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
42+
t.column :texture, :string
43+
t.column :flavor, :string
3344
end
34-
ensure
35-
ActiveRecord::SchemaMigration.drop_table
36-
ActiveRecord::Base.primary_key_prefix_type = old_primary_key_prefix_type
3745
end
3846

39-
def test_schema_define
40-
ActiveRecord::Schema.define(version: 7) do
41-
create_table :fruits do |t|
42-
t.column :color, :string
43-
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
44-
t.column :texture, :string
45-
t.column :flavor, :string
46-
end
47-
end
48-
49-
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
50-
assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" }
51-
assert_equal 7, ActiveRecord::Migrator::current_version
52-
end
47+
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
48+
assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" }
49+
assert_equal 7, ActiveRecord::Migrator::current_version
50+
end
5351

54-
def test_schema_define_w_table_name_prefix
55-
table_name = ActiveRecord::SchemaMigration.table_name
56-
old_table_name_prefix = ActiveRecord::Base.table_name_prefix
57-
ActiveRecord::Base.table_name_prefix = "nep_"
58-
ActiveRecord::SchemaMigration.table_name = "nep_#{table_name}"
59-
ActiveRecord::Schema.define(version: 7) do
60-
create_table :fruits do |t|
61-
t.column :color, :string
62-
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
63-
t.column :texture, :string
64-
t.column :flavor, :string
65-
end
52+
def test_schema_define_w_table_name_prefix
53+
table_name = ActiveRecord::SchemaMigration.table_name
54+
old_table_name_prefix = ActiveRecord::Base.table_name_prefix
55+
ActiveRecord::Base.table_name_prefix = "nep_"
56+
ActiveRecord::SchemaMigration.table_name = "nep_#{table_name}"
57+
ActiveRecord::Schema.define(version: 7) do
58+
create_table :fruits do |t|
59+
t.column :color, :string
60+
t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle
61+
t.column :texture, :string
62+
t.column :flavor, :string
6663
end
67-
assert_equal 7, ActiveRecord::Migrator::current_version
68-
ensure
69-
ActiveRecord::Base.table_name_prefix = old_table_name_prefix
70-
ActiveRecord::SchemaMigration.table_name = table_name
7164
end
65+
assert_equal 7, ActiveRecord::Migrator::current_version
66+
ensure
67+
ActiveRecord::Base.table_name_prefix = old_table_name_prefix
68+
ActiveRecord::SchemaMigration.table_name = table_name
69+
end
7270

73-
def test_schema_raises_an_error_for_invalid_column_type
74-
assert_raise NoMethodError do
75-
ActiveRecord::Schema.define(version: 8) do
76-
create_table :vegetables do |t|
77-
t.unknown :color
78-
end
71+
def test_schema_raises_an_error_for_invalid_column_type
72+
assert_raise NoMethodError do
73+
ActiveRecord::Schema.define(version: 8) do
74+
create_table :vegetables do |t|
75+
t.unknown :color
7976
end
8077
end
8178
end
79+
end
8280

83-
def test_schema_subclass
84-
Class.new(ActiveRecord::Schema).define(version: 9) do
85-
create_table :fruits
86-
end
87-
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
81+
def test_schema_subclass
82+
Class.new(ActiveRecord::Schema).define(version: 9) do
83+
create_table :fruits
8884
end
85+
assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" }
86+
end
8987

90-
def test_normalize_version
91-
assert_equal "118", ActiveRecord::SchemaMigration.normalize_migration_number("0000118")
92-
assert_equal "002", ActiveRecord::SchemaMigration.normalize_migration_number("2")
93-
assert_equal "017", ActiveRecord::SchemaMigration.normalize_migration_number("0017")
94-
assert_equal "20131219224947", ActiveRecord::SchemaMigration.normalize_migration_number("20131219224947")
95-
end
88+
def test_normalize_version
89+
assert_equal "118", ActiveRecord::SchemaMigration.normalize_migration_number("0000118")
90+
assert_equal "002", ActiveRecord::SchemaMigration.normalize_migration_number("2")
91+
assert_equal "017", ActiveRecord::SchemaMigration.normalize_migration_number("0017")
92+
assert_equal "20131219224947", ActiveRecord::SchemaMigration.normalize_migration_number("20131219224947")
93+
end
9694

97-
def test_schema_load_with_multiple_indexes_for_column_of_different_names
98-
ActiveRecord::Schema.define do
99-
create_table :multiple_indexes do |t|
100-
t.string "foo"
101-
t.index ["foo"], name: "multiple_indexes_foo_1"
102-
t.index ["foo"], name: "multiple_indexes_foo_2"
103-
end
95+
def test_schema_load_with_multiple_indexes_for_column_of_different_names
96+
ActiveRecord::Schema.define do
97+
create_table :multiple_indexes do |t|
98+
t.string "foo"
99+
t.index ["foo"], name: "multiple_indexes_foo_1"
100+
t.index ["foo"], name: "multiple_indexes_foo_2"
104101
end
102+
end
105103

106-
indexes = @connection.indexes("multiple_indexes")
104+
indexes = @connection.indexes("multiple_indexes")
107105

108-
assert_equal 2, indexes.length
109-
assert_equal ["multiple_indexes_foo_1", "multiple_indexes_foo_2"], indexes.collect(&:name).sort
110-
end
106+
assert_equal 2, indexes.length
107+
assert_equal ["multiple_indexes_foo_1", "multiple_indexes_foo_2"], indexes.collect(&:name).sort
108+
end
111109

112-
def test_timestamps_without_null_set_null_to_false_on_create_table
113-
ActiveRecord::Schema.define do
114-
create_table :has_timestamps do |t|
115-
t.timestamps
116-
end
110+
def test_timestamps_without_null_set_null_to_false_on_create_table
111+
ActiveRecord::Schema.define do
112+
create_table :has_timestamps do |t|
113+
t.timestamps
117114
end
118-
119-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
120-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
121115
end
122116

123-
def test_timestamps_without_null_set_null_to_false_on_change_table
124-
ActiveRecord::Schema.define do
125-
create_table :has_timestamps
117+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
118+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
119+
end
126120

127-
change_table :has_timestamps do |t|
128-
t.timestamps default: Time.now
129-
end
130-
end
121+
def test_timestamps_without_null_set_null_to_false_on_change_table
122+
ActiveRecord::Schema.define do
123+
create_table :has_timestamps
131124

132-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
133-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
125+
change_table :has_timestamps do |t|
126+
t.timestamps default: Time.now
127+
end
134128
end
135129

136-
def test_timestamps_without_null_set_null_to_false_on_add_timestamps
137-
ActiveRecord::Schema.define do
138-
create_table :has_timestamps
139-
add_timestamps :has_timestamps, default: Time.now
140-
end
130+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
131+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
132+
end
141133

142-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
143-
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
134+
def test_timestamps_without_null_set_null_to_false_on_add_timestamps
135+
ActiveRecord::Schema.define do
136+
create_table :has_timestamps
137+
add_timestamps :has_timestamps, default: Time.now
144138
end
139+
140+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
141+
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
145142
end
146143
end

0 commit comments

Comments
 (0)