# Migrate from Supabase

> Run the plan first, review warnings, then apply. The source is read, not modified. Keep it until you have tested sign-in, data, uploads, functions and traffic. Arrange a maintenance window for cutover: a dump does not continuously replicate later writes.

Source: https://docs.infaris.com/en/pulseguard/hosting-migrate-supabase

## What it is

Run the plan first, review warnings, then apply. The source is read, not modified. Keep it until you have tested sign-in, data, uploads, functions and traffic. Arrange a maintenance window for cutover: a dump does not continuously replicate later writes.

## Quick start and CLI

```bash
infaris-guard hosting migrate supabase <projectref> --secrets-file .env.migrate --plan
infaris-guard hosting migrate supabase <projectref> --secrets-file .env.migrate --yes
infaris-guard hosting migrate status
```

## SDK and code

```ts
// Auth example after migration. Values come from your new Auth attachment.
import { createClient } from '@infaris/auth-js';
const auth = createClient(
  process.env.NEXT_PUBLIC_INFARIS_AUTH_URL!,
  process.env.NEXT_PUBLIC_INFARIS_AUTH_KEY!,
);
await auth.signInWithOtp({ email: 'sanne@example.nl' });
```

## Secure defaults

Keep source secrets in the ignored `.env.migrate` file, readable only by you. Use the names below, never actual secrets as CLI arguments. Buckets and functions become private unless you explicitly choose `--keep-public`. Table grants are not copied: review target RLS and exposure.

## Limits

Steps: `database,auth,storage,functions,cron,realtime`. Database transfer uses PostgreSQL 17 client tools (`pg_dump` and `psql`); set `INFARIS_PG_BIN` if needed. Functions come from `supabase/functions`, or `--functions-dir`. Unsupported extensions, SQL cron and incompatible policies appear in the report. There is no general SQL policy translator.

## FAQ

**Interrupted?** Repeat the command with the same source and options; it resumes from `.infaris/migrate-supabase-<project>.json`. Keep that file. **Result?** Read the matching `.md` report and `.env.diff` file in `.infaris`. **Skip a step?** `--skip` takes a comma-separated list of the steps above. **Roll back?** Keep the source and switch traffic back; there is no general undo for created target resources.

## Source credentials and cutover checks

In `.env.migrate` (placeholders, not working values):

```dotenv
SUPABASE_DB_URL=postgresql://...
SUPABASE_ACCESS_TOKEN=...
SUPABASE_SERVICE_ROLE_KEY=...
```

Replace Auth, Data and Storage clients with Infaris clients. User IDs are retained, but password hashes are not imported. Ask users to request an OTP. Reconfigure OAuth and SSO. Check policies and references to `auth.users`.

1. Compare row and file counts and review all skipped items in the report.
2. Test sign-in, MFA, RLS with two users, uploads and background work.
3. Update SDK URLs and environment values and publish a test version.
4. Stop source writes for final transfer; check differences before switching traffic.
5. Change DNS and callbacks deliberately, verify the live app and retain the source for rollback.
