Importing database dump in Ruby on Rails

Ideakart
ruby-rails-tips
Published in
1 min readAug 10, 2021

Sometimes, we need to load the data from sandbox environments, production environments into our local application.
We generally get a dump.tar.gz or zipped file, let’s see how we can import the data.
1. Unzip the data.
2. Drop the database that you have in your local, you can drop it in two ways
a. rails db:drop
b. You can login to your database like for e.g if you are using psql, just type psql, then do drop mydatabase .
3. Now we need to create the database. Again from rails directory you can do either
a. rails db:create
b. create mydatabase .
4. Now you can load your unzipped database by doing either of the given below steps
a.rails db < mydatadump
b.psql -u username -p password mydatabase < mydatadump

You can go with either approaches i.e. both works. This is to unlock beginners from not getting stuck with the data import.

Also, you can checkout the below video to see the above in action.

While writing this got to see other alternatives also, follow
https://stackoverflow.com/questions/8342642/how-can-i-import-a-sql-file-into-a-rails-database/28874165.

--

--