Sha256: da9a53547b784d58b2765e47d4c9799491958b5b05278f477e46531f634fd885

Contents?: true

Size: 1.37 KB

Versions: 55

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'avm/postgresql/instance/data_unit'

module Avm
  module Postgresql
    class Instance
      def initialize(env, connection_params)
        @env = env
        @connection_params = connection_params.with_indifferent_access
      end

      def data_unit
        ::Avm::Postgresql::Instance::DataUnit.new(self)
      end

      def dump_command
        env.command('pg_dump', '--no-privileges', '--clean', '--no-owner', *common_command_args)
           .envvar('PGPASSWORD', password)
      end

      def dump_gzip_command
        dump_command.append(['@ESC_|', 'gzip', '-9', '-c'])
      end

      def psql_command
        env.command("@ESC_PGPASSWORD=#{password}", 'psql', *common_command_args)
      end

      def psql_command_command(sql)
        psql_command.append(['--quiet', '--tuples-only', '--command', sql])
      end

      private

      attr_reader :env, :connection_params

      def common_command_args
        ['--host', host, '--username', user, '--port', port, name]
      end

      def host
        connection_params[:host] || '127.0.0.1'
      end

      def port
        connection_params[:port] || '5432'
      end

      def user
        connection_params.fetch(:user)
      end

      def password
        connection_params.fetch(:password)
      end

      def name
        connection_params.fetch(:name)
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
avm-tools-0.113.2 lib/avm/postgresql/instance.rb
avm-tools-0.113.1 lib/avm/postgresql/instance.rb
avm-tools-0.113.0 lib/avm/postgresql/instance.rb
avm-tools-0.112.0 lib/avm/postgresql/instance.rb
avm-tools-0.111.0 lib/avm/postgresql/instance.rb
avm-tools-0.110.0 lib/avm/postgresql/instance.rb
avm-tools-0.109.1 lib/avm/postgresql/instance.rb
avm-tools-0.109.0 lib/avm/postgresql/instance.rb
avm-tools-0.108.0 lib/avm/postgresql/instance.rb
avm-tools-0.107.0 lib/avm/postgresql/instance.rb
avm-tools-0.106.0 lib/avm/postgresql/instance.rb
avm-tools-0.105.0 lib/avm/postgresql/instance.rb
avm-tools-0.104.0 lib/avm/postgresql/instance.rb
avm-tools-0.103.1 lib/avm/postgresql/instance.rb
avm-tools-0.103.0 lib/avm/postgresql/instance.rb
avm-tools-0.102.2 lib/avm/postgresql/instance.rb
avm-tools-0.102.1 lib/avm/postgresql/instance.rb
avm-tools-0.102.0 lib/avm/postgresql/instance.rb
avm-tools-0.101.0 lib/avm/postgresql/instance.rb
avm-tools-0.100.0 lib/avm/postgresql/instance.rb