Reputation: 45
I am new to ruby on rails framework and build some Blogs,portfolio like applications using rails.For that i used sqlite as my database. I would like to create a scalable applications and though sqlite is a lightweight database. I would like to change the database as postgresql , Mysql and mongodb etc.
So my question is if i change the database ,did i need to change rails code or it will be same as using sqlite?
Upvotes: 0
Views: 86
Reputation: 2996
ActiveRecord is a database-agnostic abstraction. This means your models, and the way you query the tables that they represent, should not change much as you swap out the underlying database, provided you are only doing basic AR querying and you are sticking closely to Rails conventions.
However, it is advisable to use the same database (e.g. Postgres or MySQL) in Development, as you are planning to use in Production, because you can run into issues when you try to deploy your app.
You will need to add the Gem for the database you want to use in your Gemfile:
#gem "sqlite3"
gem "pg"
And then change your config/database.yml to connect to your new database:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
port: 5432
username: root
password:
development:
<<: *default
database: yourapp_development
test:
<<: *default
database: yourapp_test
If you are going to migrate to using Postgres (my personal favorite) I recommend you watch this Railscast.
Upvotes: 1