File: active_record_table_definition.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (41 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

# ActiveRecord custom method definitions with timezone information.
# See https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/11229

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|
          column(column_name, :datetime_with_timezone, **options)
        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)
        column(column_name, :datetime_with_timezone, **options)
      end

      # Disable timestamp alias to datetime
      def aliased_types(name, fallback)
        fallback
      end
    end
  end
end