Crunchy Bridge and Koyeb

Integrate a managed Crunchy Bridge Postgres database to your application running on Koyeb and benefit from Koyeb native autoscaling, automatic HTTPS (SSL), auto-healing, and global load-balancing across our edge network with zero configuration.

Crunchy Bridge is a fully managed Postgres service from Crunchy Data. It runs and manages your Postgres database and offers backups, disaster recovery with point-in-time recovery, and built-in connection pooling.

This guide explains how to connect a Crunchy Bridge PostgreSQL database to an application running on Koyeb. To successfully follow this documentation, you will need to have:

Create a Crunchy Bridge PostgreSQL database

To create a Crunchy Bridge PostgreSQL database, sign into your Crunchy Bridge account.

On the Crunchy Bridge control panel, start by clicking the Create Cluster button to provision a cluster and access the database creation page.

  1. Give a name to your cluster, e.g., postgres-koyeb
  2. Select the Cloud Service provider for your Postgres database between AWS, Azure, or GCP. For this guide, we use AWS.
  3. Pick the Region to run the database in. Here, we use EU Central (Frankfurt) as our compute will be deployed in this region on Koyeb.
  4. Select a database Tier. Depending on the tier you select you will be able to access different instances type. For this guide, we use the Hobby tier.
  5. Choose the Instance size according to your needs. Here we use the Hobby-0 with 0.5 GB memory and 2vCores.
  6. Pick the PostgreSQL Version to use for the database. Here we use Postgres 15.
  7. Choose the amount of Storage needed for your database, e.g., 10 GB.
  8. Depending on your project's criticality, there is an option to enable High Availability. In our case, we don't need it and keep the default value to No.

When you are done configuring your database, click the Create Cluster button. Your cluster will be provisioned.

Prepare the database on your machine

The application we will deploy on Koyeb that connects to the Crunchy Bridge PostgreSQL uses Prisma as an ORM. Prisma is an open-source ORM. We use it to synchronize our database schema with our Prisma schema.

Before deploying the application, we will need to perform a migration to create the database schema and seed data.

Clone the example application

Start by cloning the application that will connect to the PostgreSQL database on your machine and navigate to the app directory by running the following commands:

git clone git@github.com:koyeb/example-express-prisma.git cd example-express-prisma

Retrieve your Crunchy Bridge Postgres connection string

On the Crunchy Bridge control panel, click on the Connection tab to retrieve the connection string to connect the database.

By default, three Roles are created to connect your database with different privileges. You can learn more about these roles and permissions in the Crunchy Bridge’s User Management documentation.

For this guide, we will use the application role to connect the database which has standard permissions. Select the URL format and copy it for the next step.

Initialize and seed the database

To synchronize our database schema with our Prisma schema and seed data, run the following commands in your terminal:

DATABASE_URL="<YOUR_CRUNCHY_BRIDGE_CONNECTION_STRING>" npx prisma db push DATABASE_URL="<YOUR_CRUNCHY_BRIDGE_CONNECTION_STRING>" npx prisma db seed

Make sure to replace <YOUR_CRUNCHY_BRIDGE_CONNECTION_STRING> with your connection string.

Deploy the application on Koyeb

You can deploy on Koyeb using the control panel or via the Koyeb CLI.

Via the Koyeb control panel

To deploy the example application using the control panel, follow these steps:

  1. Create a new Koyeb App.
  2. Setgithub.com/koyeb/example-express-prisma as the GitHub repository to deploy and keep the default branch main.
  3. Add a DATABASE_URL environment variable to indicate the application how to connect to the Postgres database. Give the environment variable a name, DATABASE_URL and enter the connection string from earlier as the value.
  4. Name your service, for instance express-postgres.
  5. Click the Create service button.

Koyeb is now building the application. Once the build has finished, you will be able to access your application running on Koyeb by clicking the URL ending with .koyeb.app.

The example application exposes a /planets endpoint that you can use to list planets from the database we prepared earlier. Once your deployment is live, you should see the following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets:

[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]

Via the Koyeb CLI

To deploy the example application using the Koyeb CLI, run the following command in your terminal:

koyeb app init express-postgres \ --git github.com/koyeb/example-express-prisma \ --git-branch main \ --ports 8080:http \ --routes /:8080 \ --env PORT=8080 \ --env DATABASE_URL="<YOUR_CRUNCHY_BRIDGE_CONNECTION_STRING>"

Make sure to replace <YOUR_CRUNCHY_BRIDGE_CONNECTION_STRING> with your connection string.

Access deployment logs

To track the app deployment and visualize build logs, execute the following command:

koyeb service logs express-postgres/express-postgres -t build

Access your app

Once the deployment of your application has finished, you can retrieve the public domain to access your application by running the following command:

$ koyeb app get express-postgres ID NAME DOMAINS CREATED AT ec6a4311 express-postgres ["express-postgres-myorg.koyeb.app"] 4 Nov 22 16:16 UTC

The example application exposes a /planets endpoint that you can use to list planets from the database we prepared earlier. Once your deployment is live, you should see the following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets:

[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]

Delete the example application and Crunchy Bridge PostgreSQL database

To delete the example application and the Crunchy Bridge PostgreSQL database and avoid incurring any charges, follow these steps:

  • From the Crunchy Bridge dashboard, go to the "Settings" tab and click "Destroy Cluster". Follow the instructions.
  • From the Koyeb control panel, select the App to delete. Under the "Settings" tab, click the "Delete" button and follow the instructions.