File size: 1,648 Bytes
e61ae14 | 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 | -- ============================================================
-- 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;
|