0

I'm a beginner in Rails and I'm curious whether I'm better off setting the database to Postgres from the beginning or I can just use SQLite and forget about it until later. And if setting it in the beginning is better, should I simply follow the 3.12 in http://guides.rubyonrails.org/configuring.html#configuring-a-database or are there more things to be done? It seems like I need to do more but it's not really clear. For example, other than adapter, which the instruction says to change, there are more code with SQLite built-in and I'm not sure whether I need to do anything to them as well:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

2 Answers 2

2

If you intend to use Postgres than it makes sense to setup the application to use it from the get go.

While it is possible migrate data from SQLite to Postgres and vice-versa you would be better off not having to deal with the potential issues that can occur.

In general you want to develop and test on the same database system you are deploying to as they have different features and subtile differences in how they interpret the SQL standards. You don't want to find them out by pushing to the production server and then getting a very angry phone call.

This can definitely can bite you in the *rse when deploying to Postgres as it is rather strict (its a good thing).

A decent config would be:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: my_app_dev

test:
  <<: *default
  database: my_app_test

production:
  <<: *default
  database: my_app_production

Note that on Heroku and other Platform-as-a-Service (PaaS) services you can simply leave out the production section as it will be overwritten in a post commit hook.

See also:

Sign up to request clarification or add additional context in comments.

Comments

0

You can install the Postgresql gem using either:

gem install pg in your terminal

or

gem 'pg' in your Gemfile.

Then you just need to go into config/database.yml and set up something similar to this:

development:
  adapter: postgresql
  encoding: unicode
  database: myapp_development
  pool: 5

test:
  adapter: postgresql
  encoding: unicode
  database: myapp_test
  pool: 5

From there, just run your migrations, and you should be all set up!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.