Permalink
Browse files

Correctly parse bigint defaults in PostgreSQL

  • Loading branch information...
1 parent dce398d commit 661365e7ce445955996c9024b76cea84e4f31a02 @subwindow subwindow committed Apr 5, 2013
View
5 activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Default values for PostgreSQL bigint types now get parsed and dumped to the
+ schema correctly.
+
+ *Erik Peterson*
+
* `has_many` using `:through` now obeys the order clause mentioned in
through association. Fixes #10016.
View
2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -80,7 +80,7 @@ def self.extract_value_from_default(default)
when /\A'(.*)'::(num|date|tstz|ts|int4|int8)range\z/m
$1
# Numeric types
- when /\A\(?(-?\d+(\.\d*)?\)?)\z/
+ when /\A\(?(-?\d+(\.\d*)?\)?(::bigint)?)\z/
$1
# Character types
when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/m
View
5 activerecord/test/cases/schema_dumper_test.rb
@@ -242,6 +242,11 @@ def test_schema_dump_includes_decimal_options
end
if current_adapter?(:PostgreSQLAdapter)
+ def test_schema_dump_includes_bigint_default
+ output = standard_dump
+ assert_match %r{t.integer\s+"bigint_default",\s+limit: 8,\s+default: 0}, output
+ end
+
def test_schema_dump_includes_extensions
connection = ActiveRecord::Base.connection
skip unless connection.supports_extensions?
View
1 activerecord/test/schema/postgresql_specific_schema.rb
@@ -32,6 +32,7 @@
char3 text default 'a text field',
positive_integer integer default 1,
negative_integer integer default -1,
+ bigint_default bigint default 0::bigint,
decimal_number decimal(3,2) default 2.78,
multiline_default text DEFAULT '--- []

0 comments on commit 661365e

Please sign in to comment.