Skip to content

Add a log on renaming field to help future beginner  #6218

Open

Description

@Pompedup

Hello !

Problem

I was looking for adding a @map or @@map for 10 minutes but when I was doing prisma introspect, it just erase the @map without any information (no warning or error)

Suggested solution

It would be great to have a message that say somethings like

These fields have unknow `@map` column from the previous Prisma schema.
- Model "salesImport", field: "updateDate"

Alternatives

Just say that it remove some field because they were not actual columns

Additional context

update_date            Int
update_date            Int                  @map("updateDate") // don't work but just remove the `@map`
updateDate             Int                  @map("update_date") // that was expected

Thanks a lot
Have a good day :)

Activity

  1. added
    bug/0-unknown
    kind/bug
    on Mar 25, 2021
  2. do4gr commented on Mar 25, 2021

    @do4gr
    Member

    Thanks for reporting this, I think I now understand what you mean and am able to reproduce. My more extensive reproduction of a bug caused by this:

    If you start with this datamodel and deploy it:

    model Simple {
      id          Int @id
      update_date            Int                  @map("updateDate") // don't work but just remove the `@map`
      updateDate             Int                  @map("update_date") // that was expected
    }

    Then enter this data simple{id: 1, update_date:1, updateDate:10}.

    Then introspect it again, you get

    model Simple {
      id                    Int   @id
      updateDate   Int
      update_date Int
    }

    If you then fetch your data again you get: simple{id: 1, update_date:10, updateDate:1}.

    This is a bug since the column data is now matched to a different field.

    I'm not sure yet what exactly would be the fix here. I would tend to already deny the initial schema since cross-mapping fields to swap their names sounds dangerous already.

  3. Pompedup commented on Mar 25, 2021

    @Pompedup
    Author

    I will explain a lil more.

    My db has fields id and update_date (no updateDate In my bdd)

    The problem was that when I do this :

    model Simple {
      id          Int @id
      update_date            Int                  @map("updateDate")
    }
    

    and then introspect, it just remove @map("updateDate") because updateDate isn't a field of my db and write no error/warning message

    It's just what works:

    model Simple {
      id          Int @id
      updateDate             Int                  @map("update_date")
    }
    

    I was asking if when it remove a wrong @map, it tell us that it didn't find the field

  4. added
    bug/2-confirmed
    and removed
    bug/0-unknown
    on Mar 31, 2021
  5. added this to the 2.21.0 milestone on Mar 31, 2021
  6. added
    tech/engines/datamodel
    and removed on Mar 31, 2021
  7. do4gr commented on Apr 1, 2021

    @do4gr
    Member

    Ah, ok now I understand. Thanks for clarifying this.

    Currently our approach when running introspect is the following:

    • get the state of the db schema
    • convert that into a new Prisma datamodel
    • try to detect if there is information in the previous Prisma model that cannot be represented on a db level that is still applicable to the new Prisma datamodel and apply it

    In your case of @map information being present in the old datamodel that is now no longer applicable we can not distinguish between the definition in the old datamodel being wrong and you having removed the column in the database before introspecting again. This means if we introduced the warning you are asking for it would also always show if the db schema has changed. I think that would be too noisy and confusing to always produce this warning.

    But your report helped to uncover a different edge case bug, so thanks a lot!

  8. removed their assignment
    on Apr 1, 2021
  9. added
    tech/engines
    on Mar 24, 2022
  10. added
    tech/engines/introspection engine
    and removed
    bug/2-confirmed
    kind/bug
    on Jan 12, 2023
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

    status/needs-actiontech/enginestech/engines/datamodeltech/engines/introspection enginetopic: introspectiontopic: re-introspectiontopic: schematopic: schema validation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions