2015-10-07 06:30:10 -04:00
|
|
|
module Gitlab
|
|
|
|
module Database
|
2016-02-01 21:29:37 -05:00
|
|
|
def self.adapter_name
|
|
|
|
connection.adapter_name
|
|
|
|
end
|
|
|
|
|
2015-10-07 06:30:10 -04:00
|
|
|
def self.mysql?
|
2016-02-01 21:29:37 -05:00
|
|
|
adapter_name.downcase == 'mysql2'
|
2015-10-07 06:30:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.postgresql?
|
2016-02-01 21:29:37 -05:00
|
|
|
adapter_name.downcase == 'postgresql'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.version
|
|
|
|
database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
|
2015-10-07 06:30:10 -04:00
|
|
|
end
|
2015-12-09 10:31:42 -05:00
|
|
|
|
|
|
|
def true_value
|
2016-02-15 14:13:47 -05:00
|
|
|
if Gitlab::Database.postgresql?
|
2015-12-09 10:31:42 -05:00
|
|
|
"'t'"
|
|
|
|
else
|
|
|
|
1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def false_value
|
2016-02-15 14:13:47 -05:00
|
|
|
if Gitlab::Database.postgresql?
|
2015-12-09 10:31:42 -05:00
|
|
|
"'f'"
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
|
|
|
end
|
2016-02-01 21:29:37 -05:00
|
|
|
|
|
|
|
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-07 06:30:10 -04:00
|
|
|
end
|
|
|
|
end
|