Putting models into Gems (not plugins)

Hi, we internally are creating gems out of particular sets of models,
both to share them among multiple Rails apps, but also to use them
within background scripts.

If possible, I'd like for the models to function with ActiveRecord/
ActiveSupport as the only dependencies and not require a full Rails
environment. This is for the purposes of our background jobs which
use the same set of models. This way it becomes much easier to create
and modularize the background processes as they aren't dependent on
the full Rails environment.

I've run into a number of different problems trying to homebrew this
sort of thing. The latest comes from me trying to give each set of
models its own migrations table so that I can use many of them with
the same database.

Has someone put together a good solution for this? I've been hobbling
along with my own monkeypatches to things like ActiveRecord::Migrator
and so far this has proven a rather cumbersome solution.

The latest problem I've encountered was on our CI server only: I'm
getting a "No database selected" error after the test database is
purged and it's calling "SHOW TABLES". For some reason everything
works just dandy locally.

There's still some discussion on the best way to do that - see this
ticket:

https://rails.lighthouseapp.com/projects/8994/tickets/2058-rake-tasks-for-run-engine-migrations

--Matt Jones