Advertisement
Guest User

Untitled

a guest
May 16th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. # How to setup PostgreSQL & Rails on Cloud9
  2.  
  3. At time of writing, Cloud9 has PostgreSQL pre-installed, so you won't need to install it yourself. However, its not running by default, so you will need to start it with this command in the terminal:
  4.  
  5. ```sh
  6. sudo service postgresql start
  7. ```
  8.  
  9. Change the PostgreSQL password to 'password' (or choose a different password):
  10.  
  11. ```sh
  12. sudo sudo -u postgres psql
  13.  
  14. # This will open the psql client.
  15.  
  16. # Type \password and press enter to begin process
  17. # of changing the password:
  18. postgres=# \password
  19.  
  20. # Type your new password (e.g. "password") and press enter twice:
  21. Enter new password:
  22. Enter it again:
  23.  
  24. # Password changed, quit psql with \q
  25. postgres=# \q
  26. ```
  27.  
  28. Edit your `config/database.yml` to be:
  29.  
  30. ```yml
  31. default: &default
  32. adapter: postgresql
  33. encoding: unicode
  34. pool: 5
  35.  
  36. # Important configs for cloud9, change password value
  37. # to what you entered in the previous psql step.
  38. template: template0
  39. username: ubuntu
  40. password: password
  41.  
  42. development:
  43. <<: *default
  44. database: your_app_name_development
  45.  
  46. test:
  47. <<: *default
  48. database: your_app_name_test
  49.  
  50. production:
  51. <<: *default
  52. database: your_app_name_production
  53. username: your_app_name
  54. password: <%= ENV['YOUR_APP_NAME_DATABASE_PASSWORD'] %>
  55. ```
  56.  
  57. (Note the `template`, `username`, and `password` configs in the `default` section above are essential).
  58.  
  59. Add the `pg` gem to your `Gemfile`:
  60.  
  61. ```rb
  62. gem 'pg'
  63. ```
  64.  
  65. Run `bundle install`.
  66.  
  67. Remove the sqlite gem from your `Gemfile` (and optionally delete the `db/*.sqlite3` files).
  68.  
  69. Create the database, load schema.rb, and seed the database using the `db:setup` task:
  70.  
  71. ```bash
  72. bundle exec rake db:setup
  73.  
  74. # Run bin/rake -AD db to see all db-related tasks
  75. ```
  76.  
  77. Start or restart your rails app and check it is working.
  78.  
  79. Note, the non-seed data from your old sqlite database will not be present in the new database.
  80.  
  81. If you ever want to use the psql client to interact with PostgreSQL directly, in the terminal run `psql` or run `bin/rails db`.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement