File size: 1,164 Bytes
5263a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from dotenv import load_dotenv
from sqlalchemy import create_engine, text

# Load environment variables
load_dotenv(".env", override=True)
load_dotenv("../.env", override=False)

DATABASE_URL = os.getenv("DATABASE_URL")

if not DATABASE_URL:
    print("Error: DATABASE_URL not found")
    exit(1)

def add_column():
    engine = create_engine(DATABASE_URL)
    with engine.connect() as conn:
        try:
            # Check if column exists first to avoid error
            check_sql = text("SELECT column_name FROM information_schema.columns WHERE table_name='conversations' AND column_name='summary';")
            result = conn.execute(check_sql)
            if result.fetchone():
                print("Column 'summary' already exists.")
                return

            print("Adding 'summary' column to 'conversations' table...")
            sql = text("ALTER TABLE conversations ADD COLUMN summary TEXT;")
            conn.execute(sql)
            conn.commit()
            print("Successfully added 'summary' column.")
        except Exception as e:
            print(f"Error adding column: {e}")

if __name__ == "__main__":
    add_column()