Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create local "copy" of remote Hasura server?

Tags:

graphql

hasura

I want to set up a dev environment of Hasura on my local machine, that replicates my existing production (same tables, same schema, same data).

  • What are the required steps to achieve this task?
like image 728
walkthroughthecode Avatar asked Jan 25 '26 13:01

walkthroughthecode


1 Answers

I've found this process to work well.

  1. Create a clean empty local postgresql database and Hasura instance. To update an existing local database, drop it and recreate it.

  2. Dump the schema and data from your existing Hasura server (as per the answer by @protob, but with clean_output set so that manual changes to the output do not have to be made. See pgdump for details.

    curl --location --request POST 'https://example.com/v1alpha1/pg_dump' \
      --header 'Content-Type: application/json' \
      --header 'X-Hasura-Role: admin' \
      --header 'Content-Type: text/plain' \
      --header 'x-hasura-admin-secret: {SECRET}' \
      --data-raw '{ "opts": ["-O", "-x","--inserts",  "--schema", "public"], "clean_output": true}' > hasura-db.sql
    
  3. Import the schema and data locally:

    psql -h localhost -U postgres < hasura-db.sql
    
  4. The local database has all the migrations because we copied the latest schema, so just mark them as applied:

    hasura migrate apply --skip-execution
    
    # and confirm the updated status
    hasura migrate status
    
  5. Now finally apply the Hasura metadata using the hasura CLI:

    hasura metadata apply
    

Enjoy your new instance!

like image 192
Raman Avatar answered Jan 27 '26 18:01

Raman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!