Skip to content

Database & migrations

Supabase CLI, migrations, pg_cron notes, and type generation for OpenQuok.

2 min read

Connect your agent today

Draft from chat, review in your calendar, and publish only what you approve.

Start for $0

Overview

Database workflow is managed through the Supabase CLI + the migrations under backend/supabase/.

Steps (local)

Install and configure Supabase CLI

Set your project id in backend/supabase/config.toml.

Start local Supabase

cd backend
supabase start

After the stack is up, print connection variables in shell-friendly form:

supabase status -o env

Reset DB to current migrations

supabase db reset

Generate types (optional)

pnpm db:local:typegen

Aggregated migrations

This repo aggregates SQL modules under backend/supabase/db/ into backend/supabase/migrations/.

Aggregate all modules:

pnpm db:aggregate-migrations-all

Aggregate a single module:

pnpm db:aggregate-migrations-single config

Production backup

Before you squash migrations or move a production project to a new region, back up the database and Storage. See Supabase backup.

Cron: expired refresh tokens (pg_cron)

The user-auth module includes a cron job that deletes expired rows in public.refresh_tokens (runs every Saturday at 3:30 AM GMT). It relies on the Postgres pg_cron extension.

After you enable pg_cron on Supabase Cloud, push the migrations so the cron job becomes active.

When you push schema to a linked production project (in backend/):

pnpm db:production:migration-list
pnpm db:production:push-db:dry-run
pnpm db:production:typegen
pnpm db:production:push-db

Supabase Cloud notes (pg_cron)

Search documentation
Find a docs page
Discord Support