import os
from sqlmodel import create_engine, text

# Get DB URL from env or default (adjust for production)
DATABASE_URL = os.environ.get("DATABASE_URL", "postgresql://elmeg:runfoo@localhost/elmeg")

engine = create_engine(DATABASE_URL)

def run_migration():
    with engine.connect() as conn:
        print("Adding columns to Show table...")
        try:
            conn.execute(text("ALTER TABLE show ADD COLUMN bandcamp_link VARCHAR"))
            print("Added bandcamp_link")
        except Exception as e:
            print(f"Skipping bandcamp_link (already exists?)")

        try:
            conn.execute(text("ALTER TABLE show ADD COLUMN nugs_link VARCHAR"))
            print("Added nugs_link")
        except Exception as e:
            print(f"Skipping nugs_link (already exists?)")

        print("Adding columns to Performance table...")
        try:
            conn.execute(text("ALTER TABLE performance ADD COLUMN track_url VARCHAR"))
            print("Added track_url")
        except Exception as e:
             print(f"Skipping track_url (already exists?)")
        
        conn.commit()
    print("Migration complete.")

if __name__ == "__main__":
    run_migration()
