Spaces:
Sleeping
Sleeping
File size: 2,014 Bytes
ed557c5 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/usr/bin/env python3
"""
Quick fix for production - add image_type column with default values
"""
from app.database import engine
from sqlalchemy import text
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def quick_fix():
"""Add image_type column with default values to prevent 500 errors"""
try:
with engine.connect() as connection:
trans = connection.begin()
try:
# Check if column already exists
result = connection.execute(text("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'json_schemas' AND column_name = 'image_type'
"""))
if result.fetchone():
logger.info("image_type column already exists")
else:
# Add column with default value
logger.info("Adding image_type column...")
connection.execute(text("ALTER TABLE json_schemas ADD COLUMN image_type VARCHAR DEFAULT 'crisis_map';"))
# Update existing schemas
logger.info("Updating existing schemas...")
connection.execute(text("UPDATE json_schemas SET image_type = 'crisis_map' WHERE schema_id = 'default_caption@1.0.0';"))
connection.execute(text("UPDATE json_schemas SET image_type = 'drone_image' WHERE schema_id = 'drone_caption@1.0.0';"))
trans.commit()
logger.info("Quick fix applied successfully!")
except Exception as e:
trans.rollback()
logger.error(f"Quick fix failed: {str(e)}")
raise
except Exception as e:
logger.error(f"Database connection error: {str(e)}")
raise
if __name__ == "__main__":
quick_fix()
|