-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_session.py
More file actions
59 lines (51 loc) · 2.36 KB
/
check_session.py
File metadata and controls
59 lines (51 loc) · 2.36 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import asyncio
import os
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from dotenv import load_dotenv
load_dotenv("backend/.env")
from backend.app.models import InterviewSession, Candidate, User
from backend.app.database import Base
DATABASE_URL = os.getenv("DATABASE_URL")
if "6543" in DATABASE_URL:
DATABASE_URL = DATABASE_URL.replace(":6543", ":5432")
engine = create_async_engine(DATABASE_URL, connect_args={"ssl": "require"})
AsyncSessionLocal = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async def check_session():
async with AsyncSessionLocal() as db:
print("Checking for Session 1...")
from sqlalchemy import select
result = await db.execute(select(InterviewSession).where(InterviewSession.id == 1))
session = result.scalars().first()
if session:
print("Session 1 exists.")
# Ensure it has a candidate
if not session.candidate_id:
print("Session 1 has no candidate. Fixing...")
# Create dummy candidate check first
cand_res = await db.execute(select(Candidate).limit(1))
cand = cand_res.scalars().first()
if not cand:
cand = Candidate(name="Test Candidate", email="test@example.com", resume_url="http://example.com", resume_text="Test resume")
db.add(cand)
await db.flush()
session.candidate_id = cand.id
db.add(session)
await db.commit()
else:
print("Session 1 missing. Creating dummy session...")
# Need candidate first
cand_res = await db.execute(select(Candidate).limit(1))
cand = cand_res.scalars().first()
if not cand:
cand = Candidate(name="Test Candidate", email="test@example.com", resume_url="http://example.com", resume_text="Test resume")
db.add(cand)
await db.flush()
session = InterviewSession(id=1, candidate_id=cand.id, status="pending", current_round="oa_coding")
db.add(session)
await db.commit()
print("Created Session 1.")
if __name__ == "__main__":
import sys
sys.path.append(os.getcwd())
asyncio.run(check_session())