Initial commit
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1
backend/migrations/001_create_exercises.down.sql
Executable file
1
backend/migrations/001_create_exercises.down.sql
Executable file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS exercises;
|
||||
16
backend/migrations/001_create_exercises.up.sql
Executable file
16
backend/migrations/001_create_exercises.up.sql
Executable file
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE exercises (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL CHECK(length(name) >= 1 AND length(name) <= 100),
|
||||
description TEXT DEFAULT '',
|
||||
muscle_group TEXT NOT NULL CHECK(muscle_group IN (
|
||||
'brust', 'ruecken', 'schultern', 'bizeps', 'trizeps',
|
||||
'beine', 'bauch', 'ganzkoerper', 'sonstiges'
|
||||
)),
|
||||
weight_step_kg REAL NOT NULL DEFAULT 2.5 CHECK(weight_step_kg > 0),
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE INDEX idx_exercises_muscle_group ON exercises(muscle_group) WHERE deleted_at IS NULL;
|
||||
CREATE INDEX idx_exercises_deleted_at ON exercises(deleted_at);
|
||||
2
backend/migrations/002_create_training_sets.down.sql
Executable file
2
backend/migrations/002_create_training_sets.down.sql
Executable file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS set_exercises;
|
||||
DROP TABLE IF EXISTS training_sets;
|
||||
16
backend/migrations/002_create_training_sets.up.sql
Executable file
16
backend/migrations/002_create_training_sets.up.sql
Executable file
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE training_sets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL CHECK(length(name) >= 1 AND length(name) <= 100),
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE set_exercises (
|
||||
set_id INTEGER NOT NULL REFERENCES training_sets(id) ON DELETE CASCADE,
|
||||
exercise_id INTEGER NOT NULL REFERENCES exercises(id),
|
||||
position INTEGER NOT NULL CHECK(position >= 0),
|
||||
PRIMARY KEY (set_id, exercise_id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_set_exercises_set_id ON set_exercises(set_id);
|
||||
2
backend/migrations/003_create_sessions.down.sql
Executable file
2
backend/migrations/003_create_sessions.down.sql
Executable file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS session_logs;
|
||||
DROP TABLE IF EXISTS sessions;
|
||||
25
backend/migrations/003_create_sessions.up.sql
Executable file
25
backend/migrations/003_create_sessions.up.sql
Executable file
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
set_id INTEGER NOT NULL REFERENCES training_sets(id),
|
||||
started_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ended_at DATETIME,
|
||||
note TEXT DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE TABLE session_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id INTEGER NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
||||
exercise_id INTEGER NOT NULL REFERENCES exercises(id),
|
||||
exercise_name TEXT NOT NULL,
|
||||
set_number INTEGER NOT NULL CHECK(set_number >= 1),
|
||||
weight_kg REAL NOT NULL CHECK(weight_kg >= 0 AND weight_kg <= 999),
|
||||
reps INTEGER NOT NULL CHECK(reps >= 0 AND reps <= 999),
|
||||
note TEXT DEFAULT '',
|
||||
logged_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(session_id, exercise_id, set_number)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_sessions_set_id ON sessions(set_id);
|
||||
CREATE INDEX idx_sessions_started_at ON sessions(started_at);
|
||||
CREATE INDEX idx_session_logs_session_id ON session_logs(session_id);
|
||||
CREATE INDEX idx_session_logs_exercise_id ON session_logs(exercise_id);
|
||||
8
backend/migrations/embed.go
Executable file
8
backend/migrations/embed.go
Executable file
@@ -0,0 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS enthält die eingebetteten SQL-Migrations-Dateien.
|
||||
//
|
||||
//go:embed *.sql
|
||||
var FS embed.FS
|
||||
Reference in New Issue
Block a user