81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Fix Inventory User References Script
|
||
|
|
|
||
|
|
Replaces the missing user ID c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6
|
||
|
|
with the production director user ID ae38accc-1ad4-410d-adbc-a55630908924
|
||
|
|
in all inventory.json files.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
# The incorrect user ID that needs to be replaced
|
||
|
|
OLD_USER_ID = "c1a2b3c4-d5e6-47a8-b9c0-d1e2f3a4b5c6"
|
||
|
|
|
||
|
|
# The correct production director user ID
|
||
|
|
NEW_USER_ID = "ae38accc-1ad4-410d-adbc-a55630908924"
|
||
|
|
|
||
|
|
def fix_inventory_file(filepath: Path) -> bool:
|
||
|
|
"""Fix user references in a single inventory.json file"""
|
||
|
|
try:
|
||
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||
|
|
data = json.load(f)
|
||
|
|
|
||
|
|
changed = False
|
||
|
|
|
||
|
|
# Fix ingredients
|
||
|
|
if "ingredients" in data:
|
||
|
|
for ingredient in data["ingredients"]:
|
||
|
|
if ingredient.get("created_by") == OLD_USER_ID:
|
||
|
|
ingredient["created_by"] = NEW_USER_ID
|
||
|
|
changed = True
|
||
|
|
|
||
|
|
# Fix products
|
||
|
|
if "products" in data:
|
||
|
|
for product in data["products"]:
|
||
|
|
if product.get("created_by") == OLD_USER_ID:
|
||
|
|
product["created_by"] = NEW_USER_ID
|
||
|
|
changed = True
|
||
|
|
|
||
|
|
if changed:
|
||
|
|
with open(filepath, 'w', encoding='utf-8') as f:
|
||
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||
|
|
print(f"✓ Fixed {filepath}")
|
||
|
|
return True
|
||
|
|
else:
|
||
|
|
print(f"✓ No changes needed for {filepath}")
|
||
|
|
return False
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"✗ Error processing {filepath}: {e}")
|
||
|
|
return False
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main function to fix all inventory files"""
|
||
|
|
print("=== Fixing Inventory User References ===")
|
||
|
|
print(f"Replacing {OLD_USER_ID} with {NEW_USER_ID}")
|
||
|
|
print()
|
||
|
|
|
||
|
|
base_path = Path("shared/demo/fixtures/enterprise")
|
||
|
|
|
||
|
|
# Fix parent inventory
|
||
|
|
parent_file = base_path / "parent" / "03-inventory.json"
|
||
|
|
if parent_file.exists():
|
||
|
|
fix_inventory_file(parent_file)
|
||
|
|
|
||
|
|
# Fix children inventories
|
||
|
|
children_dir = base_path / "children"
|
||
|
|
if children_dir.exists():
|
||
|
|
for child_dir in children_dir.iterdir():
|
||
|
|
if child_dir.is_dir():
|
||
|
|
inventory_file = child_dir / "03-inventory.json"
|
||
|
|
if inventory_file.exists():
|
||
|
|
fix_inventory_file(inventory_file)
|
||
|
|
|
||
|
|
print("\n=== Fix Complete ===")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|