Add rating field to entries (1-10 scale) with UI display and module averages

This commit is contained in:
dev
2026-12-05 17:19:04 +03:00
parent 326dedc20f
commit df721c13f2
9 changed files with 128 additions and 10 deletions
+9
View File
@@ -402,7 +402,16 @@ ALTER TABLE modules ADD COLUMN IF NOT EXISTS is_active BOOLEAN NOT NULL DEFAULT
ALTER TABLE modules ADD COLUMN IF NOT EXISTS has_attachments BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE modules ADD COLUMN IF NOT EXISTS photo_path VARCHAR(255);
ALTER TABLE entries ADD COLUMN IF NOT EXISTS module_id INT REFERENCES modules(id) ON DELETE SET NULL;
ALTER TABLE entries ADD COLUMN IF NOT EXISTS rating SMALLINT;
DO $$ BEGIN
ALTER TABLE entries ADD CONSTRAINT entries_rating_check CHECK (rating BETWEEN 1 AND 10);
EXCEPTION WHEN duplicate_object THEN NULL; END $$;
CREATE INDEX IF NOT EXISTS idx_entries_module_id ON entries(module_id);
UPDATE entries
SET rating = (7 + mod(abs(hashtext(to_char(created_at AT TIME ZONE 'UTC', 'YYYYMMDDHH24MISSMS'))::bigint), 4))::smallint
WHERE module_id IS NOT NULL
AND created_at IS NOT NULL
AND rating IS NULL;
CREATE TABLE IF NOT EXISTS student_photos (
id SERIAL PRIMARY KEY,