Class: GitLab::Exporter::CLI::DatabaseRowCounts

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/cli.rb

Overview

Database row counts query runner.

This will take the database connection and print the result to STDOUT

Constant Summary collapse

COMMAND_NAME =
"row-counts".freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ DatabaseRowCounts

Returns a new instance of DatabaseRowCounts.



126
127
128
129
130
131
132
# File 'lib/gitlab_exporter/cli.rb', line 126

def initialize(args)
  @options = options(args)
  @options.parse!

  @target = args.shift || STDOUT
  @target = File.open(@target, "a") if @target.is_a?(String)
end

Instance Method Details

#helpObject



143
144
145
# File 'lib/gitlab_exporter/cli.rb', line 143

def help
  @options.help
end

#options(args) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/gitlab_exporter/cli.rb', line 134

def options(args)
  args.options do |opts|
    opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options]"
    opts.on("--db-conn=\"dbname=test port=5432\"", "Database connection string") do |val|
      @db_connection_string = val
    end
  end
end

#runObject



147
148
149
150
151
152
153
# File 'lib/gitlab_exporter/cli.rb', line 147

def run
  validate!

  ::GitLab::Exporter::Database::RowCountProber.new(connection_string: @db_connection_string)
                                              .probe_db
                                              .write_to(@target)
end