Add boto3 dependency and update exercise/machine assets
- Added boto3 as a dependency in pyproject.toml and uv.lock. - Introduced multiple new exercise images in various formats (jpg, webp, avif, png). - Added new machine images to enhance the workout assets library.
This commit is contained in:
@@ -81,6 +81,13 @@ def upgrade_existing_schema(connection: Connection) -> None:
|
||||
check_sql="status IN ('active', 'finished', 'discarded')",
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE logic_workout_items "
|
||||
"ADD COLUMN IF NOT EXISTS activity_source_id UUID "
|
||||
"REFERENCES logic_activity_sources(id)"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ADD COLUMN IF NOT EXISTS source_kind VARCHAR(20)")
|
||||
)
|
||||
@@ -90,6 +97,24 @@ def upgrade_existing_schema(connection: Connection) -> None:
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ADD COLUMN IF NOT EXISTS image_s3_url_snapshot TEXT")
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE logic_workout_items "
|
||||
"ADD COLUMN IF NOT EXISTS measurement_type_snapshot VARCHAR(32) DEFAULT 'weight_reps'"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE logic_workout_items "
|
||||
"ADD COLUMN IF NOT EXISTS category_snapshot VARCHAR(32) DEFAULT 'other'"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"ALTER TABLE logic_workout_items "
|
||||
"ADD COLUMN IF NOT EXISTS equipment_snapshot VARCHAR(32) DEFAULT 'other'"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"""
|
||||
@@ -140,11 +165,63 @@ def upgrade_existing_schema(connection: Connection) -> None:
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ALTER COLUMN title_snapshot SET NOT NULL")
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"UPDATE logic_workout_items "
|
||||
"SET measurement_type_snapshot = 'weight_reps' "
|
||||
"WHERE measurement_type_snapshot IS NULL"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"UPDATE logic_workout_items "
|
||||
"SET category_snapshot = 'other' "
|
||||
"WHERE category_snapshot IS NULL"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text(
|
||||
"UPDATE logic_workout_items "
|
||||
"SET equipment_snapshot = 'other' "
|
||||
"WHERE equipment_snapshot IS NULL"
|
||||
)
|
||||
)
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ALTER COLUMN measurement_type_snapshot SET NOT NULL")
|
||||
)
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ALTER COLUMN category_snapshot SET NOT NULL")
|
||||
)
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_items ALTER COLUMN equipment_snapshot SET NOT NULL")
|
||||
)
|
||||
drop_constraint_if_exists(
|
||||
connection,
|
||||
constraint_name="ck_workout_item_exactly_one_entity",
|
||||
table_name="logic_workout_items",
|
||||
)
|
||||
add_check_constraint_if_missing(
|
||||
connection,
|
||||
constraint_name="ck_workout_item_exactly_one_entity",
|
||||
table_name="logic_workout_items",
|
||||
check_sql="(CASE WHEN activity_source_id IS NOT NULL THEN 1 ELSE 0 END + "
|
||||
"CASE WHEN exercise_id IS NOT NULL THEN 1 ELSE 0 END + "
|
||||
"CASE WHEN equipment_id IS NOT NULL THEN 1 ELSE 0 END) = 1",
|
||||
)
|
||||
drop_constraint_if_exists(
|
||||
connection,
|
||||
constraint_name="ck_workout_item_source_kind",
|
||||
table_name="logic_workout_items",
|
||||
)
|
||||
add_check_constraint_if_missing(
|
||||
connection,
|
||||
constraint_name="ck_workout_item_source_kind",
|
||||
table_name="logic_workout_items",
|
||||
check_sql="source_kind IN ('exercise', 'equipment')",
|
||||
check_sql="source_kind IN ('exercise', 'machine', 'equipment')",
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
text("ALTER TABLE logic_workout_sets ADD COLUMN IF NOT EXISTS distance_km NUMERIC(8, 3)")
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
@@ -194,6 +271,21 @@ def add_check_constraint_if_missing(
|
||||
)
|
||||
|
||||
|
||||
def drop_constraint_if_exists(
|
||||
connection: Connection,
|
||||
*,
|
||||
constraint_name: str,
|
||||
table_name: str,
|
||||
) -> None:
|
||||
exists = connection.execute(
|
||||
text("SELECT 1 FROM pg_constraint WHERE conname = :constraint_name"),
|
||||
{"constraint_name": constraint_name},
|
||||
).scalar()
|
||||
if not exists:
|
||||
return
|
||||
connection.execute(text(f"ALTER TABLE {table_name} DROP CONSTRAINT {constraint_name}"))
|
||||
|
||||
|
||||
def get_db() -> Generator[Session]:
|
||||
db: Any = SessionLocal()
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user