Spaces:
Sleeping

File size: 2,482 Bytes
5b158bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- ============================================================================
-- Vela Academy — Schema Supabase (jalankan di SQL Editor Supabase)
--
-- Data akademik TIDAK disimpan lokal agar aman saat redeploy HF Spaces.
-- Set env: SUPABASE_URL & SUPABASE_KEY (service_role, server-side only).
-- ============================================================================

create table if not exists public.courses (
  id uuid primary key default gen_random_uuid(),
  kode text default '',
  nama text not null,
  sks int default 0,
  dosen text default '',
  ruangan text default '',
  warna text default '#7C3AED',
  keywords text default '',
  created_at timestamptz not null default now()
);

create table if not exists public.notes (
  id uuid primary key default gen_random_uuid(),
  course_id uuid references public.courses(id) on delete set null,
  session_date date,
  title text default '',
  content_md text default '',
  updated_at timestamptz not null default now()
);

create table if not exists public.attendance (
  id uuid primary key default gen_random_uuid(),
  course_id uuid references public.courses(id) on delete cascade,
  session_date date not null,
  status text not null check (status in ('hadir','alpa','izin')),
  note text default '',
  created_at timestamptz not null default now(),
  unique (course_id, session_date)
);

create table if not exists public.grade_components (
  id uuid primary key default gen_random_uuid(),
  course_id uuid references public.courses(id) on delete cascade,
  name text not null,
  weight numeric not null check (weight > 0),
  score numeric check (score is null or (score >= 0 and score <= 100))
);

create table if not exists public.notification_log (
  dedup_key text primary key,
  channel text not null,
  sent_at timestamptz not null default now()
);

-- Index ringan untuk pencarian catatan
create index if not exists notes_course_idx on public.notes(course_id);
create index if not exists attendance_course_idx on public.attendance(course_id);
create index if not exists grade_course_idx on public.grade_components(course_id);

-- RLS: akses hanya dari server via service_role key (frontend tidak memegang kunci).
alter table public.courses enable row level security;
alter table public.notes enable row level security;
alter table public.attendance enable row level security;
alter table public.grade_components enable row level security;
alter table public.notification_log enable row level security;