language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Auto-replace updated table column names in vscode

Open magicmark opened this issue 4 years ago • 3 comments

Problem

When prototyping, and I update a column name (e.g. "foo" -> "bar"), I want VSCode to pop up and say "Hey! Do you want me to auto-update occurrences of foo -> bar inside prisma query statements in your code?"

(The UX here would be similar to how vscode handles auto-updating imports when file names change)

Suggested solution

This involves several challenges:

  • Working out what constitutes a column name change on a file diff. Unlike generated migrations where this needs to be 100% correct, because we'd ask the user to confirm, we could make a best guess and ask them to confirm
  • Working out what constitutes an instance of foo in code that needs to be replaced. Some ideas:
    • This only works in .ts files where we can inspect the type at a character position to confirm that's a reference to the column inside a prisma selection
    • Be dumb and grep for foo and let the user hit confirm for each one (i.e. we kick into the regular search and replace UI)

Alternatives

  • Kick into the regular search and replace UI

Thanks!

magicmark avatar Jun 09 '21 03:06 magicmark

"update a column name" refers to changing the field name in the Prisma Schema here I guess?

janpio avatar Jun 09 '21 18:06 janpio

Yes, sorry

magicmark avatar Jun 09 '21 19:06 magicmark

All good, this makes this mostly a Prisma Language tools concern (which is for example used in the VSCode extension). I moved the issue there. I agree this would be an interesting feature, when changing the schema could directly influence your Prisma Client code.

janpio avatar Jun 09 '21 20:06 janpio