Skip to content

Re-Introspection removes @@id(name) #8865

Open

Description

@janpio
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["nApi", "filterJson", "namedConstraints"]
}

"prisma": "2.29.1",

re-introspect will remove name alias defined on model

@@id(fields: [productId, warehouseId, condition], name: "pk", map: "product_quantity_pk")

after introspect, it become

@@id([productId, warehouseId, condition], map: "product_quantity_pk")

Originally posted by @xiaoyu-tamu in #8645 (comment)

Activity

  1. added
    bug/1-unconfirmed
    kind/bug
    on Aug 23, 2021
  2. added this to the 2.31.0 / 3.0.x milestone on Aug 25, 2021
  3. self-assigned this
    on Sep 2, 2021
  4. added a commit that references this issue on Sep 2, 2021
  5. tomhoule commented on Sep 3, 2021

    @tomhoule
    Contributor

    Explanation from @do4gr on slack:

    The idea was that re-introspection should only keep custom names if it is the same PK. With this change the custom name fullName for your API would stay the same even if you move the PK from (firstName, lastName) to let's say (firstName, age). This makes it easier for the user since they will have fewer needed code changes, but is also a bit dirtier I think.

    And another weird behaviour this would introduce if I read the PR correctly is that if you go from a compound with a name property to a singular PK (which technically should not have a name property) this would transfer the name into the datastructure. It cannot be rendered though, but might cause trouble down the line at some point. So I'd at least prevent that.

    Let's close prisma/prisma-engines#2205 and keep current behaviour for now.

  6. added and removed
    bug/1-unconfirmed
    kind/bug
    on Sep 3, 2021
  7. removed their assignment
    on Sep 3, 2021
  8. janpio commented on Jan 3, 2022

    @janpio
    ContributorAuthor

    Seems this is not the case any more:

    model foo {
      productId   String
      warehouseId String
      condition   String
    
      @@id(fields: [productId, warehouseId, condition], name: "pk", map: "product_quantity_pk")
    }

    becomes

    model foo {
      productId   String
      warehouseId String
      condition   String
    
      @@id([productId, warehouseId, condition], name: "pk", map: "product_quantity_pk")
    }

    Does this make sense @tomhoule @do4gr?

  9. added
    bug/0-unknown
    kind/bug
    and removed on Jan 3, 2022
  10. tomhoule commented on Jan 3, 2022

    @tomhoule
    Contributor

    My understanding would be that in this case @janpio , it's the same pk, so the name is preserved. If any of the fields changed, then the name would be gone, according to the explanation by @do4gr in my last reply.

  11. janpio commented on Jan 4, 2022

    @janpio
    ContributorAuthor

    But wasn't my reproduction the original issue here? If there is another case where this is not the case, we might want to clarify that in a new issue (or just document this as how it works).

  12. added
    tech/engines
    on Mar 24, 2022
  13. added
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on Jul 13, 2023
  14. Druue commented on Aug 17, 2023

    @Druue
    Contributor

    Yeah, this no longer occurs
    image

    Workflow:

    • Add:
    model Employee {
      id   Int
      name String
    
      @@id([id, name], name: "pk", map: "employee_custom_pk")
    }
    • db push
    • db pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bugtech/enginestopic: introspectiontopic: namedConstraintstopic: re-introspection

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions