Guest User

Untitled

a guest
Feb 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. namespace :db do
  2. namespace :migrate do
  3.  
  4. task :check_for_pending_plugin_migrations do
  5. new_migrations = {}
  6. Dir["vendor/plugins/**/migrations/*.rb"].each do |migration_file|
  7. path_parts = migration_file.split("/")
  8. plugin_name = path_parts[path_parts.index("migrations")-1]
  9. migration_name = path_parts.last
  10. unless File.exist?(File.join("db", "migrate", migration_name))
  11. new_migrations[plugin_name] ||= []
  12. new_migrations[plugin_name] << migration_name
  13. end
  14. end
  15. unless new_migrations.empty?
  16. puts "The following migrations are included in plugins, but not present in your db/migrate directory:\n\n"
  17. new_migrations.each do |plugin_name, migrations|
  18. puts "from '#{plugin_name}':"
  19. migrations.each { |m| puts "\t#{m}"}
  20. end
  21. puts "\nRun db:migrate:plugins to incorporate these migrations into your application."
  22. end
  23. end
  24.  
  25. desc 'Migrate all plugins'
  26. task :plugins do
  27. plugins_to_migrate = ENV['PLUGINS'] || "*"
  28. new_migrations = {}
  29. Dir["vendor/plugins/**/#{plugins_to_migrate}/migrations/*.rb"].each do |migration_file|
  30. FileUtils.cp(migration_file, "db/migrate")
  31. path_parts = migration_file.split("/")
  32. plugin_name = path_parts[path_parts.index("migrations")-1]
  33. migration_name = path_parts.last
  34. new_migrations[plugin_name] ||= []
  35. new_migrations[plugin_name] << migration_name
  36. end
  37. unless new_migrations.empty?
  38. puts "The following migrations have been copied into your db/migrate directory:\n\n"
  39. new_migrations.each do |plugin_name, migrations|
  40. puts "from '#{plugin_name}':"
  41. migrations.each { |m| puts "\t#{m}"}
  42. end
  43. puts "\nPlease inspect these files to be sure you're happy with what they'll do."
  44. puts "The migrations will be incorporated the next time you run 'rake db:migrate'."
  45. end
  46. end
  47.  
  48. end
  49. end
Add Comment
Please, Sign In to add comment