gitlab-org--gitlab-foss/lib/gitlab/database.rb
Connor Shea 377583a361
Enable Rubocop Casecmp Performance Cop.
Also fixes the errors caused by enabling the cop. casecmp is more performant than `.downcase` and `==`.
2016-05-10 18:23:25 -06:00

51 lines
840 B
Ruby

module Gitlab
module Database
def self.adapter_name
connection.adapter_name
end
def self.mysql?
adapter_name.casecmp('mysql2').zero?
end
def self.postgresql?
adapter_name.casecmp('postgresql').zero?
end
def self.version
database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
end
def true_value
if Gitlab::Database.postgresql?
"'t'"
else
1
end
end
def false_value
if Gitlab::Database.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
end
end