# Check what migrations need to be done inside ruby script

**URL:** <https://www.ruby-forum.com/t/check-what-migrations-need-to-be-done-inside-ruby-script/177339>\
**Category:** Rails\
**Created:** [October 15, 2009, 9:31am UTC](https://www.ruby-forum.com/t/check-what-migrations-need-to-be-done-inside-ruby-script/177339 "2009-10-15T09:31:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artrat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@artrat](https://www.ruby-forum.com/u/artrat)\
**Post date:** [October 15, 2009, 9:31am UTC](https://www.ruby-forum.com/t/check-what-migrations-need-to-be-done-inside-ruby-script/177339/1 "2009-10-15T09:31:49Z")

</div>

Hi all

I have a feature in a small app that creates the migration files needed  
from a small GUI

it executes the rake task command to generate the migration files from  
inside a ruby script

so I need to get a simple way to know what files havent been processed  
in the current migration compared to the db schema

e.g. inside the db/migrate I count the files with something like

Dir.glob(“db/migrate/\*”).size

then I get the current db version info with

%x{rake.bat db:version}.split(’ ').last.to\_i

then I compare the two values so that I can automatically execute from a  
controller

%x{rake.bat db:migrate} #windows fix to add the .bat

Is there an easier way to do this?

Thanks  
Art

---

<div class="post-metadata">

**Author:** ![artrat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b2d939/32.png) [@artrat](https://www.ruby-forum.com/u/artrat)\
**Post date:** [October 15, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/check-what-migrations-need-to-be-done-inside-ruby-script/177339/2 "2009-10-15T18:30:03Z")

</div>

Arthur R. wrote:

> ```
> Hi all
> 
> I have a feature in a small app that creates the migration files needed  
> from a small GUI
> 
> it executes the rake task command to generate the migration files from  
> inside a ruby script
> 
> so I need to get a simple way to know what files havent been processed  
> in the current migration compared to the db schema
> 
> e.g. inside the db/migrate I count the files with something like
> 
> Dir.glob(“db/migrate/\*”).size
> 
> then I get the current db version info with
> 
> %x{rake.bat db:version}.split(’ ').last.to\_i
> 
> then I compare the two values so that I can automatically execute from a  
> controller
> 
> %x{rake.bat db:migrate} #windows fix to add the .bat
> 
> Is there an easier way to do this?
> 
> Thanks  
> Art
> ```

Why not just do the migration and let rails figure out what needs to be done.Â You are duplicating what rake db:migrate does.Â   
  
Norm  
  
--~--~---------~--~----~------------~-------~--~----~  
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.   
 To post to this group, send email to removed\_email\_address@domain.invalid   
 To unsubscribe from this group, send email to removed\_email\_address@domain.invalid   
 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en  
-~----------~----~----~----~------~----~------~--~---
