GoShipped
Product

πŸ—„ Database & Storage

Postgres, pgvector, migrations, and Supabase Storage. Add product tables the same way GoShipped already does.

You don’t need to rebuild this part. Add your tables next to chat.

GoShipped uses Supabase Postgres for app data, pgvector for embeddings, and Supabase Storage for uploaded files. The FastAPI app talks to Postgres with SQLAlchemy. You add tables with migrations β€” not by clicking around in production.

supabase/migrations/     schema (source of truth)
        ↓
pnpm supabase:push       hosted
pnpm supabase:start      local (applies automatically)
        ↓
apps/api/app/db/         models + session

What is already there

Migrations in supabase/migrations/ β€” apply all of them, in filename order. Chat and memory tables start in 001_initial_schema.sql. File tables continue in 003_uploaded_files.sql, 004_uploaded_file_chunks.sql, and 005_uploaded_files_pdf.sql. 20261026143000_authorization_lockdown.sql is the current access model for those writes. Do not stop after the early files.

AreaWhat you get
Userspublic.users, filled from Auth (handle_new_user)
Chatconversations, messages, tool_calls
RAGuploaded_files, uploaded_file_chunks + vector search
Memoryagent_memory + match_agent_memory
Billingcustomers, subscriptions, webhook event ids
Settings / onboardinguser_settings
Usage & safetyusage events, rate-limit counters

pgvector is enabled in the first migration. Embedding columns are vector(1536) (OpenAI text-embedding-3-small).

supabase/seed.sql is empty on purpose.

How the API uses the database

PiecePath
URLDATABASE_URL in apps/api/.env (postgresql+asyncpg://…)
Sessionapps/api/app/db/session.py
Modelsapps/api/app/db/models.py

The API uses the database role in DATABASE_URL (the table owner). That path is not PostgREST, and it is how chat, memory, and file rows are written.

20261026143000_authorization_lockdown.sql drops client insert, update, and delete on messages, message_embeddings, tool_calls, agent_memory, uploaded_files, and uploaded_file_chunks, and revokes those privileges from anon and authenticated. Select-own policies stay. match_agent_memory and match_uploaded_file_chunks are not executable by those roles. The API calls them as the table owner.

Authenticated clients may update only display_name, avatar_url, and locale on public.users. Email stays aligned with Auth.

Billing, usage, and similar tables stay select-own or server-only. Do not add browser write policies for those rows.

Apply migrations

Use the Supabase CLI already pinned in the repo. Do not invent a second migration path.

WhereCommand
Local stackpnpm supabase:start (applies automatically)
Reset local datapnpm supabase:reset
New filepnpm supabase:new -- add_widgets
Hosted / linked projectpnpm supabase:push
Setup / deploy wizardssupabase db push after they know the DB URL

Do not run migrations inside the Vercel build. Push with the CLI (or paste SQL in the dashboard, still in filename order) before the API needs the new columns. See database migrations if the CLI workflow is new.

Private chat-files bucket

File uploads use a private bucket named chat-files (FILE_STORAGE_BUCKET). Local supabase/config.toml declares it. Hosted projects get the same bucket from 20261026143000_authorization_lockdown.sql, which also adds a restrictive storage.objects policy so anon and authenticated cannot read or write that bucket. Setup and doctor expect the bucket when features.files is on. See RAG & Files.

Add a product table

Same pattern as conversations and files: the browser may read its own rows. The API writes them.

  1. pnpm supabase:new -- add_widgets
  2. Table + indexes + ENABLE ROW LEVEL SECURITY + a select-own policy. Revoke client writes.
  3. Mirror the columns in apps/api/app/db/models.py
  4. Service + route under apps/api/app/ that inserts and updates with CurrentUser.id
  5. Local: reset or push. Hosted: pnpm supabase:push
CREATE TABLE IF NOT EXISTS public.widgets (
    id UUID PRIMARY KEY DEFAULT extensions.uuid_generate_v4(),
    user_id UUID NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
    title TEXT NOT NULL,
    metadata JSONB NOT NULL DEFAULT '{}',
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_widgets_user_id ON public.widgets(user_id);

ALTER TABLE public.widgets ENABLE ROW LEVEL SECURITY;

CREATE POLICY widgets_select_own ON public.widgets
    FOR SELECT USING (auth.uid() = user_id);

REVOKE INSERT, UPDATE, DELETE ON TABLE public.widgets FROM PUBLIC;
REVOKE INSERT, UPDATE, DELETE ON TABLE public.widgets FROM anon, authenticated;

Keep API handlers scoped to CurrentUser.id. Do not add client insert, update, or delete policies for product data.

Storage

FactDetail
Bucketchat-files (private)
Who uploadsFastAPI (apps/api/app/services/storage_service.py)
Object pathusers/{user_id}/conversations/{conversation_id}/{file_id}/{filename}
NeedsSUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY, features.files=true

SUPABASE_SECRET_KEY is an optional alias. It is used only when the value is an sb_secret_… key or a legacy service_role JWT. Any other value is ignored and SUPABASE_SERVICE_ROLE_KEY stays in place. Prefer the secret key from Dashboard β†’ Project Settings β†’ API Keys.

The lockdown migration already denies anon and authenticated access to chat-files. The API uploads with that server secret and only accepts object paths under the signed-in user. Use the same pattern for extra buckets. Official reference: Supabase Storage.

Local vs hosted

Hosted (typical): setup links the project and pushes migrations. No Docker. Create a project in the dashboard if you need one.

Local: pnpm supabase:start needs Docker. Auth mail goes to Mailpit. See local development for the CLI stack itself.

Either way, supabase/ in the repo is the schema, including the private chat-files bucket. The dashboard is for Auth URLs and SMTP β€” not a second source of truth for tables or that bucket.

pnpm supabase:* runs supabase:ensure-templates, which links repo-root templates to supabase/templates. The pinned Supabase CLI (^2.111.0) resolves email template paths from the directory you launch it in. If you invoke supabase directly from the repo root, run pnpm supabase:ensure-templates first. Without that link the CLI cannot find templates/confirmation.html.

On this page