fix: workouts sql improvements

This commit is contained in:
2026-08-29 16:16:44 +02:00
parent c466eb59bc
commit c468dac5e1
@@ -17,7 +17,7 @@ CREATE TABLE exercises (
CHECK (metric IN ('reps', 'seconds')), CHECK (metric IN ('reps', 'seconds')),
load TEXT NOT NULL DEFAULT 'bodyweight' load TEXT NOT NULL DEFAULT 'bodyweight'
CHECK (load IN ('bodyweight', 'absolute')), CHECK (load IN ('bodyweight', 'absolute')),
tags TEXT[] NOT NULL DEFAULT '{}', -- push/pull/legs/core/skill/shoulders/... tags TEXT[] NOT NULL DEFAULT '{}',
notes TEXT, notes TEXT,
progresses_from_id UUID REFERENCES exercises(id) ON DELETE SET NULL, progresses_from_id UUID REFERENCES exercises(id) ON DELETE SET NULL,
hidden BOOLEAN NOT NULL DEFAULT FALSE, hidden BOOLEAN NOT NULL DEFAULT FALSE,
@@ -77,13 +77,13 @@ CREATE TABLE workouts (
template_id UUID REFERENCES templates(id) ON DELETE SET NULL, template_id UUID REFERENCES templates(id) ON DELETE SET NULL,
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
ended_at TIMESTAMPTZ, ended_at TIMESTAMPTZ,
rpe SMALLINT CHECK (rpe BETWEEN 1 AND 10), rpe NUMERIC(3,1) CHECK (rpe BETWEEN 1.0 AND 10.0),
notes TEXT, notes TEXT,
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMPTZ deleted_at TIMESTAMPTZ
); );
CREATE INDEX workouts_time_idx ON workouts (started_at DESC); CREATE INDEX workouts_time_idx ON workouts (user_id, started_at DESC);
CREATE TABLE workout_sets ( CREATE TABLE workout_sets (
@@ -96,7 +96,7 @@ CREATE TABLE workout_sets (
weight NUMERIC(5,2), weight NUMERIC(5,2),
unit TEXT NOT NULL DEFAULT 'kg' unit TEXT NOT NULL DEFAULT 'kg'
CHECK (unit in ('kg', 'lbs')), CHECK (unit in ('kg', 'lbs')),
rpe SMALLINT CHECK (rpe BETWEEN 1 AND 10), rpe NUMERIC(3,1) CHECK (rpe BETWEEN 1.0 AND 10.0),
type TEXT NOT NULL DEFAULT 'working' type TEXT NOT NULL DEFAULT 'working'
CHECK (type IN ('warm-up', 'working', 'drop')), CHECK (type IN ('warm-up', 'working', 'drop')),
note TEXT, note TEXT,