
- Set up FastAPI project structure - Create database models for locations and weather data - Implement OpenWeatherMap API integration - Create API endpoints for current weather and history - Add health endpoint - Set up database migrations with Alembic - Update README with documentation generated with BackendIM... (backend.im)
62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
"""initial migration
|
|
|
|
Revision ID: initial_migration
|
|
Revises:
|
|
Create Date: 2025-05-12
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'initial_migration'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create locations table
|
|
op.create_table('locations',
|
|
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_locations_id'), 'locations', ['id'], unique=False)
|
|
op.create_index(op.f('ix_locations_name'), 'locations', ['name'], unique=False)
|
|
|
|
# Create weather_data table
|
|
op.create_table('weather_data',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('location_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('timestamp', sa.DateTime(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['location_id'], ['locations.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_weather_data_id'), 'weather_data', ['id'], unique=False)
|
|
op.create_index(op.f('ix_weather_data_timestamp'), 'weather_data', ['timestamp'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_weather_data_timestamp'), table_name='weather_data')
|
|
op.drop_index(op.f('ix_weather_data_id'), table_name='weather_data')
|
|
op.drop_table('weather_data')
|
|
op.drop_index(op.f('ix_locations_name'), table_name='locations')
|
|
op.drop_index(op.f('ix_locations_id'), table_name='locations')
|
|
op.drop_table('locations') |