Ruby Sinatra App & Heroku Deploy
Tags: ruby, heroku
Published: 2020-11-07 18:53:58

At the time of this article’s writing, I had just wrapped up my second project for Flatiron School’s Software Engineering program. Our task for this project was to create a Sinatra app that incorporated full CRUD(create, read, update & delete) functionality utilizing the Model View Controller software design pattern.

My project was designed to allow a user to create an account and search for their favorite movie, provide a rating and any other comments, and save that movie to their account. This being made possible by the incorporation of an API from TMDb (The movie database.) After the build process for my application was complete I wanted to deploy my app for the world to see without a user having to clown down its repo, install dependencies and run it on their local machine.

Heroku is a cloud hosting platform that was the perfect solution to help me do this. My app was built utilizing Sinatra which is a web application library and domain-specific language written in Ruby. This was not the cause of my issues though, the culprit was the relational database management system I was utilizing within my app - SQLite. Unfortunately for me, Heroku does not support SQLite on its platform. I ended up changing my database management system to PostgreSQL to get my app deployed. Let's go over it below and if you encounter the same issues you will be able to bypass them and deploy your app.

* Remove the ‘sqlite3' gem and add the ‘pg’ gem to your gemfile

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qlv2bakpc83jmusl0a9q.png)

* Remove specified versioning from ‘activerecord’ & ‘sinatra-activerecord’ gems in your gemfile if present.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/de0l03v584bvl0dbw7id.png)

* Delete the Gemfile.lock file and run ‘bundle install’ in your terminal.

* Navigate to your ‘DB’ folder and delete ‘development.sqlite’ , ‘test.sqlite’ & ‘schema.rb’ if those files exist. Ensure you only have a ‘migrate’ folder. Also make sure you are specifying your versioning for your ActiveRecord::Migration

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v2vc4b820l2gyy2ymi5j.png)

* Navigate to your ‘config’ folder and create a file ‘database.yml’, this is where we will set up our PostgreSQL database.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5u1rtm0vzxwk3aeqm9f6.png)

* Navigate to your environment.rb file and remove:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ayqr8idjitz7nazzqglh.png)

* Navigate to your ‘config.ru’ file and remove:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8fl5byau017l9efg9hg0.png)

At this point, you need to be sure you have the Postgres app installed on your machine. Ensure that the app is running. Once it is running navigate back to your terminal and run the following commands.

`rake db:create`

`rake db:migrate`

With Postgres, you have to create the databases before you migrate them. When you migrate for the first time you will run ‘rake db:create’ to create the databases. You will only need to run this once unless you drop your databases.

At this point, you will have switched from utilizing a ‘sqlite’ database to ‘postgres’ allowing you to now deploy your app and finish migrating your databases in Heroku. I hope this article was helpful in getting your app deployed if you were encountering the same issue as I did.

*This article was migrated over from Medium. The original article can be found [here](https://medium.com/@jefftswisher/sinatra-app-heroku-57a918f6c5be)*