Twaha-Rahman/e-commercify

[BUG] Avoid adding more sample data without removing old sample data with

Closed this issue · 5 comments

Describe the bug

The sample data injector currently only injects data without checking if the data already exists. This shouldn't be the default behaviour.

To Reproduce

Run the npm run fill-db script multiple times and check the database

Expected behavior

The script should remove all previous data and add new data.

Screenshots

image

So I see two possible fixes for this:

  1. Have the sample script clear the database before injecting new data.
  2. Have the sample script check for data and quit if the database already has data.

I wouldn't just make the script suddenly drop the whole database. Instead I think we should make some flag to put behind the command to decide if the DB should be dropped or not

I think dropping the DB is a more safe approach as the sample data from the previous version may not be compatible with the new version.

Afaik, the mongoimport CLI tool to import data into mongodb, does not drop existing data unless the --drop switch is used.

It also allows to specify the db for the new data using a --collection argument, which I think is useful because we don't want this tool to mix sample test data with real production data

This should simplify the procedure a lot. Thanks for the quick tip @snowteamer