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
Jérome Perrin
gitlab-ce
Commits
b367b780
Commit
b367b780
authored
Jun 20, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix PostgreSQL schema dump for `timestamptz`
parent
0a863c8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
config/initializers/active_record_data_types.rb
config/initializers/active_record_data_types.rb
+36
-5
No files found.
config/initializers/active_record_data_types.rb
View file @
b367b780
...
...
@@ -4,12 +4,43 @@
if
Gitlab
::
Database
.
postgresql?
require
'active_record/connection_adapters/postgresql_adapter'
module
ActiveRecord
module
ConnectionAdapters
class
PostgreSQLAdapter
NATIVE_DATABASE_TYPES
.
merge!
(
datetime_with_timezone:
{
name:
'timestamptz'
})
module
ActiveRecord::ConnectionAdapters::PostgreSQL::OID
# Add the class `DateTimeWithTimeZone` so we can map `timestamptz` to it.
class
DateTimeWithTimeZone
<
DateTime
def
type
:datetime_with_timezone
end
end
end
module
RegisterDateTimeWithTimeZone
# Run original `initialize_type_map` and then register `timestamptz` as a
# `DateTimeWithTimeZone`.
#
# Apparently it does not matter that the original `initialize_type_map`
# aliases `timestamptz` to `timestamp`.
#
# When schema dumping, `timestamptz` columns will be output as
# `t.datetime_with_timezone`.
def
initialize_type_map
(
mapping
)
super
mapping
mapping
.
register_type
'timestamptz'
do
|
_
,
_
,
sql_type
|
precision
=
extract_precision
(
sql_type
)
ActiveRecord
::
ConnectionAdapters
::
PostgreSQLAdapter
::
OID
::
DateTimeWithTimeZone
.
new
(
precision:
precision
)
end
end
end
class
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
prepend
RegisterDateTimeWithTimeZone
# 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:
'timestamptz'
}
end
elsif
Gitlab
::
Database
.
mysql?
require
'active_record/connection_adapters/mysql2_adapter'
...
...
@@ -17,7 +48,7 @@ elsif Gitlab::Database.mysql?
module
ActiveRecord
module
ConnectionAdapters
class
AbstractMysqlAdapter
NATIVE_DATABASE_TYPES
.
merge!
(
datetime_with_timezone:
{
name:
'timestamp'
})
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