27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Deploy away!<br />

** [out :: [server]] -- create_table(:projects)<br />

** [out :: [server]] -> 0.0012s<br />

...<br />

This indicates that the migrations have happened successfully. Unfortunately, this is in<br />

the wrong database! You spent all that time setting up a PostgreSQL server and it’s<br />

gone ahead and instead used SQLite3. The nerve!<br />

14.5.6 Choosing a database<br />

To fix this, you can make a little change to your application’s Gemfile. Rather than<br />

having sqlite3 out there in the open and not in a group, switch it to only be used in<br />

development and test by moving it down into the group :development, :test block<br />

just underneath. 26 Beneath all of the content in the file currently, define a new group<br />

like this:<br />

group :production do<br />

gem 'pg'<br />

end<br />

The pg gem provides the PostgreSQL adapter that you need to connect to your Postgre-<br />

SQL database server on your server. If you run bundle install now it will install this<br />

gem for you. Now you can make a commit for this small change and push your changes:<br />

git add Gemfile*<br />

git commit -m "Added pg gem for PostgreSQL on the server"<br />

git push<br />

You haven’t yet configured your production application to connect to PostgreSQL,<br />

which is somewhat of a problem. You would usually do this by editing the config/database<br />

.yml file in your application, but in this case you want to keep your development and production<br />

environments separate. Therefore, you’ll set this up on the server.<br />

Put this file in the shared directory of your application’s deploy, so that all releases<br />

can just symlink it to config/database.yml inside the application itself. Connect to the<br />

server now with your user and then switch over to ticketeeapp.com using sudo su<br />

ticketeeapp.com so that you can add this file. Go into this shared directory now and<br />

open a new file for editing by running these commands:<br />

cd /home/ticketeapp.com/apps/ticketee/shared<br />

mkdir config<br />

cd config<br />

nano database.yml<br />

Inside this file, put the database settings for the production environment of your<br />

application. These are as follows:<br />

production:<br />

adapter: postgresql<br />

database: ticketeeapp.com<br />

min_messages: warning<br />

26 Generally, this is a bad idea. You should always develop on the same database system that you deploy on so<br />

that you don’t run into any unexpected production issues. We’re being lazy here because it’s easier.<br />

405

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!