Skip to content

bug: seed_category_mappings.sql references categories not in initial schema — npx supabase db reset fails #95

Description

@cje-bridgyr

Symptom

npx supabase db reset fails partway through with an FK violation while applying supabase/migrations/20260304021726_seed_category_mappings.sql. The local Supabase stack cannot be brought up cleanly until this is fixed.

Root cause

20260304021726_seed_category_mappings.sql inserts rows into public.category_mappings whose category_id values reference categories that do not exist in the seed data of 00000000000000_initial_schema.sql.

The only seeded category IDs in the initial schema are:

  • salary-income
  • internal-transfer
  • external-transfer
  • round-up
  • interest
  • investments

The seed-mappings migration tries to insert rows referencing categories like `groceries`, etc., which were never inserted. The FK constraint `category_mappings_category_id_fkey` fails on the first such row, aborting the migration and leaving the local DB in a partial state.

Impact

  • `npx supabase db reset` is broken for any contributor cloning fresh.
  • New schema work cannot be verified against the real local stack — has to use a throwaway Postgres container with auth stubs.
  • Blocks UI development for any feature that needs a working local Supabase.

Possible fixes

  1. Add the missing category rows to `00000000000000_initial_schema.sql` (preferred — keeps initial schema self-consistent).
  2. Wrap the mappings inserts in `INSERT ... ON CONFLICT DO NOTHING` and pre-insert the categories at the top of `20260304021726_seed_category_mappings.sql` itself.
  3. Drop the seed-mappings migration if the data isn't load-bearing for current features.

Reproduction

```bash
git clone https://github.com/BenLaurenson/PiggyBack.git
cd PiggyBack
npm install
npx supabase start
npx supabase db reset

fails on 20260304021726_seed_category_mappings.sql

```

Discovered during

Wise Business Accounting Phase 1A foundation implementation (May 2026). Forced the implementation to verify schema changes against a `postgres:15` Docker container with hand-rolled `auth.uid()`, `authenticated`, and `service_role` stubs rather than the real Supabase stack.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions