# I wanna submit a patch for migration rake

**URL:** <https://www.ruby-forum.com/t/i-wanna-submit-a-patch-for-migration-rake/154182>\
**Category:** Rails\
**Created:** [November 26, 2008, 7:59am UTC](https://www.ruby-forum.com/t/i-wanna-submit-a-patch-for-migration-rake/154182 "2008-11-26T07:59:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [November 26, 2008, 7:59am UTC](https://www.ruby-forum.com/t/i-wanna-submit-a-patch-for-migration-rake/154182/1 "2008-11-26T07:59:44Z")

</div>

As title, too bad I don’t have experience on this one, anyone could  
help?

Here is my patch:

```
desc 'Runs the "up" for a given migration VERSION.'
task :up => :environment do
  version=
  if ENV["NAME"]
    get_migrate_task_version(ENV["NAME"])
  else
    ENV["VERSION"] ? ENV["VERSION"].to_i : nil
  end
  raise "VERSION or NAME is required" unless version
  ActiveRecord::Migrator.run(:up, "db/migrate/", version)
  Rake::Task["db:schema:dump"].invoke if

```

ActiveRecord::Base.schema\_format == :ruby  
end

```
desc 'Runs the "down" for a given migration VERSION.'
task :down => :environment do
  version= ""
  if ENV["NAME"]
    version= get_migrate_task_version(ENV["NAME"])
  else
    ENV["VERSION"] ? ENV["VERSION"].to_i : nil
  end
  raise "VERSION or NAME is required" unless version
  ActiveRecord::Migrator.run(:down, "db/migrate/", version)
  Rake::Task["db:schema:dump"].invoke if

```

ActiveRecord::Base.schema\_format == :ruby  
end

def get\_migrate\_task\_version(task\_name)  
files=Dir["#{RAILS\_ROOT}/db/migrate/\*\_#{task\_name.underscore}.rb"]  
raise “More than one task found” if files.length\>1  
raise “No task found” if files.length==0

files[0] =~ /[[:digit:]]+/  
$~[0].to\_i

end

What it does is to allow you use rake db:migrate:down/up  
NAME=YourMigrationTaskName instead of trying to dig your version with  
grep etc… it would only run when a precise migration can be found so  
to avoid mis-executed migration.

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [November 26, 2008, 5:12pm UTC](https://www.ruby-forum.com/t/i-wanna-submit-a-patch-for-migration-rake/154182/2 "2008-11-26T17:12:51Z")

</div>

On Nov 25, 2008, at 10:59 PM, goodwill wrote:

> As title, too bad I don’t have experience on this one, anyone could  
> help?

Start here. It tells you how to go about submitting a patch back to  
rails.

[http://rails.lighthouseapp.com/projects/8994/sending-patches](http://rails.lighthouseapp.com/projects/8994/sending-patches)

-philip
