Chatbot_capstone / test.py
Ezhil
repo init
601d457
raw
history blame contribute delete
911 Bytes
import psycopg2
from psycopg2.extras import RealDictCursor
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Database connection details
DB_HOST = os.getenv("DB_HOST")
DB_NAME = os.getenv("DB_NAME")
DB_USER = os.getenv("DB_USER")
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_PORT = os.getenv("DB_PORT")
# Test schema
try:
conn = psycopg2.connect(
host=DB_HOST,
database=DB_NAME,
user=DB_USER,
password=DB_PASSWORD,
port=DB_PORT,
cursor_factory=RealDictCursor
)
with conn.cursor() as cur:
cur.execute(
"SELECT column_name FROM information_schema.columns WHERE table_name = 'songs';")
result = cur.fetchall()
print("Columns in 'songs' table:", [
row["column_name"] for row in result])
conn.close()
except Exception as e:
print("Schema query failed:", str(e))