Spaces:
Sleeping
Sleeping
File size: 2,869 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#!/usr/bin/env python3
"""
Check production database status for schema table
"""
from app.database import engine
from sqlalchemy import text
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def check_production_db():
"""Check the current state of the production database"""
try:
with engine.connect() as connection:
# Check if json_schemas table exists
logger.info("1. Checking if json_schemas table exists...")
result = connection.execute(text("""
SELECT table_name
FROM information_schema.tables
WHERE table_name = 'json_schemas'
"""))
if result.fetchone():
logger.info("β json_schemas table exists")
else:
logger.error("β json_schemas table does not exist")
return
# Check table structure
logger.info("2. Checking json_schemas table structure...")
result = connection.execute(text("""
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'json_schemas'
ORDER BY ordinal_position
"""))
columns = result.fetchall()
logger.info("Current columns:")
for col in columns:
logger.info(f" - {col.column_name}: {col.data_type} (nullable: {col.is_nullable})")
# Check if image_type column exists
has_image_type = any(col.column_name == 'image_type' for col in columns)
if has_image_type:
logger.info("β image_type column exists")
else:
logger.error("β image_type column missing - this is causing the 500 error")
# Check existing schemas
logger.info("3. Checking existing schemas...")
result = connection.execute(text("SELECT schema_id, title FROM json_schemas"))
schemas = result.fetchall()
logger.info("Existing schemas:")
for schema in schemas:
logger.info(f" - {schema.schema_id}: {schema.title}")
# Check image_types table
logger.info("4. Checking image_types table...")
result = connection.execute(text("SELECT image_type, label FROM image_types"))
image_types = result.fetchall()
logger.info("Available image types:")
for it in image_types:
logger.info(f" - {it.image_type}: {it.label}")
except Exception as e:
logger.error(f"Database check failed: {str(e)}")
if __name__ == "__main__":
check_production_db()
|