Module: Gitlab::Database::MigrationHelpers::ConvertToBigint

Defined in:
lib/gitlab/database/migration_helpers/convert_to_bigint.rb

Constant Summary collapse

INDEX_OPTIONS_MAP =
{
  unique: :unique,
  order: :orders,
  opclass: :opclasses,
  where: :where,
  type: :type,
  using: :using,
  comment: :comment
}.freeze

Instance Method Summary collapse

Instance Method Details

#add_bigint_column_indexes(table_name, int_column_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/database/migration_helpers/convert_to_bigint.rb', line 37

def add_bigint_column_indexes(table_name, int_column_name)
  bigint_column_name = convert_to_bigint_column(int_column_name)

  unless column_exists?(table_name.to_s, bigint_column_name)
    raise "Bigint column '#{bigint_column_name}' does not exist on #{table_name}"
  end

  indexes(table_name).each do |i|
    next unless Array(i.columns).join(' ').match?(/\b#{int_column_name}\b/)

    create_bigint_index(table_name, i, int_column_name, bigint_column_name)
  end
end

#bigint_index_name(int_column_index_name) ⇒ Object

default ‘index_name’ method is not used because this method can be reused while swapping/dropping the indexes



52
53
54
55
56
# File 'lib/gitlab/database/migration_helpers/convert_to_bigint.rb', line 52

def bigint_index_name(int_column_index_name)
  # First 20 digits of the hash is chosen to make sure it fits the 63 chars limit
  digest = Digest::SHA256.hexdigest(int_column_index_name).first(20)
  "bigint_idx_#{digest}"
end

#columns_swapped?(table_name, column_name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/database/migration_helpers/convert_to_bigint.rb', line 27

def columns_swapped?(table_name, column_name)
  table_columns = columns(table_name.to_s)
  temp_column_name = convert_to_bigint_column(column_name)

  column = table_columns.find { |c| c.name == column_name.to_s }
  temp_column = table_columns.find { |c| c.name == temp_column_name }

  column.sql_type == 'bigint' && temp_column.sql_type == 'integer'
end

#com_or_dev_or_test_but_not_jh?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/gitlab/database/migration_helpers/convert_to_bigint.rb', line 17

def com_or_dev_or_test_but_not_jh?
  return true if Gitlab.dev_or_test_env?

  Gitlab.com? && !Gitlab.jh?
end

#temp_column_removed?(table_name, column_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/gitlab/database/migration_helpers/convert_to_bigint.rb', line 23

def temp_column_removed?(table_name, column_name)
  !column_exists?(table_name.to_s, convert_to_bigint_column(column_name))
end