Database & migrations
Supabase CLI, migrations, pg_cron notes, and type generation.
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 Reset DB to current migrations
supabase db reset Generate types (optional)
pnpm db:local:typegenAggregated 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 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 use the “Production-linked Supabase” commands on the local development page, run these (in backend/):
pnpm db:production:typegen
pnpm db:production:push-db Supabase Cloud notes (pg_cron)
Enable cron integration on Supabase Cloud
pg_cron, enable it first in the Supabase Dashboard (Integrations → Cron), then run your migrations / push. On Supabase Cloud, you can also run the following once to create the extension and grant the required privileges:
create extension pg_cron with schema pg_catalog;
grant usage on schema cron to postgres;
grant all privileges on all tables in schema cron to postgres;