Spaces:
Running
Running
File size: 6,469 Bytes
ba5edb0 |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
"""Fix JSON schemas to match validation requirements
Revision ID: 0003_fix_json_schemas
Revises: 0002_drone_pose_fields_and_schema
Create Date: 2025-01-20 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
import json
# revision identifiers, used by Alembic.
revision = '0003_fix_json_schemas'
down_revision = '0002_drone_fields'
branch_labels = None
depends_on = None
def upgrade():
"""Fix the JSON schemas to match validation requirements"""
# Fix the default crisis map schema
crisis_schema = {
"type": "object",
"properties": {
"analysis": {"type": "string"},
"metadata": {
"type": "object",
"properties": {
"title": {"type": "string"},
"source": {"type": "string"},
"type": {"type": "string"},
"countries": {"type": "array", "items": {"type": "string"}},
"epsg": {"type": "string"}
},
"required": ["title", "source", "type", "countries", "epsg"]
}
},
"required": ["analysis", "metadata"]
}
op.execute(
sa.text(
"""
UPDATE json_schemas
SET schema = CAST(:schema AS JSONB)
WHERE schema_id = 'default_caption@1.0.0'
"""
).bindparams(
schema=json.dumps(crisis_schema, separators=(",", ":"))
)
)
# Fix the drone schema (the current one is mostly correct, but let's ensure it's perfect)
drone_schema = {
"type": "object",
"properties": {
"analysis": {"type": "string"},
"metadata": {
"type": "object",
"properties": {
"title": {"type": ["string", "null"]},
"source": {"type": ["string", "null"]},
"type": {"type": ["string", "null"]},
"countries": {"type": ["array", "null"], "items": {"type": "string"}},
"epsg": {"type": ["string", "null"]},
"center_lat": {"type": ["number", "null"], "minimum": -90, "maximum": 90},
"center_lon": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"amsl_m": {"type": ["number", "null"]},
"agl_m": {"type": ["number", "null"]},
"heading_deg": {"type": ["number", "null"], "minimum": 0, "maximum": 360},
"yaw_deg": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"pitch_deg": {"type": ["number", "null"], "minimum": -90, "maximum": 90},
"roll_deg": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"rtk_fix": {"type": ["boolean", "null"]},
"std_h_m": {"type": ["number", "null"], "minimum": 0},
"std_v_m": {"type": ["number", "null"], "minimum": 0}
}
}
},
"required": ["analysis", "metadata"]
}
op.execute(
sa.text(
"""
UPDATE json_schemas
SET schema = CAST(:schema AS JSONB)
WHERE schema_id = 'drone_caption@1.0.0'
"""
).bindparams(
schema=json.dumps(drone_schema, separators=(",", ":"))
)
)
print("β Updated JSON schemas to match validation requirements")
def downgrade():
"""Revert to previous schema versions"""
# Revert crisis map schema to original
original_crisis_schema = {
"type": "object",
"properties": {
"analysis": {"type": "string"},
"metadata": {
"type": "object",
"properties": {
"title": {"type": "string"},
"source": {"type": "string"},
"type": {"type": "string"},
"countries": {"type": "array", "items": {"type": "string"}},
"epsg": {"type": "string"}
}
}
},
"required": ["analysis", "metadata"]
}
op.execute(
sa.text(
"""
UPDATE json_schemas
SET schema = CAST(:schema AS JSONB)
WHERE schema_id = 'default_caption@1.0.0'
"""
).bindparams(
schema=json.dumps(original_crisis_schema, separators=(",", ":"))
)
)
# Revert drone schema to original
original_drone_schema = {
"type": "object",
"properties": {
"analysis": {"type": "string"},
"metadata": {
"type": "object",
"properties": {
"title": {"type": ["string", "null"]},
"source": {"type": ["string", "null"]},
"type": {"type": ["string", "null"]},
"countries": {"type": ["array", "null"], "items": {"type": "string"}},
"epsg": {"type": ["string", "null"]},
"center_lat": {"type": ["number", "null"], "minimum": -90, "maximum": 90},
"center_lon": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"amsl_m": {"type": ["number", "null"]},
"agl_m": {"type": ["number", "null"]},
"heading_deg": {"type": ["number", "null"], "minimum": 0, "maximum": 360},
"yaw_deg": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"pitch_deg": {"type": ["number", "null"], "minimum": -90, "maximum": 90},
"roll_deg": {"type": ["number", "null"], "minimum": -180, "maximum": 180},
"rtk_fix": {"type": ["boolean", "null"]},
"std_h_m": {"type": ["number", "null"], "minimum": 0},
"std_v_m": {"type": ["number", "null"], "minimum": 0}
}
}
},
"required": ["analysis", "metadata"]
}
op.execute(
sa.text(
"""
UPDATE json_schemas
SET schema = CAST(:schema AS JSONB)
WHERE schema_id = 'drone_caption@1.0.0'
"""
).bindparams(
schema=json.dumps(original_drone_schema, separators=(",", ":"))
)
)
print("β Reverted JSON schemas to previous versions")
|