Search code examples
databasepostgresqlsql-deleteprismaproduction-environment

How to remove prisma models with data in production


I want to delete 2 models from a postgreSQL production database that are no longer used but have data on them.

I am a bit afraid of removing them from the schema and running prisma migrate dev and then having issues with the migration generated in production.

Therefore, my idea was to clean the database before:

1 make a query to the prod database to remove all the data from the tables related. 2 remove the models from the schema locally and run the migration. 3 push the migration to prod with the DB tables empty What do you guys think?

Should I do that or just don't be afraid and delete the models locally + run prisma migrate dev and then push the migration to prod?

Are there any other ways to accomplish what I want?

Thanks in advance!


Solution

  • The approach you listed looks good.

    Another alternative would be to delete the models from schema file and run npx prisma migrate dev command with the --create-only flag to just create the migration file without applying it to the database.

    You can inspect the migration file first and if it looks good to you then you can invoke npx prisma migrate dev again to apply it.