Guest User

Untitled

a guest
Aug 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. # file: config/database.yaml
  2.  
  3. # Define connections to the external database
  4. remote:
  5. adapter: mysql
  6. database: remote
  7. username: <%= ENV['PRODUCTION_DB_USERNAME'] || 'root' %>
  8. password: <%= ENV['PRODUCTION_DB_PASSWORD'] || '' %>
  9. host: awsserver-production-mysql.abcdef1234567890.us-west-2.rds.amazonaws.com
  10. port: 3306
  11.  
  12. test:
  13. adapter: postgresql
  14. encoding: unicode
  15. database: MyApp_test
  16. pool: 5
  17. username: <%= ENV['POSTGRESQL_DB_USERNAME'] || 'MyApp' %>
  18. password: <%= ENV['POSTGRESQL_DB_PASSWORD'] || '' %>
  19.  
  20. def connect_to_myapp_database
  21. ActiveRecord::Base.establish_connection(:adapter => "mysql",
  22. :database => 'myapp',
  23. :username => ENV['MYAPP_DB_USERNAME'],
  24. :password => ENV['MYAPP_DB_PASSWORD'],
  25. :host => 'mayapp-mysql.abcdefg123456.us-west-2.rds.amazonaws.com',
  26. :port => 3306,
  27. )
  28. end
  29.  
  30. group :development, :test do
  31. gem 'activerecord-nulldb-adapter', :git => 'git://github.com/nulldb/nulldb.git'
  32. end
  33.  
  34. class ExternalModel < ActiveRecord::Base
  35. if Rails.app.test?
  36. establish_connection(:adapter => :nulldb)
  37. else
  38. establish_connection(:myapp)
  39. end
  40.  
  41. def readonly?; true; end
  42. end
  43.  
  44. class ExternalUser < ExternalModel
  45. ...
  46. end
Add Comment
Please, Sign In to add comment