Sha256: b3b29d96dd72caeef3b69657d969fb7a4b0dec6d14100c848933e3dad0e6d568

Contents?: true

Size: 984 Bytes

Versions: 39

Compression:

Stored size: 984 Bytes

Contents

require_relative 'database_backup_adapter'

class PostgresqlBackupAdapter < DatabaseBackupAdapter
  def create_backup(file)
    `#{password_option} pg_dump --verbose -Fc \
    #{host_option} #{username_option} --file #{file} \
    #{database}
    `
  end

  def restore(file)
    `#{password_option} pg_restore --verbose --clean --no-acl --no-owner \
    #{host_option} #{username_option} -d #{database} \
    #{file}`
  end

  private

  def db_option(name)
    value = db_config(name)
    if (value)
      "--#{name}=#{value}"
    else
      ""
    end
  end

  def username_option
    db_option('username')
  end

  def password_option
    password = db_config('password')
    if password
      password_option = "PGPASSWORD=\"#{password}\""
    else
      password_option = ""
    end
  end

  def host_option
    db_option('host')
  end

  def database
    db_config "database"
  end

  def db_config(key)
    Rails.configuration.database_configuration[Rails.env][key]
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
jefferies_tube-1.2 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.1.1 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.1.0 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.5 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.4 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.3 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.2 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.1 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-1.0.0 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.9 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.8 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.7 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.6 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.5 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.4 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.3 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.2 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.1 lib/jefferies_tube/postgresql_backup_adapter.rb
jefferies_tube-0.1.0 lib/jefferies_tube/postgresql_backup_adapter.rb