BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d6515aa3
Commit
d6515aa3
authored
Aug 15, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure MySQL would not use CURRENT_TIMESTAMP
for timestamp columns magically. See:
https://gitlab.com/gitlab-org/gitlab-ce/issues/36405
parent
4a2a6d52
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
active_record_mysql_timestamp.rb
config/initializers/active_record_mysql_timestamp.rb
+30
-0
No files found.
config/initializers/active_record_mysql_timestamp.rb
0 → 100644
View file @
d6515aa3
# Make sure that MySQL won't try to use CURRENT_TIMESTAMP when the timestamp
# column is NOT NULL. See https://gitlab.com/gitlab-org/gitlab-ce/issues/36405
# And also: https://bugs.mysql.com/bug.php?id=75098
# This patch was based on:
# https://github.com/rails/rails/blob/15ef55efb591e5379486ccf53dd3e13f416564f6/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb#L34-L36
if
Gitlab
::
Database
.
mysql?
require
'active_record/connection_adapters/abstract/schema_creation'
module
MySQLTimestampFix
def
add_column_options!
(
sql
,
options
)
# By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values,
# and assigning NULL assigns the current timestamp. To permit a TIMESTAMP
# column to contain NULL, explicitly declare it with the NULL attribute.
# See http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
if
sql
.
end_with?
(
'timestamp'
)
&&
!
options
[
:primary_key
]
if
options
[
:null
]
!=
false
sql
<<
' NULL'
elsif
options
[
:column
].
default
.
nil?
sql
<<
' DEFAULT 0'
end
end
super
end
end
ActiveRecord
::
ConnectionAdapters
::
AbstractAdapter
::
SchemaCreation
.
prepend
(
MySQLTimestampFix
)
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