Class: Gitlab::Database::AlterPartition

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/alter_partition.rb

Instance Method Summary collapse

Constructor Details

#initialize(partition_name, mode, target_database: nil, logger: Logger.new($stdout)) ⇒ AlterPartition

Returns a new instance of AlterPartition.



6
7
8
9
10
11
# File 'lib/gitlab/database/alter_partition.rb', line 6

def initialize(partition_name, mode, target_database: nil, logger: Logger.new($stdout))
  @partition_name = partition_name
  @mode = mode
  @target_database = target_database
  @logger = logger
end

Instance Method Details

#executeObject



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
# File 'lib/gitlab/database/alter_partition.rb', line 13

def execute
  unless allowed_partition?
    log("#{partition_name} is not listed as one of the allowed partitions, " \
      "only #{allowed_partitions.keys} #{allowed_partitions.keys.length > 1 ? 'are' : 'is'} allowed")
    log("Please consult the database dictionary files for further info.")
    return false
  end

  success = false

  EachDatabase.each_connection(only: target_database) do |connection, database_name|
    partition_data = TaskHelpers.get_partition_info(partition_name, connection)

    if partition_data.nil?
      log("Partition #{partition_name} not present on #{database_name}")
      next
    end

    next unless valid_for_mode?(partition_data, database_name)

    alter_partition(connection, database_name, partition_data)
    success = true
  end

  success
end