Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment