Skip to content

Commit

Permalink
reformatted mock data script #338
Browse files Browse the repository at this point in the history
  • Loading branch information
asuresh-code committed Oct 17, 2024
1 parent af4591b commit f4e5b5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,14 @@ def forward(self, session: ClientSession):
logger.info("expected_lifetime forward migration")
for catalogue_item in catalogue_items:
try:
old_item = OldCatalogueItemOut(**catalogue_item)

new_item_data = {
"catalogue_category_id": old_item.catalogue_category_id,
"manufacturer_id": old_item.manufacturer_id,
"name": old_item.name,
"description": old_item.description,
"cost_gbp": old_item.cost_gbp,
"cost_to_rework_gbp": old_item.cost_to_rework_gbp,
"days_to_replace": old_item.days_to_replace,
"days_to_rework": old_item.days_to_rework,
"drawing_number": old_item.drawing_number,
"drawing_link": old_item.drawing_link,
"expected_lifetime": None,
"item_model_number": old_item.item_model_number,
"is_obsolete": old_item.is_obsolete,
"obsolete_reason": old_item.obsolete_reason,
"obsolete_replacement_catalogue_item_id": old_item.obsolete_replacement_catalogue_item_id,
"notes": old_item.notes,
"properties": old_item.properties,
"created_time": catalogue_item["created_time"],
"modified_time": catalogue_item["modified_time"],
}

new_item = NewCatalogueItemIn(**new_item_data)

update_data = new_item.model_dump()
old_catalogue_item = OldCatalogueItemOut(**catalogue_item.model_dump())

new_catalogue_item = NewCatalogueItemIn(**old_catalogue_item.model_dump())

update_data = {**new_catalogue_item.model_dump(), "modified_time": old_catalogue_item.modified_time}

self._catalogue_items_collection.update_one(
{"_id": old_item.id}, {"$set": update_data}, session=session
{"_id": old_catalogue_item.id}, {"$set": update_data}, session=session
)

except ValidationError as ve:
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def generate_random_catalogue_item(
"days_to_rework": optional_catalogue_item_field(lambda: fake.random.randint(0, 100)),
"drawing_number": optional_catalogue_item_field(lambda: str(fake.random.randint(1000, 10000))),
"drawing_link": optional_catalogue_item_field(fake.image_url),
"expected_lifetime": optional_catalogue_item_field(lambda: fake.random.randint(1000,10000)),
"expected_lifetime": optional_catalogue_item_field(lambda: fake.random.randint(1000, 10000)),
"item_model_number": optional_catalogue_item_field(fake.isbn13),
"is_obsolete": bool(obsolete_replacement_catalogue_item_id),
"obsolete_replacement_catalogue_item_id": obsolete_replacement_catalogue_item_id,
Expand Down

0 comments on commit f4e5b5e

Please sign in to comment.