This sample project demonstrates how to deploy Hasura with Defang and connect it to a Postgres database. We also demonstrate how to run a Postgres container during development and how to switch over to a managed postgres service like RDS, Neon, or others in production. If you want to get a compatible database ready to go really quickly for free, Neon is a quick and easy way to go. The sample populates the database with some sample data so you can quickly start playing with the Hasura console. It sets wide open permissions on the tables as well so you can start querying or mutating the data right away.
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
- (Optional) Install the Hasura CLI to create migrations and update metadata for your Hasura GraphQL api.
To start the development environment, run docker -f ./compose.dev.yaml up
. This will start the Postgres container and the Hasura container. The Hasura console will be available at http://localhost:8080
with the password password
.
Note: If you want to make changes to your database, permissions, etc. you should use the Hasura console and the Hasura CLI to make those changes. See the next section for more information.
If you want to edit the database, permissions, or any other Hasura settings such that you can deploy them to production, you should install the Hasura CLI. Then, after starting the development environment, you can run hasura console
inside the ./hasura
directory. This will open the Hasura console in your browser. Any changes you make in the console will be saved to the migrations
and metadata
directories. When you run defang compose up
these changes will be applied to the production environment.
NOTE: If you are using the Dev Container defined in .devcontainer/devcontainer.json, the Hasura CLI will already be installed.
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
This password will be used to allow you to access the hasura console.
This password will be used to initialize the PostgreSQL database and to connect to it. You could use a command like openssl rand -base64 16
to generate a random password.
Note
Download Defang CLI
Deploy your application to the defang playground by opening up your terminal and typing defang up
.
Keep in mind that the playground does not support managed Postgres.
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run
defang --provider=aws up
in a terminal that has access to your AWS environment variables.
Title: Hasura & PostgreSQL
Short Description: A sample project demonstrating how to deploy Hasura with Defang and connect it to a PostgreSQL database.
Tags: Hasura, GraphQL, PostgreSQL, Database
Languages: SQL, GraphQL