feat: add reviews, notifications, notes and account hardening
This commit is contained in:
29
server/migrations/017_account_views_notes.sql
Normal file
29
server/migrations/017_account_views_notes.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- 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);
|
||||
12
server/migrations/018_course_reviews.sql
Normal file
12
server/migrations/018_course_reviews.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- One review per learner per course.
|
||||
create table if not exists course_reviews (
|
||||
user_id uuid not null references users(id) on delete cascade,
|
||||
course_id uuid not null references courses(id) on delete cascade,
|
||||
rating smallint not null check (rating between 1 and 5),
|
||||
comment text not null default '',
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now(),
|
||||
primary key (user_id, course_id)
|
||||
);
|
||||
|
||||
create index if not exists course_reviews_course_index on course_reviews (course_id, updated_at desc);
|
||||
14
server/migrations/019_notifications.sql
Normal file
14
server/migrations/019_notifications.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- In-app notifications for questions and replies.
|
||||
create table if not exists notifications (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
user_id uuid not null references users(id) on delete cascade,
|
||||
kind text not null,
|
||||
title text not null,
|
||||
body text not null default '',
|
||||
href text not null,
|
||||
read_at timestamptz,
|
||||
created_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists notifications_user_index on notifications (user_id, created_at desc);
|
||||
create index if not exists notifications_unread_index on notifications (user_id) where read_at is null;
|
||||
Reference in New Issue
Block a user