BigW Consortium Gitlab

database.rb 840 Bytes
Newer Older
1 2
module Gitlab
  module Database
3 4 5 6
    def self.adapter_name
      connection.adapter_name
    end

7
    def self.mysql?
8
      adapter_name.casecmp('mysql2').zero?
9 10 11
    end

    def self.postgresql?
12
      adapter_name.casecmp('postgresql').zero?
13 14 15 16
    end

    def self.version
      database_version.match(/\A(?:PostgreSQL |)([^\s]+).*\z/)[1]
17
    end
18 19

    def true_value
20
      if Gitlab::Database.postgresql?
21 22 23 24 25 26 27
        "'t'"
      else
        1
      end
    end

    def false_value
28
      if Gitlab::Database.postgresql?
29 30 31 32 33
        "'f'"
      else
        0
      end
    end
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

    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
50 51
  end
end