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);
