API - remove 'img' column from sport since it's not used anymore

This commit is contained in:
Sam
2021-11-12 12:26:26 +01:00
parent a4ad40fdc2
commit 8237345edd
6 changed files with 33 additions and 38 deletions

View File

@ -17,6 +17,10 @@ depends_on = None
def upgrade():
op.drop_constraint('sports_img_key', 'sports', type_='unique')
op.drop_column('sports', 'img')
op.create_table(
'users_sports_preferences',
sa.Column('user_id', sa.Integer(), nullable=False),
@ -41,6 +45,32 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('users_sports_preferences')
# ### end Alembic commands ###
op.add_column(
'sports',
sa.Column(
'img', sa.VARCHAR(length=255), autoincrement=False, nullable=True
),
)
op.create_unique_constraint('sports_img_key', 'sports', ['img'])
op.execute(
"""
UPDATE sports AS s
SET img = si.img
FROM (VALUES
('Cycling (Sport)','/img/sports/cycling-sport.png'),
('Cycling (Transport)','/img/sports/cycling-transport.png'),
('Hiking','/img/sports/hiking.png'),
('Mountain Biking','/img/sports/mountain-biking.png'),
('Running','/img/sports/running.png'),
('Walking','/img/sports/walking.png'),
('Mountain Biking (Electric)','/img/sports/electric-mountain-biking.png'),
('Trail','/img/sports/trail.png'),
('Skiing (Alpine)','/img/sports/alpine-skiing.png'),
('Skiing (Cross Country)','/img/sports/cross-country-skiing.png'),
('Rowing','/img/sports/rowing.png')
) AS si(label, img)
WHERE si.label = s.label;
"""
)