Skip to content

Latest commit

 

History

History
118 lines (85 loc) · 4.39 KB

File metadata and controls

118 lines (85 loc) · 4.39 KB
title Deploy Your First Flow
description Step-by-step guide to deploying pgflow workers to Supabase.com production for the first time
sidebar
order
100
banner
content
pgflow is in public beta. <a href="/project-status/">See project status</a> for production readiness details.

import { Aside, CardGrid, LinkCard } from "@astrojs/starlight/components";

This guide walks you through deploying your pgflow workers to Supabase.com production for the first time.

Before deploying to production: - You have a working local development environment - Your flows are compiled and tested locally - You have a Supabase project (free or paid tier) The `pgflow` ControlPlane function is for local compilation only. You do not need to deploy it to production yet - only deploy your worker functions.

Get Your Database Connection String

Your workers need to connect to the production database:

  1. Open Supabase Dashboard
  2. Navigate to SettingsDatabase
  3. Scroll to Connection String section
  4. Copy the Transaction Mode connection string (uses connection pooler)

The connection string looks like:

postgresql://postgres.pooler-yourproject:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres

:::note[Why Transaction Mode?] Transaction Mode uses connection pooling (port 6543), which is required for Edge Functions. The pooler efficiently manages database connections in serverless environments. :::

If your password contains special characters (`@`, `&`, `:`, etc.), you'll need to URL-encode it. See [Connection String Encoding](/deploy/connection-string/) for details.

Set Database Secret

Workers access the database through the EDGE_WORKER_DB_URL environment variable. Set it as a Supabase secret:

npx supabase secrets set EDGE_WORKER_DB_URL="postgresql://postgres.pooler-yourproject:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres"

Replace [YOUR-PASSWORD] with your actual database password from the connection string.

:::caution[Keep Your Password Secure]

  • Never commit passwords to git
  • Never share passwords in public channels
  • Use the encoded password if it contains special characters :::

Deploy Your Worker

Deploy your Edge Function to Supabase:

npx supabase functions deploy your-worker-name

Replace your-worker-name with your actual worker function name (e.g., flow-worker).

This uploads your worker code and makes it available at:

https://your-project.supabase.co/functions/v1/your-worker-name

Start Your Worker

Workers don't start automatically after deployment. Start it with a POST request:

curl "https://your-project.supabase.co/functions/v1/your-worker-name" \
  -H "Authorization: Bearer YOUR_ANON_KEY"

Finding your ANON key:

  1. Open Supabase Dashboard
  2. Navigate to SettingsAPI
  3. Copy the anon public key

:::note Production Edge Functions have JWT verification enabled by default. Currently, workers use the anon key for self-respawning. Enhanced authentication using a dedicated secret key is planned for future releases. :::

The worker starts polling for tasks and continues running until it's stopped or times out.

Set Up the Safety Net

Edge Functions eventually stop due to platform limits or errors. Set up a pg_cron job to automatically restart workers when they stop.

Follow the safety net setup guide →

**Your workers will eventually stop without a safety net.** This is especially critical for production where workflow reliability matters.

The safety net takes 2 minutes to set up and prevents hours of debugging why workflows stopped running.

See Also