Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :create do
- desc 'Create all the local databases defined in config/database.yml'
- task :all => :environment do
- ActiveRecord::Base.configurations.each_value do |config|
- # Skip entries that don't have a database key, such as the first entry here:
- #
- # defaults: &defaults
- # adapter: mysql
- # username: root
- # password:
- # host: localhost
- #
- # development:
- # database: blog_development
- # <<: *defaults
- next unless config['database']
- # Only connect to local databases
- if config['host'] == 'localhost' || config['host'].blank?
- create_database(config)
- else
- p "This task only creates local databases. #{config['database']} is on a remote host."
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment