JOOQ on Heroku with Maven

177 views
Skip to first unread message

Robert DiFalco

unread,
Jan 14, 2015, 7:09:57 PM1/14/15
to jooq...@googlegroups.com
Is anyone using JOOQ on heroku and with heroku postgres? Here's my issue...and it may just be more of a maven question.

So I can just git push heroku master and it pushes all my source and kicks off a maven build. This SHOULD invoke my flyway migration and then generate JOOQ source. But now I am doing this programmatically in my application startup which is not ideal.

There is just one silly reason I do it this way, on all my apps my database is on DATABASE_URL which is a heroku style string that includes the driver, host, port, username, and password of a database in one HTTP URL string. 

I can't figure out the simple way to parse this in maven and give it to JOOQ and Flyway as a JDBC URL with a username and password. I'm not very maven savvy.

I *COULD* create a new configuration setting on each heroku app as well as my dev machines but then I would have to remember to update DATABASE_JDBC_URL every time DATABASE_URL changes.

I know, this is not a huge issue, but it's just one tiny thing I'm stuck on and was wondering if any one else solved it in an automated manner. Parsing the DATABASE_URL is pretty easy in code, it's just:

URI uri = new URI(databaseURL);

String jdbcUrl =
 
String.format(
 
"jdbc:%s://%s:%s/%s",
 
"postgresql", uri.getHost(), uri.getPort(), uri.getPath().substring(1));

Properties props = new Properties();

String[] credentials = uri.getUserInfo().split(":");
props
.setProperty("user", credentials[0]);
props
.setProperty("password", credentials[1]);

And it's really only valuable if I can do this for both Flyway AND jOOQ.

Thanks

Lukas Eder

unread,
Jan 15, 2015, 1:43:45 AM1/15/15
to jooq...@googlegroups.com
Instead of parsing a pre-composed URL, I'd suggest composing the different URLs from their parts and loading the parts from an external properties file.

I've also given this answer to your question on Stack Overflow:

For the record, I'll also post it here:

There are probably myriad ways to solve this with Maven, but one option is to keep a single properties file in your /src/main/resources path, load it using the properties-maven-plugin (an example can be seen in the jOOQ-Spring example), and then compose URLs using the individual parts, e.g. jOOQ and Flyway:

<url>jdbc:postgresql://${db.host}:${db.port}/${db.database}</url>
<user>${db.username}</user>
<password>${db.password}</password>

Heroku:

<database_url>postgres://${db.username}:${db.password}@${db.host}:${db.port}/${db.databa

Cheers
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert DiFalco

unread,
Jan 15, 2015, 2:01:01 AM1/15/15
to jooq...@googlegroups.com
Thanks that will work as long as I can read it from the ENVIRONMENT and nothing goes into the src/main/resources directory that has any database information. But if it's just patterns in there that could work. I'll take a look at the examples.

Lukas Eder

unread,
Jan 15, 2015, 2:07:59 AM1/15/15
to jooq...@googlegroups.com
2015-01-15 8:01 GMT+01:00 Robert DiFalco <robert....@gmail.com>:
Thanks that will work as long as I can read it from the ENVIRONMENT

OK OK YOU'RE RIGHT!

;-)

Sorry, just kidding.
 
and nothing goes into the src/main/resources directory that has any database information. But if it's just patterns in there that could work. I'll take a look at the examples.

I'm actually a bit of a Maven dunce myself, but I guess you could use profiles to load the right properties file depending on the environment you're using

Cheers
Lukas
Reply all
Reply to author
Forward
0 new messages