From 1e80a71bf1ae6dada4f5af13efa5f5a3da7f26e8 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 18 Mar 2020 11:26:09 +0100 Subject: [PATCH] Allow importing to a different port This allows me to import to a database running on port 12345, which I sometimes do need. --- lib/alchemy/tasks/helpers.rb | 3 +++ spec/tasks/helpers_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/alchemy/tasks/helpers.rb b/lib/alchemy/tasks/helpers.rb index df750f8ba7..243d6b54bc 100644 --- a/lib/alchemy/tasks/helpers.rb +++ b/lib/alchemy/tasks/helpers.rb @@ -58,6 +58,9 @@ def postgres_command(cmd = 'psql') if (host = database_config['host']) && (host != 'localhost') command << "--host='#{host}'" end + if (port = database_config['port']) + command << "--port=#{port}" + end command.join(' ') end diff --git a/spec/tasks/helpers_spec.rb b/spec/tasks/helpers_spec.rb index 10bf0098b1..0c09805790 100644 --- a/spec/tasks/helpers_spec.rb +++ b/spec/tasks/helpers_spec.rb @@ -181,6 +181,13 @@ class Foo it { is_expected.to include("PGPASSWORD='123456'") } end + context "when a port is set in the config file" do + before do + allow(File).to receive(:read).and_return("test:\n port: 5433") + end + it { is_expected.to include("--port=5433") } + end + context "when a host is set in the config file" do context "and the host is localhost" do it { is_expected.not_to include("--host=") }