prisma/language-tools

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

Akxe opened this issue · 4 comments

Akxe commented

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 commented

@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...

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
  • 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 commented

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 😊