Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :myblog do
- desc "Setup the application to support myblog."
- task (:setup => :environment) do
- puts "Checking your application for the necessary components"
- puts "Checking for the database.yml file..."
- unless File.exists?(RAILS_ROOT + '/config/database.yml')
- puts "Error: database.yml is missing: please create this file in the config/ directory and run this task again."
- exit
- end
- puts "Found database.yml, attempting to migrate the database tables..."
- unless ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
- puts "Error: Could not connect to the database. Please check your database.yml file in the config/ directory."
- exit
- end
- unless ActiveRecord::Base.connection.supports_migrations?
- puts "Error: Your database does not support migrations. Please ensure that you are using MySQL or another supported database."
- exit
- end
- begin
- ActiveRecord::Migrator.migrate("db/migrate/", 0)
- rescue
- puts "Error: Could not revert the database to version 0."
- exit
- else
- puts "Reverted the database to migration version 0. Now attempting to migrate the current version..."
- ActiveRecord::Migrator.migrate("db/migrate/", nil)
- puts "Database is now in the newest version."
- end
- puts "Attempting to load the fixtures into the database..."
- begin
- Rake::Task["db:fixtures:load"].invoke
- rescue
- puts "Error: Could not load the fixtures into the database."
- exit
- end
- puts "Would you like to add an administrative user? [y/n]"
- response = STDIN.gets
- if response.downcase.include?("y")
- puts "Username:"
- username = STDIN.gets
- puts "Password:"
- password = STDIN.gets
- admin_user = User.new(:name => username, :password => password, :human_name => 'Admin User', :e_mail => 'something@somethingelse.com', :birthdate => Time.at(0))
- admin_user.save
- admin_user.validation_hash = '0'
- admin_user.validated = true
- admin_user.save_without_validation
- puts "Added the administrative user named #{ username }"
- end
- puts "Checking for RMagick..."
- begin
- require 'RMagick'
- rescue LoadError
- puts "Warning: RMagick was not found. You cannot load the registration page."
- else
- puts "RMagick found. You can load the registration page."
- end
- puts "Your install of myblog/rms is now complete. Enjoy this product."
- end
- end
Add Comment
Please, Sign In to add comment