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

Query string in database URL is treated as part of the name by diesel database setup #1480

Closed
SamWhited opened this Issue Jan 15, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@SamWhited

SamWhited commented Jan 15, 2018

When setting up the database with diesel database setup any query string provided as part of the DSN is considered part of the database name. In the following example, I expect a database called "example" to be created:

Steps to reproduce

$ export DATABASE_URL=postgres://postgres@localhost/example?sslmode=disable
$ diesel database setup
Creating database: example?sslmode=disable
$ psql
postgres=# SELECT datname FROM pg_database WHERE datname LIKE 'example%';
        datname         
------------------------
 example?sslmode=disable

rokob added a commit to rokob/diesel that referenced this issue Jan 17, 2018

Handle query strings in database url
As per diesel-rs#1480 if the
DATABASE_URL is set to
`postgres://postgres@localhost/example?sslmode=disable` for example, the
database is parsed to be `example?sslmode=disable` rather than
`example`.

We add a test which fails without the additional code in this change.
The test ensures that `change_database_of_url` returns the proper
database name along with the full DSN including the query string as the
second return value.

Rather than going the full URL parsing route, we do the simple approach
of splitting at the the first `?` if one is present. Because of how the
query string is ultimately used this should be sufficient.

rokob added a commit to rokob/diesel that referenced this issue Jan 18, 2018

Handle query strings in database url
As per diesel-rs#1480 if the DATABASE_URL is set to has a query string, for example:

`postgres://postgres@localhost/example?sslmode=disable`

Then database is parsed to be `example?sslmode=disable` rather than `example`.

I added a test which fails without the additional code in this change. The test ensures that `change_database_of_url` returns the proper database name along with the full DSN including the query string as the second return value.

I used the url crate to handle the parsing, but followed the style of the function that current exists and just used unwrap instead of more friendly error handling.

rokob added a commit to rokob/diesel that referenced this issue Jan 19, 2018

Handle query strings in database url
As per diesel-rs#1480 if the DATABASE_URL is set to has a query string, for example:

`postgres://postgres@localhost/example?sslmode=disable`

Then database is parsed to be `example?sslmode=disable` rather than `example`.

I added a test which fails without the additional code in this change. The test ensures that `change_database_of_url` returns the proper database name along with the full DSN including the query string as the second return value.

I used the url crate to handle the parsing, but followed the style of the function that current exists and just used unwrap instead of more friendly error handling.

@sgrif sgrif closed this in #1490 Jan 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment