Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make `change_column_null` reversible. Closes #13576.

Closes #13623.
  • Loading branch information...
commit 724509a9d5322ff502aefa90dd282ba33a281a96 1 parent b502e3d
@senny senny authored
View
4 activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Make `change_column_null` revertable. Fixes #13576.
+
+ *Yves Senn*, *Nishant Modak*, *Prathamesh Sonpatki*
+
* Don't create/drop the test database if RAILS_ENV is specified explicitely.
Previously, when the environment was development, we would always
View
7 activerecord/lib/active_record/migration/command_recorder.rb
@@ -74,7 +74,7 @@ def respond_to?(*args) # :nodoc:
:rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
:change_column_default, :add_reference, :remove_reference, :transaction,
:drop_join_table, :drop_table, :execute_block, :enable_extension,
- :change_column, :execute, :remove_columns, # irreversible methods need to be here too
+ :change_column, :execute, :remove_columns, :change_column_null # irreversible methods need to be here too
].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def create_table(*args, &block)
@@ -157,6 +157,11 @@ def invert_remove_index(args)
alias :invert_add_belongs_to :invert_add_reference
alias :invert_remove_belongs_to :invert_remove_reference
+ def invert_change_column_null(args)
+ args[2] = !args[2]
+ [:change_column_null, args]
+ end
+
# Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
if @delegate.respond_to?(method)
View
16 activerecord/test/cases/migration/change_schema_test.rb
@@ -308,6 +308,22 @@ def test_keeping_default_and_notnull_constraints_on_change
assert_equal 2000, connection.select_values("SELECT money FROM testings").first.to_i
end
+ def test_change_column_null
+ testing_table_with_only_foo_attribute do
+ notnull_migration = Class.new(ActiveRecord::Migration) do
+ def change
+ change_column_null :testings, :foo, false
+ end
+ end
+ notnull_migration.new.suppress_messages do
+ notnull_migration.migrate(:up)
+ assert_equal false, connection.columns(:testings).find{ |c| c.name == "foo"}.null
+ notnull_migration.migrate(:down)
+ assert connection.columns(:testings).find{ |c| c.name == "foo"}.null
+ end
+ end
+ end
+
def test_column_exists
connection.create_table :testings do |t|
t.column :foo, :string
Please sign in to comment.
Something went wrong with that request. Please try again.