66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from sqlalchemy import text
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
from sqlalchemy.orm import sessionmaker
|
|
from app.core.config import settings
|
|
|
|
async def check_person_schema():
|
|
engine = create_async_engine(settings.DATABASE_URL, echo=False)
|
|
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
async with async_session() as session:
|
|
# Get columns of identity.persons
|
|
query = text("""
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'identity' AND table_name = 'persons'
|
|
ORDER BY ordinal_position;
|
|
""")
|
|
result = await session.execute(query)
|
|
columns = result.fetchall()
|
|
print("Columns in identity.persons:")
|
|
for col in columns:
|
|
print(f" {col[0]} ({col[1]})")
|
|
|
|
# Get columns of identity.users
|
|
query2 = text("""
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'identity' AND table_name = 'users'
|
|
ORDER BY ordinal_position;
|
|
""")
|
|
result2 = await session.execute(query2)
|
|
columns2 = result2.fetchall()
|
|
print("\nColumns in identity.users:")
|
|
for col in columns2:
|
|
print(f" {col[0]} ({col[1]})")
|
|
|
|
# Find relationship
|
|
query3 = text("""
|
|
SELECT u.email, u.person_id, p.id, p.first_name, p.last_name
|
|
FROM identity.users u
|
|
JOIN identity.persons p ON u.person_id = p.id
|
|
WHERE u.email = 'tester_pro@profibot.hu'
|
|
LIMIT 1;
|
|
""")
|
|
try:
|
|
result3 = await session.execute(query3)
|
|
user = result3.fetchone()
|
|
if user:
|
|
print(f"\nTest user found: email={user[0]}, user.person_id={user[1]}, persons.id={user[2]}, name={user[3]} {user[4]}")
|
|
else:
|
|
print("\nTest user not found")
|
|
except Exception as e:
|
|
print(f"\nError joining: {e}")
|
|
# Try alternative column names
|
|
pass
|
|
|
|
await engine.dispose()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(check_person_schema()) |