Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming relation field column does not create @map("original") #1609

Open
Akxe opened this issue Dec 6, 2023 · 4 comments
Open

Renaming relation field column does not create @map("original") #1609

Akxe opened this issue Dec 6, 2023 · 4 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: @map topic: rename

Comments

@Akxe
Copy link

Akxe commented Dec 6, 2023

Bug description

When renaming a column whose type is an enum, it will rename it, but will not add @map("originalName")

How to reproduce

  1. Use the first provided schema
  2. Using F2, rename zMena
  3. See that the name is changed, but not mapped to original

Expected behavior

It should rename and map to original to prevent errors

Prisma information

Starting schema:

model Offer {
  offerID Int                @id @default(autoincrement()) @map("idZak") @db.UnsignedSmallInt
  title   String             @map("ZNazev") @db.VarChar(45)
  zMena   Currency           @default(kc)

  @@map("zakazky")
}

enum Currency {
  kc        @map("Kč")
  eur       @map("")
  centi_eur @map("c")

  @@map("zakazky_zMena")
}

After F2 renaming (error)

model Offer {
  offerID Int                @id @default(autoincrement()) @map("idZak") @db.UnsignedSmallInt
  title   String             @map("ZNazev") @db.VarChar(45)
  currency Currency           @default(kc)

  @@map("zakazky")
}

enum Currency {
  kc        @map("Kč")
  eur       @map("")
  centi_eur @map("c")

  @@map("zakazky_zMena")
}

Environment & setup

  • OS: Windows
  • Database: MySQL
  • Node.js version: v20.9.0

Prisma Version

Environment variables loaded from .env
prisma                  : 5.7.0
@prisma/client          : 5.7.0
Computed binaryTarget   : windows
Operating System        : win32
Architecture            : x64
Node.js                 : v20.9.0
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Schema Engine           : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules\@prisma\engines\schema-engine-windows.exe)
Schema Wasm             : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash    : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio                  : 0.495.0
@Akxe Akxe added the kind/bug A reported bug. label Dec 6, 2023
@Akxe
Copy link
Author

Akxe commented Dec 6, 2023

@janpio Could you point me to the part of Rust that handles the introspection? I would love to see it for myself. I would love to help DX better for introspection. I lost the path on runCommand function in migration package...

@janpio janpio transferred this issue from prisma/prisma Dec 6, 2023
@Druue Druue added bug/2-confirmed Bug has been reproduced and confirmed. team/schema Issue for team Schema. topic: rename topic: @map labels Apr 24, 2024
@Druue
Copy link
Contributor

Druue commented Apr 24, 2024

Can confirm this isn't adding the @map attribute 🤔 This isn't an issue in introspection, the section that defines where we add @map is here in messageHandler/handleRenameRequest().

This is getting filtered out specifically because we have the following guard in place !isRelationFieldRename (i.e. it's not just about enums but all relations), I'm honestly not sure why we have this guard, however.

We would need to update our rename functionality to then also rename the related relation if we rename a relation field as that does not happen right now if we remove the guard :) We do already have the functionality for renaming a whole block, so we can re-use that

Screen.Recording.2024-04-24.at.12.46.26.mov

@Druue Druue changed the title Renaming enum column does not create @map("original") Renaming relation field column does not create @map("original") Apr 24, 2024
@janpio
Copy link
Member

janpio commented Apr 24, 2024

  • Enums are not relation fields, they are enums. (So I think the issue title update is invalid to still describe the original issue)
  • Relation fields do not use @map, as they do not represent any objects in the database - which is why this !isRelationFieldRename guard is probably in place, and enums might have been forgotten at that time.
  • Enums might actually be represented in some way via names in the databsae, but I am not sure what our @map support for enum looks like. Our docs might help.

@Akxe
Copy link
Author

Akxe commented Apr 24, 2024

While at renaming of enums. Did you try to rename the enum itself? It will simply print out no result and will not rename either side of the enum.

Other than that I think enums are probably fixed 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: @map topic: rename
Projects
None yet
Development

No branches or pull requests

3 participants