DEV Community

Saral Karki
Saral Karki

Posted on

1 2

Rails with Postgresql

Postgresrails
During the last project, it was only when I was deploying the app to heroku that I learnt that heroku supported postgresql. I then changed the database to postgresql from the default sqlite that rails came with.

For the project that I am embarking on, I decided to start off using postgresql to begin with.

I created the app the usual way rails new (appname), and then proceded to change the database detail. In the database.yml file I changed the default details to

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: app_development

test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production

Enter fullscreen mode Exit fullscreen mode

I also added the gem pg to the gemfile and ran bundle install to install postgresql.

With this done, I ran rails db:create that created the database. I then created my users model. This time around I will be using the devise gem for the users authentication process. Finally, I ran rails db:migrate and my model was ready.

After all this was done, I found out that I could have skipped the process of changing the database.yml file had I mentioned the kind of database I would be using while generating my app with rails new app --database postgresql.

Did I learn something today? Yes, I did even though I did not get a lot of coding hours logged in today. I intend to start working with devise tomorrow, so I tomorrow's post will be all about getting started with the devise gem.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay