37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""phase25 — add GPS coordinates to inspections
|
|
|
|
Adds submit_latitude and submit_longitude columns to the inspections table.
|
|
Populated at web submission time via browser Geolocation API.
|
|
Null for all existing inspections and mobile submissions (handled separately).
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = 'phase25_inspection_gps'
|
|
down_revision = 'phase24_notify_defaults'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
conn = op.get_bind()
|
|
|
|
has_lat = conn.execute(sa.text(
|
|
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS "
|
|
"WHERE TABLE_SCHEMA = DATABASE() "
|
|
" AND TABLE_NAME = 'inspections' "
|
|
" AND COLUMN_NAME = 'submit_latitude'"
|
|
)).scalar()
|
|
|
|
if not has_lat:
|
|
op.add_column('inspections',
|
|
sa.Column('submit_latitude', sa.Numeric(10, 7), nullable=True))
|
|
op.add_column('inspections',
|
|
sa.Column('submit_longitude', sa.Numeric(10, 7), nullable=True))
|
|
|
|
|
|
def downgrade():
|
|
op.drop_column('inspections', 'submit_longitude')
|
|
op.drop_column('inspections', 'submit_latitude')
|