Is It Possible to Efficiently Change Table and Column Names, Using Prisma?

I want to use prisma on an existing database. Now that I'm researching it, I realise that all my tables and columns are incorrectly named. I would like to correct the names, but I don't want to lose my data.

I did a prisma "pull" so I have a schema of my current database. But then I don't quite understand how (if possible) do I rename my tables and columns using the schema.

What are my options? Can I change the schema.prisma and make prisma take care of all the "alter" statements? How do I do this?

2

1 Answer

It's not natively supported yet. There is a Feature Request to handle renames effectively.

You can use this technique to rename your tables and fields without dropping the data.

  1. Create an empty migration file with prisma migrate dev --create-only
  2. Add sql: ALTER TABLE IF EXISTS "OldName" RENAME TO "NewName";
  3. Change table name in schema.prisma file
  4. Run prisma migrate dev
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest