FA3-Datafetch/backend/scripts/reset_all_int_tables.py
2026-01-11 21:33:47 +08:00

54 lines
1.4 KiB
Python

import os
import sys
import psycopg2
from pathlib import Path
from dotenv import load_dotenv
# Load .env
ROOT_DIR = Path(__file__).resolve().parent.parent.parent
load_dotenv(ROOT_DIR / ".env")
def get_db_connection():
db_host = os.getenv("DB_HOST", "192.168.3.195")
db_user = os.getenv("DB_USER", "value")
db_pass = os.getenv("DB_PASSWORD", "Value609!")
db_name = os.getenv("DB_NAME", "fa3")
db_port = os.getenv("DB_PORT", "5432")
return psycopg2.connect(
host=db_host, user=db_user, password=db_pass, dbname=db_name, port=db_port
)
def drop_tables():
tables = [
"ifind_int_income_statement",
"ifind_int_balance_sheet",
"ifind_int_cash_flow",
"ifind_int_daily_basic",
"ifind_int_financial_ratios",
"ifind_int_dividend",
"ifind_int_repurchase",
"ifind_int_employee"
]
conn = get_db_connection()
conn.autocommit = True
cursor = conn.cursor()
print("🧹 Starting cleanup of iFinD International tables...")
try:
for table in tables:
print(f"Dropping {table}...")
cursor.execute(f"DROP TABLE IF EXISTS {table}")
print(f"✅ Dropped {table}")
except Exception as e:
print(f"❌ Error during cleanup: {e}")
finally:
cursor.close()
conn.close()
print("🎉 Cleanup completed.")
if __name__ == "__main__":
drop_tables()