File size: 1,424 Bytes
08af9fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import os
from pathlib import Path
from dotenv import load_dotenv
from sqlmodel import create_engine, Session, select, SQLModel
from src.models.task import Task
from src.models.user import User

# Load Env
BASE_DIR = Path(__file__).resolve().parent
load_dotenv(BASE_DIR / ".env")

# 1. Check Postgres
pg_url = os.getenv("DATABASE_URL")
print(f"--- CHECKING POSTGRES ({pg_url}) ---")
if pg_url:
    try:
        engine_pg = create_engine(pg_url)
        with Session(engine_pg) as session:
            tasks = session.exec(select(Task)).all()
            print(f"Total Tasks in Postgres: {len(tasks)}")
            for t in tasks:
                print(f"ID: {t.id} | Title: {t.title} | Completed: {t.completed}")
    except Exception as e:
        print(f"Postgres Connection Failed: {e}")
else:
    print("No DATABASE_URL found.")

# 2. Check SQLite
print("\n--- CHECKING LOCAL SQLITE (todo_app.db) ---")
sqlite_path = "sqlite:///./todo_app.db"
try:
    if os.path.exists("todo_app.db"):
        engine_lite = create_engine(sqlite_path)
        with Session(engine_lite) as session:
            tasks = session.exec(select(Task)).all()
            print(f"Total Tasks in SQLite: {len(tasks)}")
            for t in tasks:
                print(f"ID: {t.id} | Title: {t.title} | Completed: {t.completed}")
    else:
        print("todo_app.db does not exist.")
except Exception as e:
    print(f"SQLite Check Failed: {e}")