diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-20 08:00:52 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-20 14:13:45 -0200 |
commit | 50f00463bd8348c35cc5dad40116e21323f6822f (patch) | |
tree | c749e764ce2832b095a448e800bb4fd27576d293 /activerecord | |
parent | bd87bd95646c2b94c602dff7d0a1f7e75c303e51 (diff) | |
download | rails-50f00463bd8348c35cc5dad40116e21323f6822f.tar.gz rails-50f00463bd8348c35cc5dad40116e21323f6822f.tar.bz2 rails-50f00463bd8348c35cc5dad40116e21323f6822f.zip |
Merge pull request #8276 from pwnall/pgsql_text_limits
Postgresql doesn't accepts limits on text columns
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Diffstat (limited to 'activerecord')
4 files changed, 35 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 7aaefe7ecc..2de834ff34 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 3.2.10 (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* + * Calling `include?` on `has_many` associations on unsaved records no longer returns `true` when passed a record with a `nil` foreign key. Fixes #7950. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 80a0c6d13c..afc363c9b2 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1078,6 +1078,13 @@ module ActiveRecord when nil, 0..0x3fffffff; super(type) else raise(ActiveRecordError, "No binary type has byte size #{limit}.") 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' return 'integer' unless limit diff --git a/activerecord/test/cases/adapters/postgresql/sql_types_test.rb b/activerecord/test/cases/adapters/postgresql/sql_types_test.rb new file mode 100644 index 0000000000..d7d40f6385 --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/sql_types_test.rb @@ -0,0 +1,18 @@ +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 diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb index 34e24b5a2e..35e12b1875 100644 --- a/activerecord/test/schema/postgresql_specific_schema.rb +++ b/activerecord/test/schema/postgresql_specific_schema.rb @@ -132,5 +132,10 @@ _SQL _SQL rescue #This version of PostgreSQL either has no XML support or is was not compiled with XML support: skipping table end + + create_table :limitless_fields, force: true do |t| + t.binary :binary, limit: 100_000 + t.text :text, limit: 100_000 + end end |