Files
Learn_System/backend/scripts
Maxim Dolgolyov 31a51956b6 feat: exam9 — назначение варианта как ДЗ + импорт нечётных в банк
Импорт 40 нечётных вариантов (v01, v03, ..., v79) в банк вопросов:
- 400 questions с allow_html=1, source_type='экзамен 9', year=2025
- 540 options (single-choice) + correct_text (short_answer)
- 40 tests (по 1 на вариант), title="Экзамен 9 — Вариант N"
- exam9_variant_tests маппинг для назначения

Назначение варианта как ДЗ на /exam9 (для учителей/админов):
- Кнопка «Назначить как ДЗ» под заголовком варианта (только если test_id есть)
- Модалка выбора классов + опциональный deadline
- POST /api/assignments/bulk с test_id из exam9_variant_tests

Поддержка HTML/SVG в вопросах банка через флаг questions.allow_html:
- Миграция 003: ALTER TABLE questions ADD COLUMN allow_html
- sessionController: SELECT возвращают allow_html и image
- test-run.html: рендер q.text и opt.text как HTML при allow_html=1
- test-result.html: то же для explanation и opt.text
- KaTeX: добавлены $...$ и $$...$$ delimiters в обеих страницах

Бонус-фикс: bulkSchema требовал class_id (single), контроллер ждёт
class_ids (array). Существующий вызов из classes.html был сломан;
исправлено вместе.

Команда: node backend/scripts/import-exam9.js  (--all для всех 80)
2026-05-16 13:13:06 +03:00
..

backend/scripts

Operational scripts for LearnSpace backend.

Cron setup (production)

# Daily backup at 4am
0 4 * * *  /path/to/repo/backend/scripts/backup.sh

# Weekly verification at 6am Sunday (cron mails on non-zero exit)
0 6 * * 0  /path/to/repo/backend/scripts/verify-backup.sh

Scripts

backup.sh

Creates a safe SQLite snapshot via VACUUM INTO. Keeps last 7 backups (configurable via KEEP=14).

./backup.sh                        # default: ../data/learnspace.db → ../../backups/
./backup.sh /path/to/db /path/to/backups
KEEP=14 ./backup.sh

verify-backup.sh

Restores the latest backup to /tmp, runs PRAGMA integrity_check, compares row counts vs production.

Exit codes:

  • 0 — all checks passed
  • 2 — no backup files found
  • 3 — latest backup older than 48h (backup job may have stopped)
  • 4integrity_check failed (backup is corrupt)
  • 5 — user count diverged >5% from production
./verify-backup.sh
BACKUP_DIR=/custom/backups PROD_DB=/custom/db.sqlite ./verify-backup.sh

check-route-auth.js

Scans src/routes/*.js for :id-bearing routes without an auth-guard middleware. Fails if new unprotected routes exceed the current baseline.

npm run lint:routes

import-content.js (coming in Task 8)

Imports question collections from YAML manifests into the database.

npm run import:content -- ../content/phys/ct-2024.yaml

Deploy order (first time / fresh server)

npm install
npm run migrate
npm run seed:permissions
npm start