提交 1fa6c9e5 编写于 作者: R Ryuta Kamizono 提交者: Andrew White

Allow bigint with default nil for avoiding auto increment primary key

Such as #10404, #18206.
上级 fb6f0d40
* Allow bigint with default nil for avoiding auto increment primary key.
*Ryuta Kamizono*
* Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`.
We should omit the collation entirely rather than providing a default.
......
......@@ -3,7 +3,7 @@ module ConnectionAdapters
module MySQL
module ColumnMethods
def primary_key(name, type = :primary_key, **options)
options[:auto_increment] = true if type == :bigint
options[:auto_increment] = true if type == :bigint && !options.key?(:default)
super
end
......
......@@ -4,8 +4,11 @@ module MySQL
module ColumnDumper
def column_spec_for_primary_key(column)
spec = {}
if column.auto_increment?
spec[:id] = ':bigint' if column.bigint?
if column.bigint?
spec[:id] = ':bigint'
spec[:default] = schema_default(column) || 'nil' unless column.auto_increment?
spec[:unsigned] = 'true' if column.unsigned?
elsif column.auto_increment?
spec[:unsigned] = 'true' if column.unsigned?
return if spec.empty?
else
......
......@@ -280,6 +280,32 @@ def test_primary_key_method_with_ansi_quotes
con.reconnect!
end
end
class PrimaryKeyBigintNilDefaultTest < ActiveRecord::TestCase
include SchemaDumpingHelper
self.use_transactional_tests = false
def setup
@connection = ActiveRecord::Base.connection
@connection.create_table(:bigint_defaults, id: :bigint, default: nil, force: true)
end
def teardown
@connection.drop_table :bigint_defaults, if_exists: true
end
test "primary key with bigint allows default override via nil" do
column = @connection.columns(:bigint_defaults).find { |c| c.name == 'id' }
assert column.bigint?
assert_not column.auto_increment?
end
test "schema dump primary key with bigint default nil" do
schema = dump_table_schema "bigint_defaults"
assert_match %r{create_table "bigint_defaults", id: :bigint, default: nil}, schema
end
end
end
if current_adapter?(:PostgreSQLAdapter, :MysqlAdapter, :Mysql2Adapter)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册