Commit 4105f292 authored by Robert Speicher's avatar Robert Speicher

Display database type and version in Administration dashboard

Closes #12900
parent c4c919e5
......@@ -15,6 +15,7 @@ v 8.5.0 (unreleased)
- Don't vendor minified JS
- Display 404 error on group not found
- Track project import failure
- Display database type and version in Administration dashboard
- Fix visibility level text in admin area (Zeger-Jan van de Weg)
- Warn admin during OAuth of granting admin rights (Zeger-Jan van de Weg)
- Update the ExternalIssue regex pattern (Blake Hitchcock)
......
......@@ -92,6 +92,11 @@
Rails
%span.pull-right
#{Rails::VERSION::STRING}
%p
= Gitlab::Database.adapter_name
%span.pull-right
= Gitlab::Database.version
%hr
.row
.col-sm-4
......
module Gitlab
module Database
def self.adapter_name
connection.adapter_name
end
def self.mysql?
ActiveRecord::Base.connection.adapter_name.downcase == 'mysql2'
adapter_name.downcase == 'mysql2'
end
def self.postgresql?
ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
adapter_name.downcase == 'postgresql'
end
def self.version
database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
end
def true_value
case ActiveRecord::Base.connection.adapter_name.downcase
when 'postgresql'
if self.class.postgresql?
"'t'"
else
1
......@@ -18,12 +25,31 @@ module Gitlab
end
def false_value
case ActiveRecord::Base.connection.adapter_name.downcase
when 'postgresql'
if self.class.postgresql?
"'f'"
else
0
end
end
private
def self.connection
ActiveRecord::Base.connection
end
def self.database_version
row = connection.execute("SELECT VERSION()").first
if postgresql?
row['version']
else
row.first
end
end
def connection
self.class.connection
end
end
end
......@@ -14,4 +14,24 @@ describe Gitlab::Database, lib: true do
it { is_expected.to satisfy { |val| val == true || val == false } }
end
describe '.version' do
context "on mysql" do
it "extracts the version number" do
allow(described_class).to receive(:database_version).
and_return("5.7.12-standard")
expect(described_class.version).to eq '5.7.12-standard'
end
end
context "on postgresql" do
it "extracts the version number" do
allow(described_class).to receive(:database_version).
and_return("PostgreSQL 9.4.4 on x86_64-apple-darwin14.3.0")
expect(described_class.version).to eq '9.4.4'
end
end
end
end
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