Guest User

Untitled

a guest
Mar 6th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. # ... inside resource:db namespace ...
  2. task :init => :environment do
  3. desc "Creates a resource"
  4. new_database = ENV["NEW_DATABASE"]
  5. ActiveRecord::Base.connection.create_database(new_database)
  6. ActiveRecord::Base.connection.execute(%Q[GRANT ALL PRIVILEGES ON #{new_database}.* TO '#{ENV["USERNAME"]}'@'%' IDENTIFIED BY '#{ENV["PASSWORD"]}'])
  7. ActiveRecord::Base.establish_connection(
  8. :adapter => "mysql",
  9. :host => ENV["HOST"],
  10. :username => ENV["USERNAME"],
  11. :password => ENV["PASSWORD"],
  12. :database => new_database
  13. )
  14. Rake::Task["resource:db:migrate"].invoke
  15. end
  16.  
  17. # ... on the command line ...
  18.  
  19. rake resource:db:init RAILS_ENV=resource HOST=localhost DATABASE=integrated_development USERNAME=example PASSWORD=secret NEW_DATABASE=resouce_abs23
Add Comment
Please, Sign In to add comment