REFACTOR external service and improve websocket training
This commit is contained in:
69
services/external/migrations/versions/20251007_0733_add_city_data_tables.py
vendored
Normal file
69
services/external/migrations/versions/20251007_0733_add_city_data_tables.py
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
"""Add city data tables
|
||||
|
||||
Revision ID: 20251007_0733
|
||||
Revises: 44983b9ad55b
|
||||
Create Date: 2025-10-07 07:33:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = '20251007_0733'
|
||||
down_revision = '44983b9ad55b'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'city_weather_data',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('city_id', sa.String(length=50), nullable=False),
|
||||
sa.Column('date', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('temperature', sa.Float(), nullable=True),
|
||||
sa.Column('precipitation', sa.Float(), nullable=True),
|
||||
sa.Column('humidity', sa.Float(), nullable=True),
|
||||
sa.Column('wind_speed', sa.Float(), nullable=True),
|
||||
sa.Column('pressure', sa.Float(), nullable=True),
|
||||
sa.Column('description', sa.String(length=200), nullable=True),
|
||||
sa.Column('source', sa.String(length=50), nullable=False),
|
||||
sa.Column('raw_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('idx_city_weather_lookup', 'city_weather_data', ['city_id', 'date'], unique=False)
|
||||
op.create_index(op.f('ix_city_weather_data_city_id'), 'city_weather_data', ['city_id'], unique=False)
|
||||
op.create_index(op.f('ix_city_weather_data_date'), 'city_weather_data', ['date'], unique=False)
|
||||
|
||||
op.create_table(
|
||||
'city_traffic_data',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('city_id', sa.String(length=50), nullable=False),
|
||||
sa.Column('date', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('traffic_volume', sa.Integer(), nullable=True),
|
||||
sa.Column('pedestrian_count', sa.Integer(), nullable=True),
|
||||
sa.Column('congestion_level', sa.String(length=20), nullable=True),
|
||||
sa.Column('average_speed', sa.Float(), nullable=True),
|
||||
sa.Column('source', sa.String(length=50), nullable=False),
|
||||
sa.Column('raw_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('idx_city_traffic_lookup', 'city_traffic_data', ['city_id', 'date'], unique=False)
|
||||
op.create_index(op.f('ix_city_traffic_data_city_id'), 'city_traffic_data', ['city_id'], unique=False)
|
||||
op.create_index(op.f('ix_city_traffic_data_date'), 'city_traffic_data', ['date'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index(op.f('ix_city_traffic_data_date'), table_name='city_traffic_data')
|
||||
op.drop_index(op.f('ix_city_traffic_data_city_id'), table_name='city_traffic_data')
|
||||
op.drop_index('idx_city_traffic_lookup', table_name='city_traffic_data')
|
||||
op.drop_table('city_traffic_data')
|
||||
|
||||
op.drop_index(op.f('ix_city_weather_data_date'), table_name='city_weather_data')
|
||||
op.drop_index(op.f('ix_city_weather_data_city_id'), table_name='city_weather_data')
|
||||
op.drop_index('idx_city_weather_lookup', table_name='city_weather_data')
|
||||
op.drop_table('city_weather_data')
|
||||
Reference in New Issue
Block a user