prisma
prisma copied to clipboard
`prisma db push` should not delete externally managed indexes
Problem
I am using the mongoDB provider and I have a 2dsphere geo index. Since prisma doesn't support such an index, I manually create it.
However, when running prisma db push, the index is deleted:

I am running prisma db push as part of my startup procedure, each time a container starts... so this is a clear problem for me.
Suggested solution
There should be a way to flag a specific index so that prisma db push doesn't delete it. Perhaps using the @ignore flag
I've realized a workaround: If I create the index manually first and define a normal index in the prisma schema, but use the same index name, prisma won't overwrite it and won't delete it.
For example
@@index([geometry], map: "geometry_2dsphere")
Did the current index not get picked up when running db pull?
The problem with "do not delete externally managed index" is that it basically says "do not delete things you do not know about" - and that would mean leaving all kinds of things around potentially and not actually doing what db push promises - to get the database into the state you have defined in your Prisma schema. Also, where would you put something like an @ignore flag if you do not know about it in the first place 😐
I've realized a workaround: If I create the index manually first and define a normal index in the prisma schema, but use the same index name, prisma won't overwrite it and won't delete it.
For example
@@index([geometry], map: "geometry_2dsphere")
After some update it stop working for me. It overrides geospatial index with a default one. @janpio was something changed in the recent releases?
// cut
@@index([location], map: "location_2dsphere")
// cut
Hey @paulrostorp
If you don't mind, could you provide a piece of the schema that is now supporting GeoJSON with the workaround? That might help the Prisma team come up with something as well.
From what I understood is something close to this, is that right?
model Address {
id Int @id @default(auto()) @map("_id") @db.ObjectId
location Json
@@index([location], map: "location_2dsphere")
}