gregwebs / haskell-heroku

Haskell helpers for deploying to Heroku
BSD 3-Clause "New" or "Revised" License
18 stars 6 forks source link

Make the library a bit more flexible internally #2

Closed crabmusket closed 11 years ago

crabmusket commented 11 years ago

I've refactored the library to allow it to search for different environment variables and database URI schemes. For example, I'm using a MongoHQ database where the environment variable is called "MONGOHQ_URL" and the database URL starts with mongo:.

gregwebs commented 11 years ago

Looks great! It seems that MongoHQ is a little ad-hoc. Do they work with a mongodb: prefix also?

crabmusket commented 11 years ago

Whoops, I meant a mongodb: prefix. MongoLab uses that URI as well, and the environment variable is called "MONGOLAB_URI". OpenRedis uses "OPENREDIS_URL" and redis:, so it seems like this is a common point of difference. This was the lowest-impact way I could see to do it, while keeping most of the existing code.

I should mention that test.hs still runs fine - there's no API change.

gregwebs commented 11 years ago

should there be a Web.Heroku.MongoDB with 'mongodb:' bound and a function for mongoHQ and mongoLab?

crabmusket commented 11 years ago

I have one waiting to pull request ;). I actually have Web.Heroku.MongoHQ that exports dbConnParams and parseDatabaseUrl with the MongoHQ settings. The idea would be to have another module again for MongoLab. Unless you'd prefer to have a single module per actual database.

gregwebs commented 11 years ago

Generally I prefer combining modules in a situation where there are few exports. It makes for a faster install time and a smaller hierarchy with just one file to open in an editor. I generally break out modules to manage import/export, keep module size small enough to comprehend, or create strong logical divisions. Not a big deal though

crabmusket commented 11 years ago

Hmm, I'm finding other changes I need to make to get this working properly with Mongo. I've fixed the issues I can find relating to this script, but when I push my code to Heroku I get a user error (connection timed out). I read that Yesod didn't support authenticating mongo connections ca. 2012. Is that still the case?

gregwebs commented 11 years ago

No, there is support in Persistent for auth connection parameters and they can be specified in the mongoDB.yaml file. But this is a url parser, so there may be some work to make it work with what persistent is expecting, maybe you can come up with the delta. I do see "database" instead of "dbname". Arguably persistent-mongoDB itself should be able to parse a connection url.

https://github.com/yesodweb/persistent/blob/master/persistent-mongoDB/Database/Persist/MongoDB.hs#L744

crabmusket commented 11 years ago

I found the problem. I was incorrectly parsing the port number, which I didn't leave to the default value. This is what I ended up with - and after we get MongoDB support in this module on Hackage then I'll be able to use it ;P.