Files
compor-academy/server/migrations/017_account_views_notes.sql
Cauê Faleiros fff63f5efa
All checks were successful
CI / Validate frontend and API (push) Successful in 59s
CI / Build and publish Docker images (push) Successful in 23s
feat: add reviews, notifications, notes and account hardening
2026-11-05 17:27:36 -03:00

30 lines
1.3 KiB
SQL

-- Session version so password changes can invalidate existing JWTs.
alter table users
add column if not exists token_version integer not null default 0;
-- One view per learner per course per day, used to keep the view counter honest.
create table if not exists course_views (
course_id uuid not null references courses(id) on delete cascade,
user_id uuid not null references users(id) on delete cascade,
viewed_on date not null default current_date,
created_at timestamptz not null default now(),
primary key (course_id, user_id, viewed_on)
);
create index if not exists course_views_course_index on course_views (course_id, viewed_on);
-- Private lesson notes.
create table if not exists lesson_notes (
user_id uuid not null references users(id) on delete cascade,
lesson_id uuid not null references lessons(id) on delete cascade,
body text not null default '',
updated_at timestamptz not null default now(),
primary key (user_id, lesson_id)
);
create index if not exists lesson_notes_user_index on lesson_notes (user_id, updated_at desc);
-- Useful indexes for the community feed and user moderation screens.
create index if not exists comments_created_index on comments (created_at desc);
create index if not exists comments_author_index on comments (author_id);