49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""
|
|
Mark the current migration as complete in alembic_version table
|
|
This is needed because tables were partially created before
|
|
"""
|
|
import pymysql
|
|
from app.core.config import settings
|
|
|
|
# Connect to database
|
|
conn = pymysql.connect(
|
|
host=settings.mysql_host,
|
|
port=settings.mysql_port,
|
|
user=settings.mysql_user,
|
|
password=settings.mysql_password,
|
|
database=settings.mysql_database
|
|
)
|
|
|
|
try:
|
|
with conn.cursor() as cursor:
|
|
# Check if alembic_version table exists
|
|
cursor.execute("SHOW TABLES LIKE 'alembic_version'")
|
|
if not cursor.fetchone():
|
|
# Create alembic_version table
|
|
cursor.execute("""
|
|
CREATE TABLE alembic_version (
|
|
version_num VARCHAR(32) NOT NULL,
|
|
PRIMARY KEY (version_num)
|
|
)
|
|
""")
|
|
print("Created alembic_version table")
|
|
|
|
# Check current version
|
|
cursor.execute("SELECT version_num FROM alembic_version")
|
|
current = cursor.fetchone()
|
|
|
|
if current:
|
|
print(f"Current migration version: {current[0]}")
|
|
# Delete old version
|
|
cursor.execute("DELETE FROM alembic_version")
|
|
|
|
# Insert new version
|
|
cursor.execute(
|
|
"INSERT INTO alembic_version (version_num) VALUES ('a7802b126240')"
|
|
)
|
|
conn.commit()
|
|
print("✅ Marked migration a7802b126240 as complete")
|
|
|
|
finally:
|
|
conn.close()
|