Moving from Self Hosted Hasura OSS to Hasura Cloud
Tags: opensource, hasura, cloud
Published: 2020-08-05 11:39:41

---
title: Moving from Self Hosted Hasura OSS to Hasura Cloud
published: true
date: 2020-07-23 13:30:34 UTC
tags: oss, hasura, cloud
canonical_url: https://hasura.io/blog/moving-from-self-hosted-hasura-oss-to-hasura-cloud/
---

![](https://hasura.io/blog/content/images/2020/07/Migrating-from-OSS-to--Hasura-cloud-3.png)

We recently announced the launch of [Hasura Cloud](https://hasura.io/blog/announcing-hasura-cloud-managed-graphql-for-your-database-and-services/) that takes care of managing the GraphQL Infrastructure automatically for you, so that you can focus on building your apps and not worry about Infrastructure. If you are running Hasura OSS, it's fairly straigtforward to migrate to Hasura Cloud. We will look at why and how to migrate in this post and the benefits it brings along.

## Why migrate to Hasura Cloud?

[Hasura Cloud](https://hasura.io/cloud/) uses the OSS [graphql-engine](https://github.com/hasura/graphql-engine) as the base and provides a cloud offering on top of that. Broadly there are two benefits to move your OSS instance to Hasura Cloud.

- **Infrastructure concerns** like number of instances, cores, memory, concurrent users, high-availability, realtime monitoring and tracing are taken care of, automatically for you.  
- **GraphQL Server concerns** like data caching, rate-limiting, regression testing, error monitoring are some of the features that will be useful at scale.

With Hasura Cloud, GraphQL becomes the _invisible_ piece in your architecture. Auto-scaling kicks in if you have a sudden traffic rush and eventually the only bottleneck will be the database. To optimise for database bottlenecks, Hasura Cloud gives you monitoring and tracing features that help you understand database query performance and give you insight into what to do.

You will also have the ability to add collaborators to your team per project and give restricted access to the console and server operations among other benefits.

![](https://hasura.io/blog/content/images/2020/07/metrics-tab.png)

Read more in detail about the benefits of Hasura Cloud in our [announcement post](https://hasura.io/blog/announcing-hasura-cloud-managed-graphql-for-your-database-and-services/).

Now that you know the benefits of migrating, let's quickly look at the steps required in performing the migration. The process depends on where your current Hasura instance is running and where your database is hosted. Do remember that, the database will still remain hosted the same way as before and doesn't need any migration apart from a potential configuration update like IP whitelisting. It is only the `graphql-engine` OSS server that needs to be migrated to Hasura Cloud.

## Migration Steps

_Note:_ If you are running Hasura OSS in production, you can follow all of the steps below on your staging server first and recommend moving your production workload to Hasura Cloud once it reaches general availability.

**Step 1:** Update your current Hasura OSS GraphQL server to the latest version.

Any new project created via Hasura Cloud runs on the latest version of Hasura OSS. At the time of writing this guide, the latest version of Hasura OSS is v1.3.0 and the docker image for the same is `hasura/graphql-engine:v1.3.0`. Change yours accordingly. Before migrating, we need to ensure OSS server is on the latest version to avoid any inconsistencies in metadata and configuration. Read more on how to [update your current Hasura instance](https://hasura.io/docs/1.0/graphql/manual/deployment/updating.html#update-hge).

**Step 2:** Take a database backup and metadata snapshot.

Although updating to Hasura Cloud will only touch the internal schema that the server maintains in the database, it's a good practice to take a backup before any migration. Use `pg_dump` CLI tool or the [PG Dump API](https://hasura.io/docs/1.0/graphql/manual/api-reference/pgdump.html#id1) to take a backup of your database and take a snapshot of your metadata using the Hasura CLI. ie. `hasura metadata export`. Read more on [metadata export](https://hasura.io/docs/1.0/graphql/manual/hasura-cli/hasura_metadata_export.html#hasura-metadata-export).

**Step 3:** Find the postgres connection string for your existing database.

We need to keep the database connection URL handy before creating a project on Hasura Cloud. This would look something like **`postgres://username:password@hostname:port/dbname`**  
  
Usually the `HASURA_GRAPHQL_DATABASE_URL` env of your existing OSS instance should have the right values if you are using any of the cloud database vendors like the Google Cloud SQL, RDS, Azure Postgres etc.

But if the database is not exposed to the outside world and the server is hosted on the same cluster as the database, accessing db via internal network, then you need to expose the database on a port which is accessible from outside that server. [Support for VPC Peering will be added soon](https://hasura.io/docs/cloud/1.0/manual/projects/create.html#connect-to-database-not-exposed-over-internet) which lets you access database not exposed over internet.  
  
For example, if you are running Hasura OSS on a DigitalOcean droplet, usually created via the One-Click integration on their marketplace, then the Postgres instance is not exposed outside. In this case, you will need to modify the docker-compose file to run the db and expose on a port (for example: 5432). DigitalOcean has [Firewall Rules](https://www.digitalocean.com/docs/networking/firewalls/how-to/configure-rules/) that can be setup to limit who can access what ports.

Below is an example from Google Cloud Platform to whitelist an IP to authorize access.

![](https://hasura.io/blog/content/images/2020/07/gcp-postgres-authorized-network1.png)

We will find what IP to whitelist after creating the project on Hasura Cloud.

The whitelisting IP step varies depending on the cloud vendor where your database is hosted currently and I would recommend checking official docs of the Cloud provider to configure this.

**Step 4:** Keep the HASURA\_GRAPHQL\_\* environment variables ready

Depending on where Hasura OSS is hosted, fetch all the Hasura environment variables and their values used for the server. If it's a `docker-compose` file, then all envs used would be present there. If it's a kubernetes cluster, check the `deployment.yaml` for the env used.

_Note:_ If you are passing [server flags](https://hasura.io/docs/1.0/graphql/manual/deployment/graphql-engine-flags/reference.html#server-flag-reference) to the OSS server, make sure to find the equivalent [environment variable](https://hasura.io/docs/1.0/graphql/manual/deployment/graphql-engine-flags/reference.html#command-flags) from the docs and keep them handy.

**Step 5:** Configure necessary Postgres permissions

This step is optional and applicable only if your database is running in a controlled environment, where you might need to configure Hasura Cloud to use a specific Postgres user that your DBA gives you.

Read more about [Postgres permissions](https://hasura.io/docs/cloud/1.0/manual/reference/postgres-permissions.html) required for running Hasura Cloud.

**Step 6:** Create a new project on Hasura Cloud.

Now that all configurations are ready, we can move on to the project creation step. Click on the Deploy to Hasura button below, signup for free to create a new project.

<!--kg-card-begin: html-->[![](https://camo.githubusercontent.com/a6de317cd7d0ed4e8722684b428f72e3da614fe8/68747470733a2f2f6772617068716c2d656e67696e652d63646e2e6861737572612e696f2f696d672f6465706c6f795f746f5f6861737572612e706e67)](https://cloud.hasura.io)<!--kg-card-end: html-->

In the new project page, enter the Database URL that was obtained from Step 3.

![](https://hasura.io/blog/content/images/2020/07/new-project-cloud.png)

Note the `IP` address given in the `Allow connections to your database from Hasura Cloud IP` box. Copy that and add this IP to Whitelist in your server / database vendor as mentioned in Step 3.

Once you click on `Create project`, your project will be initialised and ideally after a few seconds you should get the `Launch Console` button enabled for the project.

**Step 7:** Configure Environment variables

This is the final step of the migration process. Once the Cloud project is initialised, click on the `Env vars` tab on the project detail page.

![](https://hasura.io/blog/content/images/2020/07/project-detail-page.png)

To add a new environment variable, click on `New Env Var` and it should open up the following screen:

![](https://hasura.io/blog/content/images/2020/07/add-env.png)

Add all the environment variables obtained from Step 4 to your Cloud project. You can ignore the `HASURA_GRAPHQL_DATABASE_URL` and `HASURA_GRAPHQL_ADMIN_SECRET` environment variables since that's already configured. In case you are using the old admin secret in other backend servers / APIs, you can update that env here so that those APIs don't break.

### Verify and test the migration

That's it! You should be able to access the Hasura Console and make all your API requests to the new endpoint from your app. You can monitor the requests and see if queries are failing from the `Pro` tab of the console.

## Local to Cloud

What if there is an instance of Hasura running on local environment? Migrating this to Hasura Cloud will involve additional steps, primarily around setting up the database itself.

- You need to setup the database somewhere (Either on Heroku Postgres via One-Click integration on Hasura Cloud, or via other cloud vendors).
- All of the steps mentioned above for migration would apply for local to cloud migration too.
- Once the cloud project is created, if you have the migrations and metadata ready for your local instance, apply them to the cloud project using the Hasura CLI via `hasura migrate apply` and `hasura metadata apply`. 
- If you don't have the migrations ready or didn't use the Console via CLI for migrations in your local dev, you can make use of the PG Dump API to export the local database schema and apply it to the new database created as the [initial migration file](https://hasura.io/docs/1.0/graphql/manual/migrations/basics.html#initializing-migrations). The metadata can be exported from your local db by using `hasura metadata export`.
- Follow the [Production Checklist](https://hasura.io/docs/1.0/graphql/manual/deployment/production-checklist.html) to ensure your local instance is ready to go live.

### Things to Note:

- Custom domains will be added soon to Hasura Cloud. This will let you configure your own domain for the API endpoint instead of the auto-generated `hasura.app` endpoint.
- Moving from Hasura OSS to Hasura Cloud (and vice-versa) is reversible as long as the server version connecting to the database remains the same on both.
- You can create the project, apply the environment variables via an API too. Read more on the [API reference](https://hasura.io/docs/cloud/1.0/manual/reference/api.html).

Let us know how the migration went through! In case you want help to troubleshoot/debug, feel free to join our [Discord server](https://hasura.io/discord) and post your queries over there.