aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-02-10 11:52:01 -0700
committerSean Griffin <sean@thoughtbot.com>2015-02-10 11:55:59 -0700
commitf1a0fa9e19b7e4ccaea191fc6cf0613880222ee7 (patch)
tree655c1e521e1bbe2a6c3cec8b8178bd7dc843c187 /activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
parentf926c1c953df6037654732c57a6c6b23db91c9fa (diff)
downloadrails-f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7.tar.gz
rails-f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7.tar.bz2
rails-f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7.zip
Refactor microsecond precision to be database agnostic
The various databases don't actually need significantly different handling for this behavior, and they can achieve it without knowing about the type of the object. The old implementation was returning a string, which will cause problems such as breaking TZ aware attributes, and making it impossible for the adapters to supply their logic for time objects.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb23
1 files changed, 9 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index c29692d6ca..054c59ef5c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -712,11 +712,6 @@ module ActiveRecord
m.alias_type %r(year)i, 'integer'
m.alias_type %r(bit)i, 'binary'
- m.register_type(%r(datetime)i) do |sql_type|
- precision = extract_precision(sql_type)
- MysqlDateTime.new(precision: precision)
- end
-
m.register_type(%r(enum)i) do |sql_type|
limit = sql_type[/^enum\((.+)\)/i, 1]
.split(',').map{|enum| enum.strip.length - 2}.max
@@ -734,6 +729,14 @@ module ActiveRecord
end
end
+ def extract_precision(sql_type)
+ if /datetime/ === sql_type
+ super || 0
+ else
+ super
+ end
+ end
+
def fetch_type_metadata(sql_type, collation = "", extra = "")
MysqlTypeMetadata.new(super(sql_type), collation: collation, extra: extra, strict: strict_mode?)
end
@@ -916,14 +919,6 @@ module ActiveRecord
TableDefinition.new(native_database_types, name, temporary, options, as)
end
- class MysqlDateTime < Type::DateTime # :nodoc:
- private
-
- def has_precision?
- precision || 0
- end
- end
-
class MysqlString < Type::String # :nodoc:
def type_cast_for_database(value)
case value
@@ -945,7 +940,7 @@ module ActiveRecord
end
def type_classes_with_standard_constructor
- super.merge(string: MysqlString, date_time: MysqlDateTime)
+ super.merge(string: MysqlString)
end
end
end