Skip to content

Some partial indexes are constantly getting recreated #29175

@david0673

Description

@david0673

Bug description

A couple indexes in our schema are getting dropped & recreated fully identical to the original every time we run prisma migrate dev... our examples:

@@index([status], map: "product_item_status_not_completed_idx", where: raw("status != 'COMPLETED'::production_status"))
@@index([lineItemId, containerQuantity, pulledQuantity], where: raw("container_quantity > 0"))

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

I'm not sure as to reproduction steps besides running prisma migrate dev with the relevant parts of the schema.

Expected vs. Actual Behavior

We expect it not to drop & recreate an identical index every time we run prisma migrate dev

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

This is as of the initial Prisma partial indexes release (I'm on Prisma 7.4.0)

Workaround

No workaround found

Prisma Schema & Queries

generator client {
  // relationJoins removed: Prisma 7.3.0 bug causes "e.map is not a function" in interactive transactions
  // Re-enable when fixed upstream (track: https://github.com/prisma/prisma/issues)
  previewFeatures = ["nativeDistinct", "partialIndexes", "views"]
  provider        = "prisma-client"
  output          = "../generated/prisma"
}

datasource db {
  provider = "postgresql"
}

model ProductionItem {
  id          BigInt    @id @default(autoincrement()) @db.BigInt
  inventoryId       BigInt           @map("inventory_id") @db.BigInt
  status            ProductionStatus @default(PLANNED)
  organizationId         String    @map("organization_id")

  @@unique([inventoryId, organizationId])
  @@index([status], map: "product_item_status_not_completed_idx", where: raw("status != 'COMPLETED'::production_status"))
  @@map("production_item")
}

model OrderLineItemAllocation {
  id          BigInt   @id @default(autoincrement()) @db.BigInt
  lineItemId       BigInt @map("line_item_id") @db.BigInt
  productionItemId BigInt @map("production_item_id") @db.BigInt
  containerQuantity Decimal @map("container_quantity") @db.Decimal(19, 3)
  pulledQuantity    Decimal @default(0) @map("pulled_quantity") @db.Decimal(19, 3)

  lineItem       OrderLineItem  @relation(fields: [lineItemId], references: [id])
  productionItem ProductionItem @relation(fields: [productionItemId], references: [id])

  @@unique([lineItemId, productionItemId])
  @@index([lineItemId, containerQuantity, pulledQuantity], where: raw("container_quantity > 0"))
  @@map("order_line_item_allocation")
}

enum ProductionStatus {
  PLANNED
  IN_PRODUCTION
  READY
  COMPLETED

  @@map("production_status")
}

Prisma Config

import 'dotenv/config';
import { defineConfig } from 'prisma/config';

const prismaRoot = `${import.meta.dirname}/../prisma`;

// Use env vars if available, otherwise use placeholders for generation
const datasourceConfig = {};
if (process.env.DATABASE_URL) {
  datasourceConfig.url = process.env.DATABASE_URL;
}
if (process.env.DATABASE_DIRECT_URL) {
  datasourceConfig.directUrl = process.env.DATABASE_DIRECT_URL;
}
if (process.env.DATABASE_SHADOW_URL) {
  datasourceConfig.shadowDatabaseUrl = process.env.DATABASE_SHADOW_URL;
}

export default defineConfig({
  datasource: datasourceConfig,
  migrations: {
    path: `${prismaRoot}/migrations`,
    seed: 'pnpm run prisma:seed:local',
  },
  schema: `${prismaRoot}/schema.prisma`,
  views: {
    path: `${prismaRoot}/views`,
  },
});

Logs & Debug Info

n/a

Environment & Setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v22.22.0

Prisma Version

Loaded Prisma config from .config/prisma.mjs.

Prisma schema loaded from prisma/schema.prisma.
prisma : 7.4.0
@prisma/client : 7.4.0
Operating System : darwin
Architecture : arm64
Node.js : v22.22.0
TypeScript : 5.9.3
Query Compiler : enabled
PSL : @prisma/prisma-schema-wasm 7.4.0-20.ab56fe763f921d033a6c195e7ddeb3e255bdbb57
Schema Engine : schema-engine-cli ab56fe763f921d033a6c195e7ddeb3e255bdbb57 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash : ab56fe763f921d033a6c195e7ddeb3e255bdbb57
Studio : 0.13.1
Preview Features : nativeDistinct, partialIndexes, views

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions