Skip to content

feat(db): add node-pg-migrate for reversible database migrations#2

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

feat(db): add node-pg-migrate for reversible database migrations#2
brnikita merged 8 commits intomainfrom
feat/db-migrations

Conversation

@brnikita
Copy link
Contributor

@brnikita brnikita commented Mar 7, 2026

Summary

  • Replace static supabase/schema.sql with node-pg-migrate for proper versioned, reversible migrations
  • Initial migration creates profiles, saved_simulations, shared_links tables with RLS policies and the handle_new_user trigger
  • Full down migration support — every migration can be reverted cleanly
  • Add npm scripts: migrate:up, migrate:down, migrate:create, migrate:dry

Usage

# Set DATABASE_URL in .env (from Supabase Dashboard → Settings → Database)
DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres

# Apply all pending migrations
npm run migrate:up

# Revert last migration
npm run migrate:down

# Preview SQL without running
npm run migrate:dry

# Create a new migration
npm run migrate:create add-some-table

Verification

  • npm run check passes
  • npm test passes (145 tests)
  • npm run build succeeds
  • Migration file has both up and down sections

Note

After merging, run npm run migrate:up against the Supabase database to create tables and fix the "Database error saving new user" sign-in error.

🤖 Generated with Claude Code

brnikita and others added 8 commits March 8, 2026 01:33
Replace static supabase/schema.sql with proper migration tooling:
- Add node-pg-migrate with pg driver
- Create initial migration with full up/down support
- Add npm scripts: migrate:up, migrate:down, migrate:create, migrate:dry
- Add DATABASE_URL to .env.example

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add migrate job to CI pipeline that runs after build+e2e pass.
Only triggers on push to main (i.e. after PR merge).
Requires DATABASE_URL secret in GitHub repo settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validates pending migrations against the live DB without executing them.
Shows the SQL that would run, catching errors before merge.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace dry-run against prod with a proper isolated test:
- Spin up Postgres 16 service container
- Create auth schema stubs (auth.users, auth.uid())
- Run migrate up → down → up to verify full reversibility
- No connection to production database on PRs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace Postgres + auth stubs with a real Supabase local instance:
- Use supabase/setup-cli + supabase db start for full auth schema
- Test up → down → up cycle to verify reversibility
- Remove auth-stubs.sql (no longer needed)
- migrate job on main now depends on migrate-check passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use supabase start (full stack) instead of db start for auth schema
- Hardcode known local DB URL instead of parsing supabase status
- Move prod migration deploy to separate workflow (triggers on migrations/** changes)
- Remove "Run Migrations" job from CI to clean up PR graph

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Required by shared_links.share_token default value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gen_random_bytes requires pgcrypto which isn't always available.
gen_random_uuid() is built into Postgres 13+ and produces equivalent tokens.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brnikita brnikita merged commit d6aad1e into main Mar 7, 2026
6 checks passed
@brnikita brnikita self-assigned this Mar 7, 2026
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