From 9ab582314852fc6c3f098387ce3a610ea2db0438 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 20 Sep 2017 15:32:07 +0800 Subject: Use now() as default MySQL timestamp Because under some configuration and versions, 0 is invalid. See: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date This was discussed in: * https://gitlab.com/gitlab-org/gitlab-ce/issues/36405#note_40120201 * https://gitlab.com/gitlab-org/gitlab-ce/issues/35376#note_40588738 * https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12841#note_40829586 --- changelogs/unreleased/use-1-for-mysql-default-timestamp.yml | 5 +++++ config/initializers/active_record_mysql_timestamp.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/use-1-for-mysql-default-timestamp.yml diff --git a/changelogs/unreleased/use-1-for-mysql-default-timestamp.yml b/changelogs/unreleased/use-1-for-mysql-default-timestamp.yml new file mode 100644 index 00000000000..80a982ebf99 --- /dev/null +++ b/changelogs/unreleased/use-1-for-mysql-default-timestamp.yml @@ -0,0 +1,5 @@ +--- +title: Use now() as default timestamp for MySQL +merge_request: 14383 +author: +type: fixed diff --git a/config/initializers/active_record_mysql_timestamp.rb b/config/initializers/active_record_mysql_timestamp.rb index af74c4ff6fb..b0e53b38978 100644 --- a/config/initializers/active_record_mysql_timestamp.rb +++ b/config/initializers/active_record_mysql_timestamp.rb @@ -17,7 +17,8 @@ if Gitlab::Database.mysql? if options[:null] != false sql << ' NULL' elsif options[:column].default.nil? - sql << ' DEFAULT 0' + # See: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14383 + sql << ' DEFAULT now()' end end -- cgit v1.2.1