File size: 1,340 Bytes
363cda9 3370983 363cda9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
"""
Run as follows:
>>> POSTGRES_HOST=localhost POSTGRES_PORT=5433 POSTGRES_PASSWORD=password123 python -m scripts.db.wipe
"""
import sys
import os
from sqlalchemy import text
# Add project root to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
sys.path.append(project_root)
from src.backend.database.candidates.client import get_engine
def wipe_database():
print("⚠️ WARNING: This will PERMANENTLY DELETE ALL RECORDS from the 'candidates' table and all related tables (CASCADE).")
confirm = input("Type 'yes' to confirm: ")
if confirm.lower() != 'yes':
print("Operation cancelled.")
return
engine = get_engine()
try:
with engine.connect() as connection:
print("Connecting to database...")
# Using TRUNCATE with CASCADE is faster and cleaner for Postgres
print("Truncating candidates table with CASCADE...")
connection.execute(text("TRUNCATE TABLE candidates CASCADE;"))
connection.commit()
print("✅ Database entries wiped successfully.")
except Exception as e:
print(f"❌ Error wiping database: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
wipe_database()
|