@@ -45,11 +45,37 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
45
45
elsif Gitlab ::Database . mysql?
46
46
require 'active_record/connection_adapters/mysql2_adapter'
47
47
48
- module ActiveRecord
49
- module ConnectionAdapters
50
- class AbstractMysqlAdapter
51
- NATIVE_DATABASE_TYPES [ :datetime_with_timezone ] = { name : 'timestamp' }
48
+ module RegisterDateTimeWithTimeZone
49
+ # Run original `initialize_type_map` and then register `timestamp` as a
50
+ # `MysqlDateTimeWithTimeZone`.
51
+ #
52
+ # When schema dumping, `timestamp` columns will be output as
53
+ # `t.datetime_with_timezone`.
54
+ def initialize_type_map ( mapping )
55
+ super mapping
56
+
57
+ mapping . register_type ( %r(timestamp)i ) do |sql_type |
58
+ precision = extract_precision ( sql_type )
59
+ ActiveRecord ::ConnectionAdapters ::AbstractMysqlAdapter ::MysqlDateTimeWithTimeZone . new ( precision : precision )
52
60
end
53
61
end
54
62
end
63
+
64
+ class ActiveRecord ::ConnectionAdapters ::AbstractMysqlAdapter
65
+ prepend RegisterDateTimeWithTimeZone
66
+
67
+ # Add the class `DateTimeWithTimeZone` so we can map `timestamp` to it.
68
+ class MysqlDateTimeWithTimeZone < MysqlDateTime
69
+ def type
70
+ :datetime_with_timezone
71
+ end
72
+ end
73
+
74
+ # Add column type `datetime_with_timezone` so we can do this in
75
+ # migrations:
76
+ #
77
+ # add_column(:users, :datetime_with_timezone)
78
+ #
79
+ NATIVE_DATABASE_TYPES [ :datetime_with_timezone ] = { name : 'timestamp' }
80
+ end
55
81
end
0 commit comments