skip to Main Content

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!

2

Answers


  1. Your plan seems a good one! This will ensure that the migration will not be affected by any data that is still present in the tables.

    Another option you could consider is to rename the tables in the database, rather than removing them entirely. This will allow you to retrieve the data later (if necessary), but it will also allow you to remove the models from your schema without any issues.

    So I would do this:

    1. Rename the tables
    2. Remove the models from the schema locally
    3. push the migration to prod
    4. Remove the renamed tables from step 1.
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search