Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use URL instead authentication and connectivity options for PostgreSQL #837

Closed
wants to merge 1 commit into from

Conversation

dzhlobo
Copy link

@dzhlobo dzhlobo commented Feb 1, 2017

Instead of specifying separte options and credentials:

  database PostgreSQL do |db|
    db.name               = "database_name"
    db.username           = "username"
    db.password           = "password"
    db.host               = "localhost"
    db.port               = 5432
  end

users may user just one -- url:

  database PostgreSQL do |db|
    db.url = "postgres://my_username:password@localhost:5432/my_database_name"
  end

Fixes backup/backup-features#39

Instead of specifying separte options and credentials:

  database PostgreSQL do |db|
    db.name               = "database_name"
    db.username           = "username"
    db.password           = "password"
    db.host               = "localhost"
    db.port               = 5432
  end

users may user just one -- `url`:

  database PostgreSQL do |db|
    db.url = "postgres://my_username:password@localhost:5432/my_database_name"
  end
@jandudulski
Copy link

Any chance to have this soon? @mrrooijen

@tombruijn
Copy link
Member

He doesn't do anything with backup anymore.

end

def pgdump_arguments
if url.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would turn this if statement around.

if url
  # options based on url
else
  # username + password method
end

"#{username_option} #{connectivity_options} #{user_options} #{tables_to_dump} " \
"#{tables_to_skip} #{name}"
else
"#{user_options} #{tables_to_dump} #{tables_to_skip} #{url}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also make this options string like this?
That way we don't have to duplicate certain options in both strings.

args = "#{tables_to_dump} #{tables_to_skip} #{user_options}"
if url
  args << " #{url}"
else
  args << " #{username_option} #{connectivity_options} #{name}"
end
args

expect(db.send(:pgdump)).to eq(
"pg_dump #{" " * (option_methods.count - 1)}"
)
context "when url is set" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when url option is set

)
end
# password_option and sudo_option leave no leading space if it's not used
context "when url is not set" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when username and password options are set

expect(db.send(:pgdump_arguments)).to eq "#{option_methods.join(" ")} #{db.url}"
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how it's testing a private method and stubbing all the option methods. But since that's how the rest of this spec is set up I'll allow it.

@@ -22,6 +22,10 @@ class Error < Backup::Error; end
attr_accessor :host, :port, :socket

##
# URL includes credentials and connectivity options
attr_accessor :url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also output a warning when this option is used in combination with the username, password, name, host, port, socket, etc options, otherwise people might use both while most options are ignored when the url option is used.
Should include some testing for that as well

For example:

def check_options
  return unless url
  ignored_options = {
    username: username,
    password: password,
    host: host,
    port: port,
    socket: socket,
    name: name
  }.reject { |_, value| value.nil? }
  return if ignored_options.empty?

  Logger.warn "PostgreSQL: the options " \
    "#{ignored_options.keys.join(", ")} are set, but will be " \
    "ignored because the `:url` option is set."
end

and call this method in the perform method, or in the initializer.

@stale
Copy link

stale bot commented Nov 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 24, 2020
@stale stale bot closed this Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support database url for PostgreSQL
3 participants