Appearance
scores
Gamification scoring events. Each row is an event that awarded points to a user. Append-only.
- ETL strategy:
append - PK:
id
Columns
| Column | Type | Description |
|---|---|---|
id | BIGINT | PK. |
id_tenant | BIGINT | FK → tenants.id. |
id_user | BIGINT | FK → users.id. |
id_product | BIGINT | FK → products.id. Resolves to products.id_origin when replicated. |
id_item | BIGINT | Lesson that produced the score, for lesson_completed, question_asked and comment_posted; NULL for the other types. |
type | TEXT | Event category. Enum — see below. |
key | TEXT | What the event is about: the lesson (lesson_completed, question_asked, comment_posted), the product (course_*, certificate_issued) or the exam (exam_passed); NULL for manual. |
score | INTEGER | Points awarded. |
created_at | TIMESTAMPTZ |
Enum · type
| Value | Meaning |
|---|---|
lesson_completed | Lesson marked as completed. |
course_started | Course started by the learner. |
course_progress_50 | Reached 50% of the course. |
course_progress_75 | Reached 75% of the course. |
course_progress_90 | Reached 90% of the course. |
course_completed | Course completed (100%). |
certificate_issued | Certificate issued. |
question_asked | Question / inquiry posted. |
comment_posted | Comment posted. |
exam_passed | Exam passed. |
manual | Points awarded manually by an admin. |
The same names appear in
tenants.meta.gamification.events— matchscores.typeagainst that map to know how manypointseach event awards.
Legacy rows. Rows loaded before the source reorganization (Cademí V6-E38, 2026-10) carried the legacy Portuguese text in
type(aula_concluida,curso_*,prova_aprovada,certificado_emitido,comentario,duvida),NULLintype, or a message id inid_item. On 2026-10-21 every row still present in the source was rewritten in the shape above (seed upsert byid,created_atunchanged). Rows whose event was later deleted in the source were kept as loaded: they are the only ones that still show a legacytype, aNULLtype, or anid_itemonexam_passed. Filter them out withtype IN (<enum above>)when only current events matter.
Patterns
sql
-- Top 10 learners this month
SELECT id_user, sum(score) AS month_points
FROM lms.scores
WHERE created_at >= date_trunc('month', now())
GROUP BY id_user
ORDER BY 2 DESC
LIMIT 10;
-- Event distribution
SELECT type, count(*), sum(score)
FROM lms.scores
WHERE created_at >= now() - interval '7 days'
GROUP BY type
ORDER BY 2 DESC;