|
|
""" |
|
|
μ
λ‘λλ νμΌκ³Ό λ°μ΄ν°λ² μ΄μ€ μ 보λ₯Ό μμ νλ μ€ν¬λ¦½νΈ |
|
|
""" |
|
|
import os |
|
|
import sys |
|
|
import sqlite3 |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
if sys.platform == 'win32': |
|
|
sys.stdout.reconfigure(encoding='utf-8') |
|
|
sys.stderr.reconfigure(encoding='utf-8') |
|
|
|
|
|
def reset_upload_data(): |
|
|
"""μ
λ‘λλ νμΌκ³Ό DB λ°μ΄ν° μμ """ |
|
|
try: |
|
|
|
|
|
db_path = os.path.join('instance', 'finance_analysis.db') |
|
|
if not os.path.exists(db_path): |
|
|
|
|
|
db_path = 'finance_analysis.db' |
|
|
if not os.path.exists(db_path): |
|
|
print(f"λ°μ΄ν°λ² μ΄μ€ νμΌμ μ°Ύμ μ μμ΅λλ€: {db_path}") |
|
|
return False |
|
|
|
|
|
print(f"λ°μ΄ν°λ² μ΄μ€ κ²½λ‘: {db_path}") |
|
|
|
|
|
|
|
|
conn = sqlite3.connect(db_path) |
|
|
cursor = conn.cursor() |
|
|
|
|
|
|
|
|
cursor.execute("SELECT id, file_path FROM uploaded_file") |
|
|
files_to_delete = cursor.fetchall() |
|
|
|
|
|
print(f"\nμμ ν νμΌ μ: {len(files_to_delete)}κ°") |
|
|
|
|
|
|
|
|
deleted_files = 0 |
|
|
failed_files = [] |
|
|
|
|
|
for file_id, file_path in files_to_delete: |
|
|
if file_path and os.path.exists(file_path): |
|
|
try: |
|
|
os.remove(file_path) |
|
|
deleted_files += 1 |
|
|
print(f" β νμΌ μμ : {os.path.basename(file_path)}") |
|
|
except Exception as e: |
|
|
failed_files.append((file_path, str(e))) |
|
|
print(f" β νμΌ μμ μ€ν¨: {os.path.basename(file_path)} - {str(e)}") |
|
|
|
|
|
|
|
|
print(f"\nλ°μ΄ν°λ² μ΄μ€ λ°μ΄ν° μμ μ€...") |
|
|
|
|
|
|
|
|
cursor.execute("DELETE FROM document_chunk") |
|
|
chunk_count = cursor.rowcount |
|
|
print(f" β document_chunk: {chunk_count}κ° μ²ν¬ μμ ") |
|
|
|
|
|
|
|
|
cursor.execute("DELETE FROM uploaded_file") |
|
|
file_count = cursor.rowcount |
|
|
print(f" β uploaded_file: {file_count}κ° νμΌ μ 보 μμ ") |
|
|
|
|
|
|
|
|
cursor.execute("DELETE FROM chat_message") |
|
|
message_count = cursor.rowcount |
|
|
print(f" β chat_message: {message_count}κ° λ©μμ§ μμ ") |
|
|
|
|
|
|
|
|
cursor.execute("DELETE FROM chat_session") |
|
|
session_count = cursor.rowcount |
|
|
print(f" β chat_session: {session_count}κ° μΈμ
μμ ") |
|
|
|
|
|
|
|
|
conn.commit() |
|
|
conn.close() |
|
|
|
|
|
print(f"\n{'='*60}") |
|
|
print(f"μμ μλ£!") |
|
|
print(f" - νμΌ μμ€ν
: {deleted_files}κ° νμΌ μμ ") |
|
|
print(f" - λ°μ΄ν°λ² μ΄μ€: {file_count}κ° νμΌ μ 보, {chunk_count}κ° μ²ν¬ μμ ") |
|
|
if failed_files: |
|
|
print(f"\nμμ μ€ν¨ν νμΌ ({len(failed_files)}κ°):") |
|
|
for file_path, error in failed_files: |
|
|
print(f" - {file_path}: {error}") |
|
|
print(f"{'='*60}\n") |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"\nμ€λ₯ λ°μ: {str(e)}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
return False |
|
|
|
|
|
if __name__ == '__main__': |
|
|
import sys |
|
|
|
|
|
print("="*60) |
|
|
print("μ
λ‘λ λ°μ΄ν° μ΄κΈ°ν μ€ν¬λ¦½νΈ") |
|
|
print("="*60) |
|
|
print("\nλ€μ λ°μ΄ν°κ° μμ λ©λλ€:") |
|
|
print(" - μ
λ‘λλ λͺ¨λ νμΌ (uploads ν΄λ)") |
|
|
print(" - λ°μ΄ν°λ² μ΄μ€μ uploaded_file ν
μ΄λΈ") |
|
|
print(" - λ°μ΄ν°λ² μ΄μ€μ document_chunk ν
μ΄λΈ (RAG μ²ν¬)") |
|
|
print(" - λ°μ΄ν°λ² μ΄μ€μ chat_message ν
μ΄λΈ (μ±ν
κΈ°λ‘)") |
|
|
print(" - λ°μ΄ν°λ² μ΄μ€μ chat_session ν
μ΄λΈ (μ±ν
μΈμ
)") |
|
|
print("\nμ¬μ©μ μ 보λ μ μ§λ©λλ€.") |
|
|
print("="*60) |
|
|
|
|
|
|
|
|
auto_confirm = '--yes' in sys.argv or '-y' in sys.argv |
|
|
|
|
|
if not auto_confirm: |
|
|
try: |
|
|
confirm = input("\nμ λ§ μμ νμκ² μ΅λκΉ? (yes/no): ") |
|
|
except (EOFError, KeyboardInterrupt): |
|
|
print("\nμ
λ ₯μ΄ μ·¨μλμμ΅λλ€. μλ μ€ν λͺ¨λλ‘ μ§νν©λλ€.") |
|
|
confirm = 'yes' |
|
|
else: |
|
|
confirm = 'yes' |
|
|
print("\nμλ μ€ν λͺ¨λ: νμΈ μμ΄ μμ λ₯Ό μ§νν©λλ€.") |
|
|
|
|
|
if confirm.lower() in ['yes', 'y', 'μ', 'γ
']: |
|
|
success = reset_upload_data() |
|
|
if success: |
|
|
print("\nμ΄κΈ°νκ° μλ£λμμ΅λλ€. μ΄μ μλ‘ νμΌμ μ
λ‘λν μ μμ΅λλ€.") |
|
|
else: |
|
|
print("\nμ΄κΈ°ν μ€ μ€λ₯κ° λ°μνμ΅λλ€.") |
|
|
else: |
|
|
print("\nμ·¨μλμμ΅λλ€.") |
|
|
|
|
|
|