Is there a way to rename a table without dropping ...
# prisma-migrate
s
Is there a way to rename a table without dropping all data?
a
Sorry about the late reply @sven . Right now you have to modify the migration file to change the DROP and CREATE TABLE statements to an ALTER TABLE statement. We are looking to improve this in the future via an interactive feature n migrate dev. This is the issue to follow for this: https://github.com/prisma/prisma/issues/7790
s
Actually I have found a better way:
👀 1
a
What is it? I am curious
s
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
It did not cause a drift for me
if it does then stop and make sure the changes in schema.prisma match your changes in migration.sql
a
It’s more or less equivalent to what I suggested, just flipped order and creating a new migration instead of having Prisma generate a new migration and change the DDL.
If it works for you, great. The issue 7790 is to have Prisma Migrate handle renames out of the box. When it finds such a change it would prompt you as a user to indicate if you want to rename a table or drop the old and create a new table, so it would be more failsafe.
s
That sounds like a great feature.
👍 1