You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a log on renaming field to help future beginner #6218
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 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:
modelSimple {idInt@idupdate_dateInt@map("updateDate")// don't work but just remove the `@map`updateDateInt@map("update_date")// that was expected}
Then enter this data simple{id: 1, update_date:1, updateDate:10}.
Then introspect it again, you get
modelSimple {idInt@idupdateDateIntupdate_dateInt}
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.
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!
Activity
do4gr commentedon Mar 25, 2021
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:
Then enter this data simple{id: 1, update_date:1, updateDate:10}.
Then introspect it again, you get
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.
Pompedup commentedon Mar 25, 2021
I will explain a lil more.
My db has fields
idandupdate_date(noupdateDateIn my bdd)The problem was that when I do this :
and then introspect, it just remove
@map("updateDate")because updateDate isn't a field of my db and write no error/warning messageIt's just what works:
I was asking if when it remove a wrong
@map, it tell us that it didn't find the fielddo4gr commentedon Apr 1, 2021
Ah, ok now I understand. Thanks for clarifying this.
Currently our approach when running introspect is the following:
In your case of
@mapinformation 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!