Skip to content

fix(migration): permission group migration error#4258

Merged
icecrasher321 merged 1 commit intostagingfrom
fix/migration-perm-groups
Apr 22, 2026
Merged

fix(migration): permission group migration error#4258
icecrasher321 merged 1 commit intostagingfrom
fix/migration-perm-groups

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Fix broken migration

Type of Change

  • Bug fix

@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 Building Building Preview, Comment Apr 22, 2026 4:08am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 22, 2026

PR Summary

Medium Risk
Touches a production data migration that reshapes permission-group scoping and constraints; incorrect execution could impact access control data, though the changes aim to reduce failure/retry risk.

Overview
Hardens migration 0194_careless_pete_wisdom to be idempotent so it can be safely re-run after partial failures.

It switches DDL to IF NOT EXISTS/conditional blocks for added columns, foreign keys, dropped constraints/indexes/columns, and created unique indexes, and explicitly drops the NOT NULL constraint on permission_group.organization_id before inserting workspace-scoped clones (then proceeds with the same clone/copy/delete steps).

Reviewed by Cursor Bugbot for commit 060472e. Configure here.

@icecrasher321 icecrasher321 merged commit 51ace65 into staging Apr 22, 2026
13 of 14 checks passed
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR hardens the 0194 permission-group migration by wrapping every previously non-idempotent DDL statement in appropriate IF NOT EXISTS / IF EXISTS guards and adds a new step 1b that drops the NOT NULL constraint on permission_group.organization_id before the clone-insert step, which was the root cause of failure when the original migration was re-run after a partial execution.

Confidence Score: 5/5

Safe to merge — all changes are idempotency improvements with no destructive or data-altering new logic; only remaining comments are minor style suggestions.

Every changed statement is a guard addition (IF NOT EXISTS / IF EXISTS) or the new step 1b DROP NOT NULL, which is a no-op when the column is already nullable. No P0/P1 defects were found; the two inline comments are P2 style improvements to the schema filter in the information_schema lookups.

No files require special attention; the migration logic is sound.

Important Files Changed

Filename Overview
packages/db/migrations/0194_careless_pete_wisdom.sql Adds idempotency guards (IF NOT EXISTS / IF EXISTS) throughout the migration and introduces step 1b to DROP NOT NULL on organization_id before cloning rows — fixes migration failures on partial re-runs.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    S0["Step 0: Backfill workspace→org links\n(grandfathered workspaces)"]
    S1["Step 1: ADD COLUMN IF NOT EXISTS\nworkspace_id on permission_group\n& permission_group_member"]
    S1FK["Add FK constraints\n(DO $$ IF NOT EXISTS $$)"]
    S1b["Step 1b: DROP NOT NULL on\npermission_group.organization_id\n🆕 new in this PR"]
    S2["Step 2: CREATE TEMP TABLE\n__permission_group_clone_plan\nON COMMIT DROP"]
    S3["Step 3: INSERT cloned\npermission_group rows\n(organization_id = NULL)"]
    S4["Step 4: Copy permission_group_member\nrows to workspace clones"]
    S5["Step 5: DELETE legacy\norg-scoped rows"]
    S6["Step 6: SET NOT NULL\non both workspace_id columns"]
    S7["Step 7: DROP IF EXISTS old constraints/indexes\nCREATE IF NOT EXISTS new indexes"]
    S8["Step 8: Sweep residual\nconfig keys"]

    S0 --> S1 --> S1FK --> S1b --> S2 --> S3 --> S4 --> S5 --> S6 --> S7 --> S8

    style S1b fill:#ffd700,stroke:#b8860b
    style S1 fill:#90EE90,stroke:#228B22
    style S1FK fill:#90EE90,stroke:#228B22
    style S7 fill:#90EE90,stroke:#228B22
Loading

Reviews (1): Last reviewed commit: "fix(migration): permission group migrati..." | Re-trigger Greptile

Comment thread packages/db/migrations/0194_careless_pete_wisdom.sql
Comment thread packages/db/migrations/0194_careless_pete_wisdom.sql
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