API - add missing indexes on Workout table

This commit is contained in:
Sam 2022-02-05 11:58:07 +01:00
parent 136162334f
commit bfea21bc3c
3 changed files with 42 additions and 6 deletions

View File

@ -0,0 +1,34 @@
"""add missing indexes on Workout table
Revision ID: e30007d681cb
Revises: ed409fd9db9d
Create Date: 2022-02-05 11:52:23.847975
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e30007d681cb'
down_revision = 'ed409fd9db9d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_workouts_map_id'), 'workouts', ['map_id'], unique=False)
op.create_index(op.f('ix_workouts_sport_id'), 'workouts', ['sport_id'], unique=False)
op.create_index(op.f('ix_workouts_user_id'), 'workouts', ['user_id'], unique=False)
op.create_index(op.f('ix_workouts_workout_date'), 'workouts', ['workout_date'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_workouts_workout_date'), table_name='workouts')
op.drop_index(op.f('ix_workouts_user_id'), table_name='workouts')
op.drop_index(op.f('ix_workouts_sport_id'), table_name='workouts')
op.drop_index(op.f('ix_workouts_map_id'), table_name='workouts')
# ### end Alembic commands ###

View File

@ -593,13 +593,13 @@ class TestGetWorkoutsWithFilters(ApiTestCaseMixin):
'Fri, 23 Feb 2018 00:00:00 GMT'
== data['data']['workouts'][0]['workout_date']
)
assert '0:10:00' == data['data']['workouts'][0]['duration']
assert '0:16:40' == data['data']['workouts'][0]['duration']
assert 'creation_date' in data['data']['workouts'][1]
assert (
'Fri, 23 Feb 2018 00:00:00 GMT'
== data['data']['workouts'][1]['workout_date']
)
assert '0:16:40' == data['data']['workouts'][1]['duration']
assert '0:10:00' == data['data']['workouts'][1]['duration']
assert data['pagination'] == {
'has_next': False,
'has_prev': False,

View File

@ -124,9 +124,11 @@ class Workout(BaseModel):
unique=True,
nullable=False,
)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
user_id = db.Column(
db.Integer, db.ForeignKey('users.id'), index=True, nullable=False
)
sport_id = db.Column(
db.Integer, db.ForeignKey('sports.id'), nullable=False
db.Integer, db.ForeignKey('sports.id'), index=True, nullable=False
)
title = db.Column(db.String(255), nullable=True)
gpx = db.Column(db.String(255), nullable=True)
@ -134,7 +136,7 @@ class Workout(BaseModel):
modification_date = db.Column(
db.DateTime, onupdate=datetime.datetime.utcnow
)
workout_date = db.Column(db.DateTime, nullable=False)
workout_date = db.Column(db.DateTime, index=True, nullable=False)
duration = db.Column(db.Interval, nullable=False)
pauses = db.Column(db.Interval, nullable=True)
moving = db.Column(db.Interval, nullable=True)
@ -147,7 +149,7 @@ class Workout(BaseModel):
ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h
bounds = db.Column(postgresql.ARRAY(db.Float), nullable=True)
map = db.Column(db.String(255), nullable=True)
map_id = db.Column(db.String(50), nullable=True)
map_id = db.Column(db.String(50), index=True, nullable=True)
weather_start = db.Column(JSON, nullable=True)
weather_end = db.Column(JSON, nullable=True)
notes = db.Column(db.String(500), nullable=True)