49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
import os
|
|
|
|
cert_path = 'fondexuzb-firebase-adminsdk-fbsvc-7b0e2d6200.json'
|
|
cred = credentials.Certificate(cert_path)
|
|
if not firebase_admin._apps:
|
|
firebase_admin.initialize_app(cred)
|
|
db = firestore.client()
|
|
|
|
def explore():
|
|
# 1. Vendor Attributes
|
|
v_attrs = list(db.collection('vendor_attributes').stream())
|
|
v_attr_ids = {doc.id for doc in v_attrs}
|
|
print(f"Total vendor_attributes: {len(v_attrs)}")
|
|
for doc in v_attrs:
|
|
print(f" - {doc.id}: {doc.to_dict().get('title')}")
|
|
|
|
# 2. Review Attributes
|
|
r_attrs = list(db.collection('review_attributes').stream())
|
|
print(f"Total review_attributes: {len(r_attrs)}")
|
|
|
|
# 3. Check for other potential collections
|
|
all_collections = [c.id for c in db.collections()]
|
|
keyword_matches = [c for c in all_collections if any(k in c.lower() for k in ['attr', 'option', 'variant', 'spec', 'prop'])]
|
|
print(f"Collections matching keywords: {keyword_matches}")
|
|
|
|
# 4. Cross-reference with products
|
|
print("\nChecking products for missing attribute IDs...")
|
|
products = db.collection('vendor_products').limit(100).stream()
|
|
missing_ids = set()
|
|
for product in products:
|
|
data = product.to_dict()
|
|
item_attr = data.get('item_attribute')
|
|
if item_attr and isinstance(item_attr, dict):
|
|
attrs = item_attr.get('attributes') or []
|
|
for a in attrs:
|
|
a_id = a.get('attribute_id')
|
|
if a_id and a_id not in v_attr_ids:
|
|
missing_ids.add(a_id)
|
|
|
|
if missing_ids:
|
|
print(f"Found {len(missing_ids)} attribute IDs used in products but NOT in vendor_attributes: {missing_ids}")
|
|
else:
|
|
print("All attribute IDs found in products are accounted for in vendor_attributes.")
|
|
|
|
if __name__ == "__main__":
|
|
explore()
|