views:

1582

answers:

4

I would like to use postgresql with foreign keys to define relationships in data so that other platforms/apps would also be able to easily use the same database. Having some kind of ruby DSL to define database schema with migration support would also be great. Which framework would you recommend for me?

Is there some kind of framework for only handling database schema changes, migrations and versions separate of ORM?

A: 

Is there a good reason not to use ActiveRecord? It's kind of a standard for Ruby...

DanSingerman
Yes. The OP wants ts share a database between multiple applications. This is not one of ActiveRecord's strong points.
finnw
Nothing about AR stops you doing that though.
DanSingerman
standard doesn't mean good. It's dependency on ActiveSupport might be dangerous for a standalone app.
SztupY
+2  A: 

Check out DataMapper. I recently used it with Sinatra and deployed the app to Heroku. The only SQL I had to write was CREATE DATABASE. Everything else DataMapper provided for me with the .auto_migrate! and .auto_upgrade! functionality.

The foreign key support is in the dm-constraints plugin.

Be aware that DataMapper is in version 0.9.11.

Jonas Elfström
I stopped reading when I saw "one-to-one mapping between rows and objects." That IMHO is a common mistake in ORM designs. The two projects I've worked on that used such systems ran into nasty problems with transactions.
finnw
Please elaborate, I fail to see the connection.
Jonas Elfström
and ActiveRecord has the same drawbacks anyway
SztupY
+2  A: 

Between ActiveRecord and DataMapper I'd chose the latter. Both use the Active Record pattern, so you'll actually get your database tables back in objects without fancy domain logic, but DataMapper is way easier to work with, and is thread-safe. There is also Sequel, but which I'm not familiar with.

If you need a framework to handle migrations I'd advise merb. Althoug it's a complete web framework starting 1.1 it can handle migrations for the three previously mentioned ORM framework (including separate and auto migrations)

SztupY
+1  A: 

M4DBI may also be of interest. A low-level ORM which leverages DBI to allow you to write raw SQL if you like.

Pistos
This looks like good work Pistos. Your rationale is right on the mark.
naturalethic