提交 a8a60e92 编写于 作者: V Victor Costan

Postgresql doesn't accepts limits on text columns.

上级 abb38fea
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##
* When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is silently dropped.
Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits on these types.
*Victor Costan*
* Don't change STI type when calling `ActiveRecord::Base#becomes`. * Don't change STI type when calling `ActiveRecord::Base#becomes`.
Add `ActiveRecord::Base#becomes!` with the previous behavior. Add `ActiveRecord::Base#becomes!` with the previous behavior.
......
...@@ -396,6 +396,13 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil) ...@@ -396,6 +396,13 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
when nil, 0..0x3fffffff; super(type) when nil, 0..0x3fffffff; super(type)
else raise(ActiveRecordError, "No binary type has byte size #{limit}.") else raise(ActiveRecordError, "No binary type has byte size #{limit}.")
end end
when 'text'
# PostgreSQL doesn't support limits on text columns.
# The hard limit is 1Gb, according to section 8.3 in the manual.
case limit
when nil, 0..0x3fffffff; super(type)
else raise(ActiveRecordError, "The limit on text can be at most 1GB - 1byte.")
end
when 'integer' when 'integer'
return 'integer' unless limit return 'integer' unless limit
......
require "cases/helper"
class SqlTypesTest < ActiveRecord::TestCase
def test_binary_types
assert_equal 'bytea', type_to_sql(:binary, 100_000)
assert_raise ActiveRecord::ActiveRecordError do
type_to_sql :binary, 4294967295
end
assert_equal 'text', type_to_sql(:text, 100_000)
assert_raise ActiveRecord::ActiveRecordError do
type_to_sql :text, 4294967295
end
end
def type_to_sql(*args)
ActiveRecord::Base.connection.type_to_sql(*args)
end
end
...@@ -192,5 +192,10 @@ ...@@ -192,5 +192,10 @@
_SQL _SQL
rescue #This version of PostgreSQL either has no XML support or is was not compiled with XML support: skipping table rescue #This version of PostgreSQL either has no XML support or is was not compiled with XML support: skipping table
end end
create_table :limitless_fields, force: true do |t|
t.binary :binary, limit: 100_000
t.text :text, limit: 100_000
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册