shinkan-jinkendo/backend/migrations/034_exercise_progression_edge_variants.sql
Lars ae6c089366
Some checks failed
Deploy Development / deploy (push) Successful in 39s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / playwright-tests (push) Failing after 41s
chore: update versioning and enhance exercise progression graph functionality
- Incremented application version to 0.8.7 and updated database schema version to 20260430034.
- Enhanced exercise progression graph functionality by adding support for exercise variants as node endpoints and bulk creation of progression sequences.
- Updated changelog to reflect new features and improvements related to progression graphs and API enhancements.
2026-05-03 18:07:52 +02:00

46 lines
1.7 KiB
SQL

-- Migration 034: Progressionskanten optional mit Übungsvarianten (Knoten = Übung oder konkrete Variante).
-- UNIQUE und CHECK angepasst; Kanten innerhalb derselben Übung nur zwischen verschiedenen Varianten.
ALTER TABLE exercise_progression_edges
ADD COLUMN IF NOT EXISTS from_exercise_variant_id INT REFERENCES exercise_variants(id) ON DELETE CASCADE,
ADD COLUMN IF NOT EXISTS to_exercise_variant_id INT REFERENCES exercise_variants(id) ON DELETE CASCADE;
CREATE INDEX IF NOT EXISTS idx_progression_edges_from_variant ON exercise_progression_edges(from_exercise_variant_id)
WHERE from_exercise_variant_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_progression_edges_to_variant ON exercise_progression_edges(to_exercise_variant_id)
WHERE to_exercise_variant_id IS NOT NULL;
DO $$
BEGIN
ALTER TABLE exercise_progression_edges
DROP CONSTRAINT exercise_progression_edges_graph_id_from_exercise_id_to_exercise_id_edge_type_key;
EXCEPTION
WHEN undefined_object THEN NULL;
END $$;
DO $$
BEGIN
ALTER TABLE exercise_progression_edges DROP CONSTRAINT exercise_progression_edges_check;
EXCEPTION
WHEN undefined_object THEN NULL;
END $$;
ALTER TABLE exercise_progression_edges ADD CONSTRAINT exercise_progression_edges_endpoints_distinct CHECK (
(from_exercise_id <> to_exercise_id)
OR (
from_exercise_variant_id IS NOT NULL
AND to_exercise_variant_id IS NOT NULL
AND from_exercise_variant_id <> to_exercise_variant_id
)
);
CREATE UNIQUE INDEX IF NOT EXISTS exercise_progression_edges_unique_endpoints
ON exercise_progression_edges (
graph_id,
from_exercise_id,
COALESCE(from_exercise_variant_id, 0),
to_exercise_id,
COALESCE(to_exercise_variant_id, 0),
edge_type
);