# The state of Rails 2.3 / Engines migrations

**URL:** <https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200>\
**Category:** Engines\
**Created:** [February 9, 2010, 10:43pm UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200 "2010-02-09T22:43:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [February 9, 2010, 10:43pm UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200/1 "2010-02-09T22:43:33Z")

</div>

Hey everyone,

I’ve been out of the loop for a minute regarding engines, but I’m  
looking to update Substruct to Engines 2.3/Rails 2.3 if possible.

My last investigation stopped when running into the migrations issue.  
I’m wondering if there is a recommended way to handle engine  
migrations / legacy migrations (001\_my\_migration.rb) with 2.3. The  
official site mentions some “things being in the works” but I didn’t  
really see anything past that.

Any advice or a link to a blog post would be cool. Thanks much.

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [February 9, 2010, 10:47pm UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200/2 "2010-02-09T22:47:39Z")

</div>

I’ve been handling them by including a generator in my plugin, which  
generates a migration (or possibly multiple migrations). You’d have to  
generate and run the migration in each app using the plugin, which is a  
bit  
clunky, but seems to be okay as a workaround.

Nat

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [February 9, 2010, 10:54pm UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200/3 "2010-02-09T22:54:05Z")

</div>

Having just taken the plunge and updated my old 2.0.2 site to 2.3.5 with  
all the trimmings, I can offer a few thoughts.

The latest engines plugin does handle legacy migrations, but you need to  
do some tweaking.

First off, you need to set Rails to use numeric migrations, or you’ll  
have lots of headaches. Alternately, I suppose you can manually  
timestamp your old migrations, but I haven’t tried that one yet… You  
can set Rails to use numeric migrations by setting:  
config.active\_record.timestamped\_migrations = false

Once that’s done, you need (possibly) to run: rake  
db:migrate:upgrade\_plugin\_migration

This will make sure you have the proper DB tables, and put an entry into  
that table for every old plugin migrations you have, in the format  
“\<#\>-”

At this point, you should be in good shape. Your db state matches your  
code state, with one entry in schema\_migrations for every plugin  
migration and every main app migration.

The final trick is to use: rake db:migrate:all

Use this to upgrade your DB instead of the old ./script/generate  
plugin\_migration bit. The engines plugin will run all existing plugins,  
find all new migrations, and apply them correctly.

Hope that helps!

-Rob

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [August 27, 2010, 3:26am UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200/4 "2010-08-27T03:26:11Z")

</div>

Rob M. wrote:

> Having just taken the plunge and updated my old 2.0.2 site to 2.3.5 with  
> all the trimmings, I can offer a few thoughts.
> 
> The latest engines plugin does handle legacy migrations, but you need to  
> do some tweaking.
> 
> First off, you need to set Rails to use numeric migrations, or you’ll  
> have lots of headaches. Alternately, I suppose you can manually  
> timestamp your old migrations, but I haven’t tried that one yet… You  
> can set Rails to use numeric migrations by setting:  
> config.active\_record.timestamped\_migrations = false
> 
> Once that’s done, you need (possibly) to run: rake  
> db:migrate:upgrade\_plugin\_migration
> 
> This will make sure you have the proper DB tables, and put an entry into  
> that table for every old plugin migrations you have, in the format  
> “\<#\>-”
> 
> At this point, you should be in good shape. Your db state matches your  
> code state, with one entry in schema\_migrations for every plugin  
> migration and every main app migration.
> 
> The final trick is to use: rake db:migrate:all
> 
> Use this to upgrade your DB instead of the old ./script/generate  
> plugin\_migration bit. The engines plugin will run all existing plugins,  
> find all new migrations, and apply them correctly.
> 
> Hope that helps!
> 
> -Rob

That does help and I think I’ll go with that.

I’ve found you can run rake db:migrate:plugin NAME=pluginname and it  
runs fine.

The only issue I can’t seem to solve is how to back out migrations  
applied in this way. Have you any guidance there?

Doesn’t look like there’s any sort of rake db:migrate:plugin:down  
…wondering if there should be?

---

<div class="post-metadata">

**Author:** ![subimage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@subimage](https://www.ruby-forum.com/u/subimage)\
**Post date:** [February 11, 2010, 4:55pm UTC](https://www.ruby-forum.com/t/the-state-of-rails-2-3-engines-migrations/183200/5 "2010-02-11T16:55:42Z")

</div>

only thing I know of is  
[http://www.ruby-forum.com/topic/196976#new](http://www.ruby-forum.com/topic/196976#new)

I think I got migrations to work all right. It’s been awhile.

-r
