DEV Community

Cate
Cate

Posted on

Migrating from SQLite3 to PostgreSql Database - Heroku

Introduction

Are you planning to deploy your SQLite3 based backend to Heroku? If you answered this question with a yes, then you are at the right place. This is because you will have to migrate your databases from SQLite3 to PostgreSql.
Most of the time we use SQLite for development purposes but when the time for deployment comes, we have to migrate our databases to PostgreSql in order to host it to Heroku.
This is the process I went through to migrate my SQLite based project to PostgreSql then deployed it on Heroku:

Install PostgreSql

I started by installing PostgreSql app in to my laptop. This app provides a simple user interface to manage your databases. Depending on your laptop's OS, go ahead and download this app.

Edit Gemfile

In your Ruby project, Gemfile contains all of the gems that your project is dependent on. Locate the SQLite gem and replace it with PostgreSql gem.
gem 'sqlite3' to gem 'pg'
After editing your Gemfile, run bundle install command to install PostgreSql gem.

Edit database.yml file

This file contains information about your database configurations. Since we want to migrate from SQLite3 to PostgreSql, change adapter setting as follows:
adapter: sqlite3 to adapter: postgresql

Run rake db:migrate command to setup a PostgreSql Database and schema.

Conclusion

At this point, your PostgreSql setup should be working. Next time I will be showing you how to host the project to Heroku.

Top comments (0)