Spaces:
Sleeping

vela-app / docs /reference /journal_schema.sql
fahmialfayadh
feat(add docs): add /docs url yang menampilkan docs projek ini
33cda0a
Raw History Blame Contribute Delete
1.65 kB
-- ============================================================
-- Journal Feature Schema — run once in Supabase SQL Editor
-- Table: public.journals (free-form notes, markdown content)
-- Access: service_key via Supabase REST (RLS enforced for others)
-- ============================================================
create extension if not exists "pgcrypto";
create table if not exists public.journals (
id uuid primary key default gen_random_uuid(),
title text not null,
content_md text not null default '',
tags text[] not null default '{}',
entry_date date,
source text not null default 'dashboard', -- dashboard | whatsapp | agent
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists journals_entry_date_idx on public.journals (entry_date desc);
create index if not exists journals_created_at_idx on public.journals (created_at desc);
create index if not exists journals_tags_idx on public.journals using gin (tags);
-- keep updated_at fresh on every update
create or replace function public.set_updated_at()
returns trigger as $$
begin
new.updated_at = now();
return new;
end;
$$ language plpgsql;
drop trigger if exists journals_set_updated_at on public.journals;
create trigger journals_set_updated_at
before update on public.journals
for each row execute function public.set_updated_at();
-- RLS: dashboard/agent/gateway use the service_role key which bypasses RLS.
-- Enable RLS so the anon key cannot read/write anything.
alter table public.journals enable row level security;