diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-25 16:03:24 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-25 16:03:24 +0300 |
commit | 7668c9660fe30338044afd7886a0fac56e6e82b9 (patch) | |
tree | 9cff3242eae13112b8953d44dec24e303beab673 /lib | |
parent | 901159bbae51d818cd6f643da713eee8319923da (diff) | |
parent | 1ec356a0b5b6594ef0df3fb764cb57c0859ca86f (diff) |
Merge branch 'jprovazn-rails5-mysql-datetime' into 'master'
[Rails5] Fix MysqlDateTimeWithTimeZone in rails 5
Closes #46275
See merge request gitlab-org/gitlab-ce!19613
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mysql_zero_date.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/mysql_zero_date.rb b/lib/mysql_zero_date.rb new file mode 100644 index 00000000000..64634f789da --- /dev/null +++ b/lib/mysql_zero_date.rb @@ -0,0 +1,18 @@ +# Disable NO_ZERO_DATE mode for mysql in rails 5. +# We use zero date as a default value +# (config/initializers/active_record_mysql_timestamp.rb), in +# Rails 5 using zero date fails by default (https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/75450216) +# and NO_ZERO_DATE has to be explicitly disabled. Disabling strict mode +# is not sufficient. + +require 'active_record/connection_adapters/abstract_mysql_adapter' + +module MysqlZeroDate + def configure_connection + super + + @connection.query "SET @@SESSION.sql_mode = REPLACE(@@SESSION.sql_mode, 'NO_ZERO_DATE', '');" # rubocop:disable Gitlab/ModuleWithInstanceVariables + end +end + +ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend(MysqlZeroDate) if Gitlab.rails5? |