Skip to content

Commit 649f251

Browse files
committed
Revert "Merge pull request rails#3603 from vijaydev/change_table_without_block_arg"
This reverts commit 81fad6a, reversing changes made to 23101de. Conflicts: activerecord/test/cases/migration_test.rb
1 parent d8b2b6a commit 649f251

File tree

2 files changed

+7
-66
lines changed

2 files changed

+7
-66
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,14 @@ def create_table(table_name, options = {}, &blk)
242242
#
243243
# See also Table for details on
244244
# all of the various column transformation
245-
def change_table(table_name, options = {}, &blk)
246-
bulk_change = supports_bulk_alter? && options[:bulk]
247-
recorder = bulk_change ? ActiveRecord::Migration::CommandRecorder.new(self) : self
248-
table = Table.new(table_name, recorder)
249-
250-
if block_given?
251-
if blk.arity == 1
252-
yield table
253-
else
254-
table.instance_eval(&blk)
255-
end
245+
def change_table(table_name, options = {})
246+
if supports_bulk_alter? && options[:bulk]
247+
recorder = ActiveRecord::Migration::CommandRecorder.new(self)
248+
yield Table.new(table_name, recorder)
249+
bulk_change_table(table_name, recorder.commands)
250+
else
251+
yield Table.new(table_name, self)
256252
end
257-
bulk_change_table(table_name, recorder.commands) if bulk_change
258253
end
259254

260255
# Renames a table.

activerecord/test/cases/migration_test.rb

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,60 +1757,6 @@ def test_create_table_should_not_have_mixed_syntax
17571757
end
17581758
end
17591759
end
1760-
1761-
def test_change_table_without_block_parameter_no_bulk
1762-
Person.connection.create_table :testings, :force => true do
1763-
string :foo
1764-
end
1765-
assert Person.connection.column_exists?(:testings, :foo, :string)
1766-
1767-
Person.connection.change_table :testings do
1768-
remove :foo
1769-
integer :bar
1770-
end
1771-
1772-
assert_equal %w(bar id), Person.connection.columns(:testings).map { |c| c.name }.sort
1773-
ensure
1774-
Person.connection.drop_table :testings rescue nil
1775-
end
1776-
1777-
if ActiveRecord::Base.connection.supports_bulk_alter?
1778-
def test_change_table_without_block_parameter_with_bulk
1779-
Person.connection.create_table :testings, :force => true do
1780-
string :foo
1781-
end
1782-
assert Person.connection.column_exists?(:testings, :foo, :string)
1783-
1784-
assert_queries(1) do
1785-
Person.connection.change_table(:testings, :bulk => true) do
1786-
integer :bar
1787-
string :foo_bar
1788-
end
1789-
end
1790-
1791-
assert_equal %w(bar foo foo_bar id), Person.connection.columns(:testings).map { |c| c.name }.sort
1792-
ensure
1793-
Person.connection.drop_table :testings rescue nil
1794-
end
1795-
end
1796-
1797-
def test_change_table_should_not_have_mixed_syntax
1798-
Person.connection.create_table :testings, :force => true do
1799-
string :foo
1800-
end
1801-
assert_raise(NoMethodError) do
1802-
Person.connection.change_table :testings do |t|
1803-
t.remove :foo
1804-
integer :bar
1805-
end
1806-
end
1807-
assert_raise(NameError) do
1808-
Person.connection.change_table :testings do
1809-
t.remove :foo
1810-
integer :bar
1811-
end
1812-
end
1813-
end
18141760
end # SexierMigrationsTest
18151761

18161762
class MigrationLoggerTest < ActiveRecord::TestCase

0 commit comments

Comments
 (0)