"""add workouts limit for global map and first point geometry to workouts

Revision ID: 0a2e2369b972
Revises: fed271354410
Create Date: 2025-09-17 16:56:55.920185

"""
from alembic import op
import sqlalchemy as sa
from geoalchemy2 import Geometry

# revision identifiers, used by Alembic.
revision = '0a2e2369b972'
down_revision = 'fed271354410'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('app_config', schema=None) as batch_op:
        batch_op.add_column(sa.Column('global_map_workouts_limit', sa.Integer(), server_default='10000', nullable=False))

    with op.batch_alter_table('workouts', schema=None) as batch_op:
        batch_op.add_geospatial_column(sa.Column('start_point_geom', Geometry(geometry_type='POINT', srid=4326, dimension=2, spatial_index=False, from_text='ST_GeomFromEWKT', name='geometry'), nullable=True))
        batch_op.create_geospatial_index('idx_workouts_start_point_geom', ['start_point_geom'], unique=False, postgresql_using='gist', postgresql_ops={})

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('workouts', schema=None) as batch_op:
        batch_op.drop_geospatial_index('idx_workouts_start_point_geom', postgresql_using='gist', column_name='start_point_geom')
        batch_op.drop_geospatial_column('start_point_geom')

    with op.batch_alter_table('app_config', schema=None) as batch_op:
        batch_op.drop_column('global_map_workouts_limit')

    # ### end Alembic commands ###
