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

parent 134df14c
...@@ -163,7 +163,7 @@ ...@@ -163,7 +163,7 @@
%span.float-right %span.float-right
#{Rails::VERSION::STRING} #{Rails::VERSION::STRING}
%p %p
= Gitlab::Database.adapter_name = Gitlab::Database.human_adapter_name
%span.float-right %span.float-right
= Gitlab::Database.version = Gitlab::Database.version
%p %p
......
...@@ -5,6 +5,6 @@ if defined?(Rails::Console) ...@@ -5,6 +5,6 @@ if defined?(Rails::Console)
puts "-------------------------------------------------------------------------------------" puts "-------------------------------------------------------------------------------------"
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})" puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}" 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 "-------------------------------------------------------------------------------------" puts "-------------------------------------------------------------------------------------"
end end
...@@ -27,6 +27,10 @@ module Gitlab ...@@ -27,6 +27,10 @@ module Gitlab
config['adapter'] config['adapter']
end end
def self.human_adapter_name
postgresql? ? 'PostgreSQL' : 'MySQL'
end
def self.mysql? def self.mysql?
adapter_name.casecmp('mysql2').zero? adapter_name.casecmp('mysql2').zero?
end end
......
...@@ -34,9 +34,6 @@ namespace :gitlab do ...@@ -34,9 +34,6 @@ namespace :gitlab do
puts "Sidekiq Version:#{Sidekiq::VERSION}" puts "Sidekiq Version:#{Sidekiq::VERSION}"
puts "Go Version:\t#{go_version[1] || "unknown".color(:red)}" 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") project = Group.new(path: "some-group").projects.build(path: "some-project")
# construct clone URLs # construct clone URLs
http_clone_url = project.http_url_to_repo http_clone_url = project.http_url_to_repo
...@@ -49,7 +46,8 @@ namespace :gitlab do ...@@ -49,7 +46,8 @@ namespace :gitlab do
puts "Version:\t#{Gitlab::VERSION}" puts "Version:\t#{Gitlab::VERSION}"
puts "Revision:\t#{Gitlab.revision}" puts "Revision:\t#{Gitlab.revision}"
puts "Directory:\t#{Rails.root}" 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 "URL:\t\t#{Gitlab.config.gitlab.url}"
puts "HTTP Clone URL:\t#{http_clone_url}" puts "HTTP Clone URL:\t#{http_clone_url}"
puts "SSH Clone URL:\t#{ssh_clone_url}" puts "SSH Clone URL:\t#{ssh_clone_url}"
......
...@@ -17,6 +17,20 @@ describe Gitlab::Database do ...@@ -17,6 +17,20 @@ describe Gitlab::Database do
end end
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 # These are just simple smoke tests to check if the methods work (regardless
# of what they may return). # of what they may return).
describe '.mysql?' do describe '.mysql?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment