Forum: Ruby on Rails I wanna submit a patch for migration rake

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
William Y. (Guest)
on 2008-11-26 08:59
(Received via mailing list)
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.
Philip H. (Guest)
on 2008-11-26 18:12
(Received via mailing list)
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

-philip
This topic is locked and can not be replied to.