Skip to content

Multiple @@index on same columns from partial indexes cannot be emitted #786

@olgen

Description

@olgen

Package and version

  • prisma-next: 0.12.0
  • @prisma-next/postgres: 0.12.0
  • Node: v22.x
  • Package manager: bun 1.3.x
  • OS: macOS (darwin)
  • Source DB: PostgreSQL 15 (local Supabase)

What happened?

Postgres allows multiple distinct indexes on the same column(s) — commonly partial indexes with different WHERE clauses. contract infer emits them as multiple @@index attributes on the same column set:

model RejectedUploads {
  accountId String @map("account_id")
  // ...
  @@index([accountId], map: "idx_rejected_uploads_account_id")
  @@index([accountId], map: "idx_rejected_uploads_unresolved")
  @@index([accountId], map: "rejected_uploads_account_open_idx")
}

contract emit rejects multiple @@index definitions with the same column set within one model. Deduplicating by column set (our workaround) loses real partial indexes from the DB.

What did you expect to happen?

PSL should support partial index predicates (WHERE …) or otherwise preserve distinct Postgres indexes that share the same key columns.

Minimal reproduction

  1. DB table with 2+ indexes on the same column(s) where at least one is partial (different pg_indexes.indexdef / WHERE clause)
  2. contract infercontract emit
  3. Emit fails or forces dropping duplicate @@index lines

Workaround

Dedupe @@index([…]) by column set before emit (loses partial-index fidelity).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions