Sha256: 28fa45f408a1d5a45056532d3ae833b0b4b0a4e41b055dfe0b78d1e7cf8f9972

Contents?: true

Size: 1.32 KB

Versions: 17

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
        ::Marty::RailsApp.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

17 entries across 17 versions & 1 rubygems

Version Path
marty-14.3.0 lib/marty/diagnostic/database.rb
marty-14.0.0 lib/marty/diagnostic/database.rb
marty-13.0.2 lib/marty/diagnostic/database.rb
marty-11.0.0 lib/marty/diagnostic/database.rb
marty-10.0.3 lib/marty/diagnostic/database.rb
marty-10.0.2 lib/marty/diagnostic/database.rb
marty-10.0.0 lib/marty/diagnostic/database.rb
marty-9.5.1 lib/marty/diagnostic/database.rb
marty-9.5.0 lib/marty/diagnostic/database.rb
marty-9.3.3 lib/marty/diagnostic/database.rb
marty-9.3.2 lib/marty/diagnostic/database.rb
marty-9.3.0 lib/marty/diagnostic/database.rb
marty-8.5.0 lib/marty/diagnostic/database.rb
marty-8.4.1 lib/marty/diagnostic/database.rb
marty-8.3.1 lib/marty/diagnostic/database.rb
marty-8.2.0 lib/marty/diagnostic/database.rb
marty-8.0.0 lib/marty/diagnostic/database.rb