Forum: Ruby on Rails Engines and migrations

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2ebf42f8625b86c0e91ae7bd4e2bef52?d=identicon&s=25 Raymond O'Connor (nappin)
on 2007-04-11 06:41
I'm writing two apps.  App_1 uses a subset of models (and thus
migrations) of App_2, and both apps use the same database.  At first I
thought engines would be the perfect way to include the models and
migrations in both apps while keeping things DRY, but I'm a little
uneasy as to how the migrations will work.

From my understanding all the models and migrations used in both apps
will go into the engine.  Then in App_2, I can call a command to append
all the migrations in the engine onto the migrations already in
db/migrations folder.  The problem is App_1 has all the same migrations
except they start at 001, while in App_2 they start at a later version,
which leads to problems migrating.

Do I understand how to use engines correctly?  Is there a better
approach to writing multiple apps, while keeping things DRY?

05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2007-04-11 10:45
(Received via mailing list)
There shouldn't be a problem here. If you had your shared migration in
a plugin, the engines plugin provides the "script/generate
plugin_migration" command to perform these migrations *at whatever
point your application is currently at*.

In practice, this means that in App_1, you might end up with
RAILS_ROOT/db/migrate/002_migrate_shared_plugin_to_version_1.rb, and
in App_2 you may get RAILS_ROOT/db/migrate/
152_migrate_shared_plugin_to_version_1.rb, but of which should run
fine (presuming that your shared migration doesn't depend on anything
in the current DB state).

I think the misunderstanding is here: "I can call a command to append
all the migrations in the engine onto the migrations already in db/
migrations folder." The migrations from the plugin are never appended,
copied or moved. Instead, they are called in a single command within
the RAILS_ROOT/db/migrate generated migration:


...which would run all of the migrations (up to version 5, in this
case, but normally this is just the latest version) in the plugin



On Apr 11, 5:41 am, Raymond O'Connor <rails-mailing-l...@andreas-
This topic is locked and can not be replied to.