aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-22 11:19:56 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-22 11:19:56 -0700
commit96ce1f2553f895bfd25e7ca677fb7ed746d04fdd (patch)
treeaa7b6b7dd270bddacc17e495a0e999b66ef47059 /activerecord/lib
parenta232831f2dc0dd2ccec0ab152a87614b1fc95fb0 (diff)
parent6657ec9a0a05c1b3ddcb7aa679ebfdb7e0bc4959 (diff)
downloadrails-96ce1f2553f895bfd25e7ca677fb7ed746d04fdd.tar.gz
rails-96ce1f2553f895bfd25e7ca677fb7ed746d04fdd.tar.bz2
rails-96ce1f2553f895bfd25e7ca677fb7ed746d04fdd.zip
Merge pull request #6821 from tonywok/pg_datetime_precision
Allow precision option for postgresql datetimes
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 43e243581c..a9940209fa 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -187,6 +187,7 @@ module ActiveRecord
case sql_type
when /^bigint/i; 8
when /^smallint/i; 2
+ when /^timestamp/i; nil
else super
end
end
@@ -201,6 +202,8 @@ module ActiveRecord
def extract_precision(sql_type)
if sql_type == 'money'
self.class.money_precision
+ elsif sql_type =~ /timestamp/i
+ $1.to_i if sql_type =~ /\((\d+)\)/
else
super
end
@@ -1285,6 +1288,13 @@ module ActiveRecord
when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
end
+ when 'datetime'
+ return super unless precision
+
+ case precision
+ when 0..6; "timestamp(#{precision})"
+ else raise(ActiveRecordError, "No timestamp type has precision of #{precision}. The allowed range of precision is from 0 to 6")
+ end
else
super
end