diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-15 09:09:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-15 09:09:53 +0000 |
commit | 260e9dadce54e1bafefa6c34a9f09bf6b70f5c18 (patch) | |
tree | 55a0c7a2d1602b56b6d6dde80164e50d7dc29512 /lib/gitlab/database/migration_helpers.rb | |
parent | 0702e2171fd180f79ed6c8841b97ddcc0264d9da (diff) | |
download | gitlab-ce-260e9dadce54e1bafefa6c34a9f09bf6b70f5c18.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database/migration_helpers.rb')
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 7a7906a42d0..642f8a0fde3 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -10,8 +10,6 @@ module Gitlab # https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS MAX_IDENTIFIER_NAME_LENGTH = 63 - - PERMITTED_TIMESTAMP_COLUMNS = %i[created_at updated_at deleted_at].to_set.freeze DEFAULT_TIMESTAMP_COLUMNS = %i[created_at updated_at].freeze # Adds `created_at` and `updated_at` columns with timezone information. @@ -28,33 +26,23 @@ module Gitlab # :default - The default value for the column. # :null - When set to `true` the column will allow NULL values. # The default is to not allow NULL values. - # :columns - the column names to create. Must be one - # of `Gitlab::Database::MigrationHelpers::PERMITTED_TIMESTAMP_COLUMNS`. + # :columns - the column names to create. Must end with `_at`. # Default value: `DEFAULT_TIMESTAMP_COLUMNS` # # All options are optional. def add_timestamps_with_timezone(table_name, options = {}) - options[:null] = false if options[:null].nil? columns = options.fetch(:columns, DEFAULT_TIMESTAMP_COLUMNS) - default_value = options[:default] - - validate_not_in_transaction!(:add_timestamps_with_timezone, 'with default value') if default_value columns.each do |column_name| validate_timestamp_column_name!(column_name) - # If default value is presented, use `add_column_with_default` method instead. - if default_value - add_column_with_default( - table_name, - column_name, - :datetime_with_timezone, - default: default_value, - allow_null: options[:null] - ) - else - add_column(table_name, column_name, :datetime_with_timezone, **options) - end + add_column( + table_name, + column_name, + :datetime_with_timezone, + default: options[:default], + null: options[:null] || false + ) end end @@ -1818,11 +1806,11 @@ into similar problems in the future (e.g. when new tables are created). end def validate_timestamp_column_name!(column_name) - return if PERMITTED_TIMESTAMP_COLUMNS.member?(column_name) + return if column_name.to_s.end_with?('_at') raise <<~MESSAGE Illegal timestamp column name! Got #{column_name}. - Must be one of: #{PERMITTED_TIMESTAMP_COLUMNS.to_a} + Must end with `_at`} MESSAGE end |