I am aware of the heroku pg:push
command which pushes an entire database up to Heroku.
Now that I am launching my product, I would like to be able to push up only a specific table that contains information collected locally without overwriting existing tables (such as users).
Is there a command that enables me to only push specific tables to heroku?
I wrote script which extracts DB url from heroku. Then it dumps single tables from production and restores them on development/localhost. Run it like this:
Code:
If I understand correctly, you just need a single database table with its locally created data pushed to your Rails production app. Maybe this is a simplistic approach, but you could create a migration for your table and then populate using
db/seeds.rb
.After you've populated the seeds.rb file and pushed your repo to heroku:
Also, if your local table has a ton of data and you're using Rails 4, check out the seed dump gem: https://github.com/rroblak/seed_dump. This will take your existing db data and map it to the seed format.
My suggestion is to use PostgreSQL dump/restore capabilities directly using the
pg_dump
andpsql
commands.With
pg_dump
you can dump a specific table from your local databaseThen grab the Heroku PostgreSQL connection string from the configs
and restore the table in the remote database, using the information retrieved from Heroku.
You will need to customize the
-p
,-h
and-U
parameters, as well as the database name. The password will be prompted bypsql
.You can also use the
pg_restore
to filter a dump and restore the table, but I personally preferpsql
.Note that Heroku is recommending the use of PostgreSQL tools in several documentations, such as Importing and Exporting for large data, or whenever the provided CLI commands don't cover specific cases like the one in this question.