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

Allow url to include the username/password #2132

Closed
AlJohri opened this issue Sep 5, 2018 · 9 comments
Closed

Allow url to include the username/password #2132

AlJohri opened this issue Sep 5, 2018 · 9 comments

Comments

@AlJohri
Copy link

@AlJohri AlJohri commented Sep 5, 2018

Which version and edition of Flyway are you using?

Flyway Community Edition 5.1.4 by Boxfuse

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

Command-line

Which database are you using (type & version)?

Postgres 10.0

Which operating system are you using?

macOS

Currently, FLYWAY_URL only accepts jdbc:postgresql://{host}:{port}/{dbname}'. I tried giving it a full database uri such as: jdbc:postgresql://{user}:{pass}@{host}:{port}/{dbname} but that didn't work- it still asked me for the username.

Any chance it can parse out the user and pass right out of the FLYWAY_URL?

Thanks!

@axelfontaine axelfontaine changed the title [feature request] allow flyway_url to include the username/password Allow url to include the username/password Sep 20, 2018
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Sep 20, 2018

Did it work with -n? See https://flywaydb.org/documentation/commandline/#credentials

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Oct 3, 2018

Any news?

@AlJohri
Copy link
Author

@AlJohri AlJohri commented Oct 3, 2018

sorry, haven't gotten a chance to test yet. will do!

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Oct 17, 2018

Closing due to lack of response.

@AlJohri
Copy link
Author

@AlJohri AlJohri commented Nov 21, 2018

@axelfontaine let's re-open this issue. it did not work.

attempt one:

FLYWAY_URL=jdbc:postgresql://root:mypass@myhost/mydb flyway -n migrate
Flyway Community Edition 5.2.1 by Boxfuse
Nov 21, 2018 5:33:47 PM org.postgresql.Driver parseURL
WARNING: JDBC URL invalid port number: mypass@myhost
ERROR: java.lang.NullPointerException

attempt two:

FLYWAY_URL=jdbc:postgresql://root:mypass@myhost:5432/mydb flyway -n migrate

fails with:

Flyway Community Edition 5.2.1 by Boxfuse
ERROR:
Unable to obtain connection from database (jdbc:postgresql://root:mypass@myhost:5432/mydb) for user 'null': The connection attempt failed.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State  : 08001
Error Code : 0
Message    : The connection attempt failed.

here's my wishlist of ways I wish FLYWAY could smartly parse the database url:

  • handle postgres or postgresql (allows keeping consistent with libpq
  • allow dropped jdbc:. it should be assumed, I'm passing in an environment variable called FLYWAY_URL, it's meant specifically for flyway
  • allow defaulting the port 5432 for postgres. it thought everything before the slash until the first colon was the port. for example, in root:mypass@myhost/mydb it think the port is mypass@myhost. this can be parsed out slightly smarter to prevent this
  • and last but not least, take the username and password from the FLYWAY_URL itself

I would be happy to help with any and all of the above. thanks @axelfontaine!

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Nov 22, 2018

Note that this is primarily a limitation of the PostgreSQL JDBC driver, so I opened an issue directly with them: pgjdbc/pgjdbc#1346

Note that they already do support the following syntax:

jdbc:postgresql://localhost/test?user=fred&password=secret

@axelfontaine axelfontaine removed this from the Flyway 6.0.0 milestone Nov 22, 2018
@axelfontaine axelfontaine added this to the Someday-Maybe milestone Nov 22, 2018
@AlJohri
Copy link
Author

@AlJohri AlJohri commented Jul 9, 2019

hey @axelfontaine I just tried using jdbc:postgresql://localhost/test?user=fred&password=secret but it still asks for the user and password

flyway -url="jdbc:postgresql://host-dev-us-east-1.perso.aws.arc.pub:5432/history?user=uzr&password=psswrd" -locations="filesystem:$(pwd)/sql" migrate

@MikielAgutu MikielAgutu removed this from the On the Radar milestone Mar 19, 2020
@MikielAgutu MikielAgutu added this to the Flyway 6.3.2 milestone Mar 19, 2020
@juliahayward
Copy link
Member

@juliahayward juliahayward commented Mar 19, 2020

V6.3.2 will not prompt if it sees user and password in the URL (in the form the Postgres driver is happy with, such as ?user=foo&password=bar)

@kyr0
Copy link

@kyr0 kyr0 commented Dec 8, 2021

Can confirm that this approach doesn't work with the gradle plugin + JDBC/MySQL, unfortunately

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

No branches or pull requests

5 participants