Skip to content

feat(db): reversible migrations with node-pg-migrate#3

Merged
brnikita merged 2 commits intomainfrom
feat/db-migrations
Mar 7, 2026
Merged

feat(db): reversible migrations with node-pg-migrate#3
brnikita merged 2 commits intomainfrom
feat/db-migrations

Conversation

@brnikita
Copy link
Contributor

@brnikita brnikita commented Mar 7, 2026

Summary

  • Add node-pg-migrate for versioned, reversible database migrations (up/down)
  • Initial migration: profiles, saved_simulations, shared_links tables + handle_new_user trigger
  • CI: test migrations against full Supabase instance (up → down → up) on every PR
  • CD: auto-deploy migrations to prod on merge to main (deploy-migrations.yml)
  • Fix handle_new_user trigger: add SET search_path = public (was causing "Database error saving new user")
  • Fix saveSimulation: include user_id from auth session (was causing RLS 403)

npm scripts

Command Description
npm run migrate:up Apply pending migrations
npm run migrate:down Revert last migration
npm run migrate:create <name> Create new migration file
npm run migrate:dry Preview SQL without running

Verification

  • npm run check passes
  • npm test passes (145 tests)
  • npm run build succeeds
  • Migration up/down/up cycle verified in CI (full Supabase instance)
  • OAuth sign-in works on prod (trigger fix applied)

🤖 Generated with Claude Code

brnikita and others added 2 commits March 8, 2026 02:23
GoTrue (supabase_auth_admin) uses a different search_path than postgres.
Without explicit search_path = public, the INSERT INTO profiles fails
with "Database error saving new user" on OAuth/email sign-up.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The INSERT was missing user_id, causing RLS policy violation (42501).
Now reads user.id from authStore before inserting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brnikita brnikita self-assigned this Mar 7, 2026
@brnikita brnikita merged commit 681ccce into main Mar 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant