weatherdataapi-t0r1ss/alembic/versions/f9a8b7c6d5e4_initial_migration.py
Automated Action 1468af1391 Add Weather Data API with OpenWeatherMap integration
- Created FastAPI application with SQLite database integration
- Implemented OpenWeatherMap client with caching
- Added endpoints for current weather, forecasts, and history
- Included comprehensive error handling and validation
- Set up Alembic migrations
- Created detailed README with usage examples

generated with BackendIM... (backend.im)
2025-05-12 14:26:44 +00:00

66 lines
2.6 KiB
Python

"""Initial migration
Revision ID: f9a8b7c6d5e4
Revises:
Create Date: 2025-05-12 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f9a8b7c6d5e4'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# Create cities table
op.create_table(
'cities',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('country', sa.String(), nullable=True),
sa.Column('latitude', sa.Float(), nullable=True),
sa.Column('longitude', sa.Float(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_cities_id'), 'cities', ['id'], unique=False)
op.create_index(op.f('ix_cities_name'), 'cities', ['name'], unique=False)
# Create weather_records table
op.create_table(
'weather_records',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('city_id', sa.Integer(), nullable=True),
sa.Column('temperature', sa.Float(), nullable=True),
sa.Column('feels_like', sa.Float(), nullable=True),
sa.Column('humidity', sa.Integer(), nullable=True),
sa.Column('pressure', sa.Integer(), nullable=True),
sa.Column('wind_speed', sa.Float(), nullable=True),
sa.Column('wind_direction', sa.Integer(), nullable=True),
sa.Column('weather_condition', sa.String(), nullable=True),
sa.Column('weather_description', sa.String(), nullable=True),
sa.Column('clouds', sa.Integer(), nullable=True),
sa.Column('rain_1h', sa.Float(), nullable=True),
sa.Column('snow_1h', sa.Float(), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['city_id'], ['cities.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_weather_records_id'), 'weather_records', ['id'], unique=False)
op.create_index(op.f('ix_weather_records_timestamp'), 'weather_records', ['timestamp'], unique=False)
def downgrade():
op.drop_index(op.f('ix_weather_records_timestamp'), table_name='weather_records')
op.drop_index(op.f('ix_weather_records_id'), table_name='weather_records')
op.drop_table('weather_records')
op.drop_index(op.f('ix_cities_name'), table_name='cities')
op.drop_index(op.f('ix_cities_id'), table_name='cities')
op.drop_table('cities')