Search code examples
javascriptreactjspostgresqlapollohasura

Client side data backup on Hasura


So the question is: How can I get client-side backups so that a user can get their own data to a downloadable file, which can then later be used to restore all of the data?

Information about my stack:

I use React, mobx, apollo in the frontend. I use Hasura with Postgresql in the backend.

My application is going to be multi-tenant, I have not yet implemented the multi-tenancy, but probably it will happen so that each tenant shares the same Hasura database, and tenant_id will let them access to only their own data.

The data itself is built on multiple tables with one-to-many relationships. So the backup essentially has to be an image of sort of the users' whole data, containing the necessary information so that when it is restored, all the relationships work as before.

First I approached this problem in a naive(or at least I think it's naive) way, which meant I added a button on my client-side to download the data, pressing the button results in apollo making a query of the data from Hasura, and exporting the data as JSON for the client to download.

Now in the back of my head, I think there is a more reliable and secure way to do this. Of course, I don't want the user to be able to get the whole dump from the database, only all of the records that the user has access to.


Solution

  • Create two Hasura actions that would be responsible for exporting and importing of the data. Those actions would point to 2 microservices that would query/mutate the db as per our exact requirements regarding data security/sanitation.