#!/usr/bin/env python3
"""Fix alembic version in database"""

from sqlalchemy import create_engine, text
from app.core.config import settings

# Create database connection
engine = create_engine(settings.database_url)

with engine.connect() as conn:
    # Delete the problematic version
    conn.execute(text("DELETE FROM alembic_version WHERE version_num = '3ede847231ff'"))
    conn.commit()
    print("✓ Removed problematic alembic version")

    # Check current version
    result = conn.execute(text("SELECT version_num FROM alembic_version"))
    versions = result.fetchall()

    if versions:
        print(f"Current version(s): {[v[0] for v in versions]}")
    else:
        print("No alembic version found in database")
        # Set to the base version before our new migrations
        conn.execute(text("INSERT INTO alembic_version (version_num) VALUES ('271dc036ea80')"))
        conn.commit()
        print("✓ Set alembic version to 271dc036ea80")

print("\nDone!")
