"""initial schema Revision ID: 928b78044640 Revises: Create Date: 2026-03-16 12:53:09.720225 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = '928b78044640' down_revision: Union[str, None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('riders', sa.Column('id', sa.UUID(), nullable=False), sa.Column('telegram_id', sa.BigInteger(), nullable=True), sa.Column('telegram_username', sa.String(length=100), nullable=True), sa.Column('avatar_url', sa.String(length=500), nullable=True), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('ftp', sa.Float(), nullable=True), sa.Column('lthr', sa.Integer(), nullable=True), sa.Column('weight', sa.Float(), nullable=True), sa.Column('zones_config', postgresql.JSONB(astext_type=sa.Text()), nullable=True), sa.Column('goals', sa.String(length=500), nullable=True), sa.Column('experience_level', sa.String(length=50), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_riders_telegram_id'), 'riders', ['telegram_id'], unique=True) op.create_table('activities', sa.Column('id', sa.UUID(), nullable=False), sa.Column('rider_id', sa.UUID(), nullable=False), sa.Column('name', sa.String(length=200), nullable=True), sa.Column('activity_type', sa.String(length=50), nullable=False), sa.Column('date', sa.DateTime(timezone=True), nullable=False), sa.Column('duration', sa.Integer(), nullable=False), sa.Column('distance', sa.Float(), nullable=True), sa.Column('elevation_gain', sa.Float(), nullable=True), sa.Column('file_path', sa.String(length=500), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), sa.ForeignKeyConstraint(['rider_id'], ['riders.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('fitness_history', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('rider_id', sa.UUID(), nullable=False), sa.Column('date', sa.Date(), nullable=False), sa.Column('ctl', sa.Float(), nullable=False), sa.Column('atl', sa.Float(), nullable=False), sa.Column('tsb', sa.Float(), nullable=False), sa.Column('ramp_rate', sa.Float(), nullable=True), sa.ForeignKeyConstraint(['rider_id'], ['riders.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_fitness_history_date'), 'fitness_history', ['date'], unique=False) op.create_table('training_plans', sa.Column('id', sa.UUID(), nullable=False), sa.Column('rider_id', sa.UUID(), nullable=False), sa.Column('goal', sa.String(length=200), nullable=False), sa.Column('start_date', sa.Date(), nullable=False), sa.Column('end_date', sa.Date(), nullable=False), sa.Column('phase', sa.String(length=50), nullable=True), sa.Column('weeks_json', postgresql.JSONB(astext_type=sa.Text()), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), sa.ForeignKeyConstraint(['rider_id'], ['riders.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('activity_metrics', sa.Column('id', sa.UUID(), nullable=False), sa.Column('activity_id', sa.UUID(), nullable=False), sa.Column('tss', sa.Float(), nullable=True), sa.Column('normalized_power', sa.Float(), nullable=True), sa.Column('intensity_factor', sa.Float(), nullable=True), sa.Column('variability_index', sa.Float(), nullable=True), sa.Column('avg_power', sa.Float(), nullable=True), sa.Column('max_power', sa.Integer(), nullable=True), sa.Column('avg_hr', sa.Integer(), nullable=True), sa.Column('max_hr', sa.Integer(), nullable=True), sa.Column('avg_cadence', sa.Integer(), nullable=True), sa.Column('avg_speed', sa.Float(), nullable=True), sa.Column('calories', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('activity_id') ) op.create_table('data_points', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('activity_id', sa.UUID(), nullable=False), sa.Column('timestamp', sa.DateTime(timezone=True), nullable=False), sa.Column('power', sa.Integer(), nullable=True), sa.Column('heart_rate', sa.Integer(), nullable=True), sa.Column('cadence', sa.Integer(), nullable=True), sa.Column('speed', sa.Float(), nullable=True), sa.Column('latitude', sa.Float(), nullable=True), sa.Column('longitude', sa.Float(), nullable=True), sa.Column('altitude', sa.Float(), nullable=True), sa.Column('temperature', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_data_points_timestamp'), 'data_points', ['timestamp'], unique=False) op.create_table('diary_entries', sa.Column('id', sa.UUID(), nullable=False), sa.Column('activity_id', sa.UUID(), nullable=False), sa.Column('ai_summary', sa.Text(), nullable=True), sa.Column('rider_notes', sa.Text(), nullable=True), sa.Column('mood', sa.String(length=50), nullable=True), sa.Column('rpe', sa.Integer(), nullable=True), sa.Column('sleep_hours', sa.Float(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('activity_id') ) op.create_table('intervals', sa.Column('id', sa.UUID(), nullable=False), sa.Column('activity_id', sa.UUID(), nullable=False), sa.Column('start_ts', sa.DateTime(timezone=True), nullable=False), sa.Column('end_ts', sa.DateTime(timezone=True), nullable=False), sa.Column('interval_type', sa.String(length=50), nullable=False), sa.Column('avg_power', sa.Float(), nullable=True), sa.Column('avg_hr', sa.Integer(), nullable=True), sa.Column('duration', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('power_curves', sa.Column('id', sa.UUID(), nullable=False), sa.Column('activity_id', sa.UUID(), nullable=False), sa.Column('curve_data', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.ForeignKeyConstraint(['activity_id'], ['activities.id'], ), sa.PrimaryKeyConstraint('id') ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_table('power_curves') op.drop_table('intervals') op.drop_table('diary_entries') op.drop_index(op.f('ix_data_points_timestamp'), table_name='data_points') op.drop_table('data_points') op.drop_table('activity_metrics') op.drop_table('training_plans') op.drop_index(op.f('ix_fitness_history_date'), table_name='fitness_history') op.drop_table('fitness_history') op.drop_table('activities') op.drop_index(op.f('ix_riders_telegram_id'), table_name='riders') op.drop_table('riders') # ### end Alembic commands ###