debian-mirror-gitlab/config/initializers/active_record_table_definition.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.2 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
# ActiveRecord custom method definitions with timezone information.
2019-12-04 20:38:33 +05:30
# See https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/11229
2017-09-10 17:25:29 +05:30
require 'active_record/connection_adapters/abstract/schema_definitions'
module ActiveRecord
module ConnectionAdapters
class TableDefinition
# Appends columns `created_at` and `updated_at` to a table.
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.timestamps_with_timezone
# end
def timestamps_with_timezone(**options)
options[:null] = false if options[:null].nil?
[:created_at, :updated_at].each do |column_name|
2021-02-22 17:27:13 +05:30
column(column_name, :datetime_with_timezone, **options)
2017-09-10 17:25:29 +05:30
end
end
# Adds specified column with appropriate timestamp type
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.datetime_with_timezone :did_something_at
# end
def datetime_with_timezone(column_name, **options)
2021-02-22 17:27:13 +05:30
column(column_name, :datetime_with_timezone, **options)
2017-09-10 17:25:29 +05:30
end
2018-11-18 11:00:15 +05:30
# Disable timestamp alias to datetime
def aliased_types(name, fallback)
fallback
end
2017-09-10 17:25:29 +05:30
end
end
end