The following rake task can be used to update the migration pointer without actually migrate in rails databases for rails under 2.0.2. This is sometimes useful if you applied something manually or want to skip some migration anyway.
Usage examples:
rake db:pretend:migrate
rake db:pretend:migrate VERSION=20080730181045
rake db:pretend:rollback
namespace(:db) do
namespace(:pretend) do
desc "Pretend the database migrated 1 step or to VERSION=<nn>"
task :migrate => :environment do
c = ActiveRecord::Base.connection
if ENV['VERSION']
version = ENV['VERSION'].to_i
else
version = c.select_one("select version from schema_info")['version'].to_i + 1
end
c.execute("update schema_info set version = #{version}")
puts "Current version: #{version}"
end
desc "Pretend that the last migration did not happen"
task :rollback => :environment do
c = ActiveRecord::Base.connection
version = c.select_one("select version from schema_info")['version'].to_i - 1
c.execute("update schema_info set version = #{version}")
puts "Current version: #{version}"
end
end
end
No comments:
Post a Comment