debian-mirror-gitlab/lib/gitlab/database.rb

52 lines
840 B
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
module Gitlab
module Database
2016-04-02 18:10:28 +05:30
def self.adapter_name
connection.adapter_name
end
2015-10-24 18:46:33 +05:30
def self.mysql?
2016-06-02 11:05:42 +05:30
adapter_name.casecmp('mysql2').zero?
2015-10-24 18:46:33 +05:30
end
def self.postgresql?
2016-06-02 11:05:42 +05:30
adapter_name.casecmp('postgresql').zero?
2016-04-02 18:10:28 +05:30
end
def self.version
database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
2015-10-24 18:46:33 +05:30
end
2015-12-23 02:04:40 +05:30
def true_value
2016-04-02 18:10:28 +05:30
if Gitlab::Database.postgresql?
2015-12-23 02:04:40 +05:30
"'t'"
else
1
end
end
def false_value
2016-04-02 18:10:28 +05:30
if Gitlab::Database.postgresql?
2015-12-23 02:04:40 +05:30
"'f'"
else
0
end
end
2016-04-02 18:10:28 +05:30
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
2015-10-24 18:46:33 +05:30
end
end