Re-create migrations init tables

This commit is contained in:
Urtzi Alfaro
2025-10-09 20:47:31 +02:00
parent b420af32c5
commit dbc7f2fa0d
19 changed files with 112 additions and 195 deletions

View File

@@ -1,69 +0,0 @@
"""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')

View File

@@ -1,8 +1,8 @@
"""initial_schema_20251006_1517
"""initial_schema_20251009_2039
Revision ID: 44983b9ad55b
Revision ID: e1c05c379c10
Revises:
Create Date: 2025-10-06 15:17:13.717978+02:00
Create Date: 2025-10-09 20:39:49.989716+02:00
"""
from typing import Sequence, Union
@@ -12,7 +12,7 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '44983b9ad55b'
revision: str = 'e1c05c379c10'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
@@ -20,6 +20,42 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('city_traffic_data',
sa.Column('id', sa.UUID(), 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)
op.create_table('city_weather_data',
sa.Column('id', sa.UUID(), 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('traffic_background_jobs',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('job_type', sa.String(length=50), nullable=False),
@@ -221,4 +257,12 @@ def downgrade() -> None:
op.drop_index('idx_jobs_completed', table_name='traffic_background_jobs')
op.drop_index('idx_jobs_city_status', table_name='traffic_background_jobs')
op.drop_table('traffic_background_jobs')
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')
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')
# ### end Alembic commands ###