Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
ec7b3a8d
Commit
ec7b3a8d
authored
Jun 21, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MySQL schema dump for `timestamp`
parent
b367b780
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
config/initializers/active_record_data_types.rb
config/initializers/active_record_data_types.rb
+30
-4
No files found.
config/initializers/active_record_data_types.rb
View file @
ec7b3a8d
...
@@ -45,11 +45,37 @@ if Gitlab::Database.postgresql?
...
@@ -45,11 +45,37 @@ if Gitlab::Database.postgresql?
elsif
Gitlab
::
Database
.
mysql?
elsif
Gitlab
::
Database
.
mysql?
require
'active_record/connection_adapters/mysql2_adapter'
require
'active_record/connection_adapters/mysql2_adapter'
module
ActiveRecord
module
RegisterDateTimeWithTimeZone
module
ConnectionAdapters
# Run original `initialize_type_map` and then register `timestamp` as a
class
AbstractMysqlAdapter
# `MysqlDateTimeWithTimeZone`.
NATIVE_DATABASE_TYPES
[
:datetime_with_timezone
]
=
{
name:
'timestamp'
}
#
# When schema dumping, `timestamp` columns will be output as
# `t.datetime_with_timezone`.
def
initialize_type_map
(
mapping
)
super
mapping
mapping
.
register_type
(
%r(timestamp)i
)
do
|
sql_type
|
precision
=
extract_precision
(
sql_type
)
ActiveRecord
::
ConnectionAdapters
::
AbstractMysqlAdapter
::
MysqlDateTimeWithTimeZone
.
new
(
precision:
precision
)
end
end
end
end
end
end
class
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
prepend
RegisterDateTimeWithTimeZone
# Add the class `DateTimeWithTimeZone` so we can map `timestamp` to it.
class
MysqlDateTimeWithTimeZone
<
MysqlDateTime
def
type
:datetime_with_timezone
end
end
# Add column type `datetime_with_timezone` so we can do this in
# migrations:
#
# add_column(:users, :datetime_with_timezone)
#
NATIVE_DATABASE_TYPES
[
:datetime_with_timezone
]
=
{
name:
'timestamp'
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment