-
-
Save shanlalit/89021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Usage: | |
# rake db:rollback_to_common branch=production | |
# git checkout -m production | |
# rake db:migrate | |
# | |
namespace :db do | |
desc 'Rolls back database to common migration state between current branch and another' | |
task :rollback_to_common do | |
FileUtils.cd(RAILS_ROOT) do | |
diff = `git-diff --name-only HEAD #{ENV['branch']} db/migrate` | |
first_difference = diff.split("\n").sort.first | |
migration_files = Dir.glob(File.join('db', 'migrate', '*.rb')).sort | |
common_version_index = migration_files.index(first_difference) - 1 | |
version = migration_files[common_version_index].match(/^db\/migrate\/(\d{14})/)[1] | |
puts `rake db:migrate VERSION=#{version}` | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment