Add helper method to return a human-friendly name for database adapter

This commit is contained in:
Douglas Barbosa Alexandre 2019-03-21 17:05:01 -03:00
parent 134df14c1c
commit a86f48c79b
No known key found for this signature in database
GPG key ID: F1E98EF6393565A0
5 changed files with 22 additions and 6 deletions

View file

@ -163,7 +163,7 @@
%span.float-right
#{Rails::VERSION::STRING}
%p
= Gitlab::Database.adapter_name
= Gitlab::Database.human_adapter_name
%span.float-right
= Gitlab::Database.version
%p

View file

@ -5,6 +5,6 @@ if defined?(Rails::Console)
puts "-------------------------------------------------------------------------------------"
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}"
puts " #{Gitlab::Database.adapter_name}:".ljust(justify) + Gitlab::Database.version
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version
puts "-------------------------------------------------------------------------------------"
end

View file

@ -27,6 +27,10 @@ module Gitlab
config['adapter']
end
def self.human_adapter_name
postgresql? ? 'PostgreSQL' : 'MySQL'
end
def self.mysql?
adapter_name.casecmp('mysql2').zero?
end

View file

@ -34,9 +34,6 @@ namespace :gitlab do
puts "Sidekiq Version:#{Sidekiq::VERSION}"
puts "Go Version:\t#{go_version[1] || "unknown".color(:red)}"
# check database adapter
database_adapter = ActiveRecord::Base.connection.adapter_name.downcase
project = Group.new(path: "some-group").projects.build(path: "some-project")
# construct clone URLs
http_clone_url = project.http_url_to_repo
@ -49,7 +46,8 @@ namespace :gitlab do
puts "Version:\t#{Gitlab::VERSION}"
puts "Revision:\t#{Gitlab.revision}"
puts "Directory:\t#{Rails.root}"
puts "DB Adapter:\t#{database_adapter}"
puts "DB Adapter:\t#{Gitlab::Database.human_adapter_name}"
puts "DB Version:\t#{Gitlab::Database.version}"
puts "URL:\t\t#{Gitlab.config.gitlab.url}"
puts "HTTP Clone URL:\t#{http_clone_url}"
puts "SSH Clone URL:\t#{ssh_clone_url}"

View file

@ -17,6 +17,20 @@ describe Gitlab::Database do
end
end
describe '.human_adapter_name' do
it 'returns PostgreSQL when using PostgreSQL' do
allow(described_class).to receive(:postgresql?).and_return(true)
expect(described_class.human_adapter_name).to eq('PostgreSQL')
end
it 'returns MySQL when using MySQL' do
allow(described_class).to receive(:postgresql?).and_return(false)
expect(described_class.human_adapter_name).to eq('MySQL')
end
end
# These are just simple smoke tests to check if the methods work (regardless
# of what they may return).
describe '.mysql?' do