fix(migrations): remove duplicate indexes#2501
Merged
icecrasher321 merged 1 commit intostagingfrom Dec 20, 2025
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile SummaryThis PR removes duplicate index definitions that were already created in migration 0125 and adds defensive SQL patterns for idempotency.
These changes make the migration safer to run multiple times and eliminate database errors from duplicate index creation attempts. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant M as Migration Script
participant DB as PostgreSQL Database
participant WEL as workflow_execution_logs
participant W as workflow
participant WS as workspace
Note over M,DB: Step 1: Add nullable column
M->>DB: ALTER TABLE ADD COLUMN IF NOT EXISTS workspace_id
DB-->>M: Column added or already exists
Note over M,DB: Step 2: Backfill workspace_id
M->>DB: UPDATE workflow_execution_logs<br/>SET workspace_id FROM workflow<br/>WHERE workspace_id IS NULL
DB->>W: Join workflow table
W-->>DB: Return workspace_id values
DB->>WEL: Update rows with workspace_id
DB-->>M: Rows updated
Note over M,DB: Step 3: Delete orphaned logs
M->>DB: DELETE WHERE workspace_id IS NULL
DB->>WEL: Remove orphaned records
DB-->>M: Orphaned records deleted
Note over M,DB: Step 4: Add NOT NULL constraint
M->>DB: ALTER COLUMN workspace_id SET NOT NULL
DB-->>M: Constraint added
Note over M,DB: Step 5: Add foreign key (with existence check)
M->>DB: IF NOT EXISTS constraint check
DB-->>M: Constraint status
alt Constraint doesn't exist
M->>DB: ADD CONSTRAINT FOREIGN KEY
DB->>WS: Link to workspace table
DB-->>M: Foreign key added
else Constraint exists
M->>M: Skip constraint creation
end
Note over M,DB: Step 6: Create index (idempotent)
M->>DB: CREATE INDEX IF NOT EXISTS<br/>workflow_execution_logs_workspace_started_at_idx
DB-->>M: Index created or already exists
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of Change
Testing
Tested manually
Checklist