Sha256: 0defbe2625cdeff6891f66976f2a6c141c2d63699e89a32023f6fd9448ada609

Contents?: true

Size: 1.32 KB

Versions: 26

Compression:

Stored size: 1.32 KB

Contents

module Marty::Diagnostic::Database
  def self.db_name
    ActiveRecord::Base.connection_config[:database]
  end

  def self.db_server_name
    ActiveRecord::Base.connection_config[:host] || 'undefined'
  end

  def self.db_adapter_name
    ActiveRecord::Base.connection.adapter_name
  end

  def self.db_time
    ActiveRecord::Base.connection.execute('SELECT NOW();')[0]['now']
  end

  def self.db_version
    ActiveRecord::Base.connection.execute('SELECT VERSION();')[0]['version']
  end

  def self.db_schema
    current = ActiveRecord::Migrator.current_version
    raise "Migration is needed.\nCurrent Version: #{current}" if
      ActiveRecord::Migrator.needs_migration?

    current.to_s
  end

  def self.get_postgres_connections
    conn = ActiveRecord::Base.connection.execute('SELECT datname,'\
                                                 'application_name,'\
                                                 'state,'\
                                                 'pid,'\
                                                 'client_addr '\
                                                 'FROM pg_stat_activity')
    conn.each_with_object({}) do |conn, h|
      h[conn['datname']] ||= []
      h[conn['datname']] << conn.except('datname')
    end
  end

  def self.current_connections
    get_postgres_connections[db_name]
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
marty-3.0.1 other/marty/diagnostic/database.rb
marty-4.0.0.rc2 other/marty/diagnostic/database.rb
marty-3.0.0 other/marty/diagnostic/database.rb
marty-2.9.3 other/marty/diagnostic/database.rb
marty-2.9.2 other/marty/diagnostic/database.rb
marty-2.9.1 other/marty/diagnostic/database.rb
marty-2.8.0 other/marty/diagnostic/database.rb
marty-2.7.3 other/marty/diagnostic/database.rb
marty-2.7.2 other/marty/diagnostic/database.rb
marty-2.7.1 other/marty/diagnostic/database.rb
marty-2.7.0 other/marty/diagnostic/database.rb
marty-2.6.8 other/marty/diagnostic/database.rb
marty-2.6.7 other/marty/diagnostic/database.rb
marty-2.6.6 other/marty/diagnostic/database.rb
marty-2.6.5 other/marty/diagnostic/database.rb
marty-2.6.4 other/marty/diagnostic/database.rb
marty-2.6.3 other/marty/diagnostic/database.rb
marty-2.6.2 other/marty/diagnostic/database.rb
marty-2.6.1 other/marty/diagnostic/database.rb
marty-2.6.0 other/marty/diagnostic/database.rb