# Engines and migrations

**URL:** <https://www.ruby-forum.com/t/engines-and-migrations/91653>\
**Category:** Rails\
**Created:** [April 11, 2007, 6:41am UTC](https://www.ruby-forum.com/t/engines-and-migrations/91653 "2007-04-11T06:41:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [April 11, 2007, 6:41am UTC](https://www.ruby-forum.com/t/engines-and-migrations/91653/1 "2007-04-11T06:41:15Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [April 11, 2007, 10:45am UTC](https://www.ruby-forum.com/t/engines-and-migrations/91653/2 "2007-04-11T10:45:17Z")

</div>

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:

Rails.plugins[:shared\_plugin].migrate(5)

…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  
dynamically.

HTH

James

On Apr 11, 5:41 am, Raymond O’Connor \<rails-mailing-l…@andreas-
