aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-11 06:41:49 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-04-11 06:41:49 -0700
commit68239487bfbb467d1f7e7e33f493257e041a90a8 (patch)
treed02ef3d3edf2f1a8bb1b813dd2205b2ef0e7b683
parent536f316cd3586e63675e6aba440763b4f0deee9c (diff)
parenta6d9e16e41906ce656993781d2579c4a848a83a1 (diff)
downloadrails-68239487bfbb467d1f7e7e33f493257e041a90a8.tar.gz
rails-68239487bfbb467d1f7e7e33f493257e041a90a8.tar.bz2
rails-68239487bfbb467d1f7e7e33f493257e041a90a8.zip
Merge pull request #10172 from senny/10098_backport
Backport: Correctly parse bigint defaults in PostgreSQL
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb5
-rw-r--r--activerecord/test/schema/postgresql_specific_schema.rb1
4 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 5e5e1490c4..bf6a26b1be 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,11 @@
## unreleased ##
+* Default values for PostgreSQL bigint types now get parsed and dumped to the
+ schema correctly.
+ Backport #10098.
+
+ *Erik Peterson*
+
* Removed warning when `auto_explain_threshold_in_seconds` is set and the
connection adapter doesn't support explain.
This is causing a regression since the Active Record Railtie is trying to
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index cbbb195458..04de08e876 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -142,7 +142,7 @@ module ActiveRecord
when NilClass
nil
# 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
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 0a9643b7e0..629e5e0fff 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -206,6 +206,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
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_xml_shorthand_definition
output = standard_dump
if %r{create_table "postgresql_xml_data_type"} =~ output
diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb
index b2c655ddcd..4f546df2eb 100644
--- a/activerecord/test/schema/postgresql_specific_schema.rb
+++ b/activerecord/test/schema/postgresql_specific_schema.rb
@@ -30,6 +30,7 @@ ActiveRecord::Schema.define do
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 '--- []