import os
import psycopg2
from dotenv import load_dotenv

load_dotenv()

def migrate_updated_at():
    try:
        conn = psycopg2.connect(
            host=os.getenv("DB_HOST"),
            port=os.getenv("DB_PORT"),
            database=os.getenv("DB_NAME"),
            user=os.getenv("DB_USER"),
            password=os.getenv("DB_PASSWORD")
        )
        with conn.cursor() as cur:
            # Add updated_at column
            cur.execute("""
                ALTER TABLE google_review 
                ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
            """)
            print("Added 'updated_at' column.")
            conn.commit()
            print("Migration completed successfully.")
            
    except Exception as e:
        print(f"Error migrating database: {e}")
    finally:
        if conn: conn.close()

if __name__ == "__main__":
    migrate_updated_at()
