Spaces:
Running
Running
migration fix
Browse files
py_backend/alembic/versions/0021_add_image_type_to_json_schemas.py
CHANGED
@@ -27,8 +27,8 @@ def upgrade():
|
|
27 |
# [email protected] -> crisis_map
|
28 |
op.execute("UPDATE json_schemas SET image_type = 'crisis_map' WHERE schema_id = '[email protected]'")
|
29 |
|
30 |
-
# [email protected] ->
|
31 |
-
op.execute("UPDATE json_schemas SET image_type = '
|
32 |
|
33 |
|
34 |
def downgrade():
|
|
|
27 |
# [email protected] -> crisis_map
|
28 |
op.execute("UPDATE json_schemas SET image_type = 'crisis_map' WHERE schema_id = '[email protected]'")
|
29 |
|
30 |
+
# [email protected] -> drone_image
|
31 |
+
op.execute("UPDATE json_schemas SET image_type = 'drone_image' WHERE schema_id = '[email protected]'")
|
32 |
|
33 |
|
34 |
def downgrade():
|
py_backend/check_production_db.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Check production database status for schema table
|
4 |
+
"""
|
5 |
+
|
6 |
+
from app.database import engine
|
7 |
+
from sqlalchemy import text
|
8 |
+
import logging
|
9 |
+
|
10 |
+
logging.basicConfig(level=logging.INFO)
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
|
13 |
+
def check_production_db():
|
14 |
+
"""Check the current state of the production database"""
|
15 |
+
|
16 |
+
try:
|
17 |
+
with engine.connect() as connection:
|
18 |
+
|
19 |
+
# Check if json_schemas table exists
|
20 |
+
logger.info("1. Checking if json_schemas table exists...")
|
21 |
+
result = connection.execute(text("""
|
22 |
+
SELECT table_name
|
23 |
+
FROM information_schema.tables
|
24 |
+
WHERE table_name = 'json_schemas'
|
25 |
+
"""))
|
26 |
+
|
27 |
+
if result.fetchone():
|
28 |
+
logger.info("β json_schemas table exists")
|
29 |
+
else:
|
30 |
+
logger.error("β json_schemas table does not exist")
|
31 |
+
return
|
32 |
+
|
33 |
+
# Check table structure
|
34 |
+
logger.info("2. Checking json_schemas table structure...")
|
35 |
+
result = connection.execute(text("""
|
36 |
+
SELECT column_name, data_type, is_nullable
|
37 |
+
FROM information_schema.columns
|
38 |
+
WHERE table_name = 'json_schemas'
|
39 |
+
ORDER BY ordinal_position
|
40 |
+
"""))
|
41 |
+
|
42 |
+
columns = result.fetchall()
|
43 |
+
logger.info("Current columns:")
|
44 |
+
for col in columns:
|
45 |
+
logger.info(f" - {col.column_name}: {col.data_type} (nullable: {col.is_nullable})")
|
46 |
+
|
47 |
+
# Check if image_type column exists
|
48 |
+
has_image_type = any(col.column_name == 'image_type' for col in columns)
|
49 |
+
if has_image_type:
|
50 |
+
logger.info("β image_type column exists")
|
51 |
+
else:
|
52 |
+
logger.error("β image_type column missing - this is causing the 500 error")
|
53 |
+
|
54 |
+
# Check existing schemas
|
55 |
+
logger.info("3. Checking existing schemas...")
|
56 |
+
result = connection.execute(text("SELECT schema_id, title FROM json_schemas"))
|
57 |
+
schemas = result.fetchall()
|
58 |
+
|
59 |
+
logger.info("Existing schemas:")
|
60 |
+
for schema in schemas:
|
61 |
+
logger.info(f" - {schema.schema_id}: {schema.title}")
|
62 |
+
|
63 |
+
# Check image_types table
|
64 |
+
logger.info("4. Checking image_types table...")
|
65 |
+
result = connection.execute(text("SELECT image_type, label FROM image_types"))
|
66 |
+
image_types = result.fetchall()
|
67 |
+
|
68 |
+
logger.info("Available image types:")
|
69 |
+
for it in image_types:
|
70 |
+
logger.info(f" - {it.image_type}: {it.label}")
|
71 |
+
|
72 |
+
except Exception as e:
|
73 |
+
logger.error(f"Database check failed: {str(e)}")
|
74 |
+
|
75 |
+
if __name__ == "__main__":
|
76 |
+
check_production_db()
|
py_backend/quick_fix_production.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Quick fix for production - add image_type column with default values
|
4 |
+
"""
|
5 |
+
|
6 |
+
from app.database import engine
|
7 |
+
from sqlalchemy import text
|
8 |
+
import logging
|
9 |
+
|
10 |
+
logging.basicConfig(level=logging.INFO)
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
|
13 |
+
def quick_fix():
|
14 |
+
"""Add image_type column with default values to prevent 500 errors"""
|
15 |
+
|
16 |
+
try:
|
17 |
+
with engine.connect() as connection:
|
18 |
+
trans = connection.begin()
|
19 |
+
|
20 |
+
try:
|
21 |
+
# Check if column already exists
|
22 |
+
result = connection.execute(text("""
|
23 |
+
SELECT column_name
|
24 |
+
FROM information_schema.columns
|
25 |
+
WHERE table_name = 'json_schemas' AND column_name = 'image_type'
|
26 |
+
"""))
|
27 |
+
|
28 |
+
if result.fetchone():
|
29 |
+
logger.info("image_type column already exists")
|
30 |
+
else:
|
31 |
+
# Add column with default value
|
32 |
+
logger.info("Adding image_type column...")
|
33 |
+
connection.execute(text("ALTER TABLE json_schemas ADD COLUMN image_type VARCHAR DEFAULT 'crisis_map';"))
|
34 |
+
|
35 |
+
# Update existing schemas
|
36 |
+
logger.info("Updating existing schemas...")
|
37 |
+
connection.execute(text("UPDATE json_schemas SET image_type = 'crisis_map' WHERE schema_id = '[email protected]';"))
|
38 |
+
connection.execute(text("UPDATE json_schemas SET image_type = 'drone_image' WHERE schema_id = '[email protected]';"))
|
39 |
+
|
40 |
+
trans.commit()
|
41 |
+
logger.info("Quick fix applied successfully!")
|
42 |
+
|
43 |
+
except Exception as e:
|
44 |
+
trans.rollback()
|
45 |
+
logger.error(f"Quick fix failed: {str(e)}")
|
46 |
+
raise
|
47 |
+
|
48 |
+
except Exception as e:
|
49 |
+
logger.error(f"Database connection error: {str(e)}")
|
50 |
+
raise
|
51 |
+
|
52 |
+
if __name__ == "__main__":
|
53 |
+
quick_fix()
|