# Using a generator to handle migrations

**URL:** <https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085>\
**Category:** Engines Development\
**Created:** [September 7, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085 "2009-09-07T16:05:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [September 7, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085/1 "2009-09-07T16:05:16Z")

</div>

James, on your presentation at railsconf (  
[http://rails-engines.org/news/2009/05/18/engines-at-railsconf/](http://rails-engines.org/news/2009/05/18/engines-at-railsconf/)) you  
suggest  
(for now) making your own generator to handle the migrations issue. Can  
you  
elaborate on that method?

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [September 7, 2009, 11:03pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085/2 "2009-09-07T23:03:49Z")

</div>

Quoting Andrew R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> James, on your presentation at railsconf (  
> [http://rails-engines.org/news/2009/05/18/engines-at-railsconf/](http://rails-engines.org/news/2009/05/18/engines-at-railsconf/)) you suggest  
> (for now) making your own generator to handle the migrations issue. Can you  
> elaborate on that method?

I am not James - but I recently needed something like that. I used the  
Clearance engine as a model for buillding the migrations I wanted.

> **[GitHub - thoughtbot/clearance: Rails authentication with email & password.](https://github.com/thoughtbot/clearance/tree/main)**
>
> main

## James, is there video anywhere of your talk? I got a lot out of the slides but there are a couple where I would like more detail as was probably provided at the talk.

Cynthia K.

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [September 7, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085/3 "2009-09-07T23:06:10Z")

</div>

Not sure if it’s useful information or not, but in the repository I  
use for engines, I’ve made it simply use the current Rails migration  
mechanism, ie, no generator is required, the migrations in plugins are  
automatically ran.

My repository is way out of date though… I should really do a pull  
to see if it works just fine with the recent changes.

Miles

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [September 7, 2009, 11:10pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085/4 "2009-09-07T23:10:16Z")

</div>

I’ve got a small plugin that might help you:

> **[GitHub - henrypoydar/engines-helper: A Rails 2.3+ plugin that provides...](https://github.com/henrypoydar/engines-helper)**
>
> A Rails 2.3+ plugin that provides database migrations and asset support for 'engine' type plugins - GitHub - henrypoydar/engines-helper: A Rails 2.3+ plugin that provides database migration...

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [September 7, 2009, 11:13pm UTC](https://www.ruby-forum.com/t/using-a-generator-to-handle-migrations/175085/5 "2009-09-07T23:13:11Z")

</div>

2009/9/7 Cynthia K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Quoting Andrew R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > James, on your presentation at railsconf (  
> > [http://rails-engines.org/news/2009/05/18/engines-at-railsconf/](http://rails-engines.org/news/2009/05/18/engines-at-railsconf/)) you suggest  
> > (for now) making your own generator to handle the migrations issue. Can you  
> > elaborate on that method?
> 
> I am not James - but I recently needed something like that. I used the  
> Clearance engine as a model for buillding the migrations I wanted.
> 
> [GitHub - thoughtbot/clearance: Rails authentication with email & password. · GitHub](http://github.com/thoughtbot/clearance/tree/master)

This is basically correct - you want to use the ‘migration\_template’  
method available in the generator mechanism to copy a migration file  
into db/migrate, and Clearance is a reasonable example where this  
happens.

The reason we do this is to place the migration in the appropriate  
part of the application timeline; this is one of the issues I covered  
in my presentation. You can see my blog for more discussion of this  
([interblah.net - Plugin Migrations](http://interblah.net/plugin-migrations)), but the gist is that I  
believe it is important to preserve the order migrations were applied.

The other part of the migration issue is tracking which migrations  
have already run; there’s no reason why you couldn’t run the migration  
generators from Clearance multiple times, for example. This isn’t a  
big deal normally, but comes into play if you’re trying to ‘upgrade’  
an engine in-place, and incorporate a new migration.

> James, is there video anywhere of your talk? I got a lot out of the  
> slides but there are a couple where I would like more detail as was  
> probably provided at the talk.

There’s no video (probably for the best, to be honest), but I’m happy  
to answer questions here, if you’ve got them.

- James
