amiable-iguana's avatar

Undo Seeded Data

I have an e-commerce application, and I have mistakenly seeded some incorrect data that has been run on production database.

What is the best practice to correct this data?

I have some new categories that I need to add and some need renaming, and I also have some products that were generated by factories which need to be deleted.

My plan is to update the category seeder, and delete the product seeder and run a migration to correct the incorrect data on prod, is this the correct way to do this?

0 likes
5 replies
tisuchi's avatar

@amiable-iguana ⚠️ First of all, it's not a good idea to run a seeder in production.

From your situation, I rather go with manual checking and remove whatever is needed. So far I know, there is no way to revert this data back in one shot.

2 likes
amiable-iguana's avatar

@tisuchi thank you for your reply, that’s interesting, can I ask why seeders shouldn’t be run in production, I hadn’t heard that before…

And if you can’t run seeders in production, what is best practice for populating data?

MohamedTammam's avatar

@amiable-iguana Depending on the logic of your app.

Let's assume a case where you need to populate some categories in your database programmatically. You can use seeders or a command to do that. Seeders might be bad because it might miss your production database if your run a wrong seeder (which happens) as in your case.

I also preferer to go check the records manually and delete one by one. Or run a SQL query that delete records in a range of IDs after CAREFULLY CHECKING THE DATABASE NEW IDs

2 likes
tisuchi's avatar

@amiable-iguana This is the concept of Database seeder.

Database seeding is populating a database with an initial set of data. It's common to load seed data such as initial user accounts or dummy data upon initial setup of an application.

Ref: https://en.wikipedia.org/wiki/Database_seeding#:~:text=Database%20seeding%20is%20populating%20a,initial%20setup%20of%20an%20application.

The main purpose of using a seeder is to populate dummy or initial data for loading the application. Some people use it for production (including me in some cases) specifically for generating real-life data, but if you don't use it wisely, it might be messed with your existing data.

This was my stand.

2 likes
Snapey's avatar

assuming you cannot just revert to a backup?

e-commerce site, should probably be backed up at least hourly

1 like

Please or to participate in this conversation.