提交 edaf32ce 编写于 作者: R Ryuta Kamizono

Merge pull request #38130 from mvastola/fix-sqlite3-add-not-null-columns-issue-38129

Fix adding non-null column to existing SQLite3 table
上级 d34e3080
......@@ -363,7 +363,8 @@ def table_structure(table_name)
# See: https://www.sqlite.org/lang_altertable.html
# SQLite has an additional restriction on the ALTER TABLE statement
def invalid_alter_table_type?(type, options)
type.to_sym == :primary_key || options[:primary_key]
type.to_sym == :primary_key || options[:primary_key] ||
options[:null] == false && options[:default].nil?
end
def alter_table(table_name, foreign_keys = foreign_keys(table_name), **options)
......
......@@ -324,6 +324,14 @@ def test_columns_with_not_null
end
end
def test_add_column_with_not_null
with_example_table "id integer PRIMARY KEY AUTOINCREMENT, number integer not null" do
assert_nothing_raised { @conn.add_column :ex, :name, :string, null: false }
column = @conn.columns("ex").find { |x| x.name == "name" }
assert_not column.null, "column should not be null"
end
end
def test_indexes_logs
with_example_table do
assert_logged [["PRAGMA index_list(\"ex\")", "SCHEMA", []]] do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册