提交 972d18ea 编写于 作者: H hotatekaoru

Add `change_null` for `change_table`

To change a NOT NULL constraint `reversible`.

When changing a NOT NULL constraint, we use `ActiveRecord::ConnectionAdapters::SchemaStatements#change` method that is not reversible, so `up` and `down` methods were required. Actually, we can use `change_column_null` method if only one constraint changed, but if we want to change multiple constarints with ALTER QUERY, `up` and `down` methods were required.
上级 92d03850
......@@ -496,6 +496,7 @@ def add_column(name, type, **options)
# t.timestamps
# t.change
# t.change_default
# t.change_null
# t.rename
# t.references
# t.belongs_to
......@@ -615,6 +616,16 @@ def change_default(column_name, default_or_changes)
@base.change_column_default(name, column_name, default_or_changes)
end
# Sets or removes a NOT NULL constraint on a column.
#
# t.change_null(:qualification, true)
# t.change_null(:qualification, false, 0)
#
# See {connection.change_column_null}[rdoc-ref:SchemaStatements#change_column_null]
def change_null(column_name, null, default = nil)
@base.change_column_null(name, column_name, null, default)
end
# Removes the column(s) from the table definition.
#
# t.remove(:qualification)
......
......@@ -281,6 +281,13 @@ def test_change_default_changes_column
end
end
def test_change_null_changes_column
with_change_table do |t|
@connection.expect :change_column_null, nil, [:delete_me, :bar, true, nil]
t.change_null :bar, true
end
end
def test_remove_drops_single_column
with_change_table do |t|
if RUBY_VERSION < "2.7"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册