class Brillo::Adapter::Postgres

Public Instance Methods

load_command() click to toggle source
# File lib/brillo/adapter/postgres.rb, line 4
def load_command
  host = config["host"] ? "--host #{config["host"]}" : ""
  password = config["password"] ? "PGPASSWORD=#{config["password"]} " : ""
  search_path = config["schema_search_path"] ? "PGOPTIONS=--search_path=#{config["schema_search_path"]} " : ""
  inline_options = password + search_path
  "#{inline_options}psql #{host} -U #{config.fetch("username")} #{config.fetch("database")}"
end
recreate_db() click to toggle source
Calls superclass method Brillo::Adapter::Base#recreate_db
# File lib/brillo/adapter/postgres.rb, line 22
      def recreate_db
        logger.info "Dropping all connections to #{config[:database]}"
        ActiveRecord::Base.connection.execute(
          <<-SQL
          -- Disconnect all others from the database we are about to drop.
          -- Without this, the drop will fail and so the load will abort.
          SELECT pg_terminate_backend(pg_stat_activity.pid)
          FROM pg_stat_activity
          WHERE pg_stat_activity.datname = '#{config[:database]}'
            AND pid <> pg_backend_pid();
          SQL
        )
        super
      end