Skip to content

v0.6.54: migration error logs#4261

Merged
icecrasher321 merged 1 commit intomainfrom
staging
Apr 22, 2026
Merged

v0.6.54: migration error logs#4261
icecrasher321 merged 1 commit intomainfrom
staging

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

improvement(migrations): log better errors (#4260)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 22, 2026 5:09am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 22, 2026

PR Summary

Medium Risk
Touches database migrations and index/constraint ordering; while the change is small, it affects schema invariants during data migration and could impact production migration behavior if assumptions differ.

Overview
Improves the 0194 permission-group rebase migration by dropping the legacy permission_group_member_user_id_unique index earlier (before cloning) to prevent unique-constraint violations while inserting per-workspace membership clones.

Updates packages/db/scripts/migrate.ts to log richer Postgres error diagnostics (PG code, constraint/table/column, failing query/parameters, nested causes, and stack) instead of only printing error.message.

Reviewed by Cursor Bugbot for commit 41a1b50. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR makes two targeted improvements to the migration infrastructure: it moves the DROP INDEX for permission_group_member_user_id_unique from step 7 to step 1c in migration 0194 so the legacy global uniqueness constraint is removed before the cloning INSERT in step 4 (which would otherwise violate it), and it replaces the bare error.message log in migrate.ts with a printMigrationError helper that surfaces all Postgres driver diagnostic fields — constraint name, PG error code, hint, failing query, cause chain, and stack trace — making future migration failures much easier to diagnose.

Confidence Score: 5/5

Safe to merge — both changes are correct, well-documented, and idempotent.

The SQL reordering fixes a real constraint-violation bug that would have caused migration 0194 to fail on databases with multi-workspace users; the DROP INDEX IF EXISTS is idempotent so re-runs are safe. The printMigrationError function is purely additive, handles all error shapes defensively, and the function declaration is correctly hoisted in the ES module scope. No P0/P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
packages/db/migrations/0194_careless_pete_wisdom.sql Moves DROP INDEX on permission_group_member_user_id_unique from step 7 (late cleanup) to step 1c (before cloning), preventing a unique-constraint violation when inserting cloned member rows in step 4.
packages/db/scripts/migrate.ts Replaces single-field error.message logging with a comprehensive printMigrationError function that surfaces all Postgres driver diagnostic fields (code, constraint, hint, query, etc.) on migration failure.

Sequence Diagram

sequenceDiagram
    participant Script as migrate.ts
    participant Drizzle as drizzle-orm migrator
    participant PG as PostgreSQL

    Script->>Drizzle: migrate(drizzle(client), { migrationsFolder })
    Drizzle->>PG: Run migration SQL statements
    alt Migration succeeds
        PG-->>Drizzle: OK
        Drizzle-->>Script: resolved
        Script->>Script: console.log("Migrations applied successfully.")
    else Migration fails
        PG-->>Drizzle: PostgresError (code, constraint, hint, query…)
        Drizzle-->>Script: throws Error
        Script->>Script: printMigrationError(error)
        Note over Script: Logs message, PG fields (code,<br/>constraint, hint, table, etc.),<br/>failing query, parameters,<br/>cause chain, stack
        Script->>Script: process.exit(1)
    end
    Script->>PG: client.end() [finally]
Loading

Reviews (1): Last reviewed commit: "improvement(migrations): log better erro..." | Re-trigger Greptile

@icecrasher321 icecrasher321 merged commit 7c619e7 into main Apr 22, 2026
31 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