Created
November 27, 2008 15:37
-
-
Save lazyatom/29774 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
namespace :db do | |
namespace :migrate do | |
task :check_for_pending_plugin_migrations do | |
new_migrations = {} | |
Dir["vendor/plugins/**/migrations/*.rb"].each do |migration_file| | |
path_parts = migration_file.split("/") | |
plugin_name = path_parts[path_parts.index("migrations")-1] | |
migration_name = path_parts.last | |
unless File.exist?(File.join("db", "migrate", migration_name)) | |
new_migrations[plugin_name] ||= [] | |
new_migrations[plugin_name] << migration_name | |
end | |
end | |
unless new_migrations.empty? | |
puts "The following migrations are included in plugins, but not present in your db/migrate directory:\n\n" | |
new_migrations.each do |plugin_name, migrations| | |
puts "from '#{plugin_name}':" | |
migrations.each { |m| puts "\t#{m}"} | |
end | |
puts "\nRun db:migrate:plugins to incorporate these migrations into your application." | |
end | |
end | |
desc 'Migrate all plugins' | |
task :plugins do | |
plugins_to_migrate = ENV['PLUGINS'] || "*" | |
new_migrations = {} | |
Dir["vendor/plugins/**/#{plugins_to_migrate}/migrations/*.rb"].each do |migration_file| | |
FileUtils.cp(migration_file, "db/migrate") | |
path_parts = migration_file.split("/") | |
plugin_name = path_parts[path_parts.index("migrations")-1] | |
migration_name = path_parts.last | |
new_migrations[plugin_name] ||= [] | |
new_migrations[plugin_name] << migration_name | |
end | |
unless new_migrations.empty? | |
puts "The following migrations have been copied into your db/migrate directory:\n\n" | |
new_migrations.each do |plugin_name, migrations| | |
puts "from '#{plugin_name}':" | |
migrations.each { |m| puts "\t#{m}"} | |
end | |
puts "\nPlease inspect these files to be sure you're happy with what they'll do." | |
puts "The migrations will be incorporated the next time you run 'rake db:migrate'." | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment