diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /config/initializers/active_record_data_types.rb | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'config/initializers/active_record_data_types.rb')
-rw-r--r-- | config/initializers/active_record_data_types.rb | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/config/initializers/active_record_data_types.rb b/config/initializers/active_record_data_types.rb deleted file mode 100644 index 7f4bd32c221..00000000000 --- a/config/initializers/active_record_data_types.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -# ActiveRecord custom data type for storing datetimes with timezone information. -# See https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/11229 - -require 'active_record/connection_adapters/postgresql_adapter' - -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 = type_map) - super mapping - - register_class_with_precision( - mapping, - 'timestamptz', - ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::DateTimeWithTimeZone - ) - 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 - -def connection_active? - ActiveRecord::Base.connection.active? # rubocop:disable Database/MultipleDatabases -rescue StandardError - false -end - -# Ensure `datetime_with_timezone` columns are correctly written to schema.rb -ActiveRecord::Base.connection.send(:reload_type_map) if connection_active? - -ActiveRecord::Base.time_zone_aware_types += [:datetime_with_timezone] |