Skip to content

Commit

Permalink
enhance: refine content further
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch committed Mar 22, 2024
1 parent caba671 commit 57c9ab0
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions content/400-pulse/250-database-setup/300-railway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ toc: true

<TopBlock>

[Railway.app](https://railway.app) provides a useful feature known as [templates](https://railway.app/templates) to facilitate quick project setup. These templates allow users to package a service or a group of services into a format that can be easily reused and shared. We have two templates for Prisma Pulse that you can use:
Railway provides a useful feature known as [templates](https://railway.app/templates) to facilitate quick project setup. These templates allow users to package a service or a group of services into a format that can be easily reused and shared. We have two templates for Prisma Pulse that you can use:

- [Prisma Pulse DB Only](https://railway.app/template/pulse-pg): Provides a fresh, pre-configured PostgreSQL database which you can use with Prisma Pulse.
- [Prisma Pulse DB & App](https://railway.app/template/pulse-starter): Provides a pre-configured PostgreSQL database and a [Prisma Pulse starter app](https://github.com/prisma/pulse-starter).
Expand Down Expand Up @@ -41,10 +41,10 @@ The template consists of two [services](https://docs.railway.app/reference/servi
> **Note**:
> The `DATABASE_URL` can also be found by clicking on the **Postgres** Service and navigating to the **Variables** tab, then clicking the copy icon next to `DATABASE_URL` environment variable value.
> ![](../images/railway-database-url.png)
6. Copy the `DATABASE_URL` connection string and save it for later. Then restart your Railway database.
6. Copy the `DATABASE_URL` connection string and save it for later. Then restart your Railway database:
1. Click on the **Postgres** service that represents your deployed database.
2. Navigate to the **Deployments** tab.
3. Go into the three-dots menu on the latest deployment and click the **Restart** option.
3. Click on the three-dots menu on the latest deployment and click the **Restart** option.
7. After restarting your database, click on the **restart-db-then-delete-me** service and navigate to the **Settings** tab.
8. Scroll down to the bottom and click the red **Delete service** button.
9. You now have a Pulse-compatible PostgreSQL database running on Railway. You can now follow the instructions on the [Getting started](/pulse/getting-started) page.
Expand All @@ -68,27 +68,26 @@ The template consists of three [services](https://docs.railway.app/reference/ser
1. For the **restart-db-then-delete-me** service, click on the **Configure** button and then save the configuration by clicking on **Save Config**.
2. On the **pulse-starter** service, locate and click the **Configure** button. Within the **Environment variables** section, you'll find an option to include the `PULSE_API_KEY` environment variable. Keep the `PULSE_API_KEY` field blank for the time being. Once you've set up the database and obtained the database URL from the [Prisma Data Platform](https://console.prisma.io/), you can then add the `PULSE_API_KEY` to the **pulse-starter** service. With the empty field for the Pulse API key, click **Save Config**.
3. Click on the **Deploy** button.
3. To set up the database and make it Pulse-ready, complete the steps outlined in the [previous section](#setup-with-template-prisma-pulse-db-only), starting from **2.**, then follow the instructions below.
4. Go to the [Platform Console](https://console.prisma.io/) and select the project in which you want to active Pulse. If you don't have a project yet, create a new project via the **New project** button.
3. To set up the database and make it Pulse-ready, complete the steps outlined in the [previous section](#setup-with-template-prisma-pulse-db-only), starting from **step 2.** till **step 8.**, then follow the instructions below.
4. Go to the [Platform Console](https://console.prisma.io/) and select the project in which you want to activate Pulse. If you don't have a project yet, create a new project via the **New project** button.
5. Navigate to the project's environment in which Pulse should be activated. If you just created a new project, the only available environment is the **Production** environment.
6. Click **Enable Pulse** on the environment's page.
6. Click **Enable Pulse** on the environment's page.
7. Paste the `DATABASE_URL` that you acquired before into the **Database connection string** field. Then, finish the process by clicking **Enable Pulse**.
8. Pulse is now enabled in your project's environment. Click **Generate API key** to obtain the API key that you need in order to use Pulse in your TypeScript starter app.
9. Save the `PULSE_API_KEY` for later and click **I've securely stored my connection string**.
9. Back in the Railway UI, click on the **pulse-starter** service.
> **Note**: You'll likely find that the build failed for the **pulse-starter** service. This is because the Prisma Pulse API key wasn't provided. Do not worry, this is to be expected and not a problem for the next steps.
6. Click on the **Variables** tab.
7. Manage your `PULSE_API_KEY` environment variable:
1. If you do not have the variable, click the **New Variable** button, create the `PULSE_API_KEY` environment variable, and then paste the value of the `PULSE_API_KEY` that you obtained in the Platform Console. Then save the changes by clicking the **Add** button.
2. If you have the variable, click the three vertical dots on the `PULSE_API_KEY` row and select **Edit**. Then paste in the `API_KEY` and click the check mark icon (☑️).
8. Rebuild the **pulse-starter** service:
1. Click on the **Deployments** tab.
2. Click on the three verticle dots on the deployment that failed. Then click **Redeploy**.
3. When the deployment starts, click the **View Logs** button.
4. Then click on the **Deploy Logs** tab to follow the deployment of the Pulse starter app.
Once the deployment is finished, you Pulse starter app is running and any database events events will be logged under the **Deploy Logs** tabs of the **pulse-starter** service.

To see an event in action, follow the steps below:
10. Back in the Railway UI, click on the **pulse-starter** service.
> **Note**: You'll likely find that the build failed for the **pulse-starter** service. This is because the Prisma Pulse API key wasn't provided. Do not worry, this is to be expected and not a problem for the next steps.
11. Click on the **Variables** tab.
12. Create your `PULSE_API_KEY` environment variable: Click the **New Variable** button, create the `PULSE_API_KEY` environment variable, and then paste the value of the `PULSE_API_KEY` that you obtained in the Platform Console. Then save the changes by clicking the **Add** button.
13. With the `PULSE_API_KEY` environment variable in place, you need to rebuild the **pulse-starter** service for the environment variable to take effect:
14. Click on the **Deployments** tab.
15. Click on the three-dots menu on the deployment that failed. Then click **Redeploy**.
16. When the deployment starts, click the **View Logs** button.
17. Then click on the **Deploy Logs** tab to follow the deployment of the Pulse starter app.

Once the deployment is finished, your Pulse starter app should be running and any database events events will be logged under the **Deploy Logs** tab of the **pulse-starter** service.

To see an event in action, you need to make changes to the `User` table. You can follow the steps below to do that from the Railway UI:

1. Click on the **Postgres** service on your Railway project.
2. Click on the **Data** tab.
Expand All @@ -103,11 +102,14 @@ To see an event in action, follow the steps below:
id: 03/34334,
modelName: "User"
}
```

## Setup without using a template

1. Change the PostgreSQL database settings

You can run these queries using a tool such as [pgAdmin](https://www.pgadmin.org/), [dbeaver](https://dbeaver.io/), or any other way you might run queries on your database.

- Set the <inlinecode>[wal_level](https://www.postgresql.org/docs/current/runtime-config-wal.html)</inlinecode> to `logical`:
```sql
ALTER SYSTEM SET wal_level = logical;
Expand All @@ -124,9 +126,10 @@ To see an event in action, follow the steps below:
```sql
SELECT pg_reload_conf();
```

2. Restart your database
1. Click on your database.
2. Navigate to the **Deployments** tab.
3. Go into the three-dots menu on the latest deployment and click the **Restart** option.

After setting up your Railway database, you have to use the [connection string](https://docs.railway.app/guides/postgresql#tcp-proxy-connection) provided by Railway that allows public access your PostgreSQL database.
3. Click on the three-dots menu on the latest deployment and click the **Restart** option.
3. After setting up your Railway database, you have to use the [connection string](https://docs.railway.app/guides/postgresql#tcp-proxy-connection) provided by Railway that allows public access to your PostgreSQL database.
4. You now have a Pulse-compatible PostgreSQL database running on Railway. You can now follow the instructions on the [Getting started](/pulse/getting-started) page.

0 comments on commit 57c9ab0

Please sign in to comment.