Spaces:
Sleeping
Sleeping
Delete run_seed.py with huggingface_hub
Browse files- run_seed.py +0 -46
run_seed.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import os
|
| 3 |
-
|
| 4 |
-
# Add the current directory to sys.path to allow importing 'app'
|
| 5 |
-
sys.path.append(os.getcwd())
|
| 6 |
-
|
| 7 |
-
from sqlalchemy import create_engine
|
| 8 |
-
from sqlalchemy.pool import NullPool
|
| 9 |
-
from app.db.base import Base, settings
|
| 10 |
-
from app.api.seed import seed_database
|
| 11 |
-
from sqlalchemy.orm import sessionmaker
|
| 12 |
-
import json
|
| 13 |
-
|
| 14 |
-
def run():
|
| 15 |
-
print(">>> Starting Product Import from extra_products_vortex.json...")
|
| 16 |
-
|
| 17 |
-
# 1. Create a fresh engine with NullPool and use port 6543 (Transaction Mode)
|
| 18 |
-
# to avoid "MaxClientsInSessionMode" errors on port 5432.
|
| 19 |
-
db_url = settings.DATABASE_URL.replace(":5432/", ":6543/")
|
| 20 |
-
temp_engine = create_engine(db_url, poolclass=NullPool)
|
| 21 |
-
TempSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=temp_engine)
|
| 22 |
-
|
| 23 |
-
# 2. Ensure tables exist
|
| 24 |
-
Base.metadata.create_all(bind=temp_engine)
|
| 25 |
-
|
| 26 |
-
# 3. Setup DB Session
|
| 27 |
-
db = TempSessionLocal()
|
| 28 |
-
try:
|
| 29 |
-
# Step 1: Initialize Categories and wipe data
|
| 30 |
-
print(">>> Wiping data and creating categories...")
|
| 31 |
-
result = seed_database(clear=True, db=db)
|
| 32 |
-
if not result.isSuccess:
|
| 33 |
-
print(f"FAILED: {result.error}")
|
| 34 |
-
return
|
| 35 |
-
|
| 36 |
-
print(f"SUCCESS: {result.value.get('message')}")
|
| 37 |
-
print(f"Stats: Inserted {result.value.get('inserted_new')} products.")
|
| 38 |
-
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"CRITICAL ERROR: {str(e)}")
|
| 41 |
-
db.rollback()
|
| 42 |
-
finally:
|
| 43 |
-
db.close()
|
| 44 |
-
|
| 45 |
-
if __name__ == "__main__":
|
| 46 |
-
run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|