After a migration that added a GIN, all subsequent migrations drop and recreate this index
See original GitHub issueBug description
We recently added a Generalized Inverted Index to one of our tables.
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS btree_gin;
-- CreateIndex
CREATE INDEX "workspace_folder_workspaceId_status_name_idx" ON "workspace_folder" USING GIN ("workspaceId", "status" , "name" gin_trgm_ops);
All subsequent migrations now drop this index and recreate it, for example;
-- DropIndex
DROP INDEX "workspace_folder_workspaceId_status_name_idx";
-- CreateIndex
CREATE INDEX "workspace_invite_wid_index" ON "WorkspaceInvite"("workspaceId");
-- CreateIndex
CREATE INDEX "workspace_folder_workspaceId_status_name_idx" ON "workspace_folder" USING GIN ("workspaceId" , "status" , "name" gin_trgm_ops);
How to reproduce
- Create a migration that adds a GIN
- Create a subsequent migration via migrate dev
Expected behavior
It should not drop and recreate the GIN on subsequent migrations
Prisma information
//...
model WorkspaceInvite {
userId String @db.Uuid
workspaceId String @db.Uuid
role WorkspaceRole @default(editor)
status WorkspaceInviteStatus
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
invitedBy String? @db.Uuid
workspace Workspace @relation(fields: [workspaceId], references: [id])
@@id([userId, workspaceId])
@@unique([userId, workspaceId])
@@index([workspaceId])
}
model WorkspaceFolder {
id String @id @default(uuid()) @db.Uuid
name String
workspaceId String @db.Uuid
parentId String? @db.Uuid
createdAt DateTime @default(now())
status WorkspaceFolderStatus @default(active)
updatedAt DateTime @default(now()) @updatedAt
category WorkspaceFolderCategory @default(default)
parent WorkspaceFolder? @relation("WorkspaceFolderToWorkspaceFolder", fields: [parentId], references: [id], onDelete: Cascade)
workspace Workspace @relation(fields: [workspaceId], references: [id])
WorkspaceProjects WorkspaceProject[]
WorkspaceFolder WorkspaceFolder[] @relation("WorkspaceFolderToWorkspaceFolder")
WorkspaceSettings WorkspaceSettings[]
@@index([workspaceId], map: "workspace_folder_wid_index")
@@index([parentId], map: "parent_id_folder_index")
@@index([workspaceId, parentId], map: "workspace_id_folder_index")
@@index([workspaceId, parentId, status], map: "workspace_id_folder_index_status")
@@index([workspaceId, parentId, status, category])
@@index([workspaceId(ops: raw("")), status(ops: raw("")), name(ops: raw("gin_trgm_ops"))], type: Gin)
@@map("workspace_folder")
}
// ...
Environment & setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: v18.12.0
Prisma Version
4.3.1
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does add_index using 'gin' create a 'btree' index instead?
The reason, as explained in the Rails Migrations guide, is that a GIN index is specific to Postgres. When you are using database-specific ......
Read more >Migration | GORM - GORM
Automatically migrate your schema, to keep your schema up to date. NOTE: AutoMigrate will create tables, missing foreign keys, constraints, columns and indexes....
Read more >Adding Indexes with EF Migrations | Passion for Coding
I'll add my index creation to the Up() method and a drop statement to the Down() method to enable downgrading the database schema....
Read more >Digging Deeper Into Django Migrations - Real Python
In this step-by-step Python tutorial, you'll not only take a closer look at the new Django migrations system that is integrated into Django...
Read more >How to Migrate Sourcegraph from one cluster to another.
Steps to backup Sourcegraph Databases · Verify that the deployment is running. kubectl get pods -A · Stop all connections to the database...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes sorry I should have been a bit clearer - the workspace_invite_wid_index is the index I added, but I was expecting that to be the only line in the migration.
To be 100% clear, this is the original SQL in the first migration where the GIN was added;
And here is what gets generated in every migration now, for example running migrate dev on a fresh database;
Running migrate dev 3x results in 3 files with the above DropIndex + CreateIndex
Hi @SevInf apologies, copy pasted the wrong value. Currently using
4.3.1