# Rails ActiveRecord migrations, without Rails?

**URL:** <https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244>\
**Category:** Rails\
**Created:** [August 7, 2008, 3:37am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244 "2008-08-07T03:37:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 3:37am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/1 "2008-08-07T03:37:55Z")

</div>

Are there any frameworks out there that execute migrations as well as  
Rails does? Or how difficult of a task would it be to extract the  
migration functionality?

The practicality of having version control on changes made to a database  
is a fantastic thing and I would love to get the migration functionality  
available to Rails and apply it to any database.

I’ve started a very small app with newgen that does the initial  
bootstrapping (just builds the simple directory structure, a blank  
database.yml file and a simple Rakefile with some basic tasks), but I  
have no migration generation yet as I would like to borrow as much from  
Rails as possible (timestamps for versioning and such).

If anyone could point me in a direction, or would like me to start up a  
project on Github, feel free to chime in. I think this would benefit  
many others aside from me.

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 3:56am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/2 "2008-08-07T03:56:40Z")

</div>

On Aug 7, 2:37 am, Matthew W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Are there any frameworks out there that execute migrations as well as  
> Rails does? Or how difficult of a task would it be to extract the  
> migration functionality?

You could certainly have an almost empty rails app containing nothing  
but migrations. With what I expect what be not too much work (and not  
involving much rocket science) you could extract the relevant rake  
tasks and do away with the empty husk of the application.

Fred

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 3:57am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/3 "2008-08-07T03:57:15Z")

</div>

On Aug 7, 2:55 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Aug 7, 2:37 am, Matthew W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:\> Are there any frameworks out there that execute migrations as well as
> 
> > Rails does? Or how difficult of a task would it be to extract the  
> > migration functionality?
> 
> You could certainly have an almost empty rails app containing nothing  
> but migrations. With what I expect what be not too much work (and not  
> involving much rocket science) you could extract the relevant rake  
> tasks and do away with the empty husk of the application.

Oh, and you can also use activerecord outside of rails completely -  
it’s a standalone framework.

Fred

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 4:00am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/4 "2008-08-07T04:00:59Z")

</div>

Frederick C. wrote:

> On Aug 7, 2:55ï¿½am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > On Aug 7, 2:37ï¿½am, Matthew W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:\> Are there any frameworks out there that execute migrations as well as
> > 
> > > Rails does? ï¿½Or how difficult of a task would it be to extract the  
> > > migration functionality?
> > 
> > You could certainly have an almost empty rails app containing nothing  
> > but migrations. With what I expect what be not too much work (and ï¿½not  
> > involving much rocket science) you could extract the relevant rake  
> > tasks and do away with the empty husk of the application.
> 
> Oh, and you can also use activerecord outside of rails completely -  
> it’s a standalone framework.
> 
> Fred

I realize you can use ActiveRecord without and I do have a small base  
with a few tasks to fire off migrations, like I mentioned,but I would  
really like the migration generator that Rails provides and the other  
functionality for versioning and rolling back which is not so out of the  
box when using ActiveRecord standalone.

I have considered just using an empty Rails project and cleaning up the  
rake file but that’s as clean of a solution as I would like though I may  
end up going that route.

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 4:11am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/5 "2008-08-07T04:11:52Z")

</div>

On Aug 7, 3:00 am, Matthew W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > involving much rocket science) you could extract the relevant rake  
> > > functionality for versioning and rolling back which is not so out of the  
> > > box when using ActiveRecord standalone.

Have you looked at the rake file ? There’s really not a lot too it.  
All the migration stuff together is just over 30 lines. (The migration  
generator stuff is not much more complicated, but the functionality is  
a little more dispersed)

Eg the migrate task is just

ActiveRecord::Migrator.migrate(“db/migrate/”, ENV[“VERSION”] ?  
ENV[“VERSION”].to\_i : nil)

the rollback task is just

ActiveRecord::Migrator.rollback(‘db/migrate/’, ENV[‘STEP’] ?  
ENV[‘STEP’].to\_i : 1)

and so on.

Fred

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 7, 2008, 4:24am UTC](https://www.ruby-forum.com/t/rails-activerecord-migrations-without-rails/145244/6 "2008-08-07T04:24:38Z")

</div>

Frederick C. wrote:

> On Aug 7, 3:00ï¿½am, Matthew W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > > involving much rocket science) you could extract the relevant rake  
> > > > functionality for versioning and rolling back which is not so out of the  
> > > > box when using ActiveRecord standalone.
> 
> Have you looked at the rake file ? There’s really not a lot too it.  
> All the migration stuff together is just over 30 lines. (The migration  
> generator stuff is not much more complicated, but the functionality is  
> a little more dispersed)
> 
> Eg the migrate task is just
> 
> ActiveRecord::Migrator.migrate(“db/migrate/”, ENV[“VERSION”] ?  
> ENV[“VERSION”].to\_i : nil)
> 
> the rollback task is just
> 
> ActiveRecord::Migrator.rollback(‘db/migrate/’, ENV[‘STEP’] ?  
> ENV[‘STEP’].to\_i : 1)
> 
> and so on.
> 
> Fred

Thanks for pointing out those tasks, it’s not too bad at all. I was  
mostly focusing on the generators which are as you mentioned a little  
more dispersed.
