Skip to content

Make postgrex respect env var PGDATABASE like libpq.#239

Merged
fishcakez merged 5 commits intoelixir-ecto:masterfrom
scouten:pgdatabase-env-var
Oct 1, 2016
Merged

Make postgrex respect env var PGDATABASE like libpq.#239
fishcakez merged 5 commits intoelixir-ecto:masterfrom
scouten:pgdatabase-env-var

Conversation

@scouten
Copy link
Copy Markdown

@scouten scouten commented Sep 20, 2016

I'd like to be able to configure my database name in production via environment variable and this would help. (FWIW I'm an Elixir and Ecto newbie. Happy to make changes if needed.)

@scouten
Copy link
Copy Markdown
Author

scouten commented Sep 20, 2016

Shamelessly modeled after #11.

Copy link
Copy Markdown
Member

@fishcakez fishcakez left a comment

Choose a reason for hiding this comment

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

Thanks, just a couple of minor things.


test "env var default db name" do
System.put_env("PGDATABASE", "postgrex_test")
opts = []
Copy link
Copy Markdown
Member

@fishcakez fishcakez Sep 26, 2016

Choose a reason for hiding this comment

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

sync_connect: true please so start_link blocks to connect

opts = []
assert {:ok, pid} = P.start_link(opts)
assert {:ok, %Postgrex.Result{}} = P.query(pid, "SELECT 123", [])
System.delete_env("PGDATABASE")
Copy link
Copy Markdown
Member

@fishcakez fishcakez Sep 26, 2016

Choose a reason for hiding this comment

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

If the test fails we won't reset, can you copy the dance done with try do..after.. end and PGPORT later in this file?

@scouten
Copy link
Copy Markdown
Author

scouten commented Sep 26, 2016

@fishcakez: Sure thing. It may take me a day or two to get to it, but happy to make the changes.

@fishcakez
Copy link
Copy Markdown
Member

fishcakez commented Sep 26, 2016

@scouten this is a feature you want so do as you wish 😄. It took a week for this to get reviewed so we were very slow on this end, sorry.

@fishcakez fishcakez added this to the v1.0 milestone Sep 27, 2016
@scouten
Copy link
Copy Markdown
Author

scouten commented Oct 1, 2016

@fishcakez: I've updated per your suggestions. Please re-review. Thanks!

Copy link
Copy Markdown
Member

@fishcakez fishcakez left a comment

Choose a reason for hiding this comment

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

Looks great, just need to delete some code. Sorry if there was a mixup here, we seem to be testing same thing twice.

{:ok, pid} = P.start_link(opts)
assert_receive {:EXIT, ^pid, {%Postgrex.Error{postgres: %{code: :invalid_catalog_name}}, [_|_]}}
end
after
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We only need to test this once, either with or without :sync_connect. I think the :sync_connect example is clearer as we would only needs to assert on thestart_linkreturn value. No need to check for the:EXIT`.

@scouten
Copy link
Copy Markdown
Author

scouten commented Oct 1, 2016

@fishcakez: Thanks for the quick review. Just pushed another update.

@fishcakez fishcakez merged commit 9f21718 into elixir-ecto:master Oct 1, 2016
@fishcakez
Copy link
Copy Markdown
Member

Thank you ❤️

@scouten scouten deleted the pgdatabase-env-var branch October 1, 2016 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants