From e8405e31a8be0dccefac65ee88363bbb9568f179 Mon Sep 17 00:00:00 2001 From: Robin Dittmar Date: Thu, 27 Aug 2026 20:17:06 +0200 Subject: [PATCH] feat: db migration for workouts. still in progress --- .../000003_create_workouts.down.sql | 3 ++ .../migrations/000003_create_workouts.up.sql | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 internal/database/migrations/000003_create_workouts.down.sql create mode 100644 internal/database/migrations/000003_create_workouts.up.sql diff --git a/internal/database/migrations/000003_create_workouts.down.sql b/internal/database/migrations/000003_create_workouts.down.sql new file mode 100644 index 0000000..3624dc4 --- /dev/null +++ b/internal/database/migrations/000003_create_workouts.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS template_exercises; +DROP TABLE IF EXISTS templates; +DROP TABLE IF EXISTS exercises; \ No newline at end of file diff --git a/internal/database/migrations/000003_create_workouts.up.sql b/internal/database/migrations/000003_create_workouts.up.sql new file mode 100644 index 0000000..632c838 --- /dev/null +++ b/internal/database/migrations/000003_create_workouts.up.sql @@ -0,0 +1,45 @@ +CREATE TABLE exercises ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + equipment TEXT[] NOT NULL DEFAULT '{}' + CHECK ( + equipment <@ ARRAY [ + 'floor', + 'rings', + 'pull_up_bar', + 'dip_bars', + 'parallettes', + ]::TEXT[]), + metric TEXT NOT NULL DEFAULT 'reps' + CHECK metric IN ('reps', 'seconds'), + load TEXT NOT NULL DEFAULT 'bodyweight' + CHECK load IN ('bodyweight', 'absolute'), + tags TEXT[] NOT NULL DEFAULT '{}', -- push/pull/legs/core/skill/shoulders/... + notes TEXT, + hidden NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE UNIQUE INDEX exercises_name_key ON exercises (lower(name)); +CREATE INDEX exercises_equipment_idx ON exercises USING gin (equipment); +CREATE INDEX exercises_tags_idx ON exercises USING gin (tags); + + +CREATE TABLE templates ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name TEXT NOT NULL, + notes TEXT, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE TABLE template_exercises ( + template_id UUID NOT NULL REFERENCES templates(id) ON DELETE CASCADE, + exercise_id UUID NOT NULL REFERENCES exercises(id) ON DELETE CASCADE, + position SMALLINT NOT NULL, + target TEXT, + + PRIMARY KEY (template_id, exercise_id) +); + +-- todo: workouts, sets