Guest User

Untitled

a guest
Mar 7th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. namespace :myblog do
  2. desc "Setup the application to support myblog."
  3. task (:setup => :environment) do
  4. puts "Checking your application for the necessary components"
  5. puts "Checking for the database.yml file..."
  6. unless File.exists?(RAILS_ROOT + '/config/database.yml')
  7. puts "Error: database.yml is missing: please create this file in the config/ directory and run this task again."
  8. exit
  9. end
  10. puts "Found database.yml, attempting to migrate the database tables..."
  11. unless ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
  12. puts "Error: Could not connect to the database. Please check your database.yml file in the config/ directory."
  13. exit
  14. end
  15. unless ActiveRecord::Base.connection.supports_migrations?
  16. puts "Error: Your database does not support migrations. Please ensure that you are using MySQL or another supported database."
  17. exit
  18. end
  19. begin
  20. ActiveRecord::Migrator.migrate("db/migrate/", 0)
  21. rescue
  22. puts "Error: Could not revert the database to version 0."
  23. exit
  24. else
  25. puts "Reverted the database to migration version 0. Now attempting to migrate the current version..."
  26. ActiveRecord::Migrator.migrate("db/migrate/", nil)
  27. puts "Database is now in the newest version."
  28. end
  29. puts "Attempting to load the fixtures into the database..."
  30. begin
  31. Rake::Task["db:fixtures:load"].invoke
  32. rescue
  33. puts "Error: Could not load the fixtures into the database."
  34. exit
  35. end
  36. puts "Would you like to add an administrative user? [y/n]"
  37. response = STDIN.gets
  38. if response.downcase.include?("y")
  39. puts "Username:"
  40. username = STDIN.gets
  41. puts "Password:"
  42. password = STDIN.gets
  43. admin_user = User.new(:name => username, :password => password, :human_name => 'Admin User', :e_mail => 'something@somethingelse.com', :birthdate => Time.at(0))
  44. admin_user.save
  45. admin_user.validation_hash = '0'
  46. admin_user.validated = true
  47. admin_user.save_without_validation
  48. puts "Added the administrative user named #{ username }"
  49. end
  50. puts "Checking for RMagick..."
  51. begin
  52. require 'RMagick'
  53. rescue LoadError
  54. puts "Warning: RMagick was not found. You cannot load the registration page."
  55. else
  56. puts "RMagick found. You can load the registration page."
  57. end
  58. puts "Your install of myblog/rms is now complete. Enjoy this product."
  59. end
  60. end
Add Comment
Please, Sign In to add comment