Skip to content

Instantly share code, notes, and snippets.

@lnmunhoz
Last active May 24, 2019 05:48
Show Gist options
  • Save lnmunhoz/4f1f42bdd72f6807eaa0a6752ddac992 to your computer and use it in GitHub Desktop.
Save lnmunhoz/4f1f42bdd72f6807eaa0a6752ddac992 to your computer and use it in GitHub Desktop.
Moving data from local postgres to remote postgres using Hasura

A simple workflow to import your data from localhost to your remote Hasura instance. I think this is not the best way but this is how it worked from me after many tries.

From the localhost

hasura init --directory my-project --endpoint http://localhost:8080
cd my-project

hasura migrate create "init" --from-server
hasura migrate apply --version <version> --skip-execution
hasura migrate apply --endpoint http://another-graphql-instance.herokuapp.com

Export local database tables

# This creates the dump for two tables
pg_dump --data-only postgres \
  -t tasks \
  -t users \
  --host=localhost \
  -U postgres \
  --port=5432 > dump.sql

Now enter the file created and remove the line:

SELECT pg_catalog.set_config('search_path', '', false)

Copy the file to remote server

scp  dump.sql root@<address>:~/your-desired-path/dump.sql

Now, from the remote server

cd <your-desired-path>
psql -h localhost -U <user> -d postgres -f dump.sql

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment