prisma icon indicating copy to clipboard operation
prisma copied to clipboard

`prisma db push` should not delete externally managed indexes

Open paulrostorp opened this issue 3 years ago • 4 comments

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: Screenshot 2022-04-09 at 13 24 50

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

paulrostorp avatar Apr 09 '22 11:04 paulrostorp

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")

paulrostorp avatar Apr 09 '22 12:04 paulrostorp

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 😐

janpio avatar Apr 13 '22 18:04 janpio

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

enheit avatar May 23 '23 12:05 enheit

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")
}

rafaell-lycan avatar Jan 02 '24 21:01 rafaell-lycan