kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
10 years ago
|
module OpenProject
|
||
14 years ago
|
# This module provides some information about the currently used database
|
||
|
# adapter. It can be used to write code specific to certain database
|
||
|
# vendors which, while not not encouraged, is sometimes necessary due to
|
||
|
# syntax differences.
|
||
|
|
||
|
module Database
|
||
|
# This method returns a hash which maps the identifier of the supported
|
||
|
# adapter to a regex matching the adapter_name.
|
||
|
def self.supported_adapters
|
||
|
@adapters ||= ({
|
||
10 years ago
|
mysql: /mysql/i,
|
||
10 years ago
|
postgresql: /postgres/i
|
||
14 years ago
|
})
|
||
|
end
|
||
|
|
||
14 years ago
|
# Get the raw name of the currently used database adapter.
|
||
14 years ago
|
# This string is set by the used adapter gem.
|
||
|
def self.adapter_name
|
||
|
ActiveRecord::Base.connection.adapter_name
|
||
|
end
|
||
|
|
||
|
# returns the identifier of the currently used database type
|
||
|
def self.name
|
||
10 years ago
|
supported_adapters.find(proc { [:unknown, //] }) { |_adapter, regex|
|
||
|
adapter_name =~ regex
|
||
14 years ago
|
}[0]
|
||
|
end
|
||
14 years ago
|
|
||
14 years ago
|
# Provide helper methods to quickly check the database type
|
||
10 years ago
|
# OpenProject::Database.mysql? returns true, if we have a MySQL DB
|
||
14 years ago
|
supported_adapters.keys.each do |adapter|
|
||
|
(class << self; self; end).class_eval do
|
||
10 years ago
|
define_method(:"#{adapter.to_s}?") { send(:name) == adapter }
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
|
# Return the version of the underlying database engine.
|
||
|
# Set the +raw+ argument to true to return the unmangled string
|
||
|
# from the database.
|
||
|
def self.version(raw = false)
|
||
10 years ago
|
case name
|
||
14 years ago
|
when :mysql
|
||
|
version = ActiveRecord::Base.connection.select_value('SELECT VERSION()')
|
||
|
when :postgresql
|
||
|
version = ActiveRecord::Base.connection.select_value('SELECT version()')
|
||
11 years ago
|
raw ? version : version.match(/\APostgreSQL (\S+)/i)[1]
|
||
14 years ago
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
end
|