diff --git a/lib/backup_restore.rb b/lib/backup_restore.rb index f3e676b93e7..64c37cd5749 100644 --- a/lib/backup_restore.rb +++ b/lib/backup_restore.rb @@ -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"] diff --git a/lib/export/exporter.rb b/lib/export/exporter.rb index 19ca277e861..21068e62210 100644 --- a/lib/export/exporter.rb +++ b/lib/export/exporter.rb @@ -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(" ") diff --git a/lib/import/importer.rb b/lib/import/importer.rb index 5e1be7693a4..f4c6ddd9d67 100644 --- a/lib/import/importer.rb +++ b/lib/import/importer.rb @@ -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