Fix `datetime_with_timezone` multiple problems
## 1. The first `timestamp` column on each table in MySQL is NOT NULL and defaults to CURRENT_TIMESTAMP on update This is a MySQL "feature": https://bugs.mysql.com/bug.php?id=75098 This can cause unexpected master failures since we don't test MySQL on every branch, but we do on master, like in https://gitlab.com/gitlab-org/gitlab-ee/issues/3150#note_37391138. **Edit:** This was worked around in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13560, but it is not working for @vsizov [in the Rails 5 upgrade](https://gitlab.com/gitlab-org/gitlab-ce/issues/36405#note_40120201). **Update:** GitLab no longer supports MySQL. ## 2. Current ActiveRecord monkeypatch doesn't always generate schema with `datetime_with_timezone` See @yorickpeterse's example in [this comment](#note_37173148) > I have a migration that changes the type of two columns from `datetime` to `datetime_with_timezone` but they still get dumped as `t.datetime` in `db/schema.rb` **Update:** GitLab only supports Postgres and we use `db/structure.sql`, so we don't need to generate `db/schema.rb` with `datetime_with_timezone`. (We do have a `ee/db/geo/schema.rb` so perhaps it's possible there, but we haven't needed to do this kind of migration there. Also, we plan to migrate to `structure.sql` as well https://gitlab.com/gitlab-org/gitlab/-/issues/323806) ## 3. Current ActiveRecord monkeypatch doesn't work in Rails 5 After Rails 5 upgrade, the schema will no longer be generated with `datetime_with_timezone` columns, which will probably cause some confusion, and eventually inconsistent development/test DB setups. This was due to the following: Comment https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12841#note_35154488 > FYI In rails 5, they significantly rewrote DB adapters so this hack https://gitlab.com/gitlab-org/gitlab-ce/blob/master/config/initializers/active_record_data_types.rb#L64 does not work anymore... Comment https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12841#note_35174984 > I reverted the origin version of the `config/initializers/active_record_data_types.rb` monkey patch. It should unblock this MR but re-introduce schema dump problems, see the git log https://gitlab.com/gitlab-org/gitlab-ce/commits/master/config/initializers/active_record_data_types.rb **Update:** GitLab only supports Postgres and we use `db/structure.sql`, so we don't need to generate `db/schema.rb` with `datetime_with_timezone`. (We do have a `ee/db/geo/schema.rb` but I am unaware of this problem there. Also, we plan to migrate to `structure.sql` as well https://gitlab.com/gitlab-org/gitlab/-/issues/323806)
issue