import os
from pathlib import Path
import sqlite3

base_path = Path(r'D:\Workspace\claudeCode\AutonetSellCar.com')

# Find all .db files
db_files = []
for p in base_path.rglob('*.db'):
    if 'node_modules' not in str(p) and 'venv' not in str(p):
        db_files.append(p)

print("=" * 60)
print("발견된 DB 파일들:")
print("=" * 60)

for db_path in sorted(db_files):
    size = db_path.stat().st_size / 1024  # KB
    mtime = db_path.stat().st_mtime
    from datetime import datetime
    mtime_str = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S')
    print(f"\n{db_path}")
    print(f"  크기: {size:.1f} KB")
    print(f"  수정: {mtime_str}")

    # Check tables
    try:
        conn = sqlite3.connect(str(db_path))
        cursor = conn.cursor()
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
        tables = [t[0] for t in cursor.fetchall()]
        print(f"  테이블: {', '.join(tables[:10])}")

        # Check if car_performance_checks table exists
        if 'car_performance_checks' in tables:
            cursor.execute("SELECT COUNT(*), COUNT(pdf_path) FROM car_performance_checks WHERE pdf_path IS NOT NULL AND pdf_path != ''")
            total, with_pdf = cursor.fetchone()
            print(f"  성능점검: 총 {total}개, PDF있음 {with_pdf}개")

            # Show recent records
            cursor.execute("SELECT car_id, check_number, pdf_path FROM car_performance_checks ORDER BY id DESC LIMIT 3")
            for row in cursor.fetchall():
                print(f"    car_id={row[0]}, check_num={row[1]}, pdf={row[2]}")

        conn.close()
    except Exception as e:
        print(f"  오류: {e}")

print("\n" + "=" * 60)
