FIX: add port information when backuping/restoring

This commit is contained in:
Régis Hanol 2014-07-30 17:20:25 +02:00
parent 78e33f1931
commit 5f620c5b98
3 changed files with 6 additions and 1 deletions

View File

@ -99,7 +99,7 @@ module BackupRestore
SQL
end
DatabaseConfiguration = Struct.new(:host, :username, :password, :database)
DatabaseConfiguration = Struct.new(:host, :port, :username, :password, :database)
def self.database_configuration
config = Rails.env.production? ? ActiveRecord::Base.connection_pool.spec.config : Rails.configuration.database_configuration[Rails.env]
@ -107,6 +107,7 @@ module BackupRestore
DatabaseConfiguration.new(
config["host"],
config["port"],
config["username"] || ENV["USER"] || "postgres",
config["password"],
config["database"]

View File

@ -172,6 +172,7 @@ module Export
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present?
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
port_argument = "--port=#{db_conf.port}" if db_conf.port.present?
username_argument = "--username=#{db_conf.username}" if db_conf.username.present?
[ password_argument, # pass the password to pg_dump (if any)
@ -182,6 +183,7 @@ module Export
"--no-privileges", # prevent dumping of access privileges
"--verbose", # specifies verbose mode
host_argument, # the hostname to connect to (if any)
port_argument, # the port to connect to (if any)
username_argument, # the username to connect as (if any)
db_conf.database # the name of the database to dump
].join(" ")

View File

@ -218,6 +218,7 @@ module Import
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present?
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
port_argument = "--port=#{db_conf.port}" if db_conf.port.present?
username_argument = "--username=#{db_conf.username}" if db_conf.username.present?
[ password_argument, # pass the password to psql (if any)
@ -226,6 +227,7 @@ module Import
"--file='#{@dump_filename}'", # read the dump
"--single-transaction", # all or nothing (also runs COPY commands faster)
host_argument, # the hostname to connect to (if any)
port_argument, # the port to connect to (if any)
username_argument # the username to connect as (if any)
].join(" ")
end