Files
tutortool/backend/migrations/003_normalize_room_layout_units.sql
T
mpuchstein 4939838a7f
CI / test (push) Failing after 4m9s
CI / test (pull_request) Failing after 3m26s
fix: address PR #2 review findings across backend and frontend
- Makefile: add SHELL := /bin/bash so test-env.sh pipefail works in CI
- RoomCanvas: fix onElementClick firing on drag start (now fires on mouseup
  for click-in-place only); fix Props type to accept null; guard grid pattern
  against snapStep=0 (invalid SVG); remove unsafe null cast
- live/[slotId]: fix studentNamesBySeat $derived wrapping a function instead
  of a value — reactivity was broken, map never updated
- s/[code]: block clicks on occupied seats before hitting the backend;
  pass occupiedSeatIds to confirmed-view RoomCanvas; clear errorMsg on retry
- rooms/+page: replace alert() in deleteRoom with inline errorMsg state
- rooms/[roomId]: replace deprecated .substr with .slice
- courses.rs: assign_tutor uses fetch_optional → 404 on unknown tutor_id
  instead of propagating RowNotFound as 500
- rooms.rs: delete_room returns 404 when room does not exist; replace
  fract() != 0.0 float check with epsilon-based validation
- auth_routes.rs: refresh endpoint re-checks is_active so deactivated tutors
  cannot obtain new access tokens; fix test INSERT to include is_active
- tutors.rs: wrap delete_tutor reference checks and DELETE in a transaction
- attendance.rs: replace #[allow(clippy::type_complexity)] with type alias
- migrations/003: document > 50 heuristic precondition

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 01:55:35 +02:00

31 lines
1.6 KiB
SQL

-- Normalize room layout units: divide pixel-scale coordinates by 40.
-- Applied per element with CASE WHEN so the transform is idempotent:
-- coordinates already in grid units (≤50) are left untouched.
-- PRECONDITION: assumes no pre-existing room has pixel-scale coords ≤50.
-- Any element with pixel x/y/width/height ≤50 will be skipped (treated as
-- already converted). Verify this holds before running on a production DB.
UPDATE rooms
SET layout_json = (
SELECT json_group_array(
json_object(
'id', json_extract(value, '$.id'),
'label', json_extract(value, '$.label'),
'x', CASE WHEN CAST(json_extract(value, '$.x') AS REAL) > 50
THEN ROUND(CAST(json_extract(value, '$.x') AS REAL) / 40.0, 2)
ELSE json_extract(value, '$.x') END,
'y', CASE WHEN CAST(json_extract(value, '$.y') AS REAL) > 50
THEN ROUND(CAST(json_extract(value, '$.y') AS REAL) / 40.0, 2)
ELSE json_extract(value, '$.y') END,
'width', CASE WHEN CAST(json_extract(value, '$.width') AS REAL) > 50
THEN ROUND(CAST(json_extract(value, '$.width') AS REAL) / 40.0, 2)
ELSE json_extract(value, '$.width') END,
'height', CASE WHEN CAST(json_extract(value, '$.height') AS REAL) > 50
THEN ROUND(CAST(json_extract(value, '$.height') AS REAL) / 40.0, 2)
ELSE json_extract(value, '$.height') END,
'type', json_extract(value, '$.type')
)
)
FROM json_each(rooms.layout_json)
)
WHERE json_array_length(layout_json) > 0;