Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
03035d69
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
03035d69
编写于
5月 19, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15184 from sgrif/sg-remove-timestamp-type
Remove :timestamp column type
上级
09cc922e
d0f8c46e
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
52 addition
and
47 deletion
+52
-47
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+6
-0
activerecord/lib/active_record/attribute_assignment.rb
activerecord/lib/active_record/attribute_assignment.rb
+1
-1
activerecord/lib/active_record/attribute_methods/read.rb
activerecord/lib/active_record/attribute_methods/read.rb
+2
-2
activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
...b/active_record/attribute_methods/time_zone_conversion.rb
+2
-2
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
...record/connection_adapters/abstract/schema_definitions.rb
+7
-0
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
...lib/active_record/connection_adapters/abstract_adapter.rb
+1
-1
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
...tive_record/connection_adapters/abstract_mysql_adapter.rb
+0
-1
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+2
-2
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
...b/active_record/connection_adapters/postgresql_adapter.rb
+0
-1
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
.../lib/active_record/connection_adapters/sqlite3_adapter.rb
+0
-1
activerecord/lib/active_record/connection_adapters/type.rb
activerecord/lib/active_record/connection_adapters/type.rb
+0
-1
activerecord/lib/active_record/connection_adapters/type/date_time.rb
...d/lib/active_record/connection_adapters/type/date_time.rb
+1
-3
activerecord/lib/active_record/connection_adapters/type/timestamp.rb
...d/lib/active_record/connection_adapters/type/timestamp.rb
+0
-11
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+1
-1
activerecord/test/cases/column_test.rb
activerecord/test/cases/column_test.rb
+8
-13
activerecord/test/cases/connection_adapters/type/type_map_test.rb
...cord/test/cases/connection_adapters/type/type_map_test.rb
+2
-2
activerecord/test/cases/connection_adapters/type_lookup_test.rb
...record/test/cases/connection_adapters/type_lookup_test.rb
+2
-5
activerecord/test/cases/migration/change_schema_test.rb
activerecord/test/cases/migration/change_schema_test.rb
+17
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
03035d69
*
Remove unused
`:timestamp`
type. Transparently alias it to
`:datetime`
in all cases. Fixes inconsistencies when column types are sent outside of
`ActiveRecord`
, such as for XML Serialization.
*Sean Griffin*
*
Fix bug that added
`table_name_prefix`
and
`table_name_suffix`
to
extension names in PostgreSQL when migrating.
...
...
activerecord/lib/active_record/attribute_assignment.rb
浏览文件 @
03035d69
...
...
@@ -149,7 +149,7 @@ def instantiate_time_object(set_values)
end
def
read_time
# If column is a :time (and not :date or :
timestamp
) there is no need to validate if
# If column is a :time (and not :date or :
datetime
) there is no need to validate if
# there are year/month/day fields
if
column
.
type
==
:time
# if the column is a time set the values to their defaults as January 1, 1970, but only if they're nil
...
...
activerecord/lib/active_record/attribute_methods/read.rb
浏览文件 @
03035d69
...
...
@@ -35,7 +35,7 @@ def #{method_name}
extend
ActiveSupport
::
Concern
ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
=
[
:datetime
,
:time
stamp
,
:time
,
:date
]
ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
=
[
:datetime
,
:time
,
:date
]
included
do
class_attribute
:attribute_types_cached_by_default
,
instance_writer:
false
...
...
@@ -52,7 +52,7 @@ def cache_attributes(*attribute_names)
end
# Returns the attributes which are cached. By default time related columns
# with datatype <tt>:datetime, :time
stamp, :time
, :date</tt> are cached.
# with datatype <tt>:datetime, :time, :date</tt> are cached.
def
cached_attributes
@cached_attributes
||=
columns
.
select
{
|
c
|
cacheable_column?
(
c
)
}.
map
{
|
col
|
col
.
name
}.
to_set
end
...
...
activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
浏览文件 @
03035d69
...
...
@@ -28,7 +28,7 @@ def type
module
ClassMethods
protected
# Defined for all +datetime+ a
nd +timestamp+ a
ttributes when +time_zone_aware_attributes+ are enabled.
# Defined for all +datetime+ attributes when +time_zone_aware_attributes+ are enabled.
# This enhanced write method will automatically convert the time passed to it to the zone stored in Time.zone.
def
define_method_attribute
=
(
attr_name
)
if
create_time_zone_conversion_attribute?
(
attr_name
,
columns_hash
[
attr_name
])
...
...
@@ -51,7 +51,7 @@ def #{attr_name}=(time)
def
create_time_zone_conversion_attribute?
(
name
,
column
)
time_zone_aware_attributes
&&
!
self
.
skip_time_zone_conversion_for_attributes
.
include?
(
name
.
to_sym
)
&&
(
:datetime
==
column
.
type
||
:timestamp
==
column
.
type
)
(
:datetime
==
column
.
type
)
end
end
end
...
...
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
浏览文件 @
03035d69
...
...
@@ -262,6 +262,7 @@ def references(*args)
alias
:belongs_to
:references
def
new_column_definition
(
name
,
type
,
options
)
# :nodoc:
type
=
aliased_types
[
type
]
||
type
column
=
create_column_definition
name
,
type
limit
=
options
.
fetch
(
:limit
)
do
native
[
type
][
:limit
]
if
native
[
type
].
is_a?
(
Hash
)
...
...
@@ -292,6 +293,12 @@ def primary_key_column_name
def
native
@native
end
def
aliased_types
HashWithIndifferentAccess
.
new
(
timestamp: :datetime
,
)
end
end
class
AlterTable
# :nodoc:
...
...
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
浏览文件 @
03035d69
...
...
@@ -382,7 +382,7 @@ def initialize_type_map(m) # :nodoc:
m
.
alias_type
%r(clob)i
,
'text'
m
.
register_type
%r(date)i
,
Type
::
Date
.
new
m
.
register_type
%r(time)i
,
Type
::
Time
.
new
m
.
register_type
%r(timestamp)i
,
Type
::
Timestamp
.
new
m
.
alias_type
%r(timestamp)i
,
'datetime'
m
.
register_type
%r(datetime)i
,
Type
::
DateTime
.
new
m
.
alias_type
%r(numeric)i
,
'decimal'
m
.
alias_type
%r(number)i
,
'decimal'
...
...
activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
浏览文件 @
03035d69
...
...
@@ -163,7 +163,6 @@ def missing_default_forged_as_empty_string?(default)
:float
=>
{
:name
=>
"float"
},
:decimal
=>
{
:name
=>
"decimal"
},
:datetime
=>
{
:name
=>
"datetime"
},
:timestamp
=>
{
:name
=>
"datetime"
},
:time
=>
{
:name
=>
"time"
},
:date
=>
{
:name
=>
"date"
},
:binary
=>
{
:name
=>
"blob"
},
...
...
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
03035d69
...
...
@@ -63,7 +63,7 @@ def klass
when
:integer
then
Fixnum
when
:float
then
Float
when
:decimal
then
BigDecimal
when
:datetime
,
:time
stamp
,
:time
then
Time
when
:datetime
,
:time
then
Time
when
:date
then
Date
when
:text
,
:string
,
:binary
then
String
when
:boolean
then
Object
...
...
@@ -110,7 +110,7 @@ def type_cast(value)
when
:integer
then
klass
.
value_to_integer
(
value
)
when
:float
then
value
.
to_f
when
:decimal
then
klass
.
value_to_decimal
(
value
)
when
:datetime
,
:timestamp
then
klass
.
string_to_time
(
value
)
when
:datetime
then
klass
.
string_to_time
(
value
)
when
:time
then
klass
.
string_to_dummy_time
(
value
)
when
:date
then
klass
.
value_to_date
(
value
)
when
:binary
then
klass
.
binary_to_string
(
value
)
...
...
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
浏览文件 @
03035d69
...
...
@@ -216,7 +216,6 @@ class Table < ActiveRecord::ConnectionAdapters::Table
float:
{
name:
"float"
},
decimal:
{
name:
"decimal"
},
datetime:
{
name:
"timestamp"
},
timestamp:
{
name:
"timestamp"
},
time:
{
name:
"time"
},
date:
{
name:
"date"
},
daterange:
{
name:
"daterange"
},
...
...
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
浏览文件 @
03035d69
...
...
@@ -69,7 +69,6 @@ class SQLite3Adapter < AbstractAdapter
float:
{
name:
"float"
},
decimal:
{
name:
"decimal"
},
datetime:
{
name:
"datetime"
},
timestamp:
{
name:
"datetime"
},
time:
{
name:
"time"
},
date:
{
name:
"date"
},
binary:
{
name:
"blob"
},
...
...
activerecord/lib/active_record/connection_adapters/type.rb
浏览文件 @
03035d69
...
...
@@ -9,7 +9,6 @@
require
'active_record/connection_adapters/type/string'
require
'active_record/connection_adapters/type/text'
require
'active_record/connection_adapters/type/time'
require
'active_record/connection_adapters/type/timestamp'
require
'active_record/connection_adapters/type/type_map'
module
ActiveRecord
...
...
activerecord/lib/active_record/connection_adapters/type/date_time.rb
浏览文件 @
03035d69
require
'active_record/connection_adapters/type/timestamp'
module
ActiveRecord
module
ConnectionAdapters
module
Type
class
DateTime
<
Timestamp
# :nodoc:
class
DateTime
<
Value
# :nodoc:
def
type
:datetime
end
...
...
activerecord/lib/active_record/connection_adapters/type/timestamp.rb
已删除
100644 → 0
浏览文件 @
09cc922e
module
ActiveRecord
module
ConnectionAdapters
module
Type
class
Timestamp
<
Value
# :nodoc:
def
type
:timestamp
end
end
end
end
end
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
03035d69
...
...
@@ -516,7 +516,7 @@ def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_m
end
def
test_only_time_related_columns_are_meant_to_be_cached_by_default
expected
=
%w(datetime time
stamp time
date)
.
sort
expected
=
%w(datetime time date)
.
sort
assert_equal
expected
,
ActiveRecord
::
Base
.
attribute_types_cached_by_default
.
map
(
&
:to_s
).
sort
end
...
...
activerecord/test/cases/column_test.rb
浏览文件 @
03035d69
...
...
@@ -109,19 +109,14 @@ def test_type_cast_time
end
def
test_type_cast_datetime_and_timestamp
columns
=
[
Column
.
new
(
"field"
,
nil
,
Type
::
DateTime
.
new
),
Column
.
new
(
"field"
,
nil
,
Type
::
Timestamp
.
new
),
]
columns
.
each
do
|
column
|
assert_equal
nil
,
column
.
type_cast
(
nil
)
assert_equal
nil
,
column
.
type_cast
(
''
)
assert_equal
nil
,
column
.
type_cast
(
' '
)
assert_equal
nil
,
column
.
type_cast
(
'ABC'
)
datetime_string
=
Time
.
now
.
utc
.
strftime
(
"%FT%T"
)
assert_equal
datetime_string
,
column
.
type_cast
(
datetime_string
).
strftime
(
"%FT%T"
)
end
column
=
Column
.
new
(
"field"
,
nil
,
Type
::
DateTime
.
new
)
assert_equal
nil
,
column
.
type_cast
(
nil
)
assert_equal
nil
,
column
.
type_cast
(
''
)
assert_equal
nil
,
column
.
type_cast
(
' '
)
assert_equal
nil
,
column
.
type_cast
(
'ABC'
)
datetime_string
=
Time
.
now
.
utc
.
strftime
(
"%FT%T"
)
assert_equal
datetime_string
,
column
.
type_cast
(
datetime_string
).
strftime
(
"%FT%T"
)
end
def
test_type_cast_date
...
...
activerecord/test/cases/connection_adapters/type/type_map_test.rb
浏览文件 @
03035d69
...
...
@@ -21,7 +21,7 @@ def test_registering_types
def
test_overriding_registered_types
time
=
Time
.
new
timestamp
=
Timestamp
.
new
timestamp
=
DateTime
.
new
mapping
=
TypeMap
.
new
mapping
.
register_type
(
/time/i
,
time
)
...
...
@@ -51,7 +51,7 @@ def test_aliasing_types
def
test_changing_type_changes_aliases
time
=
Time
.
new
timestamp
=
Timestamp
.
new
timestamp
=
DateTime
.
new
mapping
=
TypeMap
.
new
mapping
.
register_type
(
/timestamp/i
,
time
)
...
...
activerecord/test/cases/connection_adapters/type_lookup_test.rb
浏览文件 @
03035d69
...
...
@@ -45,14 +45,11 @@ def test_time_types
assert_lookup_type
:time
,
'TIME'
end
def
test_timestamp_types
assert_lookup_type
:timestamp
,
'timestamp'
assert_lookup_type
:timestamp
,
'TIMESTAMP'
end
def
test_datetime_types
assert_lookup_type
:datetime
,
'datetime'
assert_lookup_type
:datetime
,
'DATETIME'
assert_lookup_type
:datetime
,
'timestamp'
assert_lookup_type
:datetime
,
'TIMESTAMP'
end
def
test_decimal_types
...
...
activerecord/test/cases/migration/change_schema_test.rb
浏览文件 @
03035d69
...
...
@@ -233,6 +233,23 @@ def test_add_column_not_null_with_default
end
end
def
test_add_column_with_timestamp_type
connection
.
create_table
:testings
do
|
t
|
t
.
column
:foo
,
:timestamp
end
klass
=
Class
.
new
(
ActiveRecord
::
Base
)
klass
.
table_name
=
'testings'
assert_equal
:datetime
,
klass
.
columns_hash
[
'foo'
].
type
if
current_adapter?
(
:PostgreSQLAdapter
)
assert_equal
'timestamp without time zone'
,
klass
.
columns_hash
[
'foo'
].
sql_type
else
assert_equal
klass
.
connection
.
type_to_sql
(
'datetime'
),
klass
.
columns_hash
[
'foo'
].
sql_type
end
end
def
test_change_column_quotes_column_names
connection
.
create_table
:testings
do
|
t
|
t
.
column
:select
,
:string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录